@bicharts/chart-host 0.5.7 → 0.5.9
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/{chunk-RENIKQVS.mjs → chunk-L5Y6RLK2.mjs} +166 -165
- package/dist/index.mjs +1 -1
- package/dist/react.mjs +1 -1
- package/package.json +1 -1
|
@@ -33,49 +33,49 @@ var COLOR_SCALE_SELF_CLAMP_PCT_MAX = 100;
|
|
|
33
33
|
|
|
34
34
|
// src/defaults.ts
|
|
35
35
|
var clamp = (n, lo, hi) => Math.max(lo, Math.min(hi, n));
|
|
36
|
-
function resolveOptions(
|
|
36
|
+
function resolveOptions(p) {
|
|
37
37
|
return {
|
|
38
38
|
// ---- host fields: pass through exactly as supplied ----
|
|
39
|
-
width:
|
|
40
|
-
height:
|
|
41
|
-
palette:
|
|
42
|
-
geoUnmatched:
|
|
43
|
-
geo:
|
|
44
|
-
geoPoint:
|
|
45
|
-
maxMapPoints:
|
|
46
|
-
uiState:
|
|
47
|
-
setUiState:
|
|
48
|
-
backgroundColor:
|
|
49
|
-
themeBg:
|
|
50
|
-
themeFg:
|
|
51
|
-
isHighContrast:
|
|
52
|
-
themeAccent:
|
|
53
|
-
cultureCode:
|
|
54
|
-
allowTooltips:
|
|
55
|
-
noDataText:
|
|
56
|
-
onSelect:
|
|
39
|
+
width: p.width,
|
|
40
|
+
height: p.height,
|
|
41
|
+
palette: p.palette,
|
|
42
|
+
geoUnmatched: p.geoUnmatched,
|
|
43
|
+
geo: p.geo,
|
|
44
|
+
geoPoint: p.geoPoint,
|
|
45
|
+
maxMapPoints: p.maxMapPoints,
|
|
46
|
+
uiState: p.uiState,
|
|
47
|
+
setUiState: p.setUiState,
|
|
48
|
+
backgroundColor: p.backgroundColor,
|
|
49
|
+
themeBg: p.themeBg,
|
|
50
|
+
themeFg: p.themeFg,
|
|
51
|
+
isHighContrast: p.isHighContrast,
|
|
52
|
+
themeAccent: p.themeAccent,
|
|
53
|
+
cultureCode: p.cultureCode,
|
|
54
|
+
allowTooltips: p.allowTooltips,
|
|
55
|
+
noDataText: p.noDataText,
|
|
56
|
+
onSelect: p.onSelect,
|
|
57
57
|
// ---- live-restyle knobs: `raw || undefined` / `.toString() || undefined` ----
|
|
58
|
-
colorScaleLow:
|
|
59
|
-
colorScaleHigh:
|
|
58
|
+
colorScaleLow: p.colorScaleLow || void 0,
|
|
59
|
+
colorScaleHigh: p.colorScaleHigh || void 0,
|
|
60
60
|
// "" (global, the default), "frame", or "self"; anything else fails open to global.
|
|
61
|
-
colorScaleScope:
|
|
61
|
+
colorScaleScope: p.colorScaleScope === "frame" || p.colorScaleScope === "self" ? p.colorScaleScope : "",
|
|
62
62
|
// Math.max(50, Math.min(100, Number(raw) || 95)) — only meaningful under "self".
|
|
63
|
-
colorScaleSelfClampPct: clamp(Number(
|
|
63
|
+
colorScaleSelfClampPct: clamp(Number(p.colorScaleSelfClampPct) || COLOR_SCALE_SELF_CLAMP_PCT_DEFAULT, COLOR_SCALE_SELF_CLAMP_PCT_MIN, COLOR_SCALE_SELF_CLAMP_PCT_MAX),
|
|
64
64
|
// Map fills: `raw || undefined` like the colour-scale endpoints. The no-data ->
|
|
65
65
|
// land cascade is left to the chart (so the fallback chain is visible in the
|
|
66
66
|
// generated code); HC substitution has already happened in the caller.
|
|
67
|
-
geoLandColor:
|
|
68
|
-
geoNoDataColor:
|
|
69
|
-
aggregation: (
|
|
67
|
+
geoLandColor: p.geoLandColor || void 0,
|
|
68
|
+
geoNoDataColor: p.geoNoDataColor || void 0,
|
|
69
|
+
aggregation: (p.aggregation == null ? "" : String(p.aggregation)) || void 0,
|
|
70
70
|
// ---- animation: booleans, default+clamp numerics, "" default enum ----
|
|
71
|
-
animAutoPlay: !!
|
|
71
|
+
animAutoPlay: !!p.animAutoPlay,
|
|
72
72
|
// Math.max(250, Math.min(5000, Number(raw) || 1000))
|
|
73
|
-
animPlaySpeedMs: clamp(Number(
|
|
73
|
+
animPlaySpeedMs: clamp(Number(p.animPlaySpeedMs) || ANIM_PLAY_SPEED_DEFAULT, ANIM_PLAY_SPEED_MIN, ANIM_PLAY_SPEED_MAX),
|
|
74
74
|
// Math.max(3, Math.min(500, Number(raw) || 60))
|
|
75
|
-
animMaxIdealFrames: clamp(Number(
|
|
76
|
-
animStopAtEnd: !!
|
|
77
|
-
filtersDuringPlay: !!
|
|
78
|
-
animTimelineStyle: (
|
|
75
|
+
animMaxIdealFrames: clamp(Number(p.animMaxIdealFrames) || ANIM_MAX_IDEAL_FRAMES_DEFAULT, ANIM_MAX_IDEAL_FRAMES_MIN, ANIM_MAX_IDEAL_FRAMES_MAX),
|
|
76
|
+
animStopAtEnd: !!p.animStopAtEnd,
|
|
77
|
+
filtersDuringPlay: !!p.filtersDuringPlay,
|
|
78
|
+
animTimelineStyle: (p.animTimelineStyle || "").toString()
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -85,12 +85,12 @@ var byAsset = /* @__PURE__ */ new Map();
|
|
|
85
85
|
var _na;
|
|
86
86
|
function geoAssetFor(geoKind) {
|
|
87
87
|
if (!geoKind) return null;
|
|
88
|
-
const
|
|
89
|
-
if (/^country/.test(
|
|
90
|
-
if (
|
|
91
|
-
if (
|
|
92
|
-
if (
|
|
93
|
-
if (
|
|
88
|
+
const k2 = geoKind.toLowerCase();
|
|
89
|
+
if (/^country/.test(k2)) return "world";
|
|
90
|
+
if (k2 === "north-america") return "world";
|
|
91
|
+
if (k2 === "world") return "world";
|
|
92
|
+
if (k2 === "us-state-code" || k2 === "us-state-name") return "us-states";
|
|
93
|
+
if (k2 === "us-zip5") return "us-zip3";
|
|
94
94
|
return null;
|
|
95
95
|
}
|
|
96
96
|
var _worldBase;
|
|
@@ -344,14 +344,14 @@ function r3(n) {
|
|
|
344
344
|
if (a2 && o && i3(a2) !== o && (a2 = null), n.city !== void 0 && n.city !== null) {
|
|
345
345
|
let r = u(String(n.city)), l = F[n.mapKind || "north-america"] ?? "N", f = Y(r);
|
|
346
346
|
if (f) {
|
|
347
|
-
let C = n.state === void 0 || n.state === null ? "" : String(n.state).trim(), d2 = C ? u(C) : "",
|
|
347
|
+
let C = n.state === void 0 || n.state === null ? "" : String(n.state).trim(), d2 = C ? u(C) : "", p = C ? H(C) : null, S = [], R = -1;
|
|
348
348
|
for (let s of f) {
|
|
349
|
-
let
|
|
350
|
-
if (!
|
|
349
|
+
let A = s.row;
|
|
350
|
+
if (!A.kinds.includes(l)) continue;
|
|
351
351
|
let c = 0;
|
|
352
|
-
if (C &&
|
|
352
|
+
if (C && A.a1 !== "") if (p && A.a1 === p || u(A.a1) === d2) c++;
|
|
353
353
|
else continue;
|
|
354
|
-
if (o) if (I(
|
|
354
|
+
if (o) if (I(A.cc) === o) c++;
|
|
355
355
|
else continue;
|
|
356
356
|
c > R ? (R = c, S = [s]) : c === R && S.push(s);
|
|
357
357
|
}
|
|
@@ -382,26 +382,26 @@ function r3(n) {
|
|
|
382
382
|
var U = { latlon: 0, city: 1, zip3: 2, state: 3, country: 4 };
|
|
383
383
|
var V = 8;
|
|
384
384
|
function N3(n, e) {
|
|
385
|
-
let t = new Array(n.length), i = new Array(n.length), o = /* @__PURE__ */ new Set(), a2 = [], r = /* @__PURE__ */ new Set(), l = [], f = /* @__PURE__ */ new Set(), C = [], d2 = { latlon: 0, city: 0, zip3: 0, state: 0, country: 0 },
|
|
385
|
+
let t = new Array(n.length), i = new Array(n.length), o = /* @__PURE__ */ new Set(), a2 = [], r = /* @__PURE__ */ new Set(), l = [], f = /* @__PURE__ */ new Set(), C = [], d2 = { latlon: 0, city: 0, zip3: 0, state: 0, country: 0 }, p = 0, S = 0, R = null;
|
|
386
386
|
for (let s = 0; s < n.length; ++s) {
|
|
387
|
-
let
|
|
387
|
+
let A = n[s], c = r3({ ...A, mapKind: e });
|
|
388
388
|
if (o3(c)) {
|
|
389
389
|
t[s] = null, i[s] = null, S++;
|
|
390
|
-
let
|
|
391
|
-
|
|
390
|
+
let M = E(A);
|
|
391
|
+
M && !f.has(M.toLowerCase()) && (f.add(M.toLowerCase()), C.length < V && C.push(M));
|
|
392
392
|
} else if (c) {
|
|
393
|
-
if (t[s] = c.lat, i[s] = c.lon,
|
|
394
|
-
let
|
|
395
|
-
|
|
393
|
+
if (t[s] = c.lat, i[s] = c.lon, p++, d2[c.precision]++, (R === null || U[c.precision] > U[R]) && (R = c.precision), U[c.precision] > U.city) {
|
|
394
|
+
let M = E(A);
|
|
395
|
+
M && !r.has(M.toLowerCase()) && (r.add(M.toLowerCase()), l.length < V && l.push(M));
|
|
396
396
|
}
|
|
397
397
|
} else {
|
|
398
398
|
t[s] = null, i[s] = null;
|
|
399
|
-
let
|
|
400
|
-
|
|
399
|
+
let M = E(A);
|
|
400
|
+
M && !o.has(M.toLowerCase()) && (o.add(M.toLowerCase()), a2.push(M));
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
let N2 = !v() && n.some((s) => s.city !== null && s.city !== void 0 && String(s.city).trim() !== "");
|
|
404
|
-
return { lat: t, lon: i, precision: R, precisionCounts: d2, coarseExamples: l, unmatched: a2, ambiguousRows: S, ambiguousExamples: C, matchedRows:
|
|
404
|
+
return { lat: t, lon: i, precision: R, precisionCounts: d2, coarseExamples: l, unmatched: a2, ambiguousRows: S, ambiguousExamples: C, matchedRows: p, totalRows: n.length, ...N2 ? { cityTableMissing: true } : {} };
|
|
405
405
|
}
|
|
406
406
|
function E(n) {
|
|
407
407
|
return [n.city, n.state, n.zip, n.country].filter((e) => e != null && String(e).trim() !== "").map((e) => String(e).trim()).join(", ");
|
|
@@ -414,16 +414,20 @@ function s3(n, e) {
|
|
|
414
414
|
return t.some((o) => o.row.kinds.includes(i));
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
-
// ../shape-core/dist/chunk-
|
|
417
|
+
// ../shape-core/dist/chunk-7GWUBKNE.mjs
|
|
418
418
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
419
|
-
var
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
419
|
+
var sn = /* @__PURE__ */ new Set(["n a", "none", "null", "nil", "unknown", "not applicable", "not available", "not specified", "unspecified", "missing", "blank", "empty", "tbd", "to be determined"]);
|
|
420
|
+
function Sn(n) {
|
|
421
|
+
return n ? sn.has(n) : true;
|
|
422
|
+
}
|
|
423
|
+
var B2 = [["AL", "Alabama"], ["AK", "Alaska"], ["AZ", "Arizona"], ["AR", "Arkansas"], ["CA", "California"], ["CO", "Colorado"], ["CT", "Connecticut"], ["DE", "Delaware"], ["FL", "Florida"], ["GA", "Georgia"], ["HI", "Hawaii"], ["ID", "Idaho"], ["IL", "Illinois"], ["IN", "Indiana"], ["IA", "Iowa"], ["KS", "Kansas"], ["KY", "Kentucky"], ["LA", "Louisiana"], ["ME", "Maine"], ["MD", "Maryland"], ["MA", "Massachusetts"], ["MI", "Michigan"], ["MN", "Minnesota"], ["MS", "Mississippi"], ["MO", "Missouri"], ["MT", "Montana"], ["NE", "Nebraska"], ["NV", "Nevada"], ["NH", "New Hampshire"], ["NJ", "New Jersey"], ["NM", "New Mexico"], ["NY", "New York"], ["NC", "North Carolina"], ["ND", "North Dakota"], ["OH", "Ohio"], ["OK", "Oklahoma"], ["OR", "Oregon"], ["PA", "Pennsylvania"], ["RI", "Rhode Island"], ["SC", "South Carolina"], ["SD", "South Dakota"], ["TN", "Tennessee"], ["TX", "Texas"], ["UT", "Utah"], ["VT", "Vermont"], ["VA", "Virginia"], ["WA", "Washington"], ["WV", "West Virginia"], ["WI", "Wisconsin"], ["WY", "Wyoming"], ["DC", "District of Columbia"], ["PR", "Puerto Rico"], ["GU", "Guam"], ["VI", "U.S. Virgin Islands"], ["AS", "American Samoa"], ["MP", "Northern Mariana Islands"]];
|
|
424
|
+
var X2 = new Set(B2.map((n) => n[0]));
|
|
425
|
+
var on = { "Ala.": "AL", "Alab.": "AL", "Ariz.": "AZ", "Ark.": "AR", "Calif.": "CA", "Cal.": "CA", "Colo.": "CO", "Col.": "CO", "Conn.": "CT", "Del.": "DE", "Fla.": "FL", "Flor.": "FL", "Ga.": "GA", "Ill.": "IL", "Ind.": "IN", "Kan.": "KS", "Kans.": "KS", "Ky.": "KY", "La.": "LA", "Md.": "MD", "Mass.": "MA", "Mich.": "MI", "Minn.": "MN", "Miss.": "MS", "Mo.": "MO", "Mont.": "MT", "Neb.": "NE", "Nebr.": "NE", "Nev.": "NV", "N.H.": "NH", "N.J.": "NJ", "N.M.": "NM", "N.Mex.": "NM", "N. Mex.": "NM", "N.Y.": "NY", "N.C.": "NC", "N.D.": "ND", "N.Dak.": "ND", "N. Dak.": "ND", "Okla.": "OK", "Ore.": "OR", "Oreg.": "OR", "Pa.": "PA", "Penn.": "PA", "Penna.": "PA", "R.I.": "RI", "S.C.": "SC", "S.D.": "SD", "S.Dak.": "SD", "S. Dak.": "SD", "Tenn.": "TN", "Tex.": "TX", "Vt.": "VT", "Va.": "VA", "Wash.": "WA", "W.Va.": "WV", "W. Va.": "WV", "Wis.": "WI", "Wisc.": "WI", "Wyo.": "WY", "D.C.": "DC", "Wash. D.C.": "DC", "Wash., D.C.": "DC", "P.R.": "PR", "V.I.": "VI" };
|
|
426
|
+
var j2 = (() => {
|
|
423
427
|
let n = /* @__PURE__ */ new Map();
|
|
424
|
-
for (let [i, s] of
|
|
428
|
+
for (let [i, s] of B2) n.set(d(s), i);
|
|
425
429
|
n.set(d("Washington DC"), "DC"), n.set(d("Washington D.C."), "DC"), n.set(d("US Virgin Islands"), "VI");
|
|
426
|
-
for (let [i, s] of Object.entries(
|
|
430
|
+
for (let [i, s] of Object.entries(on)) {
|
|
427
431
|
let o = d(i);
|
|
428
432
|
o && !n.has(o) && n.set(o, s);
|
|
429
433
|
}
|
|
@@ -436,7 +440,7 @@ function E2(n) {
|
|
|
436
440
|
function d(n) {
|
|
437
441
|
return u(n);
|
|
438
442
|
}
|
|
439
|
-
function
|
|
443
|
+
function dn(n, i) {
|
|
440
444
|
if (n == null) return null;
|
|
441
445
|
let s = String(n).trim();
|
|
442
446
|
if (s.length === 0) return null;
|
|
@@ -452,7 +456,7 @@ function ln(n, i) {
|
|
|
452
456
|
case "us-state-code":
|
|
453
457
|
case "us-state-name": {
|
|
454
458
|
let o = E2(s);
|
|
455
|
-
return
|
|
459
|
+
return X2.has(o) ? o : j2.get(d(s)) ?? null;
|
|
456
460
|
}
|
|
457
461
|
case "us-zip5": {
|
|
458
462
|
let o = /^(\d{5})(-\d{4})?$/.exec(s);
|
|
@@ -464,7 +468,7 @@ function ln(n, i) {
|
|
|
464
468
|
return null;
|
|
465
469
|
}
|
|
466
470
|
}
|
|
467
|
-
function
|
|
471
|
+
function Mn(n) {
|
|
468
472
|
switch (n) {
|
|
469
473
|
case "country-iso3":
|
|
470
474
|
case "country-iso2":
|
|
@@ -478,152 +482,149 @@ function hn(n) {
|
|
|
478
482
|
return false;
|
|
479
483
|
}
|
|
480
484
|
}
|
|
481
|
-
function
|
|
482
|
-
let s = new Array(n.length), o = /* @__PURE__ */ new Set(),
|
|
485
|
+
function In(n, i) {
|
|
486
|
+
let s = new Array(n.length), o = /* @__PURE__ */ new Set(), h3 = [], p = 0;
|
|
483
487
|
for (let S = 0; S < n.length; ++S) {
|
|
484
|
-
let T3 =
|
|
485
|
-
if (s[S] = T3, T3 !== null)
|
|
488
|
+
let T3 = dn(n[S], i);
|
|
489
|
+
if (s[S] = T3, T3 !== null) p++;
|
|
486
490
|
else {
|
|
487
|
-
let
|
|
488
|
-
if (
|
|
489
|
-
let
|
|
490
|
-
if (
|
|
491
|
-
let
|
|
492
|
-
o.has(
|
|
491
|
+
let A = n[S];
|
|
492
|
+
if (A != null) {
|
|
493
|
+
let m3 = String(A).trim();
|
|
494
|
+
if (m3.length > 0) {
|
|
495
|
+
let N2 = m3.toLowerCase();
|
|
496
|
+
o.has(N2) || (o.add(N2), h3.push(m3));
|
|
493
497
|
}
|
|
494
498
|
}
|
|
495
499
|
}
|
|
496
500
|
}
|
|
497
|
-
return { iso: s, unmatched:
|
|
501
|
+
return { iso: s, unmatched: h3, matchedRows: p, totalRows: n.length };
|
|
498
502
|
}
|
|
499
503
|
|
|
500
504
|
// ../shape-core/dist/index.mjs
|
|
501
505
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
502
|
-
var
|
|
503
|
-
var
|
|
504
|
-
|
|
505
|
-
var N = 400;
|
|
506
|
-
var mt = 97;
|
|
507
|
-
function L2(r) {
|
|
506
|
+
var L2 = 2;
|
|
507
|
+
var _2 = 400;
|
|
508
|
+
function w2(r) {
|
|
508
509
|
return !!w(r);
|
|
509
510
|
}
|
|
510
|
-
function
|
|
511
|
+
function m2(r) {
|
|
511
512
|
let n = /* @__PURE__ */ new Set();
|
|
512
513
|
for (let e of r) {
|
|
513
514
|
if (e == null) continue;
|
|
514
515
|
let i = u(String(e));
|
|
515
|
-
if (i && !n.has(i) && (n.add(i), n.size >=
|
|
516
|
+
if (!Sn(i) && !n.has(i) && (n.add(i), n.size >= _2)) break;
|
|
516
517
|
}
|
|
517
518
|
return Array.from(n);
|
|
518
519
|
}
|
|
519
|
-
function
|
|
520
|
-
let n =
|
|
521
|
-
if (n.length === 0 ||
|
|
522
|
-
let e = n.filter((
|
|
520
|
+
function h2(r) {
|
|
521
|
+
let n = m2(r);
|
|
522
|
+
if (n.length === 0 || gt(r) < 95) return false;
|
|
523
|
+
let e = n.filter((a2) => w2(a2) && !H(a2)).length, i = n.filter((a2) => !w2(a2) && !!H(a2)).length;
|
|
523
524
|
return e >= 1 && e >= i;
|
|
524
525
|
}
|
|
525
|
-
var
|
|
526
|
-
function
|
|
526
|
+
var mt = /* @__PURE__ */ new Set(["USA", "CAN", "MEX"]);
|
|
527
|
+
function N(r, n) {
|
|
527
528
|
if (!H(r)) return false;
|
|
528
529
|
let e = w(r);
|
|
529
|
-
return e ? n === "world" ? true :
|
|
530
|
+
return e ? n === "world" ? true : mt.has(e) : false;
|
|
530
531
|
}
|
|
531
|
-
function
|
|
532
|
-
let n =
|
|
532
|
+
function gt(r) {
|
|
533
|
+
let n = m2(r);
|
|
533
534
|
if (n.length === 0) return 0;
|
|
534
535
|
let e = 0;
|
|
535
|
-
for (let i of n)
|
|
536
|
+
for (let i of n) w2(i) && e++;
|
|
536
537
|
return Math.round(e / n.length * 1e3) / 10;
|
|
537
538
|
}
|
|
538
|
-
function
|
|
539
|
-
let n =
|
|
539
|
+
function v2(r) {
|
|
540
|
+
let n = m2(r);
|
|
540
541
|
if (n.length === 0) return 0;
|
|
541
542
|
let e = 0;
|
|
542
543
|
for (let i of n) H(i) && e++;
|
|
543
544
|
return Math.round(e / n.length * 1e3) / 10;
|
|
544
545
|
}
|
|
545
|
-
function
|
|
546
|
+
function $2(r) {
|
|
546
547
|
let n = /* @__PURE__ */ new Set();
|
|
547
548
|
for (let e of r) {
|
|
548
549
|
if (e == null) continue;
|
|
549
550
|
let i = String(e).trim();
|
|
550
|
-
if (i && !n.has(i) && (n.add(i), n.size >=
|
|
551
|
+
if (!Sn(u(i)) && !n.has(i) && (n.add(i), n.size >= _2)) break;
|
|
551
552
|
}
|
|
552
553
|
return Array.from(n);
|
|
553
554
|
}
|
|
554
|
-
function
|
|
555
|
-
let n =
|
|
555
|
+
function B3(r) {
|
|
556
|
+
let n = $2(r);
|
|
556
557
|
if (n.length === 0) return 0;
|
|
557
558
|
let e = 0;
|
|
558
559
|
for (let i of n) x(i).length > 0 && e++;
|
|
559
560
|
return Math.round(e / n.length * 1e3) / 10;
|
|
560
561
|
}
|
|
561
|
-
function
|
|
562
|
-
let e =
|
|
562
|
+
function ht(r, n) {
|
|
563
|
+
let e = m2(r);
|
|
563
564
|
if (e.length === 0) return 0;
|
|
564
565
|
let i = 0;
|
|
565
|
-
for (let
|
|
566
|
+
for (let a2 of e) s3(a2, n) && i++;
|
|
566
567
|
return Math.round(i / e.length * 1e3) / 10;
|
|
567
568
|
}
|
|
568
|
-
function
|
|
569
|
+
function T2(r, n) {
|
|
569
570
|
let e = 0;
|
|
570
|
-
for (let i of
|
|
571
|
+
for (let i of m2(r)) n(i) && e++;
|
|
571
572
|
return e;
|
|
572
573
|
}
|
|
573
|
-
function
|
|
574
|
+
function Ct(r, n) {
|
|
574
575
|
let e = 0;
|
|
575
|
-
for (let i of
|
|
576
|
+
for (let i of $2(r)) n(i) && e++;
|
|
576
577
|
return e;
|
|
577
578
|
}
|
|
578
|
-
function
|
|
579
|
-
let
|
|
579
|
+
function Pt(r, n, e, i) {
|
|
580
|
+
let a2 = [], g2 = [], o = {}, G2 = new Set(r), y2 = (t) => n.map((s) => s[t]);
|
|
580
581
|
for (let t of ["city", "zip", "lat", "lon", "country"]) {
|
|
581
582
|
let s = e?.[t];
|
|
582
|
-
s &&
|
|
583
|
+
s && G2.has(s) && (o[t] = s);
|
|
583
584
|
}
|
|
584
585
|
let l = e?.state;
|
|
585
|
-
if (l &&
|
|
586
|
-
let t = y2(l), s =
|
|
587
|
-
s.length > 0 && s.every((
|
|
586
|
+
if (l && G2.has(l)) {
|
|
587
|
+
let t = y2(l), s = m2(t);
|
|
588
|
+
s.length > 0 && s.every((c) => N(c, i)) ? g2.push(`state=${l} (every value is "CA", which is both Canada and California)`) : h2(t) ? (g2.push(`state=${l} (every value is a country, not a state)`), o.country || (o.country = l)) : v2(t) < 95 ? g2.push(`state=${l} (only ${v2(t)}% of values are states/provinces)`) : o.state = l;
|
|
588
589
|
}
|
|
589
|
-
let d2 = new Set(Object.values(o).filter(Boolean)),
|
|
590
|
+
let d2 = new Set(Object.values(o).filter(Boolean)), C = r.filter((t) => !d2.has(t) && !t.startsWith("__"));
|
|
590
591
|
if (!o.state) {
|
|
591
592
|
let t = null;
|
|
592
|
-
for (let s of
|
|
593
|
-
let
|
|
594
|
-
if (
|
|
595
|
-
let u2 =
|
|
596
|
-
if (u2 <
|
|
597
|
-
let S =
|
|
598
|
-
S <
|
|
593
|
+
for (let s of C) {
|
|
594
|
+
let c = y2(s);
|
|
595
|
+
if (h2(c)) continue;
|
|
596
|
+
let u2 = v2(c);
|
|
597
|
+
if (u2 < 95) continue;
|
|
598
|
+
let S = T2(c, (P2) => !!H(P2)), O2 = T2(c, (P2) => !!H(P2) && !N(P2, i));
|
|
599
|
+
S < L2 && O2 < 1 || (!t || u2 > t.pct) && (t = { name: s, pct: u2 });
|
|
599
600
|
}
|
|
600
|
-
t && (o.state = t.name, d2.add(t.name),
|
|
601
|
+
t && (o.state = t.name, d2.add(t.name), a2.push(`state=${t.name} (${t.pct}% states/provinces)`));
|
|
601
602
|
}
|
|
602
|
-
if (!o.zip) for (let t of
|
|
603
|
+
if (!o.zip) for (let t of C) {
|
|
603
604
|
if (d2.has(t)) continue;
|
|
604
|
-
let s = y2(t),
|
|
605
|
-
if (!(
|
|
606
|
-
o.zip = t, d2.add(t),
|
|
605
|
+
let s = y2(t), c = B3(s);
|
|
606
|
+
if (!(c < 95) && !(Ct(s, (u2) => x(u2).length > 0) < L2)) {
|
|
607
|
+
o.zip = t, d2.add(t), a2.push(`zip=${t} (${c}% ZIP codes)`);
|
|
607
608
|
break;
|
|
608
609
|
}
|
|
609
610
|
}
|
|
610
611
|
if (!o.country) {
|
|
611
|
-
for (let t of
|
|
612
|
-
o.country = t, d2.add(t),
|
|
612
|
+
for (let t of C) if (!d2.has(t) && h2(y2(t))) {
|
|
613
|
+
o.country = t, d2.add(t), a2.push(`country=${t}`);
|
|
613
614
|
break;
|
|
614
615
|
}
|
|
615
616
|
}
|
|
616
617
|
if (!o.city) {
|
|
617
618
|
let t = null;
|
|
618
|
-
for (let s of
|
|
619
|
+
for (let s of C) {
|
|
619
620
|
if (d2.has(s)) continue;
|
|
620
|
-
let
|
|
621
|
-
u2 <
|
|
621
|
+
let c = y2(s), u2 = ht(c, i);
|
|
622
|
+
u2 < 95 || T2(c, (S) => s3(S, i)) < L2 || (!t || u2 > t.pct) && (t = { name: s, pct: u2 });
|
|
622
623
|
}
|
|
623
|
-
t && (o.city = t.name,
|
|
624
|
+
t && (o.city = t.name, a2.push(`city=${t.name} (${t.pct}% known cities)`));
|
|
624
625
|
}
|
|
625
|
-
let
|
|
626
|
-
return o.country && !
|
|
626
|
+
let I2 = o.country ? y2(o.country) : [], R = !!o.country && h2(I2), D = R ? new Set(I2.map((t) => w(t == null ? null : String(t))).filter(Boolean)).size : 0, z2 = R && D >= 2;
|
|
627
|
+
return o.country && !z2 && !(o.city || o.state || o.zip || o.lat && o.lon) && g2.push(R ? `country=${o.country} (every row resolves to the same country - nothing to place apart)` : `country=${o.country} (values are not country identifiers)`), { bind: !!(o.city || o.state || o.zip || z2 || o.lat && o.lon) ? o : null, backfilled: a2, refused: g2 };
|
|
627
628
|
}
|
|
628
629
|
|
|
629
630
|
// src/payload.ts
|
|
@@ -637,21 +638,21 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
637
638
|
let rolesRefused = [];
|
|
638
639
|
if (bind) {
|
|
639
640
|
const dims = cols.filter((c) => !c.isMeasure).map((c) => c.name);
|
|
640
|
-
const res =
|
|
641
|
+
const res = Pt(dims, rowObjs, bind, point?.mapKind);
|
|
641
642
|
bind = res.bind;
|
|
642
643
|
rolesBackfilled = res.backfilled;
|
|
643
644
|
rolesRefused = res.refused;
|
|
644
645
|
}
|
|
645
646
|
const hasPointBind = !!bind && !!(bind.city || bind.state || bind.zip || bind.country || bind.lat && bind.lon);
|
|
646
647
|
if (hasPointBind) {
|
|
647
|
-
const
|
|
648
|
+
const p = bind;
|
|
648
649
|
const built = N3(rowObjs.map((r) => ({
|
|
649
|
-
lat:
|
|
650
|
-
lon:
|
|
651
|
-
city:
|
|
652
|
-
state:
|
|
653
|
-
zip:
|
|
654
|
-
country:
|
|
650
|
+
lat: p.lat ? r[p.lat] : null,
|
|
651
|
+
lon: p.lon ? r[p.lon] : null,
|
|
652
|
+
city: p.city ? r[p.city] : null,
|
|
653
|
+
state: p.state ? r[p.state] : null,
|
|
654
|
+
zip: p.zip ? r[p.zip] : null,
|
|
655
|
+
country: p.country ? r[p.country] : null
|
|
655
656
|
})), point?.mapKind);
|
|
656
657
|
pLat = built.lat;
|
|
657
658
|
pLon = built.lon;
|
|
@@ -678,8 +679,8 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
678
679
|
let geoIso = null;
|
|
679
680
|
let geoUnmatched;
|
|
680
681
|
let geoUnmatchedDistinct;
|
|
681
|
-
if (geo && geo.column && geo.kind &&
|
|
682
|
-
const built =
|
|
682
|
+
if (geo && geo.column && geo.kind && Mn(geo.kind)) {
|
|
683
|
+
const built = In(rowObjs.map((r) => r[geo.column]), geo.kind);
|
|
683
684
|
geoIso = built.iso;
|
|
684
685
|
geoUnmatched = { count: built.totalRows - built.matchedRows, examples: built.unmatched.slice(0, 8) };
|
|
685
686
|
geoUnmatchedDistinct = built.unmatched.length;
|
|
@@ -697,12 +698,12 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
697
698
|
a2[c] = v3 ?? null;
|
|
698
699
|
}
|
|
699
700
|
}
|
|
700
|
-
let
|
|
701
|
-
a2[
|
|
702
|
-
if (geoIso) a2[
|
|
701
|
+
let k2 = cols.length;
|
|
702
|
+
a2[k2++] = r;
|
|
703
|
+
if (geoIso) a2[k2++] = geoIso[r];
|
|
703
704
|
if (pLat && pLon) {
|
|
704
|
-
a2[
|
|
705
|
-
a2[
|
|
705
|
+
a2[k2++] = pLat[r];
|
|
706
|
+
a2[k2++] = pLon[r];
|
|
706
707
|
}
|
|
707
708
|
out[r] = a2;
|
|
708
709
|
}
|
|
@@ -742,14 +743,14 @@ function createMarkResolver(env) {
|
|
|
742
743
|
const distToPathCenterline = (el, x2, y2) => {
|
|
743
744
|
const L3 = el.getTotalLength();
|
|
744
745
|
if (!(L3 > 0)) return Number.MAX_VALUE;
|
|
745
|
-
const
|
|
746
|
-
if (!
|
|
746
|
+
const m3 = el.getScreenCTM();
|
|
747
|
+
if (!m3) return Number.MAX_VALUE;
|
|
747
748
|
let best = Number.MAX_VALUE;
|
|
748
749
|
const N2 = 64;
|
|
749
750
|
for (let i = 0; i <= N2; i++) {
|
|
750
|
-
const
|
|
751
|
-
const dx =
|
|
752
|
-
const dy =
|
|
751
|
+
const pt = el.getPointAtLength(L3 * i / N2);
|
|
752
|
+
const dx = m3.a * pt.x + m3.c * pt.y + m3.e - x2;
|
|
753
|
+
const dy = m3.b * pt.x + m3.d * pt.y + m3.f - y2;
|
|
753
754
|
const d2 = dx * dx + dy * dy;
|
|
754
755
|
if (d2 < best) best = d2;
|
|
755
756
|
}
|
|
@@ -794,9 +795,9 @@ function createMarkResolver(env) {
|
|
|
794
795
|
const findMark = (target, sel = ".d3-mark", ev) => {
|
|
795
796
|
if (!isElement(target)) return null;
|
|
796
797
|
const el = target;
|
|
797
|
-
const
|
|
798
|
-
if (
|
|
799
|
-
return
|
|
798
|
+
const m3 = el.closest(sel);
|
|
799
|
+
if (m3 && ev) return refineHitCorridor(m3, ev.clientX, ev.clientY, sel);
|
|
800
|
+
return m3;
|
|
800
801
|
};
|
|
801
802
|
const rowIdxsFromMark = (el) => {
|
|
802
803
|
if (!el) return [];
|
|
@@ -880,8 +881,8 @@ var D3_PLUGIN_PACKAGES = {
|
|
|
880
881
|
};
|
|
881
882
|
function requiredD3Plugins(code) {
|
|
882
883
|
const out = /* @__PURE__ */ new Set();
|
|
883
|
-
for (const
|
|
884
|
-
const pkg = D3_PLUGIN_PACKAGES[
|
|
884
|
+
for (const m3 of String(code || "").matchAll(/\bd3\s*\.\s*(\w+)\s*\(/g)) {
|
|
885
|
+
const pkg = D3_PLUGIN_PACKAGES[m3[1]];
|
|
885
886
|
if (pkg) out.add(pkg);
|
|
886
887
|
}
|
|
887
888
|
return [...out].sort();
|
|
@@ -893,8 +894,8 @@ function explainRenderFailure(err, d3) {
|
|
|
893
894
|
"[@bicharts/chart-host] no d3 was provided, so the generated chart could not run. Pass it explicitly \u2014 createChartHost(el, { d3 }) / <BicChart d3={d3} /> \u2014 or set window.d3. The chart needs D3 v7 (npm install d3@7). Original error: " + msg
|
|
894
895
|
);
|
|
895
896
|
}
|
|
896
|
-
const
|
|
897
|
-
const name =
|
|
897
|
+
const m3 = /d3\.(\w+) is not a function|(\w+) is not a function/.exec(msg);
|
|
898
|
+
const name = m3?.[1] ?? m3?.[2] ?? "";
|
|
898
899
|
const pkg = D3_PLUGIN_PACKAGES[name];
|
|
899
900
|
if (pkg) {
|
|
900
901
|
return new Error(
|
|
@@ -982,10 +983,10 @@ function createChartHost(container, config) {
|
|
|
982
983
|
container.classList?.[active ? "add" : "remove"](SELECTION_ACTIVE_CLASS);
|
|
983
984
|
const wanted = new Set(sel ?? []);
|
|
984
985
|
const marks = container.querySelectorAll(`.${MARK_CLASS}[${ROW_IDX_ATTR}], .${LEGEND_MARK_CLASS}[${ROW_IDX_ATTR}]`);
|
|
985
|
-
for (const
|
|
986
|
-
const rows = parseRowIdxs(
|
|
987
|
-
const
|
|
988
|
-
|
|
986
|
+
for (const m3 of Array.from(marks)) {
|
|
987
|
+
const rows = parseRowIdxs(m3.getAttribute(ROW_IDX_ATTR));
|
|
988
|
+
const on2 = active && rows.some((r) => wanted.has(r));
|
|
989
|
+
m3.classList?.[on2 ? "add" : "remove"](MARK_SELECTED_CLASS);
|
|
989
990
|
}
|
|
990
991
|
} catch {
|
|
991
992
|
}
|
|
@@ -1061,8 +1062,8 @@ function createChartHost(container, config) {
|
|
|
1061
1062
|
renderFn = compileRenderFn(config.code, win, doc, d3);
|
|
1062
1063
|
}
|
|
1063
1064
|
if (resolved.geo === void 0 && config.geoKind) {
|
|
1064
|
-
const
|
|
1065
|
-
if (
|
|
1065
|
+
const g2 = config.geoProvider?.(config.geoKind) ?? geoFromCache(config.geoKind);
|
|
1066
|
+
if (g2) resolved = { ...resolved, geo: g2 };
|
|
1066
1067
|
else if (!warnedGeo) {
|
|
1067
1068
|
warnedGeo = true;
|
|
1068
1069
|
try {
|
package/dist/index.mjs
CHANGED
package/dist/react.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bicharts/chart-host",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
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",
|