plot-light 0.3.2.1 → 0.3.3
raw patch · 5 files changed
+30/−10 lines, 5 files
Files
- CHANGELOG.md +4/−0
- plot-light.cabal +3/−2
- src/Data/Parsers.hs +3/−0
- src/Graphics/Rendering/Plot/Light/Internal/Geometry.hs +17/−7
- src/Graphics/Rendering/Plot/Light/Internal/Utils.hs +3/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+ 0.3.3++ Add Semigroup instances to everything that had Monoid instances (since from GHC 8.4.2 Semigroup m => Monoid m )+ 0.3 Stackage LTS bump to 11.0 (GHC 8.4.1)
plot-light.cabal view
@@ -1,5 +1,5 @@ name: plot-light-version: 0.3.2.1+version: 0.3.3 synopsis: A lightweight plotting library, exporting to SVG description: This library provides drawing and plotting datastructures and functions; it is aimed in particular at scientific visualization, but it also exposes its plotting primitives and a small but general purpose 2D geometry library. @@ -16,7 +16,7 @@ extra-doc-files: doc/fig/heatmap.png doc/fig/scatter.png cabal-version: >=1.18-tested-with: GHC == 8.0.2, GHC == 8.2.2+tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1, GHC == 8.4.2 library@@ -35,6 +35,7 @@ Graphics.Rendering.Plot.Light.PlotTypes.TimeSeries Graphics.Rendering.Plot.Light.PlotTypes.TimeSeries.Candlestick Graphics.Rendering.Plot.Light.Internal.Utils+ Data.Parsers build-depends: base >= 4.7 && < 5 , blaze-svg , colour
+ src/Data/Parsers.hs view
@@ -0,0 +1,3 @@+module Data.Parsers where+-- import qualified Data.Attoparsec.Text as A+
src/Graphics/Rendering/Plot/Light/Internal/Geometry.hs view
@@ -9,7 +9,7 @@ -- ** Point Point(..), mkPoint, setPointX, setPointY, -- ** LabeledPoint- LabeledPoint(..), mkLabeledPoint, labelPoint, moveLabeledPoint, moveLabeledPointBwFrames, mapLabel,+ LabeledPoint(..), mkLabeledPoint, labelPoint, mapLabel, -- ** Frame Frame(..), mkFrame, frameFromPoints, mkFrameOrigin, height, width, xmin, xmax, ymin, ymax, -- ** Axis@@ -25,7 +25,7 @@ -- ** Vector construction v2fromEndpoints, v2fromPoint, -- ** Operations on points- movePoint, moveLabeledPointV2, moveLabeledPointBwFrames, (-.), pointRange,+ movePoint, moveLabeledPoint, moveLabeledPointV2, moveLabeledPointBwFrames, (-.), pointRange, -- ** Operations on vectors frameToFrame, frameToFrameValue, -- ** Typeclasses@@ -39,7 +39,7 @@ import GHC.Generics import Data.Default.Class-+import Data.Semigroup () -- | A `Point` object defines a point in the plane@@ -125,10 +125,14 @@ def = unitFrame -- | The semigroup operation (`mappend`) applied on two `Frames` results in a new `Frame` that bounds both.++instance (Ord a) => Semigroup (Frame a) where+ (Frame p1min p1max) <> (Frame p2min p2max) = Frame (pointInf p1min p2min) (pointSup p1max p2max)+ instance (Ord a, Num a) => Monoid (Frame a) where mempty = Frame (Point 0 0) (Point 0 0)- mappend (Frame p1min p1max) (Frame p2min p2max) = Frame (pointInf p1min p2min) (pointSup p1max p2max) + mkFrame :: Point a -> Point a -> Frame a mkFrame = Frame @@ -232,10 +236,12 @@ -- | V2 is a vector in R^2 data V2 a = V2 a a deriving (Eq, Show) +instance Num a => Semigroup (V2 a) where+ (V2 a b) <> (V2 c d) = V2 (a + c) (b + d) + -- | Vectors form a monoid w.r.t. vector addition instance Num a => Monoid (V2 a) where mempty = V2 0 0- (V2 a b) `mappend` (V2 c d) = V2 (a + c) (b + d) -- | Additive group : -- @@ -319,15 +325,19 @@ -- | Diagonal matrices in R2 behave as scaling transformations data DiagMat2 a = DMat2 a a deriving (Eq, Show) +instance Num a => Semigroup (DiagMat2 a) where+ (<>) = (##)+ -- | Diagonal matrices form a monoid w.r.t. matrix multiplication and have the identity matrix as neutral element instance Num a => Monoid (DiagMat2 a) where mempty = DMat2 1 1- mappend = (##) +instance Num a => Semigroup (Mat2 a) where+ (<>) = (##)+ -- | Matrices form a monoid w.r.t. matrix multiplication and have the identity matrix as neutral element instance Num a => Monoid (Mat2 a) where mempty = Mat2 1 0 0 1- mappend = (##) -- | Create a diagonal matrix diagMat2 :: Num a => a -> a -> DiagMat2 a
src/Graphics/Rendering/Plot/Light/Internal/Utils.hs view
@@ -25,13 +25,15 @@ rr :: (Real a, Fractional c) => a -> c rr = fromRational . toRational +-- | Convert a floating point value in 'Scientific' form to 'Float' toFloat :: Scientific -> Float toFloat x = toRealFloat x :: Float -- | Separate whole and decimal part of a fractional number -- e.g. ----- > > wholeDecimal +-- > > wholeDecimal pi+-- > (3,0.14159265358979312) wholeDecimal :: (Integral a, RealFrac b) => b -> (a, b) wholeDecimal x = (w, d) where w = floor x