Last active
March 2, 2017 21:51
-
-
Save christiantakle/628f222456a6adf5d3f096deb00f39e1 to your computer and use it in GitHub Desktop.
Haskell refactor, scale functions are made from minMax + period outside
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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