plot-light 0.1.1 → 0.1.2
raw patch · 5 files changed
+60/−24 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Graphics.Rendering.Plot.Light: labelPoint :: (Point a -> l) -> Point a -> LabeledPoint l a
+ Graphics.Rendering.Plot.Light: rect :: (Show a, RealFrac a) => Point a -> a -> a -> a -> Maybe (Colour Double) -> Maybe (Colour Double) -> Svg
- Graphics.Rendering.Plot.Light: toPlot :: (Functor t, Foldable t, Show a, RealFrac a) => FigureData a -> (l -> Text) -> (l -> Text) -> a -> a -> a -> Colour Double -> (t (LabeledPoint l a) -> t (LabeledPoint l a)) -> (t (LabeledPoint l a) -> t (LabeledPoint l a)) -> (t (LabeledPoint l a) -> Svg) -> t (LabeledPoint l a) -> Svg
+ Graphics.Rendering.Plot.Light: toPlot :: (Functor t, Foldable t, Show a, RealFrac a) => FigureData a -> (l -> Text) -> (l -> Text) -> a -> a -> a -> Colour Double -> Maybe (t (LabeledPoint l a)) -> Maybe (t (LabeledPoint l a)) -> (t (LabeledPoint l a) -> Svg) -> t (LabeledPoint l a) -> Svg
Files
- plot-light.cabal +1/−1
- src/Graphics/Rendering/Plot/Light.hs +2/−2
- src/Graphics/Rendering/Plot/Light/Internal.hs +26/−7
- src/Graphics/Rendering/Plot/Light/Internal/Geometry.hs +3/−0
- src/Graphics/Rendering/Plot/Light/PlotTypes/TimeSeries.hs +28/−14
plot-light.cabal view
@@ -1,5 +1,5 @@ name: plot-light-version: 0.1.1+version: 0.1.2 synopsis: A lightweight plotting library, exporting to SVG description: A lightweight plotting library, exporting to SVG homepage: https://github.com/ocramz/plot-light
src/Graphics/Rendering/Plot/Light.hs view
@@ -22,7 +22,7 @@ module Graphics.Rendering.Plot.Light ( -- * Plot elements -- ** Geometrical primitives- rectCentered, circle, line, text, polyline, filledPolyline,+ rect, rectCentered, circle, line, text, polyline, filledPolyline, -- ** Composite plot elements filledBand, candlestick, -- ** Plot utilities@@ -32,7 +32,7 @@ -- ** SVG utilities svgHeader, -- * Types- Frame(..), Point(..), LabeledPoint(..), Axis(..),+ Frame(..), Point(..), LabeledPoint(..), labelPoint, Axis(..), -- * Geometry -- ** Vectors V2(..),
src/Graphics/Rendering/Plot/Light/Internal.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}-module Graphics.Rendering.Plot.Light.Internal (FigureData(..), Frame(..), mkFrame, mkFrameOrigin, frameToFrame, frameFromPoints, width, height, Point(..), mkPoint, LabeledPoint(..), mkLabeledPoint, Axis(..), svgHeader, rectCentered, circle, line, tick, ticks, axis, toPlot, text, polyline, filledPolyline, filledBand, candlestick, strokeLineJoin, LineStroke_(..), StrokeLineJoin_(..), TextAnchor_(..), V2(..), Mat2(..), DiagMat2(..), diagMat2, AdditiveGroup(..), VectorSpace(..), Hermitian(..), LinearMap(..), MultiplicativeSemigroup(..), MatrixGroup(..), Eps(..), norm2, normalize2, v2fromEndpoints, v2fromPoint, origin, (-.), pointRange, movePoint, moveLabeledPointV2, moveLabeledPointV2Frames, toSvgFrame, toSvgFrameLP, e1, e2) where+module Graphics.Rendering.Plot.Light.Internal (FigureData(..), Frame(..), mkFrame, mkFrameOrigin, frameToFrame, frameFromPoints, width, height, Point(..), mkPoint, LabeledPoint(..), mkLabeledPoint, labelPoint, Axis(..), svgHeader, rect, rectCentered, circle, line, tick, ticks, axis, toPlot, text, polyline, filledPolyline, filledBand, candlestick, strokeLineJoin, LineStroke_(..), StrokeLineJoin_(..), TextAnchor_(..), V2(..), Mat2(..), DiagMat2(..), diagMat2, AdditiveGroup(..), VectorSpace(..), Hermitian(..), LinearMap(..), MultiplicativeSemigroup(..), MatrixGroup(..), Eps(..), norm2, normalize2, v2fromEndpoints, v2fromPoint, origin, (-.), pointRange, movePoint, moveLabeledPointV2, moveLabeledPointV2Frames, toSvgFrame, toSvgFrameLP, e1, e2) where import Data.Monoid ((<>)) import qualified Data.Foldable as F (toList)@@ -58,7 +58,21 @@ ! SA.viewbox (vds [xmin fd, ymin fd, xmax fd, ymax fd]) +-- | A rectangle, defined by its anchor point coordinates and side lengths+--+-- > > putStrLn $ renderSvg $ rect (Point 100 200) 30 60 2 Nothing (Just C.aquamarine)+-- > <rect x="100.0" y="200.0" width="30.0" height="60.0" fill="#7fffd4" stroke="none" stroke-width="2.0" />+rect :: (Show a, RealFrac a) =>+ Point a -- ^ Center coordinates + -> a -- ^ Width+ -> a -- ^ Height+ -> a -- ^ Stroke width+ -> Maybe (C.Colour Double) -- ^ Stroke colour+ -> Maybe (C.Colour Double) -- ^ Fill colour + -> Svg+rect (Point x0 y0) wid hei sw scol fcol = S.rect ! SA.x (vd x0) ! SA.y (vd y0) ! SA.width (vd wid) ! SA.height (vd hei) ! colourFillOpt fcol ! colourStrokeOpt scol ! SA.strokeWidth (vd sw) + -- | A rectangle, defined by its center coordinates and side lengths -- -- > > putStrLn $ renderSvg $ rectCentered (Point 20 30) 15 30 (Just C.blue) (Just C.red)@@ -189,14 +203,14 @@ -> a -- ^ Y label rotation angle -> a -- ^ Stroke width -> C.Colour Double -- ^ Stroke colour- -> (t (LabeledPoint l a) -> t (LabeledPoint l a)) -- ^ X axis labels- -> (t (LabeledPoint l a) -> t (LabeledPoint l a)) -- ^ Y axis labels+ -> Maybe (t (LabeledPoint l a)) -- ^ X axis labels+ -> Maybe (t (LabeledPoint l a)) -- ^ Y axis labels -> (t (LabeledPoint l a) -> Svg) -- ^ Data rendering function -> t (LabeledPoint l a) -- ^ Data -> Svg -toPlot fd flabelx flabely rotx roty sw col1 tickXf tickYf plotf dat = do- axis oSvg X (right - left) sw col1 0.05 Continuous fontsize rotx TAEnd flabelx (V2 (-10) 0) (tickXf dat')- axis oSvg Y (top - bot) sw col1 0.05 Continuous fontsize roty TAEnd flabely (V2 (-10) 0) (tickYf dat')+toPlot fd flabelx flabely rotx roty sw col1 tickxe tickye plotf dat = do+ axis oSvg X (right - left) sw col1 0.05 Continuous fontsize rotx TAEnd flabelx (V2 (-10) 0) tickx+ axis oSvg Y (top - bot) sw col1 0.05 Continuous fontsize roty TAEnd flabely (V2 (-10) 0) ticky plotf dat' where fontsize = figLabelFontSize fd@@ -208,7 +222,12 @@ p2To = Point right bot from = frameFromPoints $ _lp <$> dat to = mkFrame oTo p2To- dat' = toSvgFrameLP from to False <$> dat+ datf = toSvgFrameLP from to False -- data mapping function + dat' = datf <$> dat+ tickDefault ti d = case ti of Just t -> datf <$> t+ Nothing -> d+ tickx = tickDefault tickxe dat'+ ticky = tickDefault tickye dat' oSvg = Point left bot
src/Graphics/Rendering/Plot/Light/Internal/Geometry.hs view
@@ -39,6 +39,9 @@ mkLabeledPoint :: Point a -> l -> LabeledPoint l a mkLabeledPoint = LabeledPoint +labelPoint :: (Point a -> l) -> Point a -> LabeledPoint l a+labelPoint lf p = LabeledPoint p (lf p)+ moveLabeledPoint :: (Point a -> Point b) -> LabeledPoint l a -> LabeledPoint l b moveLabeledPoint f (LabeledPoint p l) = LabeledPoint (f p) l
src/Graphics/Rendering/Plot/Light/PlotTypes/TimeSeries.hs view
@@ -43,27 +43,26 @@ -tsAxis' fval ftickx fticky fd sw col rot ps =- toPlot fd (T.pack . ftickx) (T.pack . fticky) rot 0 sw col - -+tsAxisTest fd sw colAxis colData rot ps =+ toPlot fd T.pack T.pack rot 0 sw colAxis (Just ptx) (Just pty) fplot ps where+ fplot lps = polyline (_lp <$> lps) sw Continuous Round colData+ --- nth xss n = reverse $ go xss n [] where--- go (_:xs) i l | i>0 = go xs (i-1) l--- go (x:xs) i l | i==0 = go xs n (x : l)--- go [] _ l = l---- tsp1 :: Maybe (TsPoint (FxRow Double))--- tsp1 = Tsp <$> mkTick 2017 16 3 20 30 01 <*> Just (FxRow pi 20 10 5.4)+fdat = FigureData 400 300 0.1 0.9 0.1 0.85 10 dat1 :: [ LabeledPoint String Double ]-dat1 = [LabeledPoint (Point 0 1) "blah",- LabeledPoint (Point 2 0) "asdf",- LabeledPoint (Point 3 1) "yo"]+dat1 = [LabeledPoint (Point 0 0) "blah",+ LabeledPoint (Point 0 1) "asdf",+ LabeledPoint (Point 1 1) "yo",+ LabeledPoint (Point 1 2) "blap",+ LabeledPoint (Point 2 2) "chow"] +ptx = labelPoint (show . _px) <$> pointRange 2 (Point 0 0) (Point 2 0)+pty = labelPoint (show . _py) <$> pointRange 2 (Point 0 0) (Point 0 2)+ to, from :: Frame Double from = frameFromPoints $ _lp <$> dat1 to = mkFrameOrigin 400 300@@ -112,3 +111,18 @@ return $ Tick d tim +++++++++-- nth xss n = reverse $ go xss n [] where+-- go (_:xs) i l | i>0 = go xs (i-1) l+-- go (x:xs) i l | i==0 = go xs n (x : l)+-- go [] _ l = l++-- tsp1 :: Maybe (TsPoint (FxRow Double))+-- tsp1 = Tsp <$> mkTick 2017 16 3 20 30 01 <*> Just (FxRow pi 20 10 5.4)