Commands
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
| Command | What it does |
|---|---|
insertChart | Inserts a chart from Chart Data and a Chart Spec |
insertChartFrom | Inserts a chart written in a registered format |
importMermaidChart | Inserts a chart from Mermaid chart source, such as pie |
insertFromText | Inserts text as a chart or a diagram, rows too |
convertCodeBlockToChart | Replaces a code block of Mermaid chart source with the chart |
insertDiagramInput | Opens an empty Quick Input |
updateChartSpec | Changes fields of the Chart Spec |
setChartRenderer | Chooses the Renderer of one chart |
updateChartAxis | Changes one axis: title, range, lines, step, labels |
applyChartLook | Gives a chart the look of another one |
convertChartToImage | Replaces a chart with an image of it |
convertImageToChart | Turns that image, which keeps the chart, back into it |
redrawChartImage | Draws that image again from the chart it keeps |
Data
| Command | What it does |
|---|---|
updateChartData | Replaces the Chart Data |
setChartLabelColumn | Chooses the column that names the rows |
setChartSeriesIn | Draws each row or each column as a series |
updateChartFrom | Replaces data and spec from text in a format |
updateChartFromGrid | Replaces the data from a grid of strings |
updateChartFromTable | Replaces the data from table JSON |
confirmDiagramInput | Turns the open Quick Input into a chart |
setDiagramInputType | Sets the type the open Quick Input becomes |
setDiagramInputView | Switches the open input between text and table |
setDiagramInputDelimiter | Sets the delimiter of the open Quick Input |
editChartAsText | Turns a chart into a Quick Input of its data |
editChartAsTable | Opens a chart as a table, and turns it back into a chart on leaving |
editDiagramAsText | Turns a Mermaid diagram into a Quick Input of its source |
convertTableToChart | Replaces a table with a chart of its data |
convertChartToTable | Replaces a chart with a table of its data |
insertLinkedChart | Inserts a chart that follows the table at the cursor or at table |
updateLinkedTable | Changes how a chart or a diagram reads its table |
setChartLayout | Shows the chart, its table, or both in the document |
linkChartToTable | Makes an existing chart follow any table |
linkChartSource | Links a chart to a Data Source |
syncChartData | Writes new data from the Data Source into the chart |
detachChartSource | Stops following the source, keeps the data last read |
relinkChartSource | Resumes following a detached chart's source |
Diagrams
| Command | What it does |
|---|---|
insertFlowDiagram | Inserts a diagram from Mermaid, draw.io or BPMN source |
updateFlowDiagram | Changes source, format, title or description |
setFlowDiagramView | Shows the drawn diagram or its source text |
convertCodeBlockToDiagram | Replaces a code block of Mermaid source with the diagram |
insertDiagramFromTable | Inserts a flowchart drawn from a table |
linkDiagramToTable | Draws a diagram from a table and follows it |
detachDiagramFromTable | Stops following the table |
renameDiagramLane | Renames a lane in every row of the table |
setDiagramNodePosition | Moves a shape of a flowchart |
resetDiagramPositions | Puts every moved shape back |
Charts and diagrams
| Command | What it does |
|---|---|
setDiagramSize | Gives a chart or a diagram a size |
setDiagramAlign | Places it left, centered or right |
updateFromText | Changes a chart or a diagram from its text |