mermaid.svg

index · mermaid

Overview

The SVG painter: a frame as one inline <svg>, for a web page. It draws the cells the other two painters draw, so a diagram on a page has the layout it has in a terminal.

Strokes are paths through cell centres, with the pixel painter's geometry: mermaid.outline holds each shape for both. Labels are <text> in the page's monospace font. Each is fitted to its cells with textLength, so its width does not hang on the reader's font.

A style name becomes a class: diagram- and the name, each dot a dash. Every stroke and every marker's fill is currentColor, so a stylesheet colours a diagram with color alone, and a page with no rule still shows one.

The string holds no id, no style attribute, no event attribute and no script. Two diagrams on a page cannot clash.

A knockout text lies on a stroke. The pixel painter clears its cells last. Nothing in a page erases, short of a mask, and a mask needs an id. So this painter cuts: a straight stroke loses the span of each cell a knockout text clears, padding included. A route breaks into pieces at the gap, and so do a group's sides, a divider and an activation's bar. No layout puts a bend, a marker or a node's outline under a knockout text.

Functions

NameSignature
numnum(n) -> text
paintpaint(frame, opts) -> svg

num(n) -> text

Write a number for SVG

At most two decimals, no trailing zero and no trailing dot. A negative nought is 0.

paint(frame, opts) -> svg

Paint a frame as one SVG string

Returns one string, from <svg to </svg>. It is also a whole SVG file.

opts:

FieldHolds
cell_w, cell_ha cell's size in user units; 10 by 20 when not given

One user unit is one CSS pixel at the picture's own size. The root's width and height give that size, and its viewBox lets a stylesheet shrink it. A stroke is a tenth of cell_h, the font eight tenths.

The paint order is the frame's: groups, boxes, routes and their markers, then the texts in one <g>.

ElementClass
the rootdiagram-flowchart or diagram-sequence, by frame.kind; none for a frame with no kind
a group, a box, a route, a textdiagram- and its style, each dot a dash
a markerits route's class and diagram-marker

The root names the picture for a reader who cannot see it. With frame.title, the root is role="img" and its aria-label is the title: a screen reader reads the title and skips the labels. With no title, the root has no role and its aria-label is the kind's name, or diagram: the labels are read as text. frame.descr, when there is one, is a <desc>, the root's first child. There is no <title> element: a browser shows one as a tooltip over the whole picture.

The frame must pass mermaid.frame.check. The painter raises nothing on a checked frame.