mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 10:12:34 +00:00
Chart builder: discoverable entry points — Build Chart door, dataset picker, no-datasets state
This commit is contained in:
@@ -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>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user