Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Parser & Printer for the dot language of graphviz
See DotParse.Examples for usage.
Synopsis
- data DotConfig = DotConfig {}
- defaultDotConfig :: DotConfig
- class DotParse a where
- testDotParser :: forall a. DotParse a => Proxy a -> DotConfig -> ByteString -> IO ()
- runDotParser :: DotParse a => ByteString -> a
- data Graph = Graph {
- strict :: Last Strict
- directed :: Last Directed
- graphid :: Last ID
- nodeAttributes :: Map ID ID
- graphAttributes :: Map ID ID
- edgeAttributes :: Map ID ID
- globalAttributes :: Map ID ID
- nodes :: [NodeStatement]
- edges :: [EdgeStatement]
- subgraphs :: [SubGraphStatement]
- defaultGraph :: Graph
- attL :: AttributeType -> ID -> Lens' Graph (Maybe ID)
- gattL :: ID -> Lens' Graph (Maybe ID)
- processDot :: Directed -> ByteString -> IO ByteString
- processDotWith :: Directed -> [String] -> ByteString -> IO ByteString
- processGraph :: Graph -> IO Graph
- processGraphWith :: DotConfig -> Graph -> IO Graph
- data Strict
- defStrict :: Last Strict -> Strict
- data Directed
- defDirected :: Last Directed -> Directed
- data ID
- label :: ID -> String
- data Compass
- newtype Port = Port {}
- data AttributeType
- data AttributeStatement = AttributeStatement {}
- data NodeStatement = NodeStatement {}
- data EdgeID
- data EdgeOp
- fromDirected :: Directed -> EdgeOp
- data EdgeStatement = EdgeStatement {}
- edgeID :: EdgeID -> Maybe ID
- edgeIDs :: EdgeStatement -> [(Maybe ID, Maybe ID)]
- edgeIDsNamed :: EdgeStatement -> [(ID, ID)]
- data Statement
- addStatement :: Statement -> Graph -> Graph
- addStatements :: [Statement] -> Graph -> Graph
- data SubGraphStatement = SubGraphStatement {
- subgraphID :: Maybe ID
- subgraphStatements :: [Statement]
- graphToChartWith :: ChartConfig -> (ID -> Text) -> Graph -> ChartOptions
- graphToChart :: Graph -> ChartOptions
- data ChartConfig = ChartConfig {}
- defaultChartConfig :: ChartConfig
- toStatements :: Directed -> Graph ByteString -> [Statement]
- toDotGraph :: Graph ByteString -> Graph
- toDotGraphWith :: Directed -> Graph -> Graph ByteString -> Graph
Documentation
printing options, for separators.
Instances
Generic DotConfig Source # | |
Show DotConfig Source # | |
Eq DotConfig Source # | |
type Rep DotConfig Source # | |
Defined in DotParse.Types type Rep DotConfig = D1 ('MetaData "DotConfig" "DotParse.Types" "dotparse-0.1.1.0-7ksB5EWrjOr2Em2eE9iYUk" 'False) (C1 ('MetaCons "DotConfig" 'PrefixI 'True) ((S1 ('MetaSel ('Just "topLevelSep") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "statementSep") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)) :*: (S1 ('MetaSel ('Just "attSep") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "subGraphSep") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))) |
defaultDotConfig :: DotConfig Source #
default separators
class DotParse a where Source #
A parser & printer class for a graphviz graph and components of its dot language
Instances
testDotParser :: forall a. DotParse a => Proxy a -> DotConfig -> ByteString -> IO () Source #
dotParse and then dotPrint:
- pretty printing error on failure.
- This is not an exact parser/printer, so the test re-parses the dotPrint, which should be idempotent
runDotParser :: DotParse a => ByteString -> a Source #
run a dotParse erroring on leftovers, Fail or Err
Representation of a full graphviz graph, as per the dot language specification
Graph | |
|
Instances
defaultGraph :: Graph Source #
Directed
graph of size 1.
>>>
BS.putStr $ dotPrint defaultDotConfig defaultGraph <> "\n"
digraph { node [height=0.5;shape=circle] graph [overlap=false;size="1!";splines=spline] edge [arrowsize=0.5] rankdir="TB" }
processDot :: Directed -> ByteString -> IO ByteString Source #
run a dot string through graphviz, collecting the augmented dot string output
processDotWith :: Directed -> [String] -> ByteString -> IO ByteString Source #
run a dot string through graphviz, supplying arguments and collecting stdout
MergeEdges (strict)
Directed (digraph | graph)
Identifier as per the dot language specifications.
>>>
runDotParser "0" :: ID
IDInt 0
>>>
runDotParser "-.123" :: ID
IDDouble (-0.123)
>>>
runParser dotParse "apple_1'" :: Result Error ID
OK (ID "apple_1") "'"
>>>
:set -XQuasiQuotes
>>>
runParser dotParse "\"hello\"" :: Result Error ID
OK (IDQuoted "hello") ""
>>>
runDotParser "<The <font color='red'><b>foo</b></font>,<br/> the <font point-size='20'>bar</font> and<br/> the <i>baz</i>>" :: ID
IDHtml "<The <font color='red'><b>foo</b></font>,<br/> the <font point-size='20'>bar</font> and<br/> the <i>baz</i>>"
>>>
runDotParser "shape=diamond" :: (ID,ID)
(ID "shape",ID "diamond")
>>>
runDotParser "fontname=\"Arial\"" :: (ID,ID)
(ID "fontname",IDQuoted "Arial")
>>>
runDotParser "[shape=diamond; color=blue] [label=label]" :: Map.Map ID ID
fromList [(ID "color",ID "blue"),(ID "label",ID "label"),(ID "shape",ID "diamond")]
Instances
label :: ID -> String Source #
ID as the equivalent plain String
note that the dot language identifier equivalence law is:
x == y if label x == label y
Compass instructions which are optionally associated with an identifier
Instances
Generic Compass Source # | |
Show Compass Source # | |
DotParse Compass Source # | |
Eq Compass Source # | |
type Rep Compass Source # | |
Defined in DotParse.Types type Rep Compass = D1 ('MetaData "Compass" "DotParse.Types" "dotparse-0.1.1.0-7ksB5EWrjOr2Em2eE9iYUk" 'False) (((C1 ('MetaCons "CompassN" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CompassNE" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CompassE" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CompassSE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CompassS" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "CompassSW" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CompassW" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CompassNW" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CompassC" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Compass_" 'PrefixI 'False) (U1 :: Type -> Type))))) |
Port instructions which are optionally associated with an identifier
data AttributeType Source #
Category of attribute
Instances
data AttributeStatement Source #
Top-level attribute statement
>>>
runDotParser "graph [overlap=false, splines=spline, size=\"1!\"];" :: Statement
StatementAttribute (AttributeStatement {attributeType = GraphType, attributes = fromList [(ID "overlap",ID "false"),(ID "size",IDQuoted "1!"),(ID "splines",ID "spline")]})
Instances
data NodeStatement Source #
Node statement
>>>
runDotParser "A [shape=diamond; color=blue]" :: Statement
StatementNode (NodeStatement {nodeID = ID "A", port = Nothing, nodeAttrs = fromList [(ID "color",ID "blue"),(ID "shape",ID "diamond")]})
Instances
An edge can be specified in as a NodeID or as a SubGraph
Instances
Generic EdgeID Source # | |
Show EdgeID Source # | |
DotParse EdgeID Source # | |
Eq EdgeID Source # | |
type Rep EdgeID Source # | |
Defined in DotParse.Types type Rep EdgeID = D1 ('MetaData "EdgeID" "DotParse.Types" "dotparse-0.1.1.0-7ksB5EWrjOr2Em2eE9iYUk" 'False) (C1 ('MetaCons "EdgeID" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ID) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Port))) :+: C1 ('MetaCons "EdgeSubGraph" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SubGraphStatement))) |
An edgeop is -> in directed graphs and -- in undirected graphs.
fromDirected :: Directed -> EdgeOp Source #
generate an EdgeOp given the type of graph.
data EdgeStatement Source #
Edge statement
>>>
runDotParser "A -> B [style=dashed, color=grey]" :: Statement
StatementEdge (EdgeStatement {edgeOp = EdgeDirected, leftEdge = EdgeID (ID "A") Nothing, rightEdges = EdgeID (ID "B") Nothing :| [], edgeAttrs = fromList [(ID "color",ID "grey"),(ID "style",ID "dashed")]})
Instances
edgeIDs :: EdgeStatement -> [(Maybe ID, Maybe ID)] Source #
list of edges in a given EdgeStatement, including anonymous SugGraphs
edgeIDsNamed :: EdgeStatement -> [(ID, ID)] Source #
edge IDs
A dot statement as per the dot language specification.
StatementNode NodeStatement | |
StatementEdge EdgeStatement | |
StatementGlobalAttribute GlobalAttributeStatement | |
StatementAttribute AttributeStatement | |
StatementSubGraph SubGraphStatement |
Instances
data SubGraphStatement Source #
A subgraph statement.
Note: each subgraph must have a unique name
>>>
runDotParser "subgraph A {A, B, C}" :: Statement
StatementSubGraph (SubGraphStatement {subgraphID = Just (ID "A"), subgraphStatements = [StatementNode (NodeStatement {nodeID = ID "A", port = Nothing, nodeAttrs = fromList []}),StatementNode (NodeStatement {nodeID = ID "B", port = Nothing, nodeAttrs = fromList []}),StatementNode (NodeStatement {nodeID = ID "C", port = Nothing, nodeAttrs = fromList []})]})
Instances
Conversion
graphToChartWith :: ChartConfig -> (ID -> Text) -> Graph -> ChartOptions Source #
convert a Graph
processed via the graphviz commands to a ChartOptions
graphToChart :: Graph -> ChartOptions Source #
convert a Graph
processed via the graphviz commands to a ChartOptions
using the default ChartConfig.
data ChartConfig Source #
Various configutaion parameters for the chart-svg Chart
ChartConfig | |
|
Instances
defaultChartConfig :: ChartConfig Source #
default parameters
toStatements :: Directed -> Graph ByteString -> [Statement] Source #
create Statements from a (no edge label) algebraic graph
toDotGraph :: Graph ByteString -> Graph Source #
Convert an algebraic graph to a dotparse graph, starting with the defaultGraph
.
toDotGraphWith :: Directed -> Graph -> Graph ByteString -> Graph Source #
Convert an algebraic graph to a dotparse graph.