Loading documentation…
Creates the per-store chart view cache a chart renderer reads from.
Views resolve lazily on first get and stay cached until a chart-change
event names that chart, so repeated frames never reread cells.
function watchChart() { } }); return () => { unsubscribe(); };}Workspace packages depending on @sheetwrite/charts
@sheetwrite/docs-startdependencyPublic exports naming createChartViewCache
import { createChartViewCache, type ChartView } from "@sheetwrite/charts";
import type { SheetId, Store } from "@sheetwrite/core";
function watchChart(
store: Store,
sheet: SheetId,
id: string,
render: (view: ChartView | null) => void,
) {
const charts = createChartViewCache(store);
render(charts.get({ sheet, id }));
const unsubscribe = charts.subscribe((event) => {
if (event.charts.some((chart) => chart.sheet === sheet && chart.id === id)) {
render(charts.get({ sheet, id }));
}
});
return () => {
unsubscribe();
charts.dispose();
};
}API reference →interface ChartViewinterface ChartViewinterface ChartViewOne immutable-by-convention rendering input, refreshed on chart-change events.API reference →type SheetId = stringtype SheetId = string;type SheetId = string;Stable identifier used to address a workbook sheet.API reference →interface Storeinterface Storeinterface StoreColumnar workbook storage, query, transaction, and subscription contract.API reference →function watchChart(store: Store, sheet: SheetId, id: string, render: (view: ChartView | null) => void): () => voidfunction watchChart(
store: Store,
sheet: SheetId,
id: string,
render: (view: ChartView | null) => void,
): () => voidfunction watchChart(
store: Store,
sheet: SheetId,
id: string,
render: (
view: ChartView | null,
) => void,
): () => voidsheet: stringlet sheet: stringlet sheet: stringSheet identity used by the simple data-first adapter. Defaults to sheet1.API reference →id: stringlet id: stringlet id: stringStable identity used by operations, history, and collaboration rebase.API reference →render: (view: ChartView | null) => voidlet render: (view: ChartView | null) => voidlet render: (
view: ChartView | null,
) => voidFill body, then return a function that releases what render set up.API reference →const charts: ChartViewProviderconst charts: ChartViewProviderconst charts: ChartViewProviderCharts to resolve again, in commit order of the edits that touched them.API reference →store: Storelet store: Storelet store: StoreAPI reference →ChartViewProvider.get(chart: ChartRef): ChartView | nullChartViewProvider.get(chart: ChartRef): ChartView | nullChartViewProvider.get(chart: ChartRef): ChartView | nullResolve on first access; later accesses use the cached committed view.API reference →ChartRef.sheet: stringinterface ChartRef {
sheet: string;
}interface ChartRef {
sheet: string;
}Sheet identity used by the simple data-first adapter. Defaults to sheet1.API reference →ChartRef.id: stringinterface ChartRef {
id: string;
}interface ChartRef {
id: string;
}Stable identity used by operations, history, and collaboration rebase.API reference →const unsubscribe: () => voidconst unsubscribe: () => voidconst unsubscribe: () => voidChartViewProvider.subscribe(listener: ChartChangeListener): () => voidChartViewProvider.subscribe(listener: ChartChangeListener): () => voidChartViewProvider.subscribe(listener: ChartChangeListener): () => voidObserve invalidation after cached views have been removed.API reference →event: ChartChangeEventlet event: ChartChangeEventlet event: ChartChangeEventAPI reference →ChartChangeEvent.charts: readonly ChartRef[]interface ChartChangeEvent {
charts: readonly ChartRef[];
}interface ChartChangeEvent {
charts: readonly ChartRef[];
}Charts to resolve again, in commit order of the edits that touched them.API reference →ReadonlyArray<ChartRef>.some(predicate: (value: ChartRef, index: number, array: readonly ChartRef[]) => unknown, thisArg?: any): booleanReadonlyArray<ChartRef>.some(predicate: (value: ChartRef, index: number, array: readonly ChartRef[]) => unknown, thisArg?: any): booleanReadonlyArray<ChartRef>.some(predicate: (value: ChartRef, index: number, array: readonly ChartRef[]) => unknown, thisArg?: any): booleanDetermines whether the specified callback function returns true for any element of an array.@param predicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.@param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.API reference →chart: ChartReflet chart: ChartReflet chart: ChartRefAPI reference →ChartViewProvider.dispose(): voidChartViewProvider.dispose(): voidChartViewProvider.dispose(): voidStop observing the store and release cached views.API reference →interface Store {
getWorkbook(): Workbook;
getCell(addr: CellAddress): ResolvedCell;
getFormula(addr: CellAddress): string | null;
getSpillAnchor(addr: CellAddress): CellAddress | null;
getRefTarget(addr: CellAddress): CellAddress | null;
recalculateVolatile(now?: Date): void;
getVisibleWindow(
sheet: SheetId,
rows: { start: number; end: number },
cols: readonly number[],
): VisibleWindowView;
getDataWindow?(
sheet: SheetId,
rows: { start: number; end: number },
// … 27 more lines — see the API reference
}interface Store {
getWorkbook(): Workbook;
getCell(addr: CellAddress): ResolvedCell;
getFormula(addr: CellAddress): string | null;
getSpillAnchor(addr: CellAddress): CellAddress | null;
getRefTarget(addr: CellAddress): CellAddress | null;
recalculateVolatile(now?: Date): void;
getVisibleWindow(
sheet: SheetId,
rows: { start: number; end: number },
cols: readonly number[],
): VisibleWindowView;
getDataWindow?(
sheet: SheetId,
rows: { start: number; end: number },
// … 27 more lines — see the API reference
}interface Store {
getWorkbook(): Workbook;
getCell(
addr: CellAddress,
): ResolvedCell;
getFormula(
addr: CellAddress,
): string | null;
getSpillAnchor(
addr: CellAddress,
): CellAddress | null;
getRefTarget(
addr: CellAddress,
): CellAddress | null;
recalculateVolatile(
now?: Date,
): void;
getVisibleWindow(
sheet: SheetId,
// … 60 more lines — see the API reference
}Columnar workbook storage, query, transaction, and subscription contract.API reference →type ChartViewCache = ChartViewProvider;type ChartViewCache = ChartViewProvider;type ChartViewCache =
ChartViewProvider;Resolved chart views for one store, refreshed only by chart-change events. Listeners run after the changed charts are invalidated, so get inside a listener always resolves the committed cell data.API reference →