@bicharts/chart-host 0.6.22 → 0.6.24

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.
package/dist/index.mjs CHANGED
@@ -2400,6 +2400,33 @@ function armGenerateGuard(next, now) {
2400
2400
  return { ...next, startedAt: now, inFlight: true };
2401
2401
  }
2402
2402
 
2403
+ // src/lastChart.ts
2404
+ function canShowLastChart(cachedVersionPersisted, cachedCodePersisted) {
2405
+ return (cachedVersionPersisted ?? 0) > 0 && String(cachedCodePersisted ?? "").trim() !== "";
2406
+ }
2407
+ function shouldRestoreVersionAfterLicenseSave(currentVersionValue, cachedVersionPersisted, cachedCodePersisted) {
2408
+ return (currentVersionValue ?? 0) === 0 && canShowLastChart(cachedVersionPersisted, cachedCodePersisted);
2409
+ }
2410
+
2411
+ // src/filterNarrowing.ts
2412
+ function isNarrowedByFilter(s2) {
2413
+ if (s2.highWaterSchemaHash === null || s2.highWaterSchemaHash !== s2.currentSchemaHash) return false;
2414
+ if (!(s2.highWaterRows > 0)) return false;
2415
+ if (!(s2.currentRows > 0)) return false;
2416
+ return s2.currentRows < s2.highWaterRows;
2417
+ }
2418
+ function isEmptiedByFilter(s2) {
2419
+ if (s2.highWaterSchemaHash === null || s2.highWaterSchemaHash !== s2.currentSchemaHash) return false;
2420
+ if (!(s2.highWaterRows > 0)) return false;
2421
+ return s2.currentRows <= 0;
2422
+ }
2423
+ function updateRowHighWater(prevRows, prevSchemaHash, currentRows, currentSchemaHash) {
2424
+ if (prevSchemaHash !== currentSchemaHash) {
2425
+ return { rows: currentRows, schemaHash: currentSchemaHash };
2426
+ }
2427
+ return { rows: Math.max(prevRows, currentRows), schemaHash: currentSchemaHash };
2428
+ }
2429
+
2403
2430
  // src/clientIdentity.ts
2404
2431
  function stableFingerprintOptions() {
2405
2432
  return { exclude: ["fonts", "system.useragent", "system.browser.version"], logging: false };
@@ -2537,6 +2564,7 @@ export {
2537
2564
  buildRenderPayload,
2538
2565
  buildReviewWire,
2539
2566
  canConfirmLaunch,
2567
+ canShowLastChart,
2540
2568
  captureSvgSnapshot,
2541
2569
  cellSuppressesNormalize,
2542
2570
  censusColourSpread,
@@ -2585,10 +2613,12 @@ export {
2585
2613
  isBlankRender,
2586
2614
  isBlindMarker,
2587
2615
  isDuplicateGenerate,
2616
+ isEmptiedByFilter,
2588
2617
  isExcelDateFormat,
2589
2618
  isHorizontalLabelRow,
2590
2619
  isInsideControl,
2591
2620
  isInvalidSentinelError,
2621
+ isNarrowedByFilter,
2592
2622
  isPhantomBox,
2593
2623
  isPillBackdropAlpha,
2594
2624
  labelBand,
@@ -2652,6 +2682,7 @@ export {
2652
2682
  sessionViewStateProvider,
2653
2683
  shouldOpenChooserOnGenerate,
2654
2684
  shouldOpenInlineChooserOnGenerate,
2685
+ shouldRestoreVersionAfterLicenseSave,
2655
2686
  shouldReview,
2656
2687
  stableFingerprintOptions,
2657
2688
  stripEsmExports,
@@ -2664,6 +2695,7 @@ export {
2664
2695
  toSourceRows,
2665
2696
  transportFailureShouldRecover,
2666
2697
  unpinScrolledAxis,
2698
+ updateRowHighWater,
2667
2699
  valuePlacementFlag,
2668
2700
  vegaSpecReadsDatesInLocalTime,
2669
2701
  withoutViewOnlyKeys
@@ -0,0 +1,38 @@
1
+ export interface NarrowingState {
2
+ /** Row count of the dataset just delivered. */
3
+ currentRows: number;
4
+ /** Most rows ever seen for highWaterSchemaHash (0 = nothing recorded yet). */
5
+ highWaterRows: number;
6
+ /** Schema the high water was recorded against (null = nothing recorded yet). */
7
+ highWaterSchemaHash: number | null;
8
+ /** Schema of the dataset just delivered. */
9
+ currentSchemaHash: number;
10
+ }
11
+ /**
12
+ * True when the current dataset is a strict, non-empty subset of the largest one this schema has
13
+ * produced - a slicer or cross-filter is narrowing the data right now, and the chart is drawable but
14
+ * thin. Zero rows is a different state with its own predicate, `isEmptiedByFilter`, so neither caller
15
+ * has to re-check a row count to learn which question it got an answer to.
16
+ */
17
+ export declare function isNarrowedByFilter(s: NarrowingState): boolean;
18
+ /**
19
+ * True when the dataset has been filtered away to NOTHING - same schema, a positive high water, and
20
+ * zero rows now.
21
+ *
22
+ * Filtered-to-nothing is legitimately empty, but it is not indistinguishable from an empty dataset,
23
+ * and treating it as one cost a reader the connection between their own click and the chart that
24
+ * then read a flat "no data". The evidence needed is the SAME high-water signal: at zero rows, on an
25
+ * unchanged schema, a positive high water means this schema HAS delivered rows before and does not
26
+ * now. Only a filter does that. A changed schema resets the high water, so field drift reads a high
27
+ * water of 0 here and keeps the plain no-data wording.
28
+ */
29
+ export declare function isEmptiedByFilter(s: NarrowingState): boolean;
30
+ /**
31
+ * Roll the high-water mark forward for a completed load. Resets (rather than maxing) when the schema
32
+ * changes, so a field swap cannot leave a stale baseline from the previous schema making every later
33
+ * load look narrowed.
34
+ */
35
+ export declare function updateRowHighWater(prevRows: number, prevSchemaHash: number | null, currentRows: number, currentSchemaHash: number): {
36
+ rows: number;
37
+ schemaHash: number;
38
+ };
@@ -39,5 +39,7 @@ export { PENDING_RECOVERY_WINDOW_MS, PENDING_RECOVERY_POLL_MS, PENDING_RECOVERY_
39
39
  export { stripJsComments } from "./codeComments";
40
40
  export { reconcileChartPick, type ChartPickReconciliation } from "./chartPick";
41
41
  export { isDuplicateGenerate, armGenerateGuard, DUPLICATE_GENERATE_WINDOW_MS, type GenerateGuardKey, type GenerateGuardState, } from "./duplicateGenerateGuard";
42
+ export { canShowLastChart, shouldRestoreVersionAfterLicenseSave } from "./lastChart";
43
+ export { isNarrowedByFilter, isEmptiedByFilter, updateRowHighWater, type NarrowingState, } from "./filterNarrowing";
42
44
  export { stableFingerprintOptions, fingerprintComponentDigest, type ClientIdSource } from "./clientIdentity";
43
45
  export type { HostServices, MarkerStore, PreferenceSource, HostTheme, ThemeSource, ThumbnailConsent, SnapshotTarget, WireSigner, WireTransport, WireResponse, CredentialTriple, CredentialSource, ViewportSource, Clock, DiagnosticEntry, DiagnosticsSink, RendererId, } from "./host/services";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Should the "show last chart" way back be offered?
3
+ *
4
+ * @param cachedVersionPersisted the PERSISTED cached version (not live render state)
5
+ * @param cachedCodePersisted the PERSISTED cached code (not live render state)
6
+ *
7
+ * True when a positive version is cached and its code is not blank.
8
+ */
9
+ export declare function canShowLastChart(cachedVersionPersisted: number | null | undefined, cachedCodePersisted: string | null | undefined): boolean;
10
+ /**
11
+ * After a licence is saved, should the host restore the cached version on its own?
12
+ *
13
+ * Only when the current version is 0 (missing reads as 0) - the reader was parked on the landing
14
+ * state - and there is a last chart to go back to (`canShowLastChart`).
15
+ */
16
+ export declare function shouldRestoreVersionAfterLicenseSave(currentVersionValue: number | null | undefined, cachedVersionPersisted: number | null | undefined, cachedCodePersisted: string | null | undefined): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/chart-host",
3
- "version": "0.6.22",
3
+ "version": "0.6.24",
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",