DeepWorks Studios Blazor Component Library

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

DwsTreeGraph

Draws a hierarchy such as an org chart or a category tree. The graph lays the nodes out itself, so the data needs no coordinates. Wide trees scroll inside the component instead of the page, or scale down with FitToWidth. Colours come from the theme.

API Reference

Disabled

Disabled greys the graph out and ignores hover and clicks. A component the permission settings disable behaves the same, and in permission select mode a click selects the whole graph instead of a node. ShowDetails=false drops the detail panel (the tooltip then describes its node to screen readers); ShowTooltip=false drops the tooltip and gives each node its label as a native title.

Root
Child A
Child B
Show Code
TreeGraph.razor

<DwsTreeGraph Name='TreeGraphDemo_States_Disabled' GraphData='@_smallTree' FitToWidth='true' Disabled='true' ShowDetails='false' />
TreeGraph.razor.cs

private readonly DwsTreeGraphNode _smallTree = new()
{
    Id = "root", Label = "Root",
    Children = [Leaf("a", "Child A"), Leaf("b", "Child B")],
};

private static DwsTreeGraphNode Leaf(string id, string label) => new() { Id = id, Label = label };

Interface-Description

Name Typ Default Description
DwsTreeGraphNode.Id string "" Identifies the node for SelectedNodeId. Should be unique; duplicates are logged and select together.
DwsTreeGraphNode.Label string "" Text shown in the node and announced for it.
DwsTreeGraphNode.Description string? null Optional second line in the node, also shown in the detail panel.
DwsTreeGraphNode.Icon string? null Optional icon CSS class shown before the label.
DwsTreeGraphNode.Color DwsColor DwsColor.Undefined Theme colour of the node. Undefined uses NodeColor.
DwsTreeGraphNode.Group string? null Legend entry the node belongs to.
DwsTreeGraphNode.Disabled bool false The node cannot be hovered, focused, clicked or selected.
DwsTreeGraphNode.Data object? null Any consumer data, for use in NodeTemplate and DetailTemplate.
DwsTreeGraphNode.Children List<DwsTreeGraphNode> [] The child nodes.
DwsTreeGraphNode.HasUnloadedChildren bool false The node has children that are not in Children yet: it is drawn collapsed with an expand button and asks LoadChildren when expanded. The graph adds the result to Children and sets this to false. Ignored without LoadChildren.
Name Typ Parameters Description
ExpandNodeAsync Task string id Draws the children of the node with the given id, loading them first for a lazy node. Works for a node inside a collapsed subtree too.
CollapseNodeAsync Task string id Hides the subtree below the node with the given id.
ExpandAllAsync Task Draws every node that is loaded; lazy nodes stay collapsed.
CollapseAllAsync Task Collapses every node with children, so only the root is left.
ExpandToLevelAsync Task Draws the tree down to the given number of levels below the root (0 = only the root) and collapses everything deeper; lazy nodes stay collapsed.
IsNodeExpanded bool string id Whether the children of the node with the given id are drawn.
ClearSelectionAsync Task Clears the selection and raises SelectedNodeIdChanged.
ScrollToNodeAsync Task string id Scrolls the graph's own viewport (never the page) so the node with the given id sits in its middle. The graph does this by itself for the selected node or the root whenever a new tree, orientation or node size is laid out.
Name Typ Default Description
GraphData DwsTreeGraphNode? null The root node of the tree. The layout is computed from the hierarchy, so nodes carry no coordinates. null shows a localized empty text. A node listed twice, or inside its own subtree, is drawn at its first place only (with a warning).
EmptyContent RenderFragment? null Shown instead of the tree 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 tree.
Caption string? null A sentence under the tree (what it shows, the source); the tree is described by it (aria-describedby).
SelectedNodeId string? null Id of the selected node. Supports @bind-SelectedNodeId; bound, the parent owns the value, unbound the graph keeps its own.
Selectable bool true Clicking a node (or Enter / Space on it) selects it. When false, clicks only raise OnNodeClick.
Orientation DwsLayoutOrientation DwsLayoutOrientation.Vertical Vertical grows the tree top-down, Horizontal left-to-right.
NodeWidth int 160 Width of a node box in pixels at natural size. Not positive falls back to the default with a warning.
NodeHeight int 56 Height of a node box in pixels at natural size. Not positive falls back to the default with a warning.
LevelSpacing int 56 Gap between a parent and its children in pixels. Negative falls back to the default.
SiblingSpacing int 16 Gap between neighbouring nodes of one level in pixels. Negative falls back to the default.
FitToWidth bool false Scales the graph down to the available width instead of scrolling it; never beyond its natural size. Without it a wide tree scrolls inside the component and labels stay readable on small screens. Scaling also shrinks the expand / collapse buttons, so a Collapsible graph used on touch screens is better left scrolling.
MaxHeight int? null Maximum height of the drawing area in pixels; a taller tree scrolls vertically.
NodeColor DwsColor DwsColor.Primary Theme colour of nodes that do not set their own Color. Exposed to templates as --dws-tree-graph-node-color.
LinkColor DwsColor DwsColor.Undefined Theme colour of the connecting lines. Undefined uses a muted text colour.
HighlightPath bool true Highlights the path from the root to the hovered or focused node.
ShowLegend bool false Lists every node Group with its colour below the graph. Nodes without a group are left out; without any group no legend is shown.
ShowDetails bool true Shows a panel below the graph with the hovered, focused or selected node (in that order), or a hint when there is none.
ShowTooltip bool true Shows a tooltip at the node under the pointer, and at the node the keyboard focuses, with its full label, description, level, number of children and group. Escape hides it until another node is hovered or focused. Placed with CSS anchor positioning; browsers without it show no tooltip (the detail panel covers them). When false, each node carries its label as a native title instead.
TooltipTemplate RenderFragment<DwsTreeGraphNode>? null Replaces the content of the tooltip.
NodeTemplate RenderFragment<DwsTreeGraphNode>? null Replaces the content of every node box (icon, label and description).
DetailTemplate RenderFragment<DwsTreeGraphNode>? null Replaces the content of the detail panel for the active node.
MaxDepth int? null Draws only this many levels at first (1 is the root alone). A node whose children are left out shows a +n button with the number of nodes below it; a click on it, or Right arrow on the node, draws its children. Null (and 0 or less) draws the whole tree.
Collapsible bool false Gives every node with children a button that collapses and expands its subtree, and makes Right / Left work as in a tree view: Right expands a collapsed node (then moves to its first child), Left collapses an expanded one (then moves to the parent). The button is not a tab stop; aria-expanded on the node says the state.
ExpandedNodeIds IReadOnlyCollection<string>? null Ids of the nodes whose children are drawn. Supports @bind-ExpandedNodeIds. Null lets the graph keep the state itself, starting from MaxDepth; a collection is the only source - a node with children whose id is not in it is collapsed.
LoadChildren Func<DwsTreeGraphNode, Task<IEnumerable<DwsTreeGraphNode>>>? null Loads the children of a node marked HasUnloadedChildren when the user expands it. Meanwhile the node is busy (aria-busy, its button shows an ellipsis); an exception is reported through HandleError and shows an error on the node, whose button tries again.
Name Typ Description
SelectedNodeIdChanged EventCallback<string?> Raised when the user selects a node or ClearSelectionAsync runs.
OnNodeClick EventCallback<DwsTreeGraphNode> Raised when an enabled node is clicked, or activated with Enter or Space. Not raised while the graph is disabled or in permission select mode.
OnNodeHover EventCallback<DwsTreeGraphNode?> Raised when the pointer enters an enabled node, and with null when it leaves. Touch input does not hover.
ExpandedNodeIdsChanged EventCallback<IReadOnlyCollection<string>> Raised with the ids of all expanded nodes when the user expands or collapses one, or one of the expand / collapse methods runs.
OnExpandedChanged EventCallback<DwsTreeGraphExpandedEventArgs> Raised with the node and its new state when the user expands or collapses it (for a lazy node after its children were loaded).
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.