isodemo

package
v0.215.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package isodemo is a runnable, self-checking showcase of the toolkit's isometric diagram widget (toolkit.IsoDiagram) and its collaborative CRDT backing store (toolkit.IsoCRDTDocument).

It is built entirely on the widget's PUBLIC API — the same calls a host application makes — and renders through the toolkit's headless capture path (toolkit.RenderPNG), so it needs no window, display server or GPU. Every scene here is assembled by a reusable builder (never hidden inside a main), so the accompanying test can render each one to an in-memory buffer and assert on EXACT projected pixel positions and colours (see isodemo_test.go), and the cmd/isodemo binary can write the same scenes to PNG files for a human to inspect.

The five families of the diagram model are all exercised:

  • toolkit.IsoNode — placed solids, some drawn as their bare shape and some as a registry icon (server / database / cloud / router / switch / storage), each with its own base colour the isometric renderer shades per face.
  • toolkit.IsoConnector — directed links in every stroke style (solid / dashed / dotted), arrow decoration (none / single / double), custom colour and width, straight or grid-routed, with path labels.
  • toolkit.IsoZone — translucent grouping regions on the ground plane.
  • toolkit.IsoText — free-floating text annotations.
  • toolkit.IsoLayer — two ordered drawing planes ("infra" behind, "monitor" in front) whose visibility the demo toggles.

ConvergedReplicas additionally proves the collaborative store: two replicas on distinct sites make CONCURRENT edits (one moves and the other recolours the same node, a third-field merge; the second replica also adds a node and a zone), exchange operations both ways and converge to a byte-identical snapshot — and therefore to a byte-identical rendering.

Index

Constants

View Source
const (
	CanvasWidth  = 760
	CanvasHeight = 560
)

Canvas is the pixel size every scene renders at. It is wide and tall enough for the default 10x10 grid, centred by the widget, to sit inside the frame with room for the raised solids and their labels.

View Source
const (
	LayerInfra   = "infra"
	LayerMonitor = "monitor"
)

Layer ids used across the showcase scene. "infra" is the back plane (lower order) and "monitor" the front plane (higher order), so a monitor-layer entity always draws over an infra-layer one whatever their isometric depth.

View Source
const (
	NodeWeb    = "web-01"
	NodeDB     = "db-01"
	NodeCloud  = "cloud-01"
	NodeRouter = "rtr-01"
	NodeSwitch = "sw-01"
	NodeStore  = "store-01"
	NodeProbe  = "mon-probe" // a bare cube (no icon) on the monitor layer
)

Node ids in the showcase scene, exported so the test can assert on the exact entities it renders.

View Source
const (

	// CollabMovedNode is the node both replicas edit concurrently: replica A
	// moves it, replica B recolours it. Different fields, so the field-wise LWW
	// merge keeps both edits.
	CollabMovedNode = "srv"
	// CollabAddedNode and CollabAddedZone are replica B's concurrent additions.
	CollabAddedNode = "cache"
	CollabAddedZone = "z-edge"
)

Collaboration scenario identities.

Variables

View Source
var (
	ColWeb    = toolkit.RGB(60, 120, 220)
	ColDB     = toolkit.RGB(40, 170, 90)
	ColCloud  = toolkit.RGB(150, 80, 210)
	ColRouter = toolkit.RGB(230, 140, 30)
	ColSwitch = toolkit.RGB(30, 180, 180)
	ColStore  = toolkit.RGB(210, 60, 60)
	ColProbe  = toolkit.RGB(240, 200, 40)
)

Base colours of the showcase nodes. Each is fully opaque so a node's top face — which the isometric renderer shades at factor 1.0 — is drawn as exactly this colour, which is what the pixel-exact assertions in the test check.

View Source
var (
	ColSync  = toolkit.RGB(200, 40, 160)
	ColRoute = toolkit.RGB(40, 40, 60)
)

Connector colours used in the showcase (each fully opaque so a stroked pixel is exactly this colour).

View Source
var (
	ColZoneCore = toolkit.RGBA{R: 60, G: 120, B: 220, A: 70}
	ColZoneEdge = toolkit.RGBA{R: 40, G: 170, B: 90, A: 70}
)

Zone fill colours: the alpha is the fill opacity, so the ground grid still shows through the tint.

View Source
var (
	CollabMovedX, CollabMovedY = 4, 6
	CollabRecolor              = toolkit.RGB(255, 90, 180)
)

The concurrent edits' target values, exported so the test asserts the exact merged state.

Functions

func BuildScene

func BuildScene() *toolkit.IsoDiagram

BuildScene assembles the full showcase diagram from the public API and returns the widget, laid out on the default 10x10 grid. It is the single reusable construction path shared by the renderer, the assertions and the cmd binary — nothing about the scene lives in a main.

The two named layers are created explicitly and made visible (a named layer is hidden until its Visible flag is set); the implicit default layer is not used, so HideMonitoring can drop a whole plane.

func ConvergedReplicas

func ConvergedReplicas() (a, b *toolkit.IsoCRDTDocument)

ConvergedReplicas builds two collaborating replicas of one diagram, applies a pair of CONCURRENT edits — replica A moves the shared node while replica B recolours that same node AND adds a node and a zone — then exchanges operations both ways so each converges. It returns the two replicas after convergence; they hold byte-identical snapshots and therefore render identically.

The edits are captured against the shared base version BEFORE either side integrates the other's operations, which is exactly the offline-then-sync pattern a real collaborative session produces.

func Generate

func Generate(dir string) ([]string, error)

Generate renders every showcase scene and writes it as a PNG into dir, returning the paths written in capture order. The first write to fail aborts and returns its error.

func HideMonitoring

func HideMonitoring(d *toolkit.IsoDiagram)

HideMonitoring flips the monitor layer of d's document to invisible, so its storage node, probe cube and "Datacenter A" annotation stop rendering while the infra plane is untouched. It is the toggle the layer-visibility capture and its assertion use.

func SelectNodes

func SelectNodes(d *toolkit.IsoDiagram, ids ...string)

SelectNodes makes ids the widget's multi-selection by appending a node reference for each onto the authoritative selection list, so every one of them draws its accent top-face outline. Appending to the observable list is the documented public equivalent of the widget's internal select — it is what a host binds a "N items selected" panel to.

func Theme

func Theme() *toolkit.Theme

Theme is the palette every scene renders with. Using one shared theme keeps the demo's rendering deterministic and lets the test predict theme-derived colours (surface, accent) exactly.

Types

type Capture

type Capture struct {
	// Name is the PNG file name written into the output directory.
	Name string
	// Widget is the scene rendered into that file.
	Widget toolkit.Widget
}

Capture names one showcase image and the widget that renders it.

func Captures

func Captures() []Capture

Captures builds every showcase scene and returns them paired with the file name each is written to, in a stable order:

  • scene.png — the full diagram, both layers visible.
  • layer-hidden.png — the same diagram with the monitor layer hidden.
  • selection.png — the full diagram with a multi-node selection active.
  • crdt-replica-a.png — replica A after CRDT convergence.
  • crdt-replica-b.png — replica B after CRDT convergence (identical to A).

It is the shared source of truth for both Generate (which writes the files) and the test (which renders and asserts on the same widgets).

Directories

Path Synopsis
cmd
isodemo command
Command isodemo renders the toolkit's isometric-diagram showcase to PNG files.
Command isodemo renders the toolkit's isometric-diagram showcase to PNG files.

Jump to

Keyboard shortcuts

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