Storage
editor.storage.diagrams tells you what the document holds and what the editor can draw. You call its functions directly, not as commands.This reads the first chart of the editor from
A first chart:
const charts = editor.storage.diagrams.listCharts()
const text = editor.storage.diagrams.read({ pos: charts[0].pos, format: 'chart-syntax' })requestSync is the only function that writes into the document, with the command
syncChartData. registerSource, setZoom, setPan and
setMaximized change this editor only, and are not saved or shared.
Charts, diagrams and tables in the document
In document order:
| Function | Returns |
|---|---|
listCharts() | Every chart, with the Chart fields |
listDiagrams() | Every diagram, see Diagram fields |
listTables() | Every table a chart or diagram can take its data from, see Table fields. Empty without the linkTables option |
getOpenInput() | The Quick Input the cursor is in, or null |
Chart fields
| Field | Value |
|---|---|
pos | The chart's position in the document, a number |
data | The Chart Data |
spec | The Chart Spec |
renderer | The Renderer id it names, or null |
source | Its Data Source, or null |
syncedAt | ISO time of the last source read, or null |
delimiter | The delimiter its rows were typed with, or null |
previewUrl | Its preview URL, or null |
layout | 'chart', 'with-table' or 'table', see setChartLayout |
tableId | The table it follows, or null |
tableRead | The settings of updateLinkedTable that differ from the default, or null |
Diagram fields
| Field | Value |
|---|---|
pos | The diagram's position |
format | Its format, such as 'mermaid' |
source | Its source text |
title | Its title, or null |
description | Its description, or null |
view | 'diagram' when it shows the picture, 'code' when it shows the source text |
options | Record<string, unknown> of other settings, such as size |
kind | The Mermaid kind, such as 'flowchart'. null for empty source, source that is no known Mermaid diagram kind, and draw.io or BPMN |
drawable | false for empty source. For Mermaid, draw.io and BPMN, whether the source is valid in that format. For another format, whether a registered Renderer for diagrams draws it |
link | The table it is drawn from, { tableId, columns }, or null |
lanes | string[], the lane names of a diagram drawn from a table, in order. Otherwise empty |
Table fields
| Field | Value |
|---|---|
pos | The table's position |
tableId | Its id once a chart or a diagram follows it, or null |
header | The texts of its first row |
headerCells | true when the first row is header cells. With header: 'auto', a first row of plain cells names the columns only if it has more than one cell and every cell after the first is filled and holds no number |
charts | How many charts follow it |
diagrams | How many diagrams are drawn from it |
followers | { pos, kind: 'chart' | 'diagram' } for each, in document order |
The open input
getOpenInput() returns { pos, view: 'chart-syntax' | 'table', type, delimiter, editing }.
type is the chart type it becomes when it becomes a chart. delimiter is null until one is set, and in a table.
editing is true when the input holds an existing chart.
Reading a chart's data
Without pos, they read the selection:
| Function | Returns |
|---|---|
read({ pos?, format? }) | The chart as text, 'chart-json' by default. Throws without a chart or for an unknown format |
readGrid({ pos? }) | A grid of strings, row 0 the header. Throws without a chart |
readTable({ pos? }) | Table JSON, or null without table nodes. Throws without a chart |
readText({ pos? }) | { format, text } of a chart or diagram, or null (Text beside the picture) |
parseFormat(format, content, type?) | { data, spec, delimiter? }. type defaults to chart.defaultType. Throws for content or a format it cannot read |
getFormat(id) | A registered format, for its serialize, or undefined |
What the editor can draw
| Function | Returns |
|---|---|
describeCapabilities() | Types, formats, Renderers, default Renderer, sources, delimiters, trigger and styles |
chartTypes | A property: built-in and registered chart types |
canRender(spec) | Whether a registered Renderer draws the type |
rendererFor(spec, preferred?, data?) | The Renderer a chart would be drawn with, or null |
diagramRendererFor(format, source?) | The Diagram Renderer for that format or source, or null |
rulesFor(renderer) | A Renderer object's rules in effect, see rendererRules |
refresh() | Nothing. Draws everything again, such as after a CSS-only theme change |
What the extension holds
What Diagrams was configured with. The lists include the built-in entries:
| Member | Value |
|---|---|
options | The options Diagrams was configured with |
chartOptions | The chart options with their defaults |
renderers, diagramRenderers | The registered Renderers |
formats, styles | The built-in formats and styles, and those of the options |
styleChart(spec, theme, scheme?) | { spec, theme } with the style the spec names applied. scheme defaults to 'light' |
Export
See Export:
| Function | Returns |
|---|---|
export(target, options?) | A promise of a file. target is { pos }, {} for the selection, or { data, spec, renderer? } |
exportAll(options?) | Files of every chart and diagram that can be drawn, with pos. Skips charts without rows or with spec.hidden |
exportDocx(options?) | A promise of { blob, notes }, see Word |
Data Sources
See Data Sources:
| Function | What it does |
|---|---|
readSource(source) | A promise of the data now. Rejects for an unknown provider or a failed read |
requestSync(source) | Writes into each linked chart, resolving true when it wrote |
registerSource(provider) | Adds or replaces a provider and returns a function that removes it |
getSource(id), listSources() | One provider or undefined, and all, in registration order |
requestSync resolves false when the read fails or no chart is linked. A failed read keeps the
snapshot and calls onSourceError.
Zoom, pan and maximize on screen
setZoom, getZoom, setPan, getPan, getShownSize, setMaximized and getMaximized set or
read how this editor shows a chart or diagram, as View functions
describes. To update your UI when setMaximized runs, listen to the editor's transaction event.
That change is not in the undo history.