NE.Standard.UI.Graph

Layered graph

public RecursiveCollection<UIGraphNode> Modules { get; } =
[
    new("storage") { Title = "Storage", Description = "Tables and files", Icon = MaterialIcons.Storage, Links = [new("storage>runtime", "runtime")] },
    new("runtime") { Title = "Runtime", BadgeTitle = "3" }
];

new LayeredGraphComponent("dependencies")
    .BindItems(nameof(Controller.Modules))
    .SetFormId("layout")
    .BindValue(nameof(Controller.Layout), mode: UIBindingMode.OnSubmit)
    .SetDirection(UIGraphDirection.TopToBottom)
    .OnNodeClick(nameof(Controller.ModuleClicked));

LayeredGraphComponent draws a bound collection of UIGraphNodes as cards — a title and a second line (Description), an icon or a picture (Image), a colour, a badge and a tooltip — and every UIGraphLink a node carries as an edge with an arrow and a caption. A node whose Shape is Icon is a circle holding its picture, or its icon when it has none, with its title standing under it — and read again under the pointer — and its badge on the rim; NodeShape on the graph is the shape of every node that names none. The nodes are the application's: a node added, changed or removed arrives while the page runs, and a change to a link is its node replaced (Links is set whole).

The layout is the layered one, left to right, right to left, top to bottom or bottom to top (Direction): the nodes stand in layers from what nothing links to towards what links to nothing, a cycle is broken at the edges that run back against the layers and those are drawn dashed, arced between the two nodes' facing sides. Only an edge on a cycle ever runs back, and a short cycle is broken where its layers run shortest, so a plant and its seed read seed, plant, product in one row; a node's edge to itself rises over the node from one side to the other. An edge longer than one layer is routed round the layers it crosses for as long as its two ends stand where the layout put them. Across the layers a node stands in line with one of what it is joined to rather than half way between two, and a long edge runs flat, so a chain reads as one row. Value is the layout document (UIGraphDocument): where the viewer dragged each node, the points an edge was bent through, and the groups. A node the document does not place is placed by the layout — all of them when no document is bound — and a node added while the page runs steps past what it would cover. Turning the direction, or changing the nodes' shape, lays out again every node still where the layout put it; one the viewer moved stays.

Editing the graph

EditStructure lets the viewer change the nodes and their links, beside moving them: Add node puts a node where the pointer was and names it at once; a node's menu renames and recolours it; a dot on the node's outgoing side, under the pointer, pulls a link to another node; the right button on an edge captions it or takes it out; Delete takes out what is chosen. A node's menu has Duplicate (Ctrl+D) — a copy under a key the canvas makes, as Add node makes one, a step off, with a link only to another copy — and Disconnect all, which takes out every link into and out of it. None of it reaches the application until the save: the document carries the draft — every node added or changed, whole, and the keys removed — and the save command applies it. The draft is the browser's, so ApplyTo holds it to what the canvas edits: it refuses it whole — nothing written, false answered — while editing is off or past its cap (maxNodes, 10 000), writes only a node's title, a colour of ColorChoices (or one a node already wears) and its links, and an added node keeps the rest only as a copy of one already there, as Duplicate makes.

[UICommand]
public void Save()
{
    if (!Layout.Draft.ApplyTo(Modules, EditStructure))
        return;

    Layout = Layout.WithoutDraft();
}

A node the application changed or removed while the viewer's own change to it waits is marked on the canvas, and its menu — an edge's, where a recipe is drawn as its edges — then carries the two answers: Take the server's lets the viewer's change to that node go, and Keep mine keeps it knowingly, tied to the node as the application now has it (one the application removed becomes one the viewer adds; one the viewer added under a key the application has since taken for a node of its own stays the viewer's, under another key, with its links and place). Left unanswered the viewer's change still stands, and saving writes it over the application's; UIGraphNodeDraft.Baseline is the node as the browser had it when the viewer began, for an application that wants to refuse or merge instead. A drafted node is its whole state, so there is no merge by field.