Storage

The readers on editor.storage.diagrams answer what is in the document and what the editor can do. Readers never change the document.
Pro ExtensionAlphaPilot program
const charts = editor.storage.diagrams.listCharts()
const text = editor.storage.diagrams.read({ pos: charts[0].pos, format: 'chart-syntax' })

Charts, diagrams and tables in the document

ReaderReturns
listCharts()Every chart, see Chart fields
listDiagrams()Every diagram, see Diagram fields
listTables()Every table a chart or a diagram can follow, see Table fields. Empty without chart.linkTables
getOpenInput()The Quick Input or input table the cursor is in, see The open input. null outside one

Chart fields

FieldValue
posThe chart's position
dataThe Chart Data
specThe Chart Spec
rendererThe Renderer the chart names
sourceIts Data Source
delimiterIts delimiter
previewUrlIts preview URL
layoutWhether it stands alone, follows a table, or is hidden below it (setChartLayout)
tableIdThe table it follows, or null
tableReadHow it reads that table, { header?, range? } with only what differs from the default, or null

Diagram fields

FieldValue
posThe diagram's position
formatIts format
sourceIts source
titleIts title
descriptionIts description
viewIts view
optionsIts options
kindThe kind of Mermaid diagram, or null
drawableWhether a Diagram Renderer for its format can draw the source
linkThe table it is drawn from, { tableId, columns }, or null
lanesThe lanes of a diagram drawn from a table, in the order they appear

Table fields

FieldValue
posThe table's position
tableIdIts id, once a chart follows it, or null
headerIts first row
headerCellsWhether that row is header cells. Without them, the row names the columns only when it holds no number outside the first column
chartsHow many charts follow it
diagramsHow many diagrams are drawn from it
followersEach chart and diagram that follows it, as { pos, kind: 'chart' | 'diagram' }, in document order

The open input

getOpenInput() returns { pos, view: 'chart-syntax' | 'table', type, delimiter, editing }.

  • editing is set when the input holds a chart being changed rather than a new one.

Reading a chart's data

readText also reads a diagram.

ReaderReturns
read({ pos?, format? })A chart as text in a format, 'chart-json' by default
readGrid({ pos? })The data as a grid of strings, row 0 the header
readTable({ pos? })The data as table JSON, or null without a table in the Schema
readText({ pos? }){ format, text } of a chart or a diagram, as an author edits it, or null (Text beside the picture)
parseFormat(format, content, type?){ data, spec, delimiter } parsed from content
getFormat(id)A registered format, for its serialize
  • parseFormat throws with a message when the content cannot be parsed.

What the editor can draw

ReaderReturns
describeCapabilities()Chart types ({ id, label, shape, description? }), formats, Renderers and their types, sources, delimiters, trigger
chartTypesThe built-in chart types and those of the chartTypes option
canRender(spec)Whether a registered Renderer draws the type
rendererFor(spec, preferred?)The Renderer a chart would be drawn with
diagramRendererFor(format)The Diagram Renderer a diagram of that format would be drawn with, or null
rulesFor(renderer)The rules a Renderer's pictures follow, its own and those of rendererRules: { attribution?, exports? }
refresh()Draws every chart and diagram again, after a theme change made in CSS

Export

ReaderReturns
export(target, options?)A chart or a diagram as a file, see export
exportAll(options?)Every chart and diagram that can be drawn, as files with their pos, in document order
exportDocx(options?)A promise of a Word document with native charts and diagrams as pictures: { blob, notes }. See Word

Data Sources

ReaderReturns
readSource(source)The data a source returns now, without writing it
requestSync(source)Reads a source and writes it into every chart linked to it
registerSource(provider)Adds a provider at run time and returns a function that removes it
getSource(id), listSources()The registered providers

Zoom, pan and maximize on screen

These act on a chart or a diagram on screen. See Size and view.

ReaderReturns
setZoom(target, zoom)Zooms it. false when it is not on screen
getZoom(target?)Its zoom, or null
setPan(target, { x, y })Moves its zoomed picture. false when it is not on screen
getPan(target?)How far the picture is moved, { x, y }, or null
getShownSize(target?)Its size as setDiagramSize takes it: its own, or the share of the column and the shape it shows now. null when it is not on screen
setMaximized(target, maximized)Lays it over the window or back into the text. false when it is not on screen
getMaximized()The position of the maximized chart or diagram, or null