Chart builder: discoverable entry points — Build Chart door, dataset picker, no-datasets state

This commit is contained in:
2026-06-12 21:46:25 +03:00
parent dbb4522d78
commit ca70b3e491
22 changed files with 625 additions and 75 deletions
+24
View File
@@ -1034,6 +1034,30 @@ export function pruneEncodings(config: BuilderConfig, base: BuilderColumns): Bui
return changed ? { ...config, encodings } : config;
}
/**
* Re-point an in-progress config at a different dataset (spec §06 → Dataset
* picker). Chart-level intent survives the switch — mark, title/subtitle,
* explicit size, sort/stack, calculated fields, and expression filters (their
* `datum` references are surfaced by the unknown-field feedback, not dropped) —
* while anything bound to a column the new dataset doesn't have is shed:
* encodings via `pruneEncodings`, predicate filters by field lookup. With a
* same-schema dataset (the common switch: a fresher version of the same data)
* everything survives verbatim.
*/
export function rebaseBuilderConfig(
config: BuilderConfig,
datasetName: string,
columns: BuilderColumns,
): BuilderConfig {
const available = new Set(effectiveColumns(columns, config.calculates).columns);
const filters = (config.filters ?? []).filter(
(f) => f.mode === 'expression' || (f.field !== undefined && available.has(f.field)),
);
const rebased: BuilderConfig = { ...config, datasetName };
if (config.filters !== undefined) rebased.filters = filters;
return pruneEncodings(rebased, columns);
}
/** A built Vega-Lite spec, as a plain object (serialize with `buildSnippetSpecText`). */
export type ChartSpec = Record<string, unknown>;