@bicharts/chart-host 0.5.88 → 0.5.89

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
@@ -1960,14 +1960,27 @@ function pickDistinctColorFromSeed(seedHex, existing, minDistance = MIN_DELTA_E)
1960
1960
  return { hex: seed.hex(), registerHex: bestCandidate.hex() };
1961
1961
  }
1962
1962
  function buildPaletteFromSeed(seedHex, count, minDistance = MIN_DELTA_E) {
1963
+ return buildPalette(() => seedHex, count, minDistance);
1964
+ }
1965
+ function buildPalette(seedFor, count, minDistance = MIN_DELTA_E) {
1963
1966
  const out = [];
1964
- if (!seedHex || !(count > 0)) return out;
1967
+ if (!(count > 0)) return out;
1965
1968
  const issued = /* @__PURE__ */ new Set();
1966
1969
  const issuedCs = [];
1967
1970
  const distance = (hex) => issuedCs.length === 0 ? Number.POSITIVE_INFINITY : Math.min(...issuedCs.map((c2) => Mt(hex).deltaE(c2, "CIE2000")));
1968
1971
  let sweep = null;
1969
1972
  let sweepAt = 0;
1973
+ let lastSeed = "";
1970
1974
  for (let i2 = 0; i2 < count; i2++) {
1975
+ let seedHex = "";
1976
+ try {
1977
+ seedHex = normalise(seedFor(i2));
1978
+ } catch {
1979
+ seedHex = "";
1980
+ }
1981
+ if (!seedHex) seedHex = lastSeed;
1982
+ if (!seedHex) break;
1983
+ lastSeed = seedHex;
1971
1984
  const { hex, registerHex } = pickDistinctColorFromSeed(seedHex, issued, minDistance);
1972
1985
  let chosen = hex;
1973
1986
  let register = registerHex;
@@ -1997,6 +2010,9 @@ function buildPaletteFromSeed(seedHex, count, minDistance = MIN_DELTA_E) {
1997
2010
  }
1998
2011
  return out;
1999
2012
  }
2013
+ function normalise(seed) {
2014
+ return typeof seed === "string" ? seed.trim() : "";
2015
+ }
2000
2016
  function sweepCandidates(seedHex) {
2001
2017
  const [h2, s2, l2] = Mt(seedHex).hsl();
2002
2018
  const baseHue = Number.isFinite(h2) ? h2 : 210;
@@ -2087,6 +2103,7 @@ export {
2087
2103
  backingHoldsGlyph,
2088
2104
  bareBase64,
2089
2105
  blankRenderFlag,
2106
+ buildPalette,
2090
2107
  buildPaletteFromSeed,
2091
2108
  buildRenderPayload,
2092
2109
  buildReviewWire,
@@ -25,4 +25,4 @@ export { SCROLL_SLACK_PX, MAX_FRAME_GROW_FACTOR, PHANTOM_FRACTION, FIT_CONTENT_S
25
25
  export { fitRenderedChart, fitReadingFor, measureContainerBoxes, svgInkReach, ctmScaleOf, type FitReading, type InkReach, type FitRenderedChartOptions, type FitRenderedChartResult, } from "./fitDom";
26
26
  export { AXIS_PIN_MIN_LABELS, AXIS_PIN_BAND_PAD_PX, AXIS_PIN_MAX_BAND_FRACTION, AXIS_PIN_TRACK_REACH_PX, isHorizontalLabelRow, labelBand, planAxisPin, axisPinPlacement, type LabelRowBox, type AxisBand, type AxisPinCandidate, type AxisPinPlan, type AxisPinEdge, } from "./fit";
27
27
  export { pinScrolledAxis, unpinScrolledAxis, type AxisPinReport } from "./fitDom";
28
- export { MIN_DELTA_E, pickDistinctColorFromSeed, buildPaletteFromSeed, type PaletteResult } from "./palette";
28
+ export { MIN_DELTA_E, pickDistinctColorFromSeed, buildPalette, buildPaletteFromSeed, type PaletteResult, type SeedForSlot, } from "./palette";
@@ -50,3 +50,29 @@ export declare function pickDistinctColorFromSeed(seedHex: string, existing: Rea
50
50
  * result and re-derive it later without the colours shifting under a saved chart.
51
51
  */
52
52
  export declare function buildPaletteFromSeed(seedHex: string, count: number, minDistance?: number): string[];
53
+ /**
54
+ * WHERE EACH SLOT'S BASE COLOUR COMES FROM. Called with the slot index, 0-based.
55
+ *
56
+ * Returning a blank or nothing means "no base colour for this slot" - the builder then falls
57
+ * back to the last one that WAS supplied, so a host whose colour source runs dry degrades into
58
+ * spreading rather than into a gap.
59
+ */
60
+ export type SeedForSlot = (slot: number) => string | null | undefined;
61
+ /**
62
+ * The general form: a palette whose BASE COLOURS the host decides, slot by slot.
63
+ *
64
+ * THIS IS THE RICH FORM AND `buildPaletteFromSeed` IS THE DEGENERATE ONE. Read that sentence
65
+ * before "simplifying" a host onto the single-seed call, because the difference is a real loss
66
+ * and it is invisible in the output - both return a plausible list of distinct colours.
67
+ *
68
+ * Power BI hands a visual a DIFFERENT theme colour per slot (`colorPalette.getColor("1")`,
69
+ * `getColor("2")`, ...). Every one of those is a deliberate choice by whoever built the report
70
+ * theme, and feeding them in per slot means the walk usually settles at step 1 and RETURNS THEM
71
+ * UNCHANGED - the chart is coloured by the theme, not by our arithmetic. Collapse that host onto
72
+ * one seed and twenty authored colours become one authored colour plus nineteen derived ones:
73
+ * still distinct, still pretty, and no longer the report's.
74
+ *
75
+ * A host with no such API - an Excel workbook offers exactly one resolvable accent - passes a
76
+ * constant provider and the walk does the spreading. That is a fallback, not the design.
77
+ */
78
+ export declare function buildPalette(seedFor: SeedForSlot, count: number, minDistance?: number): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/chart-host",
3
- "version": "0.5.88",
3
+ "version": "0.5.89",
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",