Skip to content

API Reference — Experimental: charts from your own data

Part of the API Reference. The walk-through, with live examples, is in Charts from your own data.

13 Experimental: charts from your own data

Experimental. This entry point may change or be removed without notice, and it is not part of the stable API described in the rest of this reference. It is on its own subpath, so nothing else imports it by accident. Build on it knowing that, and expect to adjust your calls when a version changes it.

Scope. This is not a general-purpose charting library. Its purpose is to let an application show the charts it already exposes to its users in Insights in other parts of the application, over data it holds itself, so that readers meet one familiar set of charts and features throughout. It draws the chart types Insights has (those a table can fill), with the library's own look, and it has no styling layer for building other charts.

Two functions draw the library's charts over your own data, which can come from anywhere your application can reach (a database, an API, a file). You hand it over as a table: one array per column, one value per row. That is the shape a database or a Parquet reader returns, so no row object is built per row. A row can be a wafer, with how many dies fell in each bin (there are no dies and no test values to load), or anything else: an order, a region and a month.

import { renderCharts, renderChartsTab } from '@wafertools/wafermap/experimental/charts';
import type {
  DataTable, PlotSpec, PlotWordsInput, TableSelection, TableTarget,
  ChartsOptions, ChartsHandle, ChartsChrome, ChartsTabOptions, ChartsTabHandle,
} from '@wafertools/wafermap/experimental/charts';
Export What it does
renderCharts Draws one chart, or several, that the page chooses, with none of the builder around them.
renderChartsTab Draws the chart builder: readers start, edit, duplicate, delete and keep their own charts from the table's columns.

The library keeps nothing. The page gives the table and the charts in, and (for the builder) is told of every change to the charts.

13.0 The table (the shape of your data)

interface DataTable {
  fields: Record<string, DataTableColumn>;   // the columns, by name
  labelField?: string;                       // the column that names each row
  outcomes?: Record<string, ArrayLike<number | bigint | string | null | undefined>>;
  goodOutcomes?: readonly number[];          // required when `outcomes` is given
  words?: PlotWordsInput;                    // what the rows, their items and the outcome are called
  outcomeNames?: Readonly<Record<string | number, string>>;   // names for outcomes, in place of "Bin 3"
}
type DataTableColumn = ArrayLike<string | number | Date | null | undefined>;
Field Notes
fields Columns by name: a device, a lot, a wafer, a date, a region, a revenue. Every column has one value per row. A column of numbers is a number a chart can use; text is a category; an ISO date (2026-03-14, with or without a time) or a Date is a date and draws on a date axis. A missing value is null or undefined. The names are what readers see in titles, axes and the builder.
labelField The column that gives each row its name. Absent, or not one of fields: "Wafer 1", "Wafer 2"… Names must be unique.
outcomes How many items fell in each outcome (dies in each hard bin; orders on time, late, cancelled), one array per outcome with a count for each row. The key is the outcome's number, written plainly (1, 2, 20; no leading zeros). A count is a whole number of 0 or more, or its bigint or text form ("1042"), which is how a database driver returns count(*). A missing count is none. Optional: without it the table has columns only, and no field offers a yield or a number of items.
goodOutcomes The outcomes that count as good (the passing bins). Required with outcomes: a table has no default to judge a row by. At least one must have a column of counts.
words What the rows (row), the things counted (item) and the good share (rate) are called, and the name of the outcome field (outcome). See PlotWordsInput.
outcomeNames Names for outcomes by number: { 1: 'On time', 2: 'Late' }.

A table is refused, with the reason, when: it has no columns; a column does not have one value per row; an outcome column is not named by a plain number; no pass outcome is given, or none of the pass outcomes has a column of counts; a count is not a whole number of 0 or more; the label column is not one of the columns; or two rows share a name. The reasons are written into the container as an alert, returned by setTable, and kept in the handle's issues.

Words and numbers. Counts and sums of a column with no unit are written in full with thousands separators (767,168) on whole-number ticks, never as an exponent.

13.1 renderCharts

function renderCharts(options: ChartsOptions): ChartsHandle

Draws one chart, or several, over a table with no builder around them: no editor, no list, no Edit, Duplicate or Delete buttons. The page chooses the charts; the library draws them. One plot is one chart on its own; several are drawn as a grid.

A plot is the definition of a chart: a small piece of JSON with the chart type, what goes on each axis and the colour. See Using a chart's JSON for the format and an example of each chart type. A table can draw bar charts, line charts, box plots, scatter plots, histograms, control charts and heatmaps; the other chart types need tests.

interface ChartsOptions {
  container: HTMLElement;
  table: DataTable;
  plots: PlotSpec[];
  chrome?: Partial<ChartsChrome>;
  onSelect?: (selection: TableSelection) => void;
  targets?: readonly TableTarget[];
  attributes?: Record<string, { label: string; facet?: boolean; date?: boolean }>;
  height?: string;                       // CSS, for each chart. Default "360px".
}
interface ChartsHandle {
  issues: string[];                      // why the table could not be read; empty when the charts are drawn
  setTable(table: DataTable): string[];  // redraw over a changed table, keeping the plots; returns its issues
  setPlots(plots: PlotSpec[]): void;     // draw other plots over the same table
  destroy(): void;
}
Option Notes
container Where the charts are drawn.
table The table.
plots The charts to draw. Unknown settings in a plot are kept, and a plot that cannot be drawn over this table says why on its chart.
chrome Which of each chart's surroundings to draw (below).
onSelect Told of a click on a bar, box or point: what it stands for and the rows behind it (TableSelection).
targets Where else a selection can go (TableTarget). With any, a click opens a menu of them; without, a click only calls onSelect.
attributes By column name: a label shown in place of the column name, facet: false to keep a column out of the field lists by default, and date: true to group a column of ISO date-times by day.
height The height of each chart.

Chrome. A chart of your own is drawn with its title and colour legend, on the page's own background, and nothing else. Turn any part back on, or the title and legend off:

interface ChartsChrome {
  title?: boolean;     // default true
  legend?: boolean;    // default true: the colour legend
  footnote?: boolean;  // default false: the statement under the title (the rows, how values were combined)
  frame?: boolean;     // default false: the chart's own border, background and padding
  menu?: boolean;      // default false: the ⋯ menu (save as PNG, save or copy data, about this chart)
  expand?: boolean;    // default false: the expand button
}
const handle = renderCharts({
  container: document.getElementById('charts')!,
  table,
  plots: [yieldByLot],
  chrome: { footnote: true, menu: true },
  onSelect: (s) => console.log(s.category, s.labels),
});
handle.setTable({ ...table, goodOutcomes: [1, 2] });   // the charts stay; the numbers change

13.2 renderChartsTab

function renderChartsTab(options: ChartsTabOptions): ChartsTabHandle

Draws the chart builder over the table: the same cards, filter, Edit, Duplicate and Delete as the My charts tab, with New chart, Import charts…, Export charts… and Delete all charts…. A reader builds a chart from the table's columns (type, what goes along the bottom, what the bars measure, colour, and a filter such as one device or wafers below 90% yield). A table has no tests, so there are no Examples drawn from them, and only the chart types a table can fill are offered.

interface ChartsTabOptions {
  container: HTMLElement;
  table: DataTable;
  plots?: PlotSpec[];
  onPlotsChange?: (plots: PlotSpec[]) => void;
  onSelect?: (selection: TableSelection) => void;
  targets?: readonly TableTarget[];
  drilldown?: boolean;                   // default true
  attributes?: Record<string, { label: string; facet?: boolean; date?: boolean }>;
}
interface ChartsTabHandle {
  issues: string[];
  setTable(table: DataTable): string[];
  destroy(): void;
}
Option Notes
plots The saved charts, as onPlotsChange last gave them: your starting charts, plus each reader's own.
onPlotsChange Told of every change to the list, a moment after the reader stops typing. Keep the whole list wherever you keep settings (a database, localStorage) and give it back as plots next time.
onSelect, targets, attributes As for renderCharts.
drilldown false: a click only calls onSelect and opens no menu.

A click on a bar, box or point opens a menu with Charts for these wafers (a new chart of just those rows, and each saved chart drawn over them) and a section of your targets. words changes "wafers" to your word.

13.3 What a click gives your page

A click on a mark calls onSelect with a TableSelection. With targets, it also opens a menu of the page's own places, each a TableTarget.

TableSelection

interface TableSelection {
  category?: string;       // the category the mark stands for (a lot, a bin, a date)
  group?: string;          // the colour group, when the chart has several
  wafers: number[];        // the rows behind it, as positions in your table, each once, in order
  labels: string[];        // their names, from the label column
  rows: Array<Record<string, string | number>>;   // their columns as the table gave them (the label column excluded), one object per row
  at: { x: number; y: number };                  // where the click was, in the page
}

wafers are positions in your table. rows carries the columns for just those rows, so a link can be built from them. The names wafers and Charts for these wafers follow the table's words; the property names do not change.

TableTarget

interface TableTarget {
  id: string;
  label: string;
  section?: string;                                       // the heading the row sits under. Default "Open elsewhere"
  unavailable?: (selection: TableSelection) => string | null;   // why this selection cannot go here, or null
  run: (selection: TableSelection) => void;
}

Each target is a row in the menu a click opens. A target that returns a reason from unavailable is greyed in the menu and shows that reason. run is called with the selection when the reader chooses the row.

targets: [
  { id: 'lot-page', label: 'Open the lot page',
    unavailable: (s) => (new Set(s.rows.map(r => r.lot)).size === 1 ? null : 'Pick wafers from one lot'),
    run: (s) => location.assign(`/lots/${s.rows[0].lot}`) },
]

13.4 PlotWordsInput

interface PlotWordsInput {
  row?: string | [string, string];             // what the rows are: 'wafer', or ['region-month', 'region-months']
  item?: string | [string, string] | null;     // what the counts are of: 'die', 'order'. null: nothing is counted
  outcome?: string | { field?: string; value?: string };   // the outcome's name as a field ("Hard bin", "Delivery"), and as a prefix of a number ("Bin")
  rate?: string;                               // the good share: 'Yield', 'On-time rate'
  outcomeNames?: Record<string | number, string>;
}

A noun given as one word is made plural by adding "s"; give [one, many] when that is wrong. Anything left out keeps its wafer word. Titles, axes, footnotes, the builder's fields and the click menu use these words. outcomeNames may be given here or on the table.

Notes

  • Size. The charts suit a table of up to a few hundred rows. With thousands, a bar for each row cannot be read, so draw lots or devices instead, or filter first. A table of 3,000 rows draws six charts in under a second, and a vertical bar or box chart with more categories than fit shows a scrolling window of them.
  • Not included. Test values, die maps and retests need dies. The table does not load, cache or paginate your data: the page hands over the arrays.
  • Derived columns. A rule such as "the first wafer of each lot" is best prepared as a column on your side (a rank, a flag) and used as an ordinary filter on it.
  • Stability. The names above, the shape of the table and the plot JSON may change between versions. The plot format is the one the My charts tab keeps (readPlotsFile and writePlotsFile read and write it), so a saved chart carries across.