DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsGraph

DwsNetworkGraph draws nodes and the links between them, at the positions the data gives or - for nodes without coordinates - at positions it works out itself. It scales down to the width it gets and moves the legend below the drawing on narrow screens; hovering, focusing or selecting a node highlights its neighbours and shows its details.

API Reference

Network graph

Node positions refer to a Width x Height coordinate space (800 x 600 by default). The drawing is shown at most Width pixels wide and shrinks with its container, keeping the ratio. Nodes and legend use theme colors, so the graph follows the light and dark theme.

  • API Gateway
  • Auth
  • Users
  • Orders
  • Message Queue
  • Database
  • Cache
Show Code
Graph.razor

<DwsNetworkGraph Name='GraphDemo_Network_Basic' GraphData='@_networkGraphData' Width='800' Height='540' />
Graph.razor.cs

private readonly DwsGraphData _networkGraphData = new()
{
    Nodes =
    [
        new DwsGraphNode { Id = "gateway", Label = "API Gateway", X = 400, Y = 70, ThemeColor = DwsColor.Primary,
                           Description = "Entry point for all client requests.",
                           Metadata = new() { ["Region"] = "eu-central", ["Replicas"] = "3" } },
        new DwsGraphNode { Id = "auth", Label = "Auth", X = 170, Y = 200, ThemeColor = DwsColor.Info },
        new DwsGraphNode { Id = "db", Label = "Database", X = 200, Y = 450, ThemeColor = DwsColor.Secondary },
        // ...
    ],
    Links =
    [
        new DwsGraphLink { Source = "gateway", Target = "auth" },
        new DwsGraphLink { Source = "auth", Target = "db" },
        // ...
    ],
};

Theme colors

NodeColor, LinkColor, LabelColor and BackgroundColor take theme colors. A node's own ThemeColor (or any CSS Color) and a link's Color override them for that element.

  • A
  • B
  • C (Error)
  • D (#8e44ad)
  • E
Show Code
Graph.razor

@foreach (DwsColor color in _nodeColors)
{
    <DwsButton Name='@($"GraphDemo_Theme_{color}")' Appearance='@(color == _nodeColor ? DwsAppearance.Filled : DwsAppearance.Outline)'
               ButtonSize='DwsSize.Small' OnClick='@(() => _nodeColor = color)'>@color</DwsButton>
}

<DwsNetworkGraph Name='GraphDemo_Network_Theme' GraphData='@_themedGraphData' Width='600' Height='300'
                 NodeColor='_nodeColor' LinkColor='DwsColor.Secondary' NodeRadius='9' />
Graph.razor.cs

private DwsColor _nodeColor = DwsColor.Primary;
private static readonly DwsColor[] _nodeColors = [DwsColor.Primary, DwsColor.Secondary, DwsColor.Info, DwsColor.Accent];

// Nodes without an own color follow NodeColor; "c" has its own theme color and "d" a CSS color.
private readonly DwsGraphData _themedGraphData = new()
{
    Nodes =
    [
        new DwsGraphNode { Id = "a", Label = "A", X = 80, Y = 150 },
        new DwsGraphNode { Id = "b", Label = "B", X = 230, Y = 70 },
        new DwsGraphNode { Id = "c", Label = "C (Error)", X = 230, Y = 230, ThemeColor = DwsColor.Error },
        new DwsGraphNode { Id = "d", Label = "D (#8e44ad)", X = 400, Y = 150, Color = "#8e44ad" },
        new DwsGraphNode { Id = "e", Label = "E", X = 540, Y = 250 },
    ],
    Links =
    [
        new DwsGraphLink { Source = "a", Target = "b" },
        new DwsGraphLink { Source = "a", Target = "c" },
        new DwsGraphLink { Source = "b", Target = "d" },
        new DwsGraphLink { Source = "c", Target = "d", Color = DwsColor.Error },
        new DwsGraphLink { Source = "d", Target = "e" },
        // Refers to a node that does not exist: skipped and logged once.
        new DwsGraphLink { Source = "e", Target = "missing" },
    ],
};

Directed links and link labels

A link with Directed gets an arrowhead that ends at the edge of the dot it points to (Directed on the graph makes every link directed; ShowArrowheads switches the arrowheads off), a link with a Label shows it at the middle of its line (ShowLinkLabels), and the detail of a node lists both as text. The two Layered layouts put every link one layer down (or to the right); the link that closes the cycle here points back up.

Show Code
Graph.razor
<DwsSwitch Name='GraphDemo_Links_Labels' @bind-Value='_showLinkLabels' Label='ShowLinkLabels' />
<DwsSwitch Name='GraphDemo_Links_Arrows' @bind-Value='_showArrowheads' Label='ShowArrowheads' />
<DwsSwitch Name='GraphDemo_Links_LeftRight' @bind-Value='_linksLeftRight' Label='Left to right' />

<DwsNetworkGraph Name='GraphDemo_Links' GraphData='@_pipelineGraphData' Width='760' Height='420' WithLegend='false'
                 Layout='@(_linksLeftRight ? DwsNetworkGraphLayout.LayeredLeftRight : DwsNetworkGraphLayout.LayeredTopDown)'
                 ShowLinkLabels='@_showLinkLabels' ShowArrowheads='@_showArrowheads' />
Graph.razor.cs
// No X / Y: the layered layout places the nodes. Directed draws an arrowhead, Label a text on the link.
private readonly DwsGraphData _pipelineGraphData = new()
{
    Nodes =
    [
        new DwsGraphNode { Id = "commit", Label = "Commit" },
        new DwsGraphNode { Id = "build", Label = "Build" },
        new DwsGraphNode { Id = "production", Label = "Production" },
    ],
    Links =
    [
        new DwsGraphLink { Source = "commit", Target = "build", Directed = true, Label = "triggers" },
        new DwsGraphLink { Source = "build", Target = "production", Directed = true },
        new DwsGraphLink { Source = "production", Target = "build", Directed = true, Label = "rollback", Color = DwsColor.Error },
    ],
};

private bool _showLinkLabels = true;
private bool _showArrowheads = true;
private bool _linksLeftRight;

Loading, caption and empty

IsLoading shows a spinner in place of the drawing while the data is on its way. Caption puts a sentence under the chart - what it shows, the source - and screen readers describe the drawing with it. EmptyContent replaces the empty text when there is nothing to draw; without it NoDataText or the localized default is shown, as in the last example. Links that refer to a missing node are skipped and logged once as a warning.

  • API Gateway
  • Auth
  • Users
  • Orders
  • Message Queue
  • Database
  • Cache

Services and the services they call.

No services are registered yet.
No nodes to display.
Show Code
Graph.razor
<DwsSwitch Name='GraphDemo_States_Loading' @bind-Value='_statesLoading' Label='IsLoading' Class='mb-2' />
<DwsNetworkGraph Name='GraphDemo_States_Chart' GraphData='@_networkGraphData' Width='800' Height='540' IsLoading='@_statesLoading' Caption='Services and the services they call.' />

<!-- Nothing to draw: your own content -->
<DwsNetworkGraph Name='GraphDemo_States_EmptyContent' GraphData='null' Width='800' Height='200' Class='mt-3'>
    <EmptyContent>
        <span>No services are registered yet.</span>
    </EmptyContent>
</DwsNetworkGraph>

<!-- Nothing to draw, no EmptyContent: NoDataText or the localized default -->
<DwsNetworkGraph Name='GraphDemo_Network_Empty' GraphData='null' Width='600' Height='200' />
Graph.razor.cs
private bool _statesLoading;

Disabled

A disabled graph is dimmed and its nodes do not react to the pointer or keyboard.

  • A
  • B
  • C (Error)
  • D (#8e44ad)
  • E
Show Code
Graph.razor

<DwsNetworkGraph Name='GraphDemo_Network_Disabled' GraphData='@_themedGraphData' Width='600' Height='300' Disabled='true' />
Graph.razor.cs

// Nodes without an own color follow NodeColor; "c" has its own theme color and "d" a CSS color.
private readonly DwsGraphData _themedGraphData = new()
{
    Nodes =
    [
        new DwsGraphNode { Id = "a", Label = "A", X = 80, Y = 150 },
        new DwsGraphNode { Id = "b", Label = "B", X = 230, Y = 70 },
        new DwsGraphNode { Id = "c", Label = "C (Error)", X = 230, Y = 230, ThemeColor = DwsColor.Error },
        new DwsGraphNode { Id = "d", Label = "D (#8e44ad)", X = 400, Y = 150, Color = "#8e44ad" },
        new DwsGraphNode { Id = "e", Label = "E", X = 540, Y = 250 },
    ],
    Links =
    [
        new DwsGraphLink { Source = "a", Target = "b" },
        new DwsGraphLink { Source = "a", Target = "c" },
        new DwsGraphLink { Source = "b", Target = "d" },
        new DwsGraphLink { Source = "c", Target = "d", Color = DwsColor.Error },
        new DwsGraphLink { Source = "d", Target = "e" },
        // Refers to a node that does not exist: skipped and logged once.
        new DwsGraphLink { Source = "e", Target = "missing" },
    ],
};

DwsNetworkGraph

Interface-Description

Name Typ Parameters Description
GetNodePosition(string nodeId) (double X, double Y)? Where the node is drawn in the coordinate space: the position the layout gave it, or its own X / Y. Null for an id the graph does not show.
ResetNodePositionsAsync Task Forgets where the user moved nodes to: every node is drawn where its X / Y or the layout puts it again.
ResetZoomAsync Task Shows everything again.
ZoomToAsync Task Shows the part between the given ends (in the units of the drawing (Width by Height, y downwards)); cut back to the whole range and to MaxZoom. Works without AllowZoom too. IsZoomed tells whether the view is zoomed.
Name Typ Default Description
GraphData DwsGraphData? null Nodes (Id, Label, X, Y, ThemeColor, Color, Radius, Description, Metadata, Data) and links (Source, Target, Value, Color, Label, Directed). Without nodes a localised message is shown. Links to a missing node and duplicate node ids are skipped and logged once as a warning.
EmptyContent RenderFragment? null Shown instead of the graph when there is nothing to draw; null shows the localized empty text.
IsLoading bool false The data is still loading: a spinner instead of the graph.
Caption string? null A sentence under the graph (what it shows, the source); the graph is described by it (aria-describedby).
Layout DwsNetworkGraphLayout DwsNetworkGraphLayout.Auto How the nodes are placed. Auto: nodes with a position keep it, nodes without one (X and Y both 0) are placed by a deterministic force-directed layout around them. Manual: every node at its X / Y, also at (0, 0). Force: every node placed by the force-directed layout, X / Y ignored. Circle: every node on a circle in data order. LayeredTopDown / LayeredLeftRight: every node in a layer (rows from the top, or columns from the left), one layer after the last node that links to it; a link that closes a cycle points back, nodes without links share the first layer, and inside a layer the nodes are ordered by their neighbours to keep crossings low. The layout never writes to the nodes; GetNodePosition returns where a node is drawn.
Width int 800 Width of the coordinate space the node positions refer to, and the largest width the drawing is shown at in pixels. The drawing shrinks with its container and keeps the Width:Height ratio.
Height int 600 Height of the coordinate space.
NodeRadius double 6 Radius of a node dot in coordinate units; a node's own Radius overrides it. Every node gets a hit area of at least 12 units, so small dots stay easy to tap.
ShowLabels bool true Shows the node labels next to the dots.
AriaLabel string? null Text read by screen readers for the whole graph. Null uses the localised "Network graph".
WithLegend bool true Shows a legend with one entry per node. Entries highlight and select their node like the node itself.
LegendPosition DwsGraphLegendPosition DwsGraphLegendPosition.Right Right places the legend next to the drawing and moves it below when the graph is narrower than 576px. Bottom always places it below.
NodeColor DwsColor DwsColor.Primary Theme color of nodes that set neither ThemeColor nor Color.
LinkColor DwsColor DwsColor.Undefined Theme color of the links; a link's own Color overrides it. Undefined uses a muted text color.
LabelColor DwsColor DwsColor.Undefined Theme color of the node labels. Undefined uses the text color.
BackgroundColor DwsColor DwsColor.Undefined Theme color behind the drawing. Undefined uses the page background.
HighlightNeighbors bool true Dims everything but the hovered, focused or selected node, its links and its direct neighbours.
ShowNodeDetail bool true Shows the details of the hovered or focused node next to it, and of the selected node until it is deselected.
NodeDetailTemplate RenderFragment<DwsGraphNode>? null Content of the node detail. Null shows the label, Description, Metadata and number of connections.
AllowSelection bool true A click on a node (or Enter/Space on a focused one) selects it; clicking it again, the empty drawing or Escape deselects it.
SelectedNodeId string? null Id of the selected node. Bind it with @bind-SelectedNodeId.
ShowLinkLabels bool true Shows the Label of the links that have one at the middle of the line (HTML, so it keeps its size). The text is also listed in the detail of both nodes.
ShowArrowheads bool true Draws an arrowhead at the target end of directed links (DwsGraphLink.Directed, or all links with Directed). The tip lies on the edge of the target dot.
Directed bool false Treats every link as directed, from its Source to its Target.
ArrowSize double 10 Length of an arrowhead in coordinate units; it is 0.7 times as wide.
AllowNodeDrag bool false Lets the user move single nodes: by dragging, or with the keyboard (Space picks the focused node up, the arrow keys move it - with Shift in single units -, Space or Enter drops it, Escape or leaving the node puts it back). Space then no longer selects a node; Enter and a click still do. A moved node stays where it was dropped and the automatic layout is not run again while the same nodes are shown. The nodes themselves are not written to. Needs interactivity for the pointer.
KeyboardDragStep double 10 How far an arrow key moves a node that was picked up, in coordinate units.
AllowZoom bool false Lets the user zoom and move the view: Ctrl / Cmd + wheel (the plain wheel while the plot has the keyboard focus), pinch, drag, and on the keyboard + / - / 0 and - with the focus on the plot itself - the arrow keys. The plot becomes a Tab stop. Needs interactivity.
MaxZoom double 8 How far the user can zoom in: the smallest part shown is one in this many, on each axis.
ShowZoomReset bool true Shows a button in the corner that shows everything again, while the view is zoomed.
Name Typ Description
OnNodeMoved EventCallback<DwsGraphNodeMovedEventArgs> Raised when the user dropped a node at a new place: Node, X, Y, PreviousX, PreviousY and ByKeyboard.
OnZoomChanged EventCallback<DwsChartZoomEventArgs> Raised when the part shown changed, by the user or a method: XMin, XMax, YMin, YMax (in the units of the drawing (Width by Height, y downwards)) and IsZoomed.
SelectedNodeIdChanged EventCallback<string?> Fired when a node is selected or deselected. Used by @bind-SelectedNodeId.
OnNodeClick EventCallback<DwsGraphNodeEventArgs> Fired when a node or its legend entry is clicked, or a focused node is activated with Enter/Space (OriginalEvent is null then). Not fired while disabled or in permission register mode.
OnNodeMouseEnter EventCallback<DwsGraphNodeEventArgs> Fired when the pointer enters a node or its legend entry, or the node gets keyboard focus.
OnNodeMouseLeave EventCallback<DwsGraphNodeEventArgs> Fired when the pointer leaves a node or its legend entry, or the node loses keyboard focus.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.