@nextgensoftwares/folio-plugin-charts
Charts in documents, opt in. A chart block holds a folio-charts chart. It is sized, aligned and wrapped like pictures. It is drawn on screen (SVG), in the reader and thumbnails (canvas), and in PDF (vectors and real text). It exports to Word as a real chart with its workbook, so "Edit Data" works.
import { chartsPlugin } from '@nextgensoftwares/folio-plugin-charts';
const composed = composePlugins(standardSchema, [chartsPlugin({ measure: (t, size, bold) => fonts.width(t, { family: 'Calibri', size, weight: bold ? 700 : 400, style: 'normal' }) })]);
// DOCX import: importDocx(bytes, { charts: true }) reads Word's charts into chart nodes.Plugin
| Export | What |
|---|---|
chartsPlugin(options?) → ChartsPlugin (ChartsPluginOptions: theme? (Partial ChartTheme, default Office's), measure? (label widths, default an estimate), panel? (inspector slot, default 'sidebar'; false: none), toolbar?) | schema, renderer, painter, commands, the toolbar's Insert ▸ Chart menu, /chart and /pie chart, the chart panel while one is selected, PDF / canvas / DOCX exporters |
chartSchema, chartSpec, CHART_NODE (also /schema) | the chart block atom: chart (sanitized), height (px), alt, caption, workbook (an imported xlsx data URL), and media's card attrs (width px or %, alignment, wrap, float, distances, offsets) |
chartsFind | the plugin's find source: a chart's title and caption for find and replace |
chartRenderer, chartBox(attrs, ctx), chartOf(attrs), captionHeight(attrs, bodySize), CHART_SIZE | layout: one custom fragment of type chart (chart, then its caption), centred by default, wrapped like media; default size is Word's (576 × 336 px) |
Commands
createChartCommands() → ChartCommands (also ChartsPlugin.commands). selectedChart(state) returns the node-selected chart: { node, pos, chart }.
| Command | What |
|---|---|
chart.insert(type?, grouping?) | a sample chart of a type at the selection, selected |
chart.update(fields) | merges chart fields (type, grouping, title, legend, labels, axes, style, smooth, markers, hole); the result is sanitized |
chart.setData(data) | new data (ChartData: categories by series); series keep colours and types |
chart.setSize({ width?, height? }) | px (or a px / % width string) |
chart.setText({ caption?, alt? }) | caption under the chart, alt text |
chart.setPlacement(patch) | wrap, side, alignment, distances, offsets, as media's PlacementPatch |
UI
| Export | What |
|---|---|
ChartPanel (editor, commands), chartPanelItem(commands, { slot?, order? }), CHART_ICON | the inspector: look (ChartFormat), data (folio-charts' ChartDataGrid), wrap and alignment, size, caption, alt text |
ChartFormat (chart, update(fields)), CHART_PALETTES | type and stacking, title, colours (Colorful, Blue, Green, Orange, Grey, Warm, Cool), vary colours, background, border, smoothing, markers, doughnut hole, legend, data labels, axes (titles, number format, bounds, gridlines, visibility) |
createChartPainter(env, captionH) | the editor and reader painter: the chart as SVG, its caption; when selected and editable, an outline and handles (right edge: width, bottom: height, corner: both, Shift keeps the ratio) committed in one step |
chartToolbarItems(commands), chartSlashItems(commands), CHART_GALLERY | the Insert ▸ Chart menu (column, stacked column, bar, line, area, pie, doughnut, scatter) and slash items |
Export
| Export | What |
|---|---|
createChartExporters(env, captionH), ChartEnv, sceneFor(attrs, w, h, captionH, env) | PDF: folio-charts' paintChartPdf (path operators, real text, the caption in italic); canvas: paintChartCanvas; DOCX: ctx.chart from folio-export-docx (a Word chart part, its workbook, alt text; inline and aligned, or floating like pictures) and the caption as an italic centred paragraph |
chartRunOptions(chart, alt) | a chart as the docx library's ChartRun options (type, stacking, series and combo types, colours as theme accents or hex, axes, labels, legend, title, alt text, doughnut hole, scatter points) |
chartsReaderPlugin({ theme?, measure? }): the same charts in the standalone reader (@nextgensoftwares/folio-reader): the layout, a DOM painter (SVG with a title for screen readers, the caption), the canvas painter (canvas paint mode) and the PDF mapping.
Read-only editors and the reader show charts without handles. The importer keeps a Word chart's workbook as workbook. Export writes a new workbook from the chart's data, so Edit Data always matches the drawing.