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/serialization.md
View on GitHub# Serialization in Blazor Diagram
Serialization is saving and loading the persistent state of a diagram (nodes, connectors, layout, styles) as a JSON string.
---
## Requirements: Two-Way Binding
**Always** use two-way binding (`@bind-`) for `Nodes` and `Connectors` when serialization is needed. Without `@bind-`, loaded data will not reflect in the UI:
```razor
<SfDiagramComponent @ref="_diagram"
@bind-Nodes="_nodes"
@bind-Connectors="_connectors" />
```
---
## Save Diagram to JSON String
```csharp
private SfDiagramComponent _diagram;
private string SaveDiagram()
{
string json = _diagram.SaveDiagram();
return json; // store in DB, localStorage, file, etc.
}
```
---
## Load Diagram from JSON String
```csharp
private async Task LoadDiagram(string json)
{
await _diagram.LoadDiagramAsync(json);
}
```
---
## Save and Load via File Download/Upload
To let users download the diagram as a `.json` file and upload it back:
**C# side:**
```csharp
@inject IJSRuntime jsRuntime
private async Task SaveToFile()
{
string data = _diagram.SaveDiagram();
// Invoke JS to trigger browser download
await jsRuntime.InvokeAsync<object>("saveDiagram", data, "my-diagram");
}
private async Task LoadFromFile()
{
_diagram.BeginUpdate();
// Invoke JS to open file picker; file content flows back via a JS interop callback
await jsRuntime.InvokeAsync<object>("click");
await _diagram.EndUpdateAsync();
}
```
**JavaScript side (in wwwroot or _Host):**
```javascript
function saveDiagram(data, fileName) {
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(data);
const a = document.createElement('a');
a.href = dataStr;
a.download = fileName + '.json';
document.body.appendChild(a);
a.click();
a.remove();
}
function click() {
document.getElementById('UploadFiles').click();
}
```
---
## Load Classic SfDiagram JSON into SfDiagramComponent
When migrating from the legacy `SfDiagram` component, load its serialized JSON with `isClassicData = true`:
```csharp
// Old SfDiagram serialized string:
string classicJson = legacyDiagram.SaveDiagram();
// Load into new SfDiagramComponent:
await _diagram.LoadDiagramAsync(classicJson, isClassicData: true);
```
---
## Mermaid Syntax (Flowchart, MindMap, Sequence)
The diagram can serialize/deserialize to Mermaid syntax for flowcharts, mind maps, and sequence diagrams.
### Save as Mermaid
```csharp
string mermaidStr = _diagram.SaveDiagramAsMermaid();
```
### Load from Mermaid
```csharp
await _diagram.LoadDiagramFromMermaidAsync(mermaidStr);
```
> **Note:** Mermaid serialization only works with `HierarchicalTree` (flowchart), `MindMap`, and sequence diagram layouts. Regular diagrams with free-form nodes will not serialize correctly to Mermaid.
---
## Common Gotchas
- **Missing `@bind-`** on `Nodes`/`Connectors` causes `LoadDiagramAsync` to load data but the UI won't update
- **`BeginUpdate()` / `EndUpdateAsync()`** wrap file-based loads to prevent intermediate re-renders
- **Custom data on nodes** — if `node.Data` is a custom object, it must be JSON-serializable; complex types with circular references will cause exceptions
- **Mermaid is layout-specific** — only flowchart, mind map, and sequence diagram layouts support Mermaid serialization
- **`LoadDiagramAsync` replaces all current content** — save current state before loading if needed
- **Classic `SfDiagram` migration** — always pass `isClassicData: true` when loading legacy diagram JSON; omitting it causes a parsing error
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 |