Skip to content

Charts Editor ​

Chart studio product published as on-codemerge/charts. Thin app entry uses a shell ViewPort and ChartsPlugin({ surface: 'workspace' }), which mounts the shared chart studio into contentTarget. Interchange via getText / setText (chart attrs JSON).



Live preview (rendered chart):

Chart JSON (getText()):

Studio layout ​

Left pane (50%) + right live preview (50%):

AreaContents
TitleAlways visible above tabs — rename without leaving Type/Data
TypeChart type grid + template picker
DataSeries / points table (auto-opens after picking a type)
SettingsAxis labels; mode (bar/area). Legend / grid only for scatter & bubble (canvas). Mermaid-backed types ignore legend/grid/orientation — see Mermaid
PreviewFills the right pane; re-renders on resize
ToolbarUndo / redo + Export as PNG (defaultChartToolbar)

Narrow viewports: Preview / Edit studio tabs (studioPaneTabs).

Render path ​

  • Bar, line, area, pie, doughnut, radar, … → @codemerge/mermaid (toMermaidSource → render). This is a Mermaid subset, not full Mermaid.js — see Mermaid.
  • Scatter / bubble → small canvas paint path.

Install ​

bash
npm install --save on-codemerge
ts
import { Editor, createDefaultPlugins } from 'on-codemerge/charts';

const host = document.getElementById('charts-editor')!;
const editor = new Editor(host, {
  chrome: 'bar',
  plugins: createDefaultPlugins(), // ChartsPlugin({ surface: 'workspace' }) + export toolbar
});

editor.on('docChanged', () => {
  console.log(editor.getText());
});

editor.setText('{"chartType":"bar","title":"Chart","data":[],"width":800,"height":400}');
editor.destroy();

createView defaults to createShellView. Local SPA: pnpm dev:charts.

Same plugin in WYSIWYG ​

ts
import { Editor, createDefaultPlugins } from 'on-codemerge';

new Editor(host, {
  plugins: [...createDefaultPlugins()], // includes ChartsPlugin({ surface: 'atom' })
});

surface: 'atom' opens the same mountChartWorkspace studio in an lg popup. Hotkey Mod-Alt-g opens the studio (does not silent-insert). PNG export: chart context menu. See Charts Plugin.

Types ​

Published types for on-codemerge/charts expect TypeScript moduleResolution: "bundler" (or skipLibCheck: true).

Document API ​

MethodRole
getText()Pretty chart attrs JSON
setText(text)Replace SoT; returns ParseError | null (SoT unchanged on error)
getJSON() / setJSON(doc)Kernel document snapshot (doc → chart)
run / command / useSame as WYSIWYG
on('docChanged', …)Subscriptions
destroy()Tear down

Document shape ​

SoT is doc → single chart child. Attrs: chartType, data, title, axes, legend, grid, size, mode, orientation.

Toolbar ​

Undo/redo from the editor kernel. Workspace adds Export PNG via defaultChartToolbar() (override with createDefaultPlugins({ toolbar })).

Local demo ​

bash
pnpm dev:charts    # apps/charts SPA
pnpm build:charts  # → dist-charts/

See also ​

Released under the MIT License.