# Blazor Diagram Component

URL: https://flexcoreui.com/demo/diagram  
Section: Components  
Controls: DiagramControl, DiagramNode, DiagramConnector  
Keywords: diagram, flowchart, workflow diagram, node connector diagram

Draw workflows in Blazor: DiagramControl renders nodes and labeled connectors as one inline SVG, with six node shapes and a click event.

## Documentation

### Params

| Name | Type | Default | Description |
|---|---|---|---|
| Nodes | List<DiagramNode>? | null | The boxes to draw, in list order. Each is placed by its own OffsetX and OffsetY; the control does no layout. Ids are matched case-insensitively. |
| Connectors | List<DiagramConnector>? | null | Lines between nodes, drawn behind them. A connector whose SourceId or TargetId matches no node is skipped. |
| Width | string | "100%" | A number of pixels ("460" or "460px") is the drawing area; the SVG and its frame are that plus the padding on both sides. A percentage or auto sizes the frame and makes the SVG 100% wide. The drawing never scales, and whatever lies past the frame is clipped. |
| Height | string | "500" | As Width, for the height. |
| CssClass | string? | null | Added to the outer fx-diagram div. |
| Padding | double | 18 | Space on every side, in pixels. Node coordinates start inside it, and with a pixel Width or Height it is added to that size. |
| SizePadPercent | double | 10 | More padding: this percentage of the larger pixel dimension, split between the two sides. Width 460, Height 530 and the default 10 would add 26.5 px a side. Only pixel sizes count; both examples set 0 and use Padding alone. |
| NodeClicked | EventCallback<DiagramNodeClickEventArgs> |  | Raised when an enabled node is clicked, before its NavigateUrl is followed; set Handled on the arguments to stay on the page. While it is bound, every enabled node gets fx-clickable and a pointer cursor. |

### Node

| Name | Type | Default | Description |
|---|---|---|---|
| Id | string | "" | The name connectors use in SourceId and TargetId, matched case-insensitively. A node with a BackgroundImage also uses it for the clip path id clip-Id, so keep it unique across diagrams on the same page. |
| OffsetX | double | 0 | Horizontal center of the node, in pixels from the left of the drawing area. Nothing is placed automatically. |
| OffsetY | double | 0 | Vertical center of the node, in pixels from the top of the drawing area. |
| Width | double | 140 | Width of the shape in pixels. |
| Height | double | 50 | Height of the shape in pixels. |
| Label | string | "" | Main text, centered, 13 px semibold in TextColor. \n starts a new line 15 px lower; the first line keeps the single-line position, so a multi-line label sits low. Text is not wrapped or clipped to the shape. |
| SubLabel | string? | null | Second line at 11 px, 16 px under the label, or 15 px under the last line of a multi-line label. The label moves up 6 px to make room. |
| Shape | DiagramControlShape | DiagramControlShape.Rectangle | Outline; see DiagramControlShape. |
| FillColor | string | "#4A90D9" | Shape fill; any SVG color. |
| StrokeColor | string | "#2C5F8A" | Outline color. |
| TextColor | string | "#FFFFFF" | Color of the label, sublabel and icon. |
| StrokeWidth | double | 2 | Outline width in pixels. |
| CornerRadius | double | 6 | Corner radius of Rectangle and RoundedRectangle alike; set 0 for square corners. Other shapes ignore it. |
| NavigateUrl | string? | null | Followed with NavigationManager.NavigateTo when the node is clicked, after NodeClicked unless that set Handled. A relative URL resolves against the base href. It makes the node clickable even without NodeClicked. |
| CssClass | string? | null | Added to the node's <g>. Style it from the page through ::deep; the first example uses .canvas ::deep .wf-current :is(rect, ellipse, polygon) { stroke: #0f172a; stroke-width: 4px; }. |
| Tooltip | string? | null | Rendered as an SVG <title>, which browsers show on hover. |
| Icon | string? | null | Short text, an emoji or one character, drawn at 16 px above the label; the label moves down to make room. |
| BackgroundImage | string? | null | Image URL drawn inside the shape and clipped to it. The label then moves 14 px below the node, outside the shape, so its TextColor has to read against the canvas. |
| BackgroundImageOpacity | double | 1.0 | Opacity of the image, 0 to 1. |
| BackgroundImageFit | ImageFit | ImageFit.Contain | How the image fills the node; see ImageFit. |
| BackgroundImagePadding | double | 4 | Inset in pixels between the node edge and a Contain or Icon image; Cover ignores it. |
| Enabled | bool | true | False fades the node to 45% opacity, turns off its pointer events (no click, hover or tooltip) and draws a 16 px close icon on its top-right corner. Connectors still attach to it. |

### Connector

| Name | Type | Default | Description |
|---|---|---|---|
| Id | string | "" | Names the arrowhead marker arrow-Id. Marker ids are shared by the whole page, so give every connector a distinct Id, across diagrams too; connectors with the same Id all use the first such marker, color included. |
| SourceId | string | "" | Id of the node at the start. |
| TargetId | string | "" | Id of the node at the arrow end. |
| Type | ConnectorType | ConnectorType.Orthogonal | Right-angle path or straight line; see ConnectorType. |
| StrokeColor | string | "#555555" | Line and arrowhead color. |
| StrokeWidth | double | 2 | Line width in pixels; the arrowhead scales with it. |
| Label | string? | null | Text on a white box at 90% opacity, at the midpoint of a straight line or of the middle segment of an orthogonal one (at the bend of a one-bend path). The box is sized at 7 px per character. |
| LabelColor | string | "#333333" | Label text color. |
| ShowArrow | bool | true | Draws the arrowhead at the target end; the line is pulled back 6 px toward the source to make room for it. |
| DashArray | string? | null | SVG stroke-dasharray, such as "6,4"; null draws a solid line. |
| SourcePort | DiagramPort | DiagramPort.Auto | Side of the start node the line leaves from. Auto picks top or bottom when the two centers are further apart vertically than horizontally, otherwise left or right. |
| TargetPort | DiagramPort | DiagramPort.Auto | Side of the end node the line arrives at, chosen the same way. |
| ArrowStyle | ArrowStyle | ArrowStyle.Open | Open chevron or closed triangle; see ArrowStyle. |
| IsBroken | bool | false | Draws the connector and its arrowhead gray (#a0a0a0), 1.5 px wide and dashed 3,3, overriding StrokeColor, StrokeWidth and DashArray. |

### Click args

| Name | Type | Default | Description |
|---|---|---|---|
| Node | DiagramNode |  | The node that was clicked. |
| Handled | bool | false | Set it to true in the handler to stop the control following the node's NavigateUrl. |

### Shapes

| Name | Description |
|---|---|
| Rectangle | A rect with its corners rounded by CornerRadius (6 unless set), drawn exactly like RoundedRectangle. |
| RoundedRectangle | The same drawing as Rectangle. |
| Ellipse | An ellipse filling the Width × Height box. |
| Diamond | Points at the middle of each edge of the Width × Height box. |
| Parallelogram | The top-left and bottom-right corners are pulled in 15 px; the slant is fixed. |
| Stadium | A rect with a corner radius of half the Height: straight sides, round ends. |

### Types

| Name | Description |
|---|---|
| Straight | One line from port to port. |
| Orthogonal | Right angles only. Two top or bottom ports: out to the halfway line, across, and in. Two left or right ports: across, up or down, across. A top or bottom source with a left or right target: one bend. A left or right source with a top or bottom target is drawn like two left or right ports and meets the target side-on. |

### Ports

| Name | Description |
|---|---|
| Auto | The side facing the other node, as described under SourcePort / TargetPort. |
| Top | Middle of the top edge. |
| Bottom | Middle of the bottom edge. |
| Left | Middle of the left edge. |
| Right | Middle of the right edge. |

### Arrows

| Name | Description |
|---|---|
| Open | Two strokes meeting at the tip. |
| Closed | A filled triangle. |

### Fits

| Name | Description |
|---|---|
| Contain | Scaled to fit inside the padded box and centered (xMidYMid meet). |
| Cover | Scaled to cover the whole node and cropped to its shape (xMidYMid slice); padding is ignored. |
| Icon | Described in the source as natural size, but drawn exactly like Contain: the same padded box and meet. |

### Css

| Name | Description |
|---|---|
| fx-diagram | Outer div. The stylesheet gives it a #fafbfc background and a 6 px radius; the control's inline style sets its size, a 1 px #c7d6ea border and overflow: hidden. |
| fx-diagram-node | Each node's <g>; opacity and filter change over 0.15 s. Every node also carries a light drop shadow, filter="url(#fx-shadow)". |
| fx-clickable | On an enabled node that has a NavigateUrl, or on every enabled node while NodeClicked is bound: 85% opacity and slightly brighter on hover, 70% while pressed. |
| fx-disabled | On a node with Enabled false: 45% opacity and pointer-events: none. |
| fx-node-label · fx-node-sublabel · fx-node-icon | Label 13 px weight 600; sublabel 11 px weight 400 at 85% opacity; icon 16 px. Each size is multiplied by --fx-zoom, and none of them takes pointer events. |
| fx-node-bg-image | The background <image>; no pointer events. |
| fx-diagram-connector | Each connector's <g>: line, label box and label. No pointer events. |
| fx-connector-label | Connector label text, 11 px times --fx-zoom. |

### Vars

| Name | Type | Description |
|---|---|---|
| --fx-zoom | 1 | Multiplies the font size of node labels, sublabels, icons and connector labels. Shapes, positions and the connector label box do not change. |

## Examples

### Workflow

```razor
@using Fx.ControlKit
@using Fx.ControlKit.Diagram

<div class="wf-layout">
    <div class="canvas">
        <DiagramControl Nodes="_workflowNodes" Connectors="_workflowConnectors" Width="460" Height="530"
                        Padding="12" SizePadPercent="0" NodeClicked="OnStepClicked" />
    </div>
    <CardControl CssClass="wf-panel" Title="@Current.Label" Subtitle="@CurrentStep.Owner" aria-live="polite">
        <ChildContent>
            <dl class="wf-facts">
                <dt>Typical time</dt>
                <dd>@CurrentStep.Typical</dd>
                <dt>What happens</dt>
                <dd>@CurrentStep.Detail</dd>
            </dl>
        </ChildContent>
        <FooterContent>
            <div class="wf-buttons">
                <ButtonControl OnClick="() => Move(-1)" Disabled="@(Index == 0)">Previous step</ButtonControl>
                <ButtonControl OnClick="() => Move(1)" Disabled="@(Index == _workflowNodes.Count - 1)">Next step</ButtonControl>
            </div>
        </FooterContent>
    </CardControl>
</div>
```

```csharp
// Workflow
private sealed record Step(string Owner, string Typical, string Detail);

private static readonly Dictionary<string, Step> Steps = new()
{
    ["arrival"] = new("Dock office", "10 minutes", "The driver hands in the delivery note; the office finds the purchase order and assigns one of the six docks."),
    ["unload"] = new("Receiving team", "30 minutes", "Pallets come off the trailer at the assigned dock and are counted against the delivery note."),
    ["inspect"] = new("Receiving lead", "15 minutes", "Cartons are checked for damage and the count is compared with the purchase order; the lead accepts or rejects the delivery."),
    ["received"] = new("Receiving team", "Same shift", "The accepted quantities are posted to the purchase order and every pallet gets a putaway label."),
    ["putaway"] = new("Forklift drivers", "Within 4 hours", "Each pallet goes to a bin in the Ambient, Chilled or Bulk zone and is scanned into that location."),
    ["available"] = new("Inventory control", "Right after putaway", "The stock shows as available to pick and the purchase order line is closed."),
    ["rejected"] = new("Dock office", "Same day", "The office records the reason on the purchase order and the pallets are reloaded for return to the supplier."),
};

private readonly List<DiagramNode> _workflowNodes = new()
{
    new() { Id = "arrival", Label = "Truck checked in", Shape = DiagramControlShape.Stadium, OffsetX = 100, OffsetY = 24, Width = 170, Height = 44, FillColor = "#0f766e", StrokeColor = "#134e4a" },
    new() { Id = "unload", Label = "Pallets unloaded", OffsetX = 100, OffsetY = 104, Width = 170, Height = 48, FillColor = "#2563eb", StrokeColor = "#1e3a8a" },
    new() { Id = "inspect", Label = "Goods inspected", Shape = DiagramControlShape.Diamond, OffsetX = 100, OffsetY = 202, Width = 170, Height = 80, FillColor = "#fbbf24", StrokeColor = "#b45309", TextColor = "#1f2937" },
    new() { Id = "received", Label = "Receipt posted", OffsetX = 100, OffsetY = 344, Width = 170, Height = 48, FillColor = "#2563eb", StrokeColor = "#1e3a8a" },
    new() { Id = "putaway", Label = "Put away", OffsetX = 100, OffsetY = 426, Width = 170, Height = 48, FillColor = "#2563eb", StrokeColor = "#1e3a8a" },
    new() { Id = "available", Label = "Stock available", Shape = DiagramControlShape.Stadium, OffsetX = 100, OffsetY = 506, Width = 170, Height = 44, FillColor = "#0f766e", StrokeColor = "#134e4a" },
    new() { Id = "rejected", Label = "Sent back", Shape = DiagramControlShape.Stadium, OffsetX = 380, OffsetY = 202, Width = 120, Height = 44, FillColor = "#fee2e2", StrokeColor = "#b91c1c", TextColor = "#991b1b" },
};

private readonly List<DiagramConnector> _workflowConnectors = new()
{
    new() { Id = "wf-1", SourceId = "arrival", TargetId = "unload" },
    new() { Id = "wf-2", SourceId = "unload", TargetId = "inspect" },
    new() { Id = "wf-3", SourceId = "inspect", TargetId = "received", Label = "accepted", StrokeColor = "#15803d", LabelColor = "#15803d" },
    new() { Id = "wf-4", SourceId = "inspect", TargetId = "rejected", Label = "rejected", StrokeColor = "#b91c1c", LabelColor = "#b91c1c", DashArray = "6,4" },
    new() { Id = "wf-5", SourceId = "received", TargetId = "putaway" },
    new() { Id = "wf-6", SourceId = "putaway", TargetId = "available" },
};

private string _currentId = "arrival";

private int Index => _workflowNodes.FindIndex(n => n.Id == _currentId);

private DiagramNode Current => _workflowNodes[Index];

private Step CurrentStep => Steps[_currentId];

protected override void OnInitialized() => ShowStep("arrival");

private void OnStepClicked(DiagramNodeClickEventArgs e) => ShowStep(e.Node.Id);

private void Move(int delta) => ShowStep(_workflowNodes[Math.Clamp(Index + delta, 0, _workflowNodes.Count - 1)].Id);   // main path, then the rejected branch; no wrap

private void ShowStep(string id)
{
    _currentId = id;
    foreach (var node in _workflowNodes)
        node.CssClass = node.Id == id ? "wf-current" : null;
}
```

### Shapes

```razor
@using Fx.ControlKit
@using Fx.ControlKit.Diagram

<div class="controls">
    <SwitchControl @bind-Checked="_followLinks" Label="Follow links" />
    <a href="demo/barcodes#barcode">Bin tag example</a>
</div>
<div class="canvas">
    <DiagramControl Nodes="_shapeNodes" Connectors="_shapeConnectors" Width="550" Height="330"
                    Padding="12" SizePadPercent="0" NodeClicked="OnShapeClicked" />
</div>
<p class="status" aria-live="polite">@_status</p>
```

```csharp
// Shapes, connectors and links
private bool _followLinks;

private string _status = "No node clicked yet.";

private readonly List<DiagramNode> _shapeNodes = new()
{
    new() { Id = "scan", Label = "Bin tag scanned", SubLabel = "Stadium", Shape = DiagramControlShape.Stadium, OffsetX = 75, OffsetY = 45, Width = 150, Height = 50,
            FillColor = "#0f766e", StrokeColor = "#134e4a", NavigateUrl = "demo/barcodes#barcode", Tooltip = "Opens the bin tag example on the Barcodes & QR page" },
    new() { Id = "quantity", Label = "Quantity entered", SubLabel = "Parallelogram", Shape = DiagramControlShape.Parallelogram, OffsetX = 275, OffsetY = 45, Width = 150, Height = 50,
            FillColor = "#2563eb", StrokeColor = "#1e3a8a" },
    new() { Id = "chilled", Label = "Chilled item?", SubLabel = "Diamond", Shape = DiagramControlShape.Diamond, OffsetX = 475, OffsetY = 45, Width = 150, Height = 84,
            FillColor = "#fbbf24", StrokeColor = "#b45309", TextColor = "#1f2937" },
    new() { Id = "coldpack", Label = "Cold pack added", SubLabel = "Rectangle, radius 0", OffsetX = 475, OffsetY = 200, Width = 150, Height = 50, CornerRadius = 0,
            FillColor = "#2563eb", StrokeColor = "#1e3a8a" },
    new() { Id = "slip", Label = "Packing slip", SubLabel = "RoundedRectangle", Icon = "✉", Shape = DiagramControlShape.RoundedRectangle, OffsetX = 275, OffsetY = 200, Width = 150, Height = 60, CornerRadius = 14,
            FillColor = "#2563eb", StrokeColor = "#1e3a8a" },
    new() { Id = "shipped", Label = "Shipped", SubLabel = "Ellipse", Icon = "✔", Shape = DiagramControlShape.Ellipse, OffsetX = 75, OffsetY = 200, Width = 150, Height = 64,
            FillColor = "#0f766e", StrokeColor = "#134e4a", Tooltip = "Pickup times are on the dock schedule" },
    new() { Id = "proof", Label = "Proof of delivery", SubLabel = "Enabled = false", Shape = DiagramControlShape.RoundedRectangle, OffsetX = 75, OffsetY = 300, Width = 150, Height = 50,
            FillColor = "#475569", StrokeColor = "#334155", Enabled = false },
};

private readonly List<DiagramConnector> _shapeConnectors = new()
{
    new() { Id = "sh-1", SourceId = "scan", TargetId = "quantity" },
    new() { Id = "sh-2", SourceId = "quantity", TargetId = "chilled", ArrowStyle = ArrowStyle.Closed },
    new() { Id = "sh-3", SourceId = "chilled", TargetId = "coldpack", Label = "yes" },
    new() { Id = "sh-4", SourceId = "chilled", TargetId = "slip", Label = "no", Type = ConnectorType.Straight, SourcePort = DiagramPort.Bottom, TargetPort = DiagramPort.Top },
    new() { Id = "sh-5", SourceId = "coldpack", TargetId = "slip", DashArray = "6,4" },
    new() { Id = "sh-6", SourceId = "slip", TargetId = "shipped", StrokeColor = "#0f766e", StrokeWidth = 3 },
    new() { Id = "sh-7", SourceId = "shipped", TargetId = "proof", IsBroken = true },
};

private void OnShapeClicked(DiagramNodeClickEventArgs e)
{
    e.Handled = !_followLinks;
    _status = e.Node.NavigateUrl is { } url && e.Handled
        ? $"{e.Node.Label}: Handled is true, so {url} did not open."
        : $"{e.Node.Label} clicked.";
}
```

