diagram

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func RenderDiagram(cx *core.Scope, code textview.CodeBlock) core.Node

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.

func (View) Render

func (v View) Render(cx *core.Scope) core.Node

Render implements core.Node.

Directories

Path Synopsis
Package locales says what base/diagram's diagrams read as, to assistive technology, in the language the app shows.
Package locales says what base/diagram's diagrams read as, to assistive technology, in the language the app shows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL