Skip to content

feat(workflows): export the flowchart as PNG, JPEG, or SVG - #995

Merged
sfmskywalker merged 4 commits into
mainfrom
claude/export-flowchart-image
Sep 7, 2026
Merged

feat(workflows): export the flowchart as PNG, JPEG, or SVG#995
sfmskywalker merged 4 commits into
mainfrom
claude/export-flowchart-image

Conversation

@sfmskywalker

Copy link
Copy Markdown
Member

Closes #585

Adds an Export action to the flowchart designer toolbox (editable and read-only views) that downloads the diagram as PNG, JPEG, or SVG.

What changed

  • Designer client library: registers @antv/x6-plugin-export (2.1.6, the last 2.x line matching the installed x6 2.18) and adds a single exportGraph(graphId, options) function that encodes the requested format, applies padding for the raster formats, appends the matching extension, and throws on an unknown format.
  • Designer interop: ExportGraphOptions/ExportGraphFormat carried through X6GraphApi, FlowchartDesigner, and FlowchartDesignerWrapper. A test pins the C#-to-JS payload contract (camel-cased properties, lower-cased format).
  • Workflows module: an ExportFlowchartDialog (format, file name, padding; padding hidden for SVG) validated with FluentValidation via Blazilla, following the dialog pattern adopted in fix(core): replace archived Blazored.FluentValidation with Blazilla #993. The proposed file name is the workflow definition's name plus a _v{version} suffix, sanitized for file-name use; to make that name available, DisplayContext gained an optional trailing WorkflowDefinition parameter, and DiagramDesignerWrapper an optional WorkflowDefinition parameter that its four hosts now pass.
  • The Export item is only offered when the X6 renderer is active; the React Flow designer has no export path, and the wrapper throws NotSupportedException rather than silently doing nothing.

Notes

  • @antv/x6-plugin-export's exportJPEG() delegates to toPNG() upstream, so it would download PNG bytes under a .jpeg name. The implementation calls toJPEG() directly and derives the extension from the same value that selects the encoder.
  • PDF is out of scope: the X6 export plugin cannot produce it, and the issue lists it as a possible format only.
  • Credit to @KnibbsyMan for the approach explored in the draft Export X6 Flowchart Content #720 (X6 export plugin, options dialog, toolbox button). That branch is far behind main and relied on the now-removed Blazored.FluentValidation package, so the feature was re-implemented on top of main instead of merged.

Verification

  • npm run build in the designer ClientLib: webpack compiled successfully.
  • dotnet build Elsa.Studio.sln: 0 errors, no new warnings.
  • Elsa.Studio.Workflows.Tests: 260 passed (new dialog, validation, file-name, and payload tests); Elsa.Studio.Workflows.Designer.Tests: 74 passed on net8.0/net9.0/net10.0.
  • Not verified in a browser (no end-to-end harness in this repository): the actual download and the visual effect of padding.

🤖 Generated with Claude Code

sfmskywalker and others added 3 commits September 7, 2026 16:30
Adds @antv/x6-plugin-export to the designer bundle, registers it on every
graph (read-only included, since exporting a diagram for documentation is
exactly what a read-only viewer is for), and exposes a single exportGraph
JavaScript function that the new X6GraphApi.ExportGraphAsync drives.

exportGraph downloads through toPNG/toJPEG/toSVG rather than the plugin's
exportPNG/exportJPEG/exportSVG helpers, because the plugin's exportJPEG
delegates to toPNG: calling it would have written PNG bytes into a file
named .jpeg, which is the kind of failure that looks like a success. The
extension is appended in the one place that knows the format, so the
downloaded file always advertises the format the user asked for.

The format crosses the interop boundary as a lowercase string, which the
JavaScript switch requires and whose default branch throws rather than
silently falling back to PNG. X6GraphApi.CreateExportPayload is internal
so that contract is pinned by a test instead of only by a browser.

Refs #585

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Adds an Export item to the flowchart designer's toolbox in both read-only
and editable mode. It opens a dialog for the format (PNG/JPEG/SVG), the
file name, and the padding, then hands the result to the designer.

The proposed file name comes from the flowchart's name, suffixed with its
version when it has one, with characters the host platform rejects in a
file name replaced by underscores.

Two details keep an invalid state from being mistaken for a working one.
The padding rule is scoped to the raster formats, which are exactly the
formats for which the dialog shows the field: validating it for SVG too
would keep the dialog open with its complaint rendered nowhere the user
could see or fix it. And the toolbox item is offered only when the X6
designer is the one being rendered, because the React Flow renderer has
no export path; FlowchartDesignerWrapper.ExportGraphAsync throws for that
case rather than returning as if it had downloaded something.

Refs #585

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The flowchart export dialog derived its proposed file name from the root
activity's JSON, which for a real workflow carries no name and whose
version is the activity type's version rather than the workflow's. Thread
the workflow definition through DisplayContext (populated by
DiagramDesignerWrapper from its hosts, which already hold it) so
FlowchartDiagramDesigner.GetDefaultFileName can derive the name and
version from the definition instead. Also localize the export format
radio labels and select them by label text rather than position in
ExportFlowchartDialogTests.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical dependency-security and binary-compatibility issues remain, alongside accessibility and validation defects.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds PNG, JPEG, and SVG export support to editable and read-only X6 flowchart designers.

Changes:

  • Adds the X6 export plugin and C#/JavaScript export pipeline.
  • Adds an export dialog with validation and generated filenames.
  • Propagates workflow metadata and tests dialog and interop behavior.
File summaries
File Review
src/modules/Elsa.Studio.Workflows/Validators/ExportGraphOptionsValidator.cs Validates export options. Moderate: padding needs a reasonable upper bound.
src/modules/Elsa.Studio.Workflows/Shared/Components/DiagramDesignerWrapper.razor.cs Passes workflow metadata into the display context.
src/modules/Elsa.Studio.Workflows/DiagramDesigners/Flowcharts/FlowchartDiagramDesignerProvider.cs Injects export dependencies.
src/modules/Elsa.Studio.Workflows/DiagramDesigners/Flowcharts/FlowchartDiagramDesigner.cs Adds export tooling and filename generation. Moderate: the icon button needs an accessible name.
src/modules/Elsa.Studio.Workflows/DiagramDesigners/Flowcharts/FlowchartDesignerWrapper.razor.cs Routes exports to X6.
src/modules/Elsa.Studio.Workflows/DiagramDesigners/Flowcharts/ExportFlowchartDialog.razor.cs Implements dialog behavior and validation.
src/modules/Elsa.Studio.Workflows/DiagramDesigners/Flowcharts/ExportFlowchartDialog.razor Defines export controls. Moderate: the format radio group needs an accessible name.
src/modules/Elsa.Studio.Workflows/Components/WorkflowInstanceViewer/Components/WorkflowInstanceDesigner.razor Supplies workflow metadata.
src/modules/Elsa.Studio.Workflows/Components/WorkflowDefinitionEditor/Components/WorkflowEditor.razor Supplies editable workflow metadata.
src/modules/Elsa.Studio.Workflows/Components/WorkflowDefinitionEditor/Components/WorkflowDefinitionVersionViewer.razor Supplies version metadata.
src/modules/Elsa.Studio.Workflows.Tests/ExportFlowchartDialogTests.cs Tests dialog validation and filenames.
src/modules/Elsa.Studio.Workflows.Designer/Models/ExportGraphOptions.cs Defines export settings.
src/modules/Elsa.Studio.Workflows.Designer/Models/ExportGraphFormat.cs Defines supported formats.
src/modules/Elsa.Studio.Workflows.Designer/Interop/X6GraphApi.cs Invokes export interop.
src/modules/Elsa.Studio.Workflows.Designer/Components/FlowchartDesigner.razor.cs Exposes graph export operations.
src/modules/Elsa.Studio.Workflows.Designer/ClientLib/src/designer/api/index.ts Exposes the client export API.
src/modules/Elsa.Studio.Workflows.Designer/ClientLib/src/designer/api/export-graph.ts Encodes and downloads exported images.
src/modules/Elsa.Studio.Workflows.Designer/ClientLib/src/designer/api/create-graph.ts Registers the X6 export plugin.
src/modules/Elsa.Studio.Workflows.Designer/ClientLib/package.json Adds the export dependency. Critical: the safe version must be pinned exactly.
src/modules/Elsa.Studio.Workflows.Designer.Tests/X6ExportPayloadTests.cs Tests the JavaScript payload contract.
src/modules/Elsa.Studio.Workflows.Core/UI/Contexts/DisplayContext.cs Carries workflow metadata. Critical: changing the positional record breaks binary compatibility.
src/modules/Elsa.Studio.Alterations/Components/AlterationDesignerHost.razor Supplies workflow metadata in alterations.
Review details
  • Files reviewed: 22/22 changed files
  • Comments generated: 5
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/modules/Elsa.Studio.Workflows.Core/UI/Contexts/DisplayContext.cs Outdated
Comment thread src/modules/Elsa.Studio.Workflows.Designer/ClientLib/package.json Outdated
Comment thread src/modules/Elsa.Studio.Workflows/Validators/ExportGraphOptionsValidator.cs Outdated
… plugin, and label the export controls

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two public constructor removals can cause MissingMethodException for existing compiled integrations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 22/22 changed files
  • Comments generated: 2
  • Review effort level: Balanced

@sfmskywalker
sfmskywalker merged commit 13a9ea4 into main Sep 7, 2026
9 checks passed
@sfmskywalker
sfmskywalker deleted the claude/export-flowchart-image branch September 7, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support export of workflows as image (PNG/SVG/PDF) in Workflow Studio

2 participants