syncfusion/blazor-ui-components-skills / skills/syncfusion-blazor-diagram
syncfusion-blazor-diagram
VerifiedBuild and troubleshoot Syncfusion Blazor diagrams using SfDiagramComponent. Trigger for flowcharts, org charts, mind maps, BPMN, UML sequence, swimlanes, symbol palettes, nodes/connectors/ports/annotations, layouts, data binding, serialization (load/save), export/print, and collaborative editing questions. Provide Blazor + Syncfusion setup steps, configuration patterns, and sample snippets.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 28.6 KB |
| references/advanced-features.md | markdown | 10.0 KB |
| references/annotations.md | markdown | 11.9 KB |
| references/bpmn.md | markdown | 6.6 KB |
| references/collaborative-editing.md | markdown | 7.0 KB |
| references/connectors.md | markdown | 6.4 KB |
| references/data-binding.md | markdown | 12.8 KB |
| references/events.md | markdown | 52.7 KB |
| references/export-print.md | markdown | 5.9 KB |
| references/getting-started.md | markdown | 5.4 KB |
| references/interaction.md | markdown | 36.7 KB |
| references/layout.md | markdown | 12.3 KB |
| references/nodes.md | markdown | 8.6 KB |
| references/overview-component.md | markdown | 5.5 KB |
| references/ports.md | markdown | 5.1 KB |
| references/serialization.md | markdown | 3.5 KB |
| references/shapes.md | markdown | 6.2 KB |
| references/styling.md | markdown | 6.1 KB |
| references/swimlane.md | markdown | 6.1 KB |
| references/symbol-palette.md | markdown | 7.7 KB |
| references/uml-class-diagram.md | markdown | 25.5 KB |
| references/uml-sequence.md | markdown | 6.5 KB |
references/collaborative-editing.md
View on GitHub# Collaborative Editing in Blazor Diagram
Collaborative editing enables multiple users to edit the same diagram simultaneously in real time.
---
## Architecture
- **SignalR** handles real-time communication between the browser and server
- **Redis** (optional) acts as a shared temporary store for multi-server deployments
- Changes that trigger `HistoryChanged` are propagated to all connected clients
- **`GetDiagramUpdates(HistoryChangedEventArgs)`** — serializes the diagram change from `HistoryChangedEventArgs` into a `List<string>` for transmission
- **`SetDiagramUpdatesAsync(List<string>)`** — applies received serialized changes from other clients to the local diagram
---
## Setup Overview
Collaborative editing requires two parts:
1. **ASP.NET Core SignalR Hub** — receives and broadcasts diagram changes
2. **Blazor App** — connects to the hub and syncs the diagram component
---
## Step 1: Create the SignalR Hub (Server Project)
```csharp
// DiagramHub.cs
using Microsoft.AspNetCore.SignalR;
public class DiagramHub : Hub
{
private readonly IDiagramStateService _stateService;
public DiagramHub(IDiagramStateService stateService)
{
_stateService = stateService;
}
public async Task BroadcastDiagramAction(string action, string data)
{
// Broadcast to all OTHER connected clients (not the sender)
await Clients.Others.SendAsync("ReceiveDiagramAction", action, data);
// Store state (e.g., in Redis or in-memory)
await _stateService.SaveAsync(action, data);
}
public async Task<string> GetCurrentState()
{
return await _stateService.GetAsync();
}
}
```
**Register in `Program.cs`:**
```csharp
builder.Services.AddSignalR();
// ...
app.MapHub<DiagramHub>("/diagramhub");
```
---
## Step 2: Connect the Blazor App to the Hub
```razor
@using Microsoft.AspNetCore.SignalR.Client
@using Syncfusion.Blazor.Diagram
@implements IAsyncDisposable
<SfDiagramComponent @ref="_diagram"
@bind-Nodes="_nodes"
@bind-Connectors="_connectors"
HistoryChanged="OnHistoryChanged" />
@code {
private SfDiagramComponent _diagram;
private DiagramObjectCollection<Node> _nodes = new();
private DiagramObjectCollection<Connector> _connectors = new();
private HubConnection _hubConnection;
protected override async Task OnInitializedAsync()
{
_hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/diagramhub"))
.Build();
// Receive changes from other clients
_hubConnection.On<string, string>("ReceiveDiagramAction", async (action, data) =>
{
await _diagram.LoadDiagramAsync(data);
await InvokeAsync(StateHasChanged);
});
await _hubConnection.StartAsync();
// Load current diagram state on join
var state = await _hubConnection.InvokeAsync<string>("GetCurrentState");
if (!string.IsNullOrEmpty(state))
await _diagram.LoadDiagramAsync(state);
}
private async void OnHistoryChanged(HistoryChangedEventArgs args)
{
// Broadcast current state after each change
string currentState = _diagram.SaveDiagram();
await _hubConnection.SendAsync("BroadcastDiagramAction", args.Action.ToString(), currentState);
}
public async ValueTask DisposeAsync()
{
await _hubConnection.DisposeAsync();
}
}
```
---
## Optimized Sync with GetDiagramUpdates / SetDiagramUpdatesAsync
Instead of sending the full `SaveDiagram()` JSON on every change, use the optimized delta-based API:
- **`GetDiagramUpdates(HistoryChangedEventArgs)`** — serializes only the change described by the history event into a compact `List<string>`
- **`SetDiagramUpdatesAsync(List<string>)`** — applies a received delta update to the local diagram without a full reload
This approach is more efficient for real-time collaboration because it transmits only what changed, not the entire diagram state.
```razor
<SfDiagramComponent @ref="_diagram"
@bind-Nodes="_nodes"
@bind-Connectors="_connectors"
HistoryChanged="OnHistoryChanged" />
@code {
private SfDiagramComponent _diagram;
private HubConnection _hubConnection;
protected override async Task OnInitializedAsync()
{
_hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/diagramhub"))
.Build();
// Receive delta updates from other clients and apply them
_hubConnection.On<List<string>>("ReceiveDiagramUpdates", async (updates) =>
{
await _diagram.SetDiagramUpdatesAsync(updates);
await InvokeAsync(StateHasChanged);
});
await _hubConnection.StartAsync();
}
private async void OnHistoryChanged(HistoryChangedEventArgs args)
{
// Serialize only the delta change (not the whole diagram)
List<string> updates = _diagram.GetDiagramUpdates(args);
// Broadcast the compact delta to other clients
await _hubConnection.SendAsync("BroadcastDiagramUpdates", updates);
}
}
```
**Hub method for delta broadcast:**
```csharp
public async Task BroadcastDiagramUpdates(List<string> updates)
{
// Forward delta to all other connected clients
await Clients.Others.SendAsync("ReceiveDiagramUpdates", updates);
}
```
> **Tip:** Use the delta-based `GetDiagramUpdates`/`SetDiagramUpdatesAsync` pattern for production collaboration. The full `SaveDiagram`/`LoadDiagramAsync` approach is simpler but sends much larger payloads, causing higher latency for complex diagrams.
---
## Multi-Server (Scale-Out) Setup
For deployments with multiple server instances, configure a SignalR backplane so all nodes share messages:
```csharp
// In Program.cs — add Redis backplane
builder.Services.AddSignalR()
.AddStackExchangeRedis("localhost:6379");
```
Store shared diagram state in Redis instead of in-memory:
```csharp
// Use IConnectionMultiplexer to store/retrieve diagram JSON in Redis
```
---
## Limitations
The following settings are **NOT** synchronized across clients — they are local only:
| Unsynchronized Setting |
|------------------------|
| `PageSettings` |
| `ContextMenu` |
| `DiagramHistoryManager` |
| `SnapSettings` |
| `Rulers` |
| `UmlSequenceDiagram` model |
| `Layout` |
| `ScrollSettings` (zoom/pan) |
Zoom and pan are per-user and not broadcast.
---
## Common Gotchas
- **Only `HistoryChanged`-tracked actions are propagated** — programmatic changes that bypass undo/redo history are not broadcast
- **Two-way binding required** — use `@bind-Nodes` and `@bind-Connectors` so `LoadDiagramAsync` correctly updates the UI
- **Race conditions** — if two users edit simultaneously, the last broadcast wins; implement optimistic locking or versioning in the hub for conflict resolution
- **Single server works without Redis** — add Redis only for load-balanced multi-instance deployments
- **Complete working sample** available at: https://github.com/syncfusion/blazor-showcase-diagram-collaborative-editing
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |