Install Diagrams

A chart library, such as ECharts, draws the charts. A Renderer connects the extension to one library. You register one Renderer for each library you use.

Alpha

Diagrams is in alpha and available through a pilot program. The API may change in future releases.

Install

  1. Contact our team to join the Tiptap Diagrams pilot program.
  2. Configure your package manager by following the private registry guide.
  3. Install the package and the library of each Renderer you use:
npm install @tiptap-pro/extension-diagrams
npm install echarts
PackageKindVersion
@tiptap/core, @tiptap/pmPeer dependency3.31 or later
echartsOptional peer dependency^6.0.0
d3Optional peer dependency^7.9.0
d3-sankeyOptional peer dependency^0.12.3, for sankey charts with D3
mermaidOptional peer dependency>=11.16.1 <12
peleOptional peer dependency1.6.0, for the Pele Renderer

The examples below also use @tiptap/starter-kit and @tiptap/extension-table. Install them too if your editor does not have them yet.

The draw.io and BPMN Renderers load their library from a file you serve. See draw.io and BPMN. Renderers lists every Renderer.

A first chart

In the demo, write rows as text, insert them as a chart, then change its type:

New tab
import { Editor } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'
import { TableKit } from '@tiptap/extension-table'
import { Diagrams, chartStyleRules } from '@tiptap-pro/extension-diagrams'
import { echartsRenderer } from '@tiptap-pro/extension-diagrams/echarts'

const style = document.createElement('style')
style.textContent = chartStyleRules()
document.head.append(style)

const editor = new Editor({
  element: document.querySelector('#editor'),
  extensions: [
    StarterKit,
    TableKit,
    Diagrams.configure({
      renderers: [echartsRenderer()],
      chart: { defaultType: 'bar' },
    }),
  ],
})

editor.commands.insertChartFrom({
  format: 'chart-syntax',
  content: 'Month | Revenue\nJan | 120\nFeb | 150\nMar | 110',
})

The editor now holds a bar chart with three bars, and the chart is selected.

  • chartStyleRules() returns the stylesheet the charts need.
  • TableKit is optional. With it, you can turn a chart into a table and back.
  • chart: { defaultType: 'bar' } gives a new chart the type bar. See defaultType.
  • chart-syntax is the Chart syntax: one row per line, with the cells separated by |.

Change it

updateChartSpec and updateChartAxis change the selected chart, such as the one A first chart inserts:

editor.commands.updateChartSpec({ spec: { type: 'line', title: 'Revenue' } })
editor.commands.updateChartAxis({ axis: 'y', changes: { title: 'EUR', min: 0 } })

The Chart Spec holds how a chart shows its data: type, title, colors and axes. Without a selected chart, both commands return false. Every change is a command, so the user can undo it and collaborators receive it. An AI model calls them through tools.

A second chart from the Quick Input

  1. Type ::: in an empty paragraph to open the Quick Input, a text field inside the document.
  2. Enter rows such as Apr | 130.
  3. Press Enter on an empty last line.

A first diagram

A flow diagram needs a Diagram Renderer. The one for Mermaid, a library that draws diagrams from text, needs mermaid:

npm install mermaid@11

This is the editor from A first chart with the Mermaid Diagram Renderer and the diagram styles, inserting a flowchart:

import { Editor } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'
import { TableKit } from '@tiptap/extension-table'
import { Diagrams, chartStyleRules, flowDiagramStyleRules } from '@tiptap-pro/extension-diagrams'
import { echartsRenderer } from '@tiptap-pro/extension-diagrams/echarts'
import { mermaidDiagramRenderer } from '@tiptap-pro/extension-diagrams/mermaid'
import rendererUrl from '@tiptap-pro/extension-diagrams/mermaid-renderer?url&no-inline'
import mermaidUrl from 'mermaid/dist/mermaid.min.js?url'

const style = document.createElement('style')
style.textContent = chartStyleRules() + flowDiagramStyleRules()
document.head.append(style)

const editor = new Editor({
  element: document.querySelector('#editor'),
  extensions: [
    StarterKit,
    TableKit,
    Diagrams.configure({
      renderers: [echartsRenderer()],
      diagramRenderers: [mermaidDiagramRenderer({ mermaidUrl, rendererUrl })],
      chart: { defaultType: 'bar' },
    }),
  ],
})

editor.commands.insertFlowDiagram({
  source: 'flowchart LR\n  order[Order placed] --> ship[Shipped]',
  title: 'Order flow',
})

The editor shows a flowchart with two boxes, and the diagram is selected.

Mermaid draws in a sandboxed iframe from two files your bundler serves: mermaidUrl is Mermaid, rendererUrl the script that draws with it. In Vite, ?url gives a file's URL, and no-inline keeps a small file from becoming a data URL, which the iframe cannot load. The Mermaid Renderer covers other bundlers.

Entry points

Each Renderer is its own entry point of the package. Your bundle then holds only the libraries you use.

Import fromWhat it holds
@tiptap-pro/extension-diagramsDiagrams, its nodes and commands, Data Sources, export, styling and tools for an AI model
@tiptap-pro/extension-diagrams/coreThe chart data types, parsers and formats, and the Word writer. It needs no Tiptap and no DOM, so it runs on a server or in a worker
@tiptap-pro/extension-diagrams/exportTurning an SVG into a PNG, WebP or a download, in the browser
@tiptap-pro/extension-diagrams/themeReading chart and diagram colors from CSS custom properties, in the browser
@tiptap-pro/extension-diagrams/echartsCharts drawn with ECharts
@tiptap-pro/extension-diagrams/d3Charts drawn with D3
@tiptap-pro/extension-diagrams/mermaidCharts and diagrams drawn with Mermaid
@tiptap-pro/extension-diagrams/drawiodraw.io diagrams
@tiptap-pro/extension-diagrams/bpmnBPMN process models
@tiptap-pro/extension-diagrams/peleMermaid diagrams drawn by Pele in a Web Worker. Pele is smaller than mermaid.js

Next

  • Data: typed rows, tables and Data Sources
  • Charts: types, appearance, axes, reference lines
  • Diagrams: Mermaid, draw.io and BPMN
  • Styling: colors, dark mode, your own classes