Skip to content

Instantly share code, notes, and snippets.

@christiantakle
Last active March 2, 2017 21:51
Show Gist options
  • Save christiantakle/628f222456a6adf5d3f096deb00f39e1 to your computer and use it in GitHub Desktop.
Save christiantakle/628f222456a6adf5d3f096deb00f39e1 to your computer and use it in GitHub Desktop.
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