Commands

Every change to a chart or a diagram is a command, so the user can undo it and collaborators receive it. Each links to its page.

The examples use the editor from A first chart. The second opens the Quick Input, a text field where the user types rows that become a chart.

editor.commands.updateChartSpec({ spec: { type: 'area', stacked: true } })
editor.chain().focus().insertDiagramInput({ type: 'pie' }).run()

How the commands behave

You run a command with editor.commands, chain several with editor.chain() and run(), and ask editor.can() whether one would work. A command returns true when it acts, even if the result equals what was there, and editor.can() returns true when it would act, without changing the document. When a command cannot act, it returns false and changes nothing.

A command that changes a chart or a diagram takes an optional pos, its position from listCharts() or listDiagrams(). Without pos, it changes the selected chart or diagram, the one the user clicked.

The insert commands insert at pos, or at the selection without it. insertDiagramInput takes no pos and always opens at the selection, and confirmDiagramInput takes a position inside the open input. insertLinkedChart, linkChartToTable, insertDiagramFromTable and linkDiagramToTable take the table's position as table. insertLinkedChart and insertDiagramFromTable take no pos and insert beside that table. The setters of the open Quick Input take a single value, such as setDiagramInputType('bar').

Reading needs no command: the reading functions are on editor.storage.diagrams.

Charts

CommandWhat it does
insertChartInserts a chart from Chart Data and a Chart Spec
insertChartFromInserts a chart written in a registered format
importMermaidChartInserts a chart from Mermaid chart source, such as pie
insertFromTextInserts text as a chart or a diagram, rows too
convertCodeBlockToChartReplaces a code block of Mermaid chart source with the chart
insertDiagramInputOpens an empty Quick Input
updateChartSpecChanges fields of the Chart Spec
setChartRendererChooses the Renderer of one chart
updateChartAxisChanges one axis: title, range, lines, step, labels
applyChartLookGives a chart the look of another one
convertChartToImageReplaces a chart with an image of it
convertImageToChartTurns that image, which keeps the chart, back into it
redrawChartImageDraws that image again from the chart it keeps

Data

CommandWhat it does
updateChartDataReplaces the Chart Data
setChartLabelColumnChooses the column that names the rows
setChartSeriesInDraws each row or each column as a series
updateChartFromReplaces data and spec from text in a format
updateChartFromGridReplaces the data from a grid of strings
updateChartFromTableReplaces the data from table JSON
confirmDiagramInputTurns the open Quick Input into a chart
setDiagramInputTypeSets the type the open Quick Input becomes
setDiagramInputViewSwitches the open input between text and table
setDiagramInputDelimiterSets the delimiter of the open Quick Input
editChartAsTextTurns a chart into a Quick Input of its data
editChartAsTableOpens a chart as a table, and turns it back into a chart on leaving
editDiagramAsTextTurns a Mermaid diagram into a Quick Input of its source
convertTableToChartReplaces a table with a chart of its data
convertChartToTableReplaces a chart with a table of its data
insertLinkedChartInserts a chart that follows the table at the cursor or at table
updateLinkedTableChanges how a chart or a diagram reads its table
setChartLayoutShows the chart, its table, or both in the document
linkChartToTableMakes an existing chart follow any table
linkChartSourceLinks a chart to a Data Source
syncChartDataWrites new data from the Data Source into the chart
detachChartSourceStops following the source, keeps the data last read
relinkChartSourceResumes following a detached chart's source

Diagrams

CommandWhat it does
insertFlowDiagramInserts a diagram from Mermaid, draw.io or BPMN source
updateFlowDiagramChanges source, format, title or description
setFlowDiagramViewShows the drawn diagram or its source text
convertCodeBlockToDiagramReplaces a code block of Mermaid source with the diagram
insertDiagramFromTableInserts a flowchart drawn from a table
linkDiagramToTableDraws a diagram from a table and follows it
detachDiagramFromTableStops following the table
renameDiagramLaneRenames a lane in every row of the table
setDiagramNodePositionMoves a shape of a flowchart
resetDiagramPositionsPuts every moved shape back

Charts and diagrams

CommandWhat it does
setDiagramSizeGives a chart or a diagram a size
setDiagramAlignPlaces it left, centered or right
updateFromTextChanges a chart or a diagram from its text