Documentation
¶
Overview ¶
Package scene is a diagram laid out: a list of items, each a thing of the diagram, where it is and what it is, in the order they are drawn — but not how they look. A backend draws a scene: the svg package as SVG, others on screens of their own.
An item says what it is by its Kind, its Role, as "flowchart.node", and, if it has an outline, by its Shape, as "diam". Its colors are tokens of the theme (see the style package), settled only when it is drawn, so a scene is drawn in any theme without being laid out again.
An item also carries what a plain backend needs to draw it: its outline as Parts, paths and boxes; for an edge, the markers at its ends; a label laid out. A backend with a look of its own may draw an item its own way from its Role, Shape, Box and, for an edge, its Route instead.
Index ¶
- Constants
- type Align
- type Item
- type Kind
- type Marker
- type MarkerType
- type Op
- type Painting
- type Part
- type Path
- func (p *Path) ArcTo(rx, ry, rot float64, large, sweep bool, x, y float64) *Path
- func (p *Path) Bounds() Rect
- func (p *Path) Close() *Path
- func (p *Path) Corners() []Point
- func (p *Path) CubeTo(c1x, c1y, c2x, c2y, x, y float64) *Path
- func (p *Path) Each(fn func(op Op, args []float64))
- func (p *Path) Ellipse(cx, cy, rx, ry float64) *Path
- func (p *Path) Flatten(tol float64) []Polyline
- func (p *Path) Last() Point
- func (p *Path) LineTo(x, y float64) *Path
- func (p *Path) MoveTo(x, y float64) *Path
- func (p *Path) Polygon(xy ...float64) *Path
- func (p *Path) QuadTo(cx, cy, x, y float64) *Path
- func (p *Path) RoundRect(r Rect, radius float64) *Path
- func (p *Path) Scaled(s, dx, dy float64) *Path
- type Picture
- type Point
- type Polyline
- type Rect
- type Role
- type Scene
- type Shape
Constants ¶
const MarkerSize = 8
MarkerSize is the length of an arrowhead.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Align ¶
type Align uint8
Align is where a label's lines are about the point it is drawn at, across; down, the label is always centered on it.
type Item ¶
type Item struct {
Kind Kind
Role Role
Shape Shape
ID string // the id the diagram's text gave it, if any
// Class is the classes the diagram's author gave the item, by name: with class statements
// and classDef's default, with :::name, or in a list of classes where the diagram takes
// one, as a kanban card or a tree view's entry does. A class's style is already in Author.
Class []string
// Tags are what the diagram says the item is beyond its role, which Pele writes among the
// classes of what it draws: a C4 element's kind ("person", "system_db"…) and "external",
// a C4 relation's kind ("rel", "birel"…) and a deployment node's ("node", "nodeL",
// "nodeR"); a gantt task's state ("done", "active", "crit", "milestone", "unscheduled");
// the branch a gantt section or a mindmap's node or edge is in ("section-0"…); a wardley
// component's sourcing ("build", "buy", "outsource", "market"); "reset" on an event
// modeling frame that resets; and "clickable", which Mermaid gives what has a click.
//
// The svg backend writes the tags and then the classes as the element's classes, for a
// host's CSS.
Tags []string
// Box is where the item is: the box of its shape, for a node or a group; for an edge, the
// box its path lies in, the control points of its curves included, and for a mark, of
// what it draws. A Text item's Box is where the diagram sets its label, as an edge
// label's patch, and is empty where the diagram gives the label no box of its own;
// LabelBox is where its label is drawn.
Box Rect
// Parts draw the outline; a backend that draws the shape its own way ignores them.
Parts []Part
// For an edge: the route it takes, as the corners of a line that runs straight between
// them, and the markers at its ends. Its curves are in Parts. Every edge has a route; a
// self-loop's, which no layout routes, is the corners its curve is drawn about
// (Path.Corners).
Route []Point
Ends [2]Marker
// Label is drawn about At: centered on it, or with its lines starting or ending there,
// as Align says, and turned by Rotate degrees about it.
Label *text.Label
At Point
Align Align
Rotate float64
// Picture is an image or an icon the item shows, as a flowchart's node may.
Picture *Picture
Style style.Style // the diagram's own
Author style.Style // what the author set with classDef and style lines
Link string // where the item leads, when it is a link
Tooltip string
}
An Item is a thing of a diagram, as it is drawn: a node, a group, an edge, a label on its own or a mark.
type Kind ¶
type Kind uint8
A Kind is the sort of thing an item is.
const ( Node Kind = iota + 1 // a shape, most often with a label: a flowchart's node, an actor Group // a box that holds others: a subgraph, a loop, a lane Edge // a line from one thing to another, with markers at its ends Text // a label on its own: a title, an edge's label, an axis's Mark // a shape with no label: a lifeline, a tick, a slice of a pie )
type Marker ¶
type Marker struct {
Type MarkerType
At Point
DX, DY float64
}
A Marker is what an edge has at an end: its kind, where its tip is, and the way it points, as a unit vector.
func (Marker) Outline ¶
Outline is the marker's shape, as Pele draws it: parts painted in the color of the edge's line. FillOnly fills a part in it and FillAndStroke strokes it too; StrokeOnly strokes it only, and Hollow fills it with the background and strokes it, so that it hides the line beneath. It is nil for a marker of no type, or of one the scene does not know.
type MarkerType ¶
type MarkerType string
A MarkerType is the kind of marker at an end of an edge, by Mermaid's names: "arrow_point", "arrow_circle", "arrow_cross"… The empty one is no marker: an end Pele draws no marker at has the empty type, whatever name the diagram's model gives it ("none", or "arrow_open" for an open line). Every type but the empty one is in the scene's table of markers, with a trim and an outline.
func (MarkerType) Join ¶
func (t MarkerType) Join() style.Join
Join is how a marker of the type turns the corners of its outline when they are stroked, over whatever the edge's style says, as Pele sets it on the marker itself; unset, the marker's corners are the edge's. Its ends are the edge's, as Pele's take theirs from the group the edges are drawn in.
func (MarkerType) Trim ¶
func (t MarkerType) Trim() float64
Trim is how far an edge stops short of its end to leave room for a marker of the type.
type Painting ¶
type Painting uint8
Painting is how a part is painted in its item's style.
const ( // FillAndStroke fills the part and strokes its outline. FillAndStroke Painting = iota // StrokeOnly strokes the part only: an edge, or a detail on a shape, as the lid of a // cylinder. StrokeOnly // FillOnly fills the part and does not stroke it: the body of a datastore, which lines // close at its top and bottom only. FillOnly // Solid fills the part in the theme's color of lines, and strokes it: the dot of a final // state, the bar of a fork. Solid // Hollow fills the part with the theme's background, and strokes it: the ring of a final // state, which hides what is beneath it. Hollow // Shade fills the part with the theme's background and does not stroke it: a stripe of // an entity's table. When the item's author set a fill, it is the background at 60% // opacity, laid over the parts drawn before it, as Pele draws an entity's stripes. Shade )
type Part ¶
A Part is a piece of an item's outline. It is a path when Path is set, and Box and Rounded are then unused; when Path is nil, it is the box Box, its corners rounded by the style's radius when Rounded is set.
type Path ¶
A Path is lines and curves: the steps, and the numbers they take, in turn. Arcs are made of cubic curves when they are added, so a backend draws only the four kinds of step, as MyGo's paths do.
func ParsePath ¶
ParsePath reads path data, as SVG's d attribute holds it: the commands M, L, H, V, C, S, Q, T, A and Z, each also in lower case for numbers relative to where the path is, with numbers repeated for a command given once. Diagrams use it for the outlines Pele draws from path data of its own, as the icons architecture and tree view diagrams know. Data that does not follow SVG's grammar is an error.
func (*Path) ArcTo ¶
ArcTo adds an elliptical arc from where the path is to x, y, as SVG's A command draws one: radii rx and ry, the ellipse turned by rot degrees, the large or the small way round, and clockwise (on the screen) when sweep is true.
func (*Path) Corners ¶
Corners are the path's points and the control points of its curves, in order: the line its curves are drawn about, which runs straight between them. It is the route of an edge whose layout gives it none, as a self-loop: the curve out of its node and back.
func (*Path) Flatten ¶
Flatten is the path as polylines, one for each of its figures, with its curves cut into straight lines that stray from them by no more than tol (0.1 when it is not above zero). It is for backends that draw no curves, or no dashes, and for finding what is near a point. A figure of a single point is left out.
type Picture ¶
type Picture struct {
Image string // the image's address, checked as the diagram's options allow
Icon string // or the icon's name, as "fa:fa-car", drawn in the color of text
Box Rect
Fit bool // the image keeps its proportions in the box; it fills it otherwise
}
A Picture is an image, or an icon by name, drawn in a box.
type Point ¶
type Point struct{ X, Y float64 }
A Point is a place in a diagram, in its units, y down.
type Polyline ¶
A Polyline is points joined by straight lines; a closed one is joined from its last point back to its first as well.
func Dash ¶
Dash cuts polylines into dashes, as SVG's stroke-dasharray and stroke-dashoffset do: the pattern is the lengths of dashes and gaps in turn, taken twice over when it has an odd number of them, and starts anew with each polyline, offset by offset along it. A dash goes round the corners it meets; a dash of no length is a polyline of two points that are the same, which a stroke with round caps draws as a dot. A pattern with a length below zero, or none above it, leaves the polylines as they are, as SVG draws them solid.
type Rect ¶
type Rect struct{ X, Y, W, H float64 }
A Rect is a box: its top left corner, its width and height.
type Role ¶
type Role string
A Role says which part of which diagram an item is, as "flowchart.node" or "sequence.lifeline". Styles are given by role.
type Scene ¶
type Scene struct {
Type string // the kind of diagram: "flowchart", "sequence"…
Width, Height float64
FontSize float64 // of text with no size of its own
Title, Desc string // for assistive technology: accTitle and accDescr
Items []Item // in the order they are drawn
}
A Scene is a diagram laid out. Every number in a scene limu.Layout or Diagram.Layout gives that places or sizes something is finite (see Finite): where Pele would draw NaN, they give an error instead. A diagram package's own Layout makes no such promise.
func (*Scene) Finite ¶
Finite reports whether every number that places or sizes something in the scene is finite: its size, and the boxes, paths, routes, markers, labels and pictures of its items. A layout given numbers at the edge of what a float64 holds, as a sankey diagram's flow of 5e-324, can work out NaN where Pele does too; limu.Layout gives an error for such a scene rather than hand it to a backend.
func (*Scene) Snap ¶
Snap moves everything in the scene onto a grid of unit: the corners of boxes, the points of paths and routes, the tips of markers and the points labels are drawn about. It is for a backend that draws on whole pixels, after layout; a box's sides are snapped each on its own, so boxes that touch go on touching. A path of straight lines has each of its points snapped; a path with curves is moved as a whole, by what puts its first point on the grid, so that its curves keep their shape, as rounding each of their points would not. The scene's size is rounded up.