Skip to content

Instantly share code, notes, and snippets.

@christiantakle christiantakle/blah.hs
Last active Mar 2, 2017

Embed
What would you like to do?
Haskell refactor, scale functions are made from minMax + period outside
-- old ----------------------------------------------------------------
mkGraphMeta (start,end) (aggregated,timeSeriesWithColor) =
(aggregated,) $ fromMaybe (Nothing,[]) $ case second unTimeSeries <$> (timeSeriesWithColor :: [(String,TimeSeries)]) of
[] -> Nothing
xss -> do
minMax@(vMin,vMax) <- getMinMax $ snd <$> (xss :: [(String,[(UTCTime,Double)])])
let
tw = end `diffUTCTime` start
fx = fromIntegral pWidth / tw
ph = fromIntegral pHeight
fy = case vMax - vMin of
0 -> 1
h -> ph / h
scalify (t,v) =
let
tx = t `diffUTCTime` start
x :: Int = floor $ tx * fx
y = ph - (v - vMin) * fy
in (fromIntegral x,y)
xss' = second (fmap scalify) <$> xss
return (Just minMax, force xss')
-- new ----------------------------------------------------------------
mkGraphMeta xs (xScale,yScale) = second (fmap (xScale *** yScale) . coerce) <$> xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.