/** * Declared grids into the chart's summary grid. * * **A table is written, not plotted.** It is the one output that is not a value * per bar: its cells are written by library calls against a handle, into a * buffer the engine empties at the start of every execution of a bar * (`compiled-program.md` 2.8 and 5.1). What survives is what the last executed * bar wrote, which is what a grid pinned to a corner of a pane shows. * * **So it is read once, after the run, and never per bar.** The obvious way to * get this wrong is to collect a grid for every bar of a long history in order * to display the last one, which costs the length of the history and throws all * of it away. The engine holds one buffer per grid rather than one per bar, and * this reads it exactly once per calculation, so a hundred thousand bars cost * the same as ten. * * A script pays the other half of that bill for itself: `cell()` on every bar of * a long history does the work of writing a grid that only the last bar's copy * is kept from, and the documentation says to guard it with `bar.isLast`. That * is a script's decision and not one this can make for it, because the buffer is * cleared per bar and an engine cannot know which execution is the last one * until it is. * * **The engine's cells are sparse and the chart's grid is dense.** A script * writes the cells it has something to say about; the chart draws rows of cells. * So the declared size is filled with blank cells and the written ones are * placed into it, which is what `language.md` 6.7 asks for from the other * direction: a cell nothing was written into is blank, never a zero. * * **The language declares as many grids as it likes, and a chart with the list * of grids draws them all** (`capabilities.ts` says which chart has it). The * list holds each grid under an id the chart keeps it by, and every declared * grid is built for it here under its declaration's key. The single `table` * hook stays beside the list with the first grid in it, because a chart * without the list reads that one. Merging two grids into the single hook * would put cells somewhere the script never asked for, so on a chart without * the list a program declaring a second grid never reaches this file: * `undrawable.ts` refuses it before any bar runs, with OS6024. * `spec/chart-narrowings.json` records both halves and * `scripts/check-chart-surface.mjs` proves both with a study that declares two. */ import type { CompiledProgram } from '../../core/emit/index.js'; import type { Grid } from '../../core/engine/index.js'; import type { InputLookup } from './fields.js'; import type { ChartGrid, ChartTableSpec } from './surfaces.js'; /** * Every grid a chart draws, from the declarations and the engine's buffers. * * Each buffer is paired with its declaration by the key both of them carry * rather than by position. The engine reads its grids in declaration order, so * the two agree today, and a pairing by position is one reordering away from * drawing one grid's cells into another grid's shape, which would be a wrong * table that looks like a right one. * * The key is the id as well. The compiler writes one per declaration and never * an empty one, and it does not move between recomputes, which is what lets the * chart keep a grid rather than build it again on every tick. */ export declare function buildTables(program: CompiledProgram, lookup: InputLookup, written: readonly Grid[]): readonly ChartTableSpec[]; /** The first grid alone, for the single hook a chart without the list reads. */ export declare function firstGrid(tables: readonly ChartTableSpec[]): ChartGrid | null; //# sourceMappingURL=tables.d.ts.map