chart-svg-0.3.3: Charting library targetting SVGs.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Path.Parser

Contents

Description

SVG path manipulation

Synopsis

Parsing

Every element of an svg path can be thought of as exactly two points in space, with instructions of how to draw a curve between them. From this point of view, one which this library adopts, a path chart is thus very similar to a line chart. There's just a lot more information about the style of this line to deal with.

References:

SVG d attribute

SVG Paths

parsePath :: Text -> Either String [PathCommand] Source #

Parse a raw path string.

>>> let outerseg1 = "M-1.0,0.5 A0.5 0.5 0.0 1 1 0.0,-1.2320508075688774 1.0 1.0 0.0 0 0 -0.5,-0.3660254037844387 1.0 1.0 0.0 0 0 -1.0,0.5 Z"
>>> parsePath outerseg1
Right [MoveTo OriginAbsolute [Point -1.0 0.5],EllipticalArc OriginAbsolute [(0.5,0.5,0.0,True,True,Point 0.0 -1.2320508075688774),(1.0,1.0,0.0,False,False,Point -0.5 -0.3660254037844387),(1.0,1.0,0.0,False,False,Point -1.0 0.5)],EndPath]

svgToPathData :: Text -> [PathData Double] Source #

Convert from an SVG d attribute text snippet to a [PathData Double]

pathDataToSvg :: [PathData Double] -> Text Source #

Convert from [PathData Double] to an SVG d path text snippet.

data PathCommand Source #

Path command definition (ripped from reanimate-svg).

Constructors

MoveTo !Origin ![Point Double]

M or m command

LineTo !Origin ![Point Double]

Line to, L or l Svg path command.

HorizontalTo !Origin ![Double]

Equivalent to the H or h svg path command.

VerticalTo !Origin ![Double]

Equivalent to the V or v svg path command.

CurveTo !Origin ![(Point Double, Point Double, Point Double)]

Cubic bezier, C or c command

SmoothCurveTo !Origin ![(Point Double, Point Double)]

Smooth cubic bezier, equivalent to S or s command

QuadraticBezier !Origin ![(Point Double, Point Double)]

Quadratic bezier, Q or q command

SmoothQuadraticBezierCurveTo !Origin ![Point Double]

Quadratic bezier, T or t command

EllipticalArc !Origin ![(Double, Double, Double, Bool, Bool, Point Double)]

Elliptical arc, A or a command.

EndPath

Close the path, Z or z svg path command.

Instances

Instances details
Generic PathCommand Source # 
Instance details

Defined in Data.Path.Parser

Associated Types

type Rep PathCommand :: Type -> Type #

Show PathCommand Source # 
Instance details

Defined in Data.Path.Parser

Eq PathCommand Source # 
Instance details

Defined in Data.Path.Parser

type Rep PathCommand Source # 
Instance details

Defined in Data.Path.Parser

type Rep PathCommand = D1 ('MetaData "PathCommand" "Data.Path.Parser" "chart-svg-0.3.3-HRZp9R2U1Kt6XiFnJzSSfo" 'False) (((C1 ('MetaCons "MoveTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Point Double])) :+: C1 ('MetaCons "LineTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Point Double]))) :+: (C1 ('MetaCons "HorizontalTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Double])) :+: (C1 ('MetaCons "VerticalTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Double])) :+: C1 ('MetaCons "CurveTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Point Double, Point Double, Point Double)]))))) :+: ((C1 ('MetaCons "SmoothCurveTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Point Double, Point Double)])) :+: C1 ('MetaCons "QuadraticBezier" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Point Double, Point Double)]))) :+: (C1 ('MetaCons "SmoothQuadraticBezierCurveTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Point Double])) :+: (C1 ('MetaCons "EllipticalArc" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Origin) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Double, Double, Double, Bool, Bool, Point Double)])) :+: C1 ('MetaCons "EndPath" 'PrefixI 'False) (U1 :: Type -> Type)))))

data Origin Source #

Tell if a path command is absolute (in the current user coordiante) or relative to the previous point.

Constructors

OriginAbsolute

Next point in absolute coordinate

OriginRelative

Next point relative to the previous

Instances

Instances details
Generic Origin Source # 
Instance details

Defined in Data.Path.Parser

Associated Types

type Rep Origin :: Type -> Type #

Methods

from :: Origin -> Rep Origin x #

to :: Rep Origin x -> Origin #

Show Origin Source # 
Instance details

Defined in Data.Path.Parser

Eq Origin Source # 
Instance details

Defined in Data.Path.Parser

Methods

(==) :: Origin -> Origin -> Bool #

(/=) :: Origin -> Origin -> Bool #

type Rep Origin Source # 
Instance details

Defined in Data.Path.Parser

type Rep Origin = D1 ('MetaData "Origin" "Data.Path.Parser" "chart-svg-0.3.3-HRZp9R2U1Kt6XiFnJzSSfo" 'False) (C1 ('MetaCons "OriginAbsolute" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OriginRelative" 'PrefixI 'False) (U1 :: Type -> Type))