@bicharts/chart-host 0.5.48 → 0.5.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-A2GMXZP7.mjs";
7
7
 
8
8
  // src/contract.ts
9
- var HOST_CONTRACT_VERSION = "1.5.0";
9
+ var HOST_CONTRACT_VERSION = "1.6.0";
10
10
  var GEO_POINT_PRECISIONS = ["latlon", "city", "zip3", "state", "country"];
11
11
  var MARK_CLASS = "d3-mark";
12
12
  var LEGEND_MARK_CLASS = "d3-legend-mark";
@@ -1197,6 +1197,23 @@ function blankRenderFlag(lang, cause) {
1197
1197
  }
1198
1198
 
1199
1199
  // src/host.ts
1200
+ function sessionViewStateProvider(container) {
1201
+ const holder = container;
1202
+ const existing = holder[CONTAINER_SLOT_UI_STATE];
1203
+ const store = existing && typeof existing === "object" ? existing : holder[CONTAINER_SLOT_UI_STATE] = {};
1204
+ return {
1205
+ load: () => store,
1206
+ save: (next) => {
1207
+ if (!next || typeof next !== "object") return;
1208
+ for (const k2 of Object.keys(store)) delete store[k2];
1209
+ Object.assign(store, next);
1210
+ }
1211
+ };
1212
+ }
1213
+ function noopViewStateProvider() {
1214
+ return { load: () => ({}), save: () => {
1215
+ } };
1216
+ }
1200
1217
  var parseRowIdxs = (s) => (s || "").split(",").map((x2) => parseInt(x2, 10)).filter((n) => Number.isFinite(n));
1201
1218
  var D3_PLUGIN_PACKAGES = {
1202
1219
  sankey: "d3-sankey",
@@ -1280,16 +1297,22 @@ function createChartHost(container, config) {
1280
1297
  }
1281
1298
  let raw = { ...config.options ?? {} };
1282
1299
  if (typeof raw.setUiState !== "function") {
1283
- const holder = container;
1284
- const existing = holder[CONTAINER_SLOT_UI_STATE];
1285
- const store = existing && typeof existing === "object" ? existing : holder[CONTAINER_SLOT_UI_STATE] = {};
1286
- if (raw.uiState && typeof raw.uiState === "object" && Object.keys(store).length === 0)
1287
- Object.assign(store, raw.uiState);
1288
- raw.uiState = store;
1300
+ const provider = config.viewState ?? sessionViewStateProvider(container);
1301
+ let bag;
1302
+ try {
1303
+ bag = provider.load() ?? {};
1304
+ } catch {
1305
+ bag = {};
1306
+ }
1307
+ if (raw.uiState && typeof raw.uiState === "object" && Object.keys(bag).length === 0)
1308
+ Object.assign(bag, raw.uiState);
1309
+ raw.uiState = bag;
1289
1310
  raw.setUiState = (s) => {
1290
1311
  if (!s || typeof s !== "object") return;
1291
- for (const k2 of Object.keys(store)) delete store[k2];
1292
- Object.assign(store, s);
1312
+ try {
1313
+ provider.save(s);
1314
+ } catch {
1315
+ }
1293
1316
  };
1294
1317
  }
1295
1318
  let resolved = resolveOptions(raw);
@@ -1587,6 +1610,8 @@ export {
1587
1610
  censusMarks,
1588
1611
  isBlankRender,
1589
1612
  blankRenderFlag,
1613
+ sessionViewStateProvider,
1614
+ noopViewStateProvider,
1590
1615
  requiredD3Plugins,
1591
1616
  explainRenderFailure,
1592
1617
  stripEsmExports,
package/dist/index.mjs CHANGED
@@ -48,13 +48,15 @@ import {
48
48
  geoFromCache,
49
49
  isBlankRender,
50
50
  loadGeo,
51
+ noopViewStateProvider,
51
52
  periodTickSuppressesFeedback,
52
53
  registerGeo,
53
54
  registerGeoAsset,
54
55
  requiredD3Plugins,
55
56
  resolveOptions,
57
+ sessionViewStateProvider,
56
58
  stripEsmExports
57
- } from "./chunk-OSJNZVRA.mjs";
59
+ } from "./chunk-B4RZSFAC.mjs";
58
60
  import "./chunk-A2GMXZP7.mjs";
59
61
 
60
62
  // src/trivial.ts
@@ -580,6 +582,34 @@ function qualifyGroupHeadingFor(row, state) {
580
582
  }
581
583
  return null;
582
584
  }
585
+ function newQualifyRefusalGroupState() {
586
+ return { poorFit: false, cannotDraw: false };
587
+ }
588
+ function refusalIsSelectable(row) {
589
+ return !!row && row.isVeto !== true;
590
+ }
591
+ function orderRefusalsForDisplay(rows) {
592
+ if (!Array.isArray(rows)) return [];
593
+ const named = rows.filter((r) => !!r && typeof r.name === "string" && r.name.trim() !== "");
594
+ return [...named.filter(refusalIsSelectable), ...named.filter((r) => !refusalIsSelectable(r))];
595
+ }
596
+ function qualifyRefusalHeadingFor(row, state) {
597
+ if (refusalIsSelectable(row)) {
598
+ if (!state.poorFit) {
599
+ state.poorFit = true;
600
+ return "poorFit";
601
+ }
602
+ return null;
603
+ }
604
+ if (!state.cannotDraw) {
605
+ state.cannotDraw = true;
606
+ return "cannotDraw";
607
+ }
608
+ return null;
609
+ }
610
+ function hasRefusalsToShow(rows) {
611
+ return orderRefusalsForDisplay(rows).length > 0;
612
+ }
583
613
 
584
614
  // src/qualifyLaunch.ts
585
615
  var qualifyPick = (chartType) => ({ kind: "pick", chartType });
@@ -888,12 +918,16 @@ export {
888
918
  explainRenderFailure,
889
919
  geoAssetFor,
890
920
  geoFromCache,
921
+ hasRefusalsToShow,
891
922
  isBlankRender,
892
923
  launchFavorStyle,
893
924
  launchGenerates,
894
925
  loadGeo,
895
926
  newQualifyGroupState,
927
+ newQualifyRefusalGroupState,
928
+ noopViewStateProvider,
896
929
  normaliseAggregation,
930
+ orderRefusalsForDisplay,
897
931
  periodTickSuppressesFeedback,
898
932
  planTrivialChart,
899
933
  qualifyAuto,
@@ -901,12 +935,15 @@ export {
901
935
  qualifyFailureFallsOpen,
902
936
  qualifyGroupHeadingFor,
903
937
  qualifyPick,
938
+ qualifyRefusalHeadingFor,
904
939
  rasterizeSvgToPngDataUrl,
940
+ refusalIsSelectable,
905
941
  registerCityTable,
906
942
  registerGeo,
907
943
  registerGeoAsset,
908
944
  requiredD3Plugins,
909
945
  resolveOptions,
946
+ sessionViewStateProvider,
910
947
  shouldOpenChooserOnGenerate,
911
948
  shouldOpenInlineChooserOnGenerate,
912
949
  shouldReview,
package/dist/react.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  createChartHost,
5
5
  geoFromCache,
6
6
  loadGeo
7
- } from "./chunk-OSJNZVRA.mjs";
7
+ } from "./chunk-B4RZSFAC.mjs";
8
8
  import "./chunk-A2GMXZP7.mjs";
9
9
 
10
10
  // src/react.tsx
@@ -1,4 +1,4 @@
1
- export declare const HOST_CONTRACT_VERSION = "1.5.0";
1
+ export declare const HOST_CONTRACT_VERSION = "1.6.0";
2
2
  export type GeoPointPrecision = "latlon" | "city" | "zip3" | "state" | "country";
3
3
  /** Every valid tier, ordered most precise → coarsest. Runtime form of GeoPointPrecision. */
4
4
  export declare const GEO_POINT_PRECISIONS: readonly GeoPointPrecision[];
@@ -16,6 +16,32 @@ export declare const CONTAINER_SLOT_ANIM_STOP = "__llmAnimStop";
16
16
  export declare const CONTAINER_SLOT_XF_CLEAR = "__llmXfClear";
17
17
  export declare const CONTAINER_SLOT_INITIAL_XF_MARK = "__llmInitialXfMark";
18
18
  export declare const CONTAINER_SLOT_UI_STATE = "__lchUiState";
19
+ /**
20
+ * WHERE A CHART'S RESTING VIEW-STATE LIVES between draws (contract 1.6.0).
21
+ *
22
+ * Generated code never sees this. It keeps reading `options.uiState` and calling
23
+ * `options.setUiState(bag)`; `createChartHost` is what binds that pair to a provider. The seam
24
+ * exists because the answer genuinely differs per host: a Power BI visual persists into the
25
+ * report file so every viewer lands on the author's view, an Excel add-in persists into the
26
+ * workbook that travels with the sheet, a React page has only the session, and a static preview
27
+ * has nowhere at all. Before this, the first of those was a raw function pair passed by one
28
+ * caller and every other host got a session store hard-coded in the host runtime.
29
+ *
30
+ * IMPLEMENTORS: `load()` must never throw and returns `{}` when nothing is stored — a chart must
31
+ * never be blocked from drawing by a storage failure. `save()` takes the WHOLE new bag (REPLACE
32
+ * semantics, matching setUiState) and MAY DEBOUNCE; a drag emits hundreds of repaints and no
33
+ * host's persistence layer is a frame buffer.
34
+ *
35
+ * READERS: whatever comes back is UNTRUSTED. It may have been written by a previous generation of
36
+ * the chart, by a different chart on the same element, or by a person editing a file. Validate and
37
+ * clamp every value you read; a key you do not recognise is not an error, it is someone else's.
38
+ */
39
+ export interface ViewStateProvider {
40
+ /** The stored bag, or {} when there is none. Never throws. */
41
+ load(): Record<string, unknown>;
42
+ /** Replace the stored bag. May debounce internally. */
43
+ save(next: Record<string, unknown>): void;
44
+ }
19
45
  export declare const HOST_CONTAINER_CLASS = "bic-chart-host";
20
46
  export declare const SELECTION_ACTIVE_CLASS = "lch-has-selection";
21
47
  export declare const MARK_SELECTED_CLASS = "lch-mark-selected";
@@ -1,7 +1,29 @@
1
- import { type RenderOptions } from "./contract";
1
+ import { type RenderOptions, type ViewStateProvider } from "./contract";
2
2
  import { type ResolveOptionsInput } from "./defaults";
3
3
  import { type MarkCensus } from "./blankRender";
4
4
  export type RenderFn = (container: HTMLElement, data: any, options: RenderOptions) => void;
5
+ /**
6
+ * THE SESSION PROVIDER — what every host got hard-coded before contract 1.6.0, now named.
7
+ *
8
+ * The bag is parked on the CONTAINER ELEMENT, which outlives the host object in every host that
9
+ * destroys and re-creates itself on the same node — the Excel add-in does exactly that on every
10
+ * resize and every cell edit, so a chart's resting knob used to reset whenever the pane moved.
11
+ * It dies with the element, which is precisely the scope "session" means here.
12
+ *
13
+ * `load()` returns the LIVE store, and `save()` mutates it in place rather than replacing the
14
+ * object, so a caller holding the bag from before a save still sees the current values. That is
15
+ * the 1.5.0 behaviour preserved exactly.
16
+ */
17
+ export declare function sessionViewStateProvider(container: HTMLElement): ViewStateProvider;
18
+ /**
19
+ * NOWHERE TO PUT IT, said out loud. For a host with no session to speak of — a server-side
20
+ * render, a static preview, a thumbnail capture — where remembering would be wrong rather than
21
+ * merely absent: a thumbnail must be the same picture every time it is taken.
22
+ *
23
+ * Deliberately not the same as omitting a provider. Omitting one gets the session store and a
24
+ * chart that remembers within the page; choosing this one says the forgetting is the point.
25
+ */
26
+ export declare function noopViewStateProvider(): ViewStateProvider;
5
27
  export interface ChartHostConfig {
6
28
  data: {
7
29
  columns: any[];
@@ -28,6 +50,10 @@ export interface ChartHostConfig {
28
50
  renderFn?: RenderFn;
29
51
  /** Partial raw options; resolveOptions applies the shared defaults/clamps. */
30
52
  options?: ResolveOptionsInput;
53
+ /** WHERE this host keeps a chart's resting view-state (contract 1.6.0). Omit for the
54
+ * session store parked on the container — the behaviour every host had before 1.6.0.
55
+ * A raw `options.setUiState` still wins over this, so an existing caller is untouched. */
56
+ viewState?: ViewStateProvider;
31
57
  /** D3 v7 instance handed to the compiled code. Default: (globalThis as any).d3. */
32
58
  d3?: any;
33
59
  /** Attach geometry for this geoKind as options.geo (choropleths / basemaps). Resolved
@@ -1,17 +1,17 @@
1
- export { HOST_CONTRACT_VERSION, GEO_POINT_PRECISIONS, MARK_CLASS, LEGEND_MARK_CLASS, AXIS_FILTER_CLASS, ROW_IDX_ATTR, XFILTER_REFRESH_EVENT, CONTAINER_SLOT_ANIM_STOP, CONTAINER_SLOT_XF_CLEAR, CONTAINER_SLOT_INITIAL_XF_MARK, CONTAINER_SLOT_UI_STATE, HOST_CONTAINER_CLASS, SELECTION_ACTIVE_CLASS, MARK_SELECTED_CLASS, ACTIVE_TICK_CLASS, DIM_OPACITY_VAR, DIM_OPACITY_DEFAULT, chartOwnsTimeline, periodTickSuppressesFeedback, ANIM_PLAY_SPEED_DEFAULT, ANIM_PLAY_SPEED_MIN, ANIM_PLAY_SPEED_MAX, ANIM_LOOP_DELAY_DEFAULT, ANIM_LOOP_DELAY_MIN, ANIM_MAX_IDEAL_FRAMES_DEFAULT, ANIM_MAX_IDEAL_FRAMES_MIN, ANIM_MAX_IDEAL_FRAMES_MAX, COLOR_SCALE_SELF_CLAMP_PCT_DEFAULT, COLOR_SCALE_SELF_CLAMP_PCT_MIN, COLOR_SCALE_SELF_CLAMP_PCT_MAX, FLIP_MODE_DEFAULT, type GeoPointPrecision, type GeoMapKind, type TimelineStyle, type FlipMode, type ColorScaleScope, type RenderOptions, } from "./contract";
1
+ export { HOST_CONTRACT_VERSION, GEO_POINT_PRECISIONS, MARK_CLASS, LEGEND_MARK_CLASS, AXIS_FILTER_CLASS, ROW_IDX_ATTR, XFILTER_REFRESH_EVENT, CONTAINER_SLOT_ANIM_STOP, CONTAINER_SLOT_XF_CLEAR, CONTAINER_SLOT_INITIAL_XF_MARK, CONTAINER_SLOT_UI_STATE, HOST_CONTAINER_CLASS, SELECTION_ACTIVE_CLASS, MARK_SELECTED_CLASS, ACTIVE_TICK_CLASS, DIM_OPACITY_VAR, DIM_OPACITY_DEFAULT, chartOwnsTimeline, periodTickSuppressesFeedback, ANIM_PLAY_SPEED_DEFAULT, ANIM_PLAY_SPEED_MIN, ANIM_PLAY_SPEED_MAX, ANIM_LOOP_DELAY_DEFAULT, ANIM_LOOP_DELAY_MIN, ANIM_MAX_IDEAL_FRAMES_DEFAULT, ANIM_MAX_IDEAL_FRAMES_MIN, ANIM_MAX_IDEAL_FRAMES_MAX, COLOR_SCALE_SELF_CLAMP_PCT_DEFAULT, COLOR_SCALE_SELF_CLAMP_PCT_MIN, COLOR_SCALE_SELF_CLAMP_PCT_MAX, FLIP_MODE_DEFAULT, type GeoPointPrecision, type GeoMapKind, type TimelineStyle, type FlipMode, type ColorScaleScope, type RenderOptions, type ViewStateProvider, } from "./contract";
2
2
  export { resolveOptions, type ResolveOptionsInput } from "./defaults";
3
3
  export { loadGeo, geoFromCache, registerGeo, registerGeoAsset, geoAssetFor, clearGeoCache, type GeoAssetName, } from "./geoLazy";
4
4
  /** REPLACE the bundled city gazetteer with another packed table. Rarely needed — see the
5
5
  * note above registerCityTable in shape-core's geoPoint.ts before using it. */
6
6
  export declare function registerCityTable(packed: string): void;
7
7
  export { buildRenderPayload, type RenderPayload, type GeoPointBinding } from "./payload";
8
- export { createChartHost, compileRenderFn, stripEsmExports, requiredD3Plugins, explainRenderFailure, type ChartHost, type ChartHostConfig, type RenderFn } from "./host";
8
+ export { createChartHost, compileRenderFn, stripEsmExports, requiredD3Plugins, explainRenderFailure, sessionViewStateProvider, noopViewStateProvider, type ChartHost, type ChartHostConfig, type RenderFn } from "./host";
9
9
  export { createMarkResolver, type MarkResolver, type MarkResolverEnv } from "./selection";
10
10
  export { planTrivialChart, compileTrivialSource, type TrivialPlan, type TrivialShapeKind } from "./trivial";
11
11
  export { captureSvgSnapshot, svgToDataUrl, svgNaturalSize, rasterizeSvgToPngDataUrl, type SnapshotOptions } from "./snapshot";
12
12
  export { shouldReview, buildReviewWire, bareBase64, actionFor, type ReviewGate, type ReviewWire, type ReviewVerdict, type ReviewAction } from "./review";
13
13
  export { askApplyImprovements, type ReviewDialogOptions, type ReviewDialogText } from "./reviewDialog";
14
- export { qualifyGroupHeadingFor, newQualifyGroupState, type QualifyGroupRow, type QualifyGroupState, type QualifyGroupHeading, } from "./qualifyGroups";
14
+ export { qualifyGroupHeadingFor, newQualifyGroupState, type QualifyGroupRow, type QualifyGroupState, type QualifyGroupHeading, orderRefusalsForDisplay, refusalIsSelectable, hasRefusalsToShow, qualifyRefusalHeadingFor, newQualifyRefusalGroupState, type QualifyRefusalRow, type QualifyRefusalGroupState, type QualifyRefusalHeading, } from "./qualifyGroups";
15
15
  export { qualifyPick, qualifyAuto, qualifyCancel, launchGenerates, launchFavorStyle, chooserFitsViewport, shouldOpenChooserOnGenerate, shouldOpenInlineChooserOnGenerate, canConfirmLaunch, confirmLaunch, qualifyFailureFallsOpen, CHOOSER_MIN_WIDTH_PX, CHOOSER_MIN_HEIGHT_PX, type QualifyLaunchOutcome, type ChooserGateInput, } from "./qualifyLaunch";
16
16
  export { computeSelectionCard, normaliseAggregation, type SelectionCardModel, type SelectionCardLine, type SelectionCardOptions, } from "./selectionCard";
17
17
  export { ensureCrossfilterHitTargets, type HitTargetReport } from "./hitTargets";
@@ -29,3 +29,54 @@ export declare function newQualifyGroupState(): QualifyGroupState;
29
29
  * 3. "projected" and 4. "notRecommended" are unchanged from the single-host original.
30
30
  */
31
31
  export declare function qualifyGroupHeadingFor(row: QualifyGroupRow, state: QualifyGroupState): QualifyGroupHeading | null;
32
+ /** One row of a qualify result's `refused` array, in the only shape this logic cares about. */
33
+ export interface QualifyRefusalRow {
34
+ name?: string | null;
35
+ /** The gate's sentence. Absent is a real answer — the blocker rested on a runtime signal. */
36
+ reason?: string | null;
37
+ /** True = a required channel is ABSENT. Absent/false = a threshold we are willing to waive. */
38
+ isVeto?: boolean | null;
39
+ }
40
+ /** Which heading to write BEFORE a refused row, if any. */
41
+ export type QualifyRefusalHeading = "poorFit" | "cannotDraw";
42
+ /** Carried across the refusal loop. One per render. */
43
+ export interface QualifyRefusalGroupState {
44
+ poorFit: boolean;
45
+ cannotDraw: boolean;
46
+ }
47
+ export declare function newQualifyRefusalGroupState(): QualifyRefusalGroupState;
48
+ /**
49
+ * MAY THE READER PICK THIS ONE? The single place that answers it, in either host.
50
+ *
51
+ * DEFAULTS TO YES, and the asymmetry is deliberate. An older server sends no `isVeto` at all, so
52
+ * every row reads selectable and the reader is offered something that may be refused — one wasted
53
+ * click, and the refusal that follows names its own reason. The opposite default would hide charts
54
+ * from readers on exactly the servers that cannot tell us it is wrong to.
55
+ */
56
+ export declare function refusalIsSelectable(row: QualifyRefusalRow | null | undefined): boolean;
57
+ /**
58
+ * The refused rows in RENDER ORDER: everything pickable first, then the vetoes.
59
+ *
60
+ * A STABLE PARTITION, not a sort — within each block the server's alphabetical order survives, so
61
+ * two answers over the same shape stay diffable. Rows without a name are dropped: a control
62
+ * labelled with nothing cannot be chosen and a reason with no subject cannot be read.
63
+ *
64
+ * The two blocks are ordered pickable-first because the reader opened this section to DO something.
65
+ * Putting the inert half above the actionable half makes them scroll past every chart they cannot
66
+ * have to reach the ones they can.
67
+ */
68
+ export declare function orderRefusalsForDisplay<T extends QualifyRefusalRow>(rows: readonly T[] | null | undefined): T[];
69
+ /**
70
+ * The heading (if any) belonging immediately before `row`, MUTATING `state` — same shape as
71
+ * `qualifyGroupHeadingFor` so the two loops read alike.
72
+ *
73
+ * Assumes `rows` came through `orderRefusalsForDisplay`; fed an unpartitioned list it would write
74
+ * a heading at every alternation, which is why the ordering and the headings are one export pair
75
+ * rather than two independent helpers a host can half-adopt.
76
+ */
77
+ export declare function qualifyRefusalHeadingFor(row: QualifyRefusalRow, state: QualifyRefusalGroupState): QualifyRefusalHeading | null;
78
+ /**
79
+ * Is there anything behind "Show all chart types"? A checkbox that reveals nothing is worse than
80
+ * no checkbox: it reads as a broken control rather than an empty category.
81
+ */
82
+ export declare function hasRefusalsToShow(rows: readonly QualifyRefusalRow[] | null | undefined): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/chart-host",
3
- "version": "0.5.48",
3
+ "version": "0.5.50",
4
4
  "description": "Run a BIC-generated D3 chart in any web host: compiles the generated render() function, applies the shared option defaults, resolves mark clicks (through tooltip overlays), owns the selection affordance, and translates row indices between cross-filtered charts. The same contract the BIC Power BI visual implements, minus Power BI. React bindings at @bicharts/chart-host/react.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",