chart-svg-0.3.0: Charting library targetting SVGs.
Safe HaskellNone
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

SVG path

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]

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d

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

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

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

Convert [PathData] to an SVG d path text.

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
Eq PathCommand Source # 
Instance details

Defined in Data.Path.Parser

Show PathCommand Source # 
Instance details

Defined in Data.Path.Parser

Generic PathCommand Source # 
Instance details

Defined in Data.Path.Parser

Associated Types

type Rep PathCommand :: Type -> Type #

type Rep PathCommand Source # 
Instance details

Defined in Data.Path.Parser

type Rep PathCommand = D1 ('MetaData "PathCommand" "Data.Path.Parser" "chart-svg-0.3.0-1YbRR4NHUjc7NyiG3vKerW" '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
Eq Origin Source # 
Instance details

Defined in Data.Path.Parser

Methods

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

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

Show Origin Source # 
Instance details

Defined in Data.Path.Parser

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 #

type Rep Origin Source # 
Instance details

Defined in Data.Path.Parser

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