Documentation
¶
Overview ¶
Package diagram draws Mermaid diagrams natively, with limu (github.com/firede/limu), which reads every diagram type Pele, the Obsidian team's Mermaid renderer, draws and lays it out: flowcharts, sequence, class, state and entity relationship diagrams, Gantt charts, pies, mind maps, timelines and more. It draws the laid-out scene on a canvas in the platform's font, which it measures the labels in too, so text fills the room the layout gave it. textview.TextView draws its mermaid code blocks so with RenderDiagram: diagram.RenderDiagram.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderDiagram ¶
RenderDiagram draws a text view's mermaid code block, as textview.TextView.RenderDiagram takes it, for textview.TextView{RenderDiagram: diagram.RenderDiagram}. It lays the diagram out to the block's viewport width, centered, retaining sideways scrolling for a diagram limu cannot fit. A copy takes its source between ```mermaid fences. A diagram that fails shows its source in the monospaced font.
Types ¶
type Theme ¶
type Theme struct {
Background core.Color // behind the diagram, and behind labels on lines
Text core.Color
Muted core.Color // secondary text, as the titles of groups
Line core.Color // edges and other lines
Surface core.Color // the inside of shapes
SurfaceAlt core.Color // the inside of groups, and of shapes set apart
Border core.Color // the outlines of shapes
Accent core.Color // what a diagram marks out
Critical core.Color // what a diagram marks as critical
// Series are the colors of a chart's series, as a pie's slices, in turn; a series left zero keeps the appearance's.
Series [8]core.Color
Radius float32
StrokeWidth float32
}
Theme is a diagram's colors, as limu's themes name them, and its corners' radius and lines' width, in points. What it leaves zero keeps the appearance's theme, so a theme may change only the colors it names.
type View ¶
type View struct {
// Source is the diagram's Mermaid text, as a mermaid code block holds it; SourceFunc follows what it reads.
Source string
SourceFunc func() string
// FontSize is the size of labels with no size of their own; 0 is 16.
FontSize core.Points
// Theme colors the diagram over the appearance's theme: Pele's light theme in light, and its gray counterpart in dark, with the same blue accent as NSGo's own look.
Theme *Theme
// ThemeFunc follows the colors it reads. Returning nil keeps the appearance's defaults. Theme and ThemeFunc are mutually exclusive.
ThemeFunc func() *Theme
// Icons supplies SVG documents by the names used in the source, such as "fa:fa-car". Missing or nil entries leave icons out. Render snapshots the map; SVGs may be shared with core.Icon.
Icons map[string]*core.SVG
// Label is what assistive technology reads in place of the diagram's title and description.
Label string
Class string
Style core.Style
StyleFunc func() core.Style
// ErrorClass and ErrorStyle style the source a diagram that fails shows instead.
ErrorClass string
ErrorStyle core.Style
TestID string
}
View draws a Mermaid diagram laid out to the width its container gives it, turning a wide flowchart to run down where it fits better. Labels use the platform's font at FontSize, scaled by the user's text size setting as text is. It colors itself with the appearance's theme, gray with a blue accent in light and in dark, and with what Theme sets over it. A diagram that does not parse, or cannot be laid out, shows its source as text in ErrorClass and ErrorStyle. Assistive technology reads it as an image, named by Label, else by the diagram's accTitle and accDescr, else as a diagram, in the language the app shows.