The document (text s) contains the literal string s. The
string shouldn't contain any newline ('n') characters. If the
string contains newline characters, the function string should
be used.
Modulegraphviz-2999.20.2.0Haskell2010
Data.GraphViz.Printing
This module defines simple helper functions for use with Text.PrettyPrint. It also re-exports all the pretty-printing combinators from that module.
Note that the PrintDot instances for Bool, etc. match those specified for use with Graphviz.
You should only be using this module if you are writing custom node
types for use with Data.GraphViz.Types. For actual printing of
code, use printDotGraph (which produces a
Text value).
The Dot language specification specifies that any identifier is in one of four forms:
Any string of alphabetic ([a-zA-Z\200-\377]) characters, underscores (
_) or digits ([0-9]), not beginning with a digit;a number [-]?(.[0-9]+ | [0-9]+(.[0-9]*)? );
any double-quoted string ("...") possibly containing escaped quotes (\");
an HTML string (<...>).
(Note that the first restriction is referring to a byte-by-byte
comparison using octal values; when using UTF-8 this corresponds to
all characters c where ord c >= 128.)
Due to these restrictions, you should only use text when you are sure that the Text in question is static and quotes are definitely needed/unneeded; it is better to use the Text instance for PrintDot. For more information, see the specification page: http://graphviz.org/doc/info/lang.html
- 3 types
- 1 class
- 85 values
- Packagegraphviz-2999.20.2.0
- Exports89
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourcePrinting.hs
The group combinator is used to specify alternative
layouts. The document (group x) undoes all line breaks in
document x. The resulting line is added to the current line if
that fits the page. Otherwise, the document x is rendered
without any changes.
Document (parens x) encloses document x in parenthesis, "("
and ")".
The empty document is, indeed, empty. Although empty has no
content, it does have a 'height' of 1 and behaves exactly like
(text "") (and is therefore not a unit of <$>).
The document (indent i x) indents document x with i spaces.
test = indent 4 (fillSep (map text
(words "the indent combinator indents these words !")))Which lays out with a page width of 20 as:
the indent
combinator
indents these
words !
(renderOneLine x) renders document x without adding any
indentation or newlines.
The document (list xs) comma separates the documents xs and
encloses them in square brackets. The documents are rendered
horizontally if that fits the page. Otherwise they are aligned
vertically. All comma separators are put in front of the
elements.
The document (rational r) shows the literal rational r using
text.
The document (double d) shows the literal double d using
text.
The document (char c) contains the literal character c. The
character shouldn't be a newline ('n'), the function line
should be used for line breaks.
The document (sep xs) concatenates all documents xs either
horizontally with (<+>), if it fits the page, or vertically
with (<$>).
sep xs = group (vsep xs)The abstract data type Doc represents pretty documents.
Doc is an instance of the Show class. (show doc) pretty
prints document doc with a page width of 100 characters and a
ribbon width of 40 characters.
show (text "hello" <$> text "world")Which would return the string "hello\nworld", i.e.
hello
world
Instances9Show, IsString, Semigroup, Monoid, Pretty, …
Show DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingShow DocDefined in wl-pprint-text-1.2.0.2 · Text.PrettyPrint.Leijen.TextIsString DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingIsString DocDefined in wl-pprint-text-1.2.0.2 · Text.PrettyPrint.Leijen.TextSemigroup DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingSemigroup DocDefined in wl-pprint-text-1.2.0.2 · Text.PrettyPrint.Leijen.TextMonoid DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingMonoid DocDefined in wl-pprint-text-1.2.0.2 · Text.PrettyPrint.Leijen.TextPretty DocDefined in wl-pprint-text-1.2.0.2 · Text.PrettyPrint.Leijen.Text
Document (dquotes x) encloses document x with double quotes
'"'.
The document (int i) shows the literal integer i using
text.
The document (hcat xs) concatenates all documents xs
horizontally with (<>).
(punctuate p xs) concatenates all documents in xs with
document p except for the last document.
someText = map text ["words","in","a","tuple"]
test = parens (align (cat (punctuate comma someText)))This is laid out on a page width of 20 as:
(words,in,a,tuple)
But when the page width is 15, it is laid out as:
(words,
in,
a,
tuple)
(If you want put the commas in front of their elements instead of at the end, you should use tupled or, in general, encloseSep.)
The document colon contains a colon, ":".
The document dot contains a single dot, ".".
The document comma contains a comma, ",".
The document equals contains an equal sign, "=".
The document langle contains a left angle, "<".
The document rangle contains a right angle, ">".
The document (x <$$> y) concatenates document x and y
with a linebreak in between. (infixr 5)
The document (x <++> y) concatenates document x and y with
a spacebreak in between. (infixr 6)
The document (x <+> y) concatenates document x and y with
a space in between. (infixr 6)
The document (x <//> y) concatenates document x and y
with a softbreak in between. This effectively puts x and y
either right next to each other or underneath each other. (infixr
5)
The document (x </> y) concatenates document x and y
with a softline in between. This effectively puts x and y
either next to each other (with a space in between) or
underneath each other. (infixr 5)
The document (align x) renders document x with the nesting
level set to the current column. It is used for example to
implement hang.
As an example, we will put a document right above another one, regardless of the current nesting level:
x $$ y = align (x <$> y)test = text "hi" <+> (text "nice" $$ text "world")which will be laid out as:
hi nice
world
Document (angles x) encloses document x in angles, "<" and
">".
The document backslash contains a back slash, "\".
Document (braces x) encloses document x in braces, "{" and
"}".
Document (brackets x) encloses document x in square brackets,
"[" and "]".
The document (cat xs) concatenates all documents xs either
horizontally with (<>), if it fits the page, or vertically
with (<$$>).
cat xs = group (vcat xs)Specifies how to create the document based upon which column it is in.
The document dquote contains a double quote, '"'.
The document (enclose l r x) encloses document x between
documents l and r using beside.
enclose l r x = l `beside` x `beside` rThe document (encloseSep l r sep xs) concatenates the documents
xs separated by sep and encloses the resulting document by
l and r. The documents are rendered horizontally if that fits
the page. Otherwise they are aligned vertically. All separators
are put in front of the elements. For example, the combinator
list can be defined with encloseSep:
list xs = encloseSep lbracket rbracket comma xs
test = text "list" <+> (list (map int [10,200,3000]))Which is laid out with a page width of 20 as:
list [10,200,3000]
But when the page width is 15, it is laid out as:
list [10
,200
,3000]
The document (fill i x) renders document x. It then appends
spaces until the width is equal to i. If the width of x is
already larger, nothing is appended. This combinator is quite
useful in practice to output a list of bindings. The following
example demonstrates this.
types = [("empty","Doc")
,("nest","Int -> Doc -> Doc")
,("linebreak","Doc")]
ptype (name,tp)
= fill 6 (text name) <+> text "::" <+> text tp
test = text "let" <+> align (vcat (map ptype types))Which is laid out as:
let empty :: Doc
nest :: Int -> Doc -> Doc
linebreak :: Doc
The document (fillBreak i x) first renders document x. It
then appends spaces until the width is equal to i. If the
width of x is already larger than i, the nesting level is
increased by i and a line is appended. When we redefine
ptype in the previous example to use fillBreak, we get a
useful variation of the previous output:
ptype (name,tp)
= fillBreak 6 (text name) <+> text "::" <+> text tpThe output will now be:
let empty :: Doc
nest :: Int -> Doc -> Doc
linebreak
:: Doc
The document (fillCat xs) concatenates documents xs
horizontally with (<>) as long as its fits the page, then
inserts a linebreak and continues doing that for all documents
in xs.
fillCat xs = foldr (<//>) empty xsThe document (fillSep xs) concatenates documents xs
horizontally with (<+>) as long as its fits the page, then
inserts a line and continues doing that for all documents in
xs.
fillSep xs = foldr (</>) empty xsThe document (float f) shows the literal float f using
text.
The hang combinator implements hanging indentation. The document
(hang i x) renders document x with a nesting level set to the
current column plus i. The following example uses hanging
indentation for some text:
test = hang 4 (fillSep (map text
(words "the hang combinator indents these words !")))Which lays out on a page with a width of 20 characters as:
the hang combinator
indents these
words !
The hang combinator is implemented as:
hang i x = align (nest i x)The document (hsep xs) concatenates all documents xs
horizontally with (<+>).
The document (integer i) shows the literal integer i using
text.
The document lbrace contains a left brace, "{".
The document lbracket contains a left square bracket, "[".
The line document advances to the next line and indents to the
current nesting level. Document line behaves like (text "
") if the line break is undone by group or if rendered with
renderOneLine.
The document lparen contains a left parenthesis, "(".
Specifies how to nest the document based upon which column it is being nested in.
The document rbrace contains a right brace, "}".
The document rbracket contains a right square bracket, "]".
The document rparen contains a right parenthesis, ")".
The document semi contains a semi colon, ";".
The document (semiBraces xs) separates the documents xs with
semi colons and encloses them in braces. The documents are
rendered horizontally if that fits the page. Otherwise they are
aligned vertically. All semi colons are put in front of the
elements.
The document space contains a single space, " ".
x <+> y = x `beside` space `beside` yThe document spacebreak behaves like space when rendered normally
but like empty when using renderCompact or renderOneLine.
The document squote contains a single quote, "'".
Document (squotes x) encloses document x with single quotes
"'".
The document (tupled xs) comma separates the documents xs and
encloses them in parenthesis. The documents are rendered
horizontally if that fits the page. Otherwise they are aligned
vertically. All comma separators are put in front of the
elements.
The document (vcat xs) concatenates all documents xs
vertically with (<$$>). If a group undoes the line breaks
inserted by vcat, all documents are directly concatenated.
The document (vsep xs) concatenates all documents xs
vertically with (<$>). If a group undoes the line breaks
inserted by vsep, all documents are separated with a space.
someText = map text (words ("text to lay out"))
test = text "some" <+> vsep someTextThis is laid out as:
some text
to
lay
out
The align combinator can be used to align the documents under their first element
test = text "some" <+> align (vsep someText)Which is printed as:
some text
to
lay
out
A type alias to indicate what is being produced.
Instances9Monad, Functor, Show, IsString, Applicative, Semigroup, …
Monad DotCodeMDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingFunctor DotCodeMDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingShow DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingIsString DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingApplicative DotCodeMDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingSemigroup DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingMonoid DotCodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingGraphvizStateM DotCodeMDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingMonadState GraphvizState DotCodeMDefined in graphviz-2999.20.2.0 · Data.GraphViz.Printing
Correctly render Graphviz output.
A class used to correctly print parts of the Graphviz Dot language. Minimal implementation is unqtDot.
Methods
unqtDot :: a -> DotCodeThe unquoted representation, for use when composing values to produce a larger printing value.
toDot :: a -> DotCodeThe actual quoted representation; this should be quoted if it contains characters not permitted a plain ID String, a number or it is not an HTML string. Defaults to unqtDot.
unqtListToDot :: [a] -> DotCodeThe correct way of representing a list of this value when printed; not all Dot values require this to be implemented. Defaults to Haskell-like list representation.
listToDot :: [a] -> DotCodeThe quoted form of unqtListToDot; defaults to wrapping double quotes around the result of unqtListToDot (since the default implementation has characters that must be quoted).
Instances102PrintDot, …
PrintDot IntegerDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot VersionDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingIgnores versionTags and assumes 'not . null . versionBranch' (usually you want 'length . versionBranch == 2').
PrintDot Word16Defined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot Word32Defined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot Word64Defined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot Word8Defined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot BoolDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot CharDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot DoubleDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot IntDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot ArrowFillDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ArrowsPrintDot ArrowModifierDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ArrowsPrintDot ArrowShapeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ArrowsPrintDot ArrowSideDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ArrowsPrintDot ArrowTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ArrowsPrintDot BrewerNameDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot BrewerSchemeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot ColorSchemeDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot ColorDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ColorsPrintDot WeightedColorDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ColorsPrintDot SVGColorDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.Colors.SVGPrintDot X11ColorDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.Colors.X11PrintDot AttributeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.CompletePrintDot AlignDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot AttributeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot CellDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot CellFormatDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot FormatDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot ImgDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot LabelDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot RowDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot ScaleDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot SideDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot StyleDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot TableDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot TextItemDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot VAlignDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.HTMLPrintDot CompassPointDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.InternalPrintDot PortNameDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.InternalPrintDot PortPosDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.InternalPrintDot ClusterModeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot DEConstraintsDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot DPointDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot DirTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot EdgeTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot FocusTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot GraphSizeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot JustificationDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LabelDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LabelSchemeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LayerIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LayerListDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LayerListSepDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LayerRangeElemDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot LayerSepDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot ModeTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot ModelDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot NodeSizeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot NormalizedDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot NumberDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot OrderDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot OutputModeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot OverlapDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot PackDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot PackModeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot PageDirDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot PathsDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot PointDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot PosDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot QuadTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot RankDirDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot RankTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot RatiosDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot RecordFieldDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot RectDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot RootDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot STStyleDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot SVGFontNamesDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot ScaleTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot ShapeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot SmoothTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot SplineDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot StartTypeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot StyleItemDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot StyleNameDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot VerticalPlacementDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot ViewPortDefined in graphviz-2999.20.2.0 · Data.GraphViz.Attributes.ValuesPrintDot GraphvizCommandDefined in graphviz-2999.20.2.0 · Data.GraphViz.Commands.AvailablePrintDot GlobalAttributesDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.CommonPrintDot GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.CommonPrintDot TextDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot TextDefined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot a => PrintDot [a]Defined in graphviz-2999.20.2.0 · Data.GraphViz.PrintingPrintDot n => PrintDot (DotGraph n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.CanonicalPrintDot n => PrintDot (DotStatements n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.CanonicalPrintDot n => PrintDot (DotSubGraph n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.CanonicalPrintDot n => PrintDot (DotGraph n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.GeneralisedPrintDot n => PrintDot (DotStatement n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.GeneralisedPrintDot n => PrintDot (DotSubGraph n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.GeneralisedPrintDot n => PrintDot (DotGraph n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.GraphUses the PrintDot instance for canonical DotGraphs.
PrintDot n => PrintDot (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.CommonPrintDot n => PrintDot (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
For use with OverloadedStrings to avoid ambiguous type variable errors.
For use with OverloadedStrings to avoid ambiguous type variable errors.
Convert to DotCode; note that this has no indentation, as we can only have one of indentation and (possibly) infinite line lengths.
Escape the specified chars as well as ".
Escape the specified chars as well as " and then wrap the
result in quotes.