@bicharts/chart-host 0.5.8 → 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-K3LSWWFS.mjs → chunk-L5Y6RLK2.mjs} +130 -132
- package/dist/index.mjs +1 -1
- package/dist/react.mjs +1 -1
- package/package.json +1 -1
|
@@ -387,17 +387,17 @@ function N3(n, e) {
|
|
|
387
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
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
|
|
395
|
-
|
|
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() !== "");
|
|
@@ -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,155 +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 =
|
|
488
|
+
let T3 = dn(n[S], i);
|
|
485
489
|
if (s[S] = T3, T3 !== null) p++;
|
|
486
490
|
else {
|
|
487
491
|
let A = n[S];
|
|
488
492
|
if (A != null) {
|
|
489
|
-
let
|
|
490
|
-
if (
|
|
491
|
-
let
|
|
492
|
-
o.has(
|
|
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 gt = /* @__PURE__ */ new Set(["n a", "none", "null", "nil", "unknown", "not applicable", "not available", "not specified", "unspecified", "missing", "blank", "empty", "tbd", "to be determined"]);
|
|
503
|
-
function M(i) {
|
|
504
|
-
return i ? gt.has(i) : true;
|
|
505
|
-
}
|
|
506
|
-
var v3 = 85;
|
|
507
506
|
var L2 = 2;
|
|
508
|
-
var
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return !!w(i);
|
|
507
|
+
var _2 = 400;
|
|
508
|
+
function w2(r) {
|
|
509
|
+
return !!w(r);
|
|
512
510
|
}
|
|
513
|
-
function
|
|
511
|
+
function m2(r) {
|
|
514
512
|
let n = /* @__PURE__ */ new Set();
|
|
515
|
-
for (let e of
|
|
513
|
+
for (let e of r) {
|
|
516
514
|
if (e == null) continue;
|
|
517
|
-
let
|
|
518
|
-
if (!
|
|
515
|
+
let i = u(String(e));
|
|
516
|
+
if (!Sn(i) && !n.has(i) && (n.add(i), n.size >= _2)) break;
|
|
519
517
|
}
|
|
520
518
|
return Array.from(n);
|
|
521
519
|
}
|
|
522
|
-
function
|
|
523
|
-
let n =
|
|
524
|
-
if (n.length === 0 ||
|
|
525
|
-
let e = n.filter((a2) => w2(a2) && !H(a2)).length,
|
|
526
|
-
return e >= 1 && e >=
|
|
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;
|
|
524
|
+
return e >= 1 && e >= i;
|
|
527
525
|
}
|
|
528
|
-
var
|
|
529
|
-
function
|
|
530
|
-
if (!H(
|
|
531
|
-
let e = w(
|
|
532
|
-
return e ? n === "world" ? true :
|
|
526
|
+
var mt = /* @__PURE__ */ new Set(["USA", "CAN", "MEX"]);
|
|
527
|
+
function N(r, n) {
|
|
528
|
+
if (!H(r)) return false;
|
|
529
|
+
let e = w(r);
|
|
530
|
+
return e ? n === "world" ? true : mt.has(e) : false;
|
|
533
531
|
}
|
|
534
|
-
function
|
|
535
|
-
let n =
|
|
532
|
+
function gt(r) {
|
|
533
|
+
let n = m2(r);
|
|
536
534
|
if (n.length === 0) return 0;
|
|
537
535
|
let e = 0;
|
|
538
|
-
for (let
|
|
536
|
+
for (let i of n) w2(i) && e++;
|
|
539
537
|
return Math.round(e / n.length * 1e3) / 10;
|
|
540
538
|
}
|
|
541
|
-
function
|
|
542
|
-
let n =
|
|
539
|
+
function v2(r) {
|
|
540
|
+
let n = m2(r);
|
|
543
541
|
if (n.length === 0) return 0;
|
|
544
542
|
let e = 0;
|
|
545
|
-
for (let
|
|
543
|
+
for (let i of n) H(i) && e++;
|
|
546
544
|
return Math.round(e / n.length * 1e3) / 10;
|
|
547
545
|
}
|
|
548
|
-
function $2(
|
|
546
|
+
function $2(r) {
|
|
549
547
|
let n = /* @__PURE__ */ new Set();
|
|
550
|
-
for (let e of
|
|
548
|
+
for (let e of r) {
|
|
551
549
|
if (e == null) continue;
|
|
552
|
-
let
|
|
553
|
-
if (!
|
|
550
|
+
let i = String(e).trim();
|
|
551
|
+
if (!Sn(u(i)) && !n.has(i) && (n.add(i), n.size >= _2)) break;
|
|
554
552
|
}
|
|
555
553
|
return Array.from(n);
|
|
556
554
|
}
|
|
557
|
-
function B3(
|
|
558
|
-
let n = $2(
|
|
555
|
+
function B3(r) {
|
|
556
|
+
let n = $2(r);
|
|
559
557
|
if (n.length === 0) return 0;
|
|
560
558
|
let e = 0;
|
|
561
|
-
for (let
|
|
559
|
+
for (let i of n) x(i).length > 0 && e++;
|
|
562
560
|
return Math.round(e / n.length * 1e3) / 10;
|
|
563
561
|
}
|
|
564
|
-
function
|
|
565
|
-
let e =
|
|
562
|
+
function ht(r, n) {
|
|
563
|
+
let e = m2(r);
|
|
566
564
|
if (e.length === 0) return 0;
|
|
567
|
-
let
|
|
568
|
-
for (let a2 of e) s3(a2, n) &&
|
|
569
|
-
return Math.round(
|
|
565
|
+
let i = 0;
|
|
566
|
+
for (let a2 of e) s3(a2, n) && i++;
|
|
567
|
+
return Math.round(i / e.length * 1e3) / 10;
|
|
570
568
|
}
|
|
571
|
-
function
|
|
569
|
+
function T2(r, n) {
|
|
572
570
|
let e = 0;
|
|
573
|
-
for (let
|
|
571
|
+
for (let i of m2(r)) n(i) && e++;
|
|
574
572
|
return e;
|
|
575
573
|
}
|
|
576
|
-
function
|
|
574
|
+
function Ct(r, n) {
|
|
577
575
|
let e = 0;
|
|
578
|
-
for (let
|
|
576
|
+
for (let i of $2(r)) n(i) && e++;
|
|
579
577
|
return e;
|
|
580
578
|
}
|
|
581
|
-
function
|
|
582
|
-
let a2 = [],
|
|
579
|
+
function Pt(r, n, e, i) {
|
|
580
|
+
let a2 = [], g2 = [], o = {}, G2 = new Set(r), y2 = (t) => n.map((s) => s[t]);
|
|
583
581
|
for (let t of ["city", "zip", "lat", "lon", "country"]) {
|
|
584
582
|
let s = e?.[t];
|
|
585
|
-
s &&
|
|
583
|
+
s && G2.has(s) && (o[t] = s);
|
|
586
584
|
}
|
|
587
585
|
let l = e?.state;
|
|
588
|
-
if (l &&
|
|
589
|
-
let t =
|
|
590
|
-
s.length > 0 && s.every((c) =>
|
|
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;
|
|
591
589
|
}
|
|
592
|
-
let
|
|
590
|
+
let d2 = new Set(Object.values(o).filter(Boolean)), C = r.filter((t) => !d2.has(t) && !t.startsWith("__"));
|
|
593
591
|
if (!o.state) {
|
|
594
592
|
let t = null;
|
|
595
|
-
for (let s of
|
|
596
|
-
let c =
|
|
597
|
-
if (
|
|
598
|
-
let u2 =
|
|
599
|
-
if (u2 <
|
|
600
|
-
let
|
|
601
|
-
|
|
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 });
|
|
602
600
|
}
|
|
603
|
-
t && (o.state = t.name,
|
|
601
|
+
t && (o.state = t.name, d2.add(t.name), a2.push(`state=${t.name} (${t.pct}% states/provinces)`));
|
|
604
602
|
}
|
|
605
|
-
if (!o.zip) for (let t of
|
|
606
|
-
if (
|
|
607
|
-
let s =
|
|
608
|
-
if (!(c <
|
|
609
|
-
o.zip = t,
|
|
603
|
+
if (!o.zip) for (let t of C) {
|
|
604
|
+
if (d2.has(t)) continue;
|
|
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)`);
|
|
610
608
|
break;
|
|
611
609
|
}
|
|
612
610
|
}
|
|
613
611
|
if (!o.country) {
|
|
614
|
-
for (let t of
|
|
615
|
-
o.country = 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}`);
|
|
616
614
|
break;
|
|
617
615
|
}
|
|
618
616
|
}
|
|
619
617
|
if (!o.city) {
|
|
620
618
|
let t = null;
|
|
621
|
-
for (let s of
|
|
622
|
-
if (
|
|
623
|
-
let c =
|
|
624
|
-
u2 <
|
|
619
|
+
for (let s of C) {
|
|
620
|
+
if (d2.has(s)) continue;
|
|
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 });
|
|
625
623
|
}
|
|
626
624
|
t && (o.city = t.name, a2.push(`city=${t.name} (${t.pct}% known cities)`));
|
|
627
625
|
}
|
|
628
|
-
let
|
|
629
|
-
return o.country && !z2 && !(o.city || o.state || o.zip || o.lat && o.lon) &&
|
|
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 };
|
|
630
628
|
}
|
|
631
629
|
|
|
632
630
|
// src/payload.ts
|
|
@@ -640,7 +638,7 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
640
638
|
let rolesRefused = [];
|
|
641
639
|
if (bind) {
|
|
642
640
|
const dims = cols.filter((c) => !c.isMeasure).map((c) => c.name);
|
|
643
|
-
const res =
|
|
641
|
+
const res = Pt(dims, rowObjs, bind, point?.mapKind);
|
|
644
642
|
bind = res.bind;
|
|
645
643
|
rolesBackfilled = res.backfilled;
|
|
646
644
|
rolesRefused = res.refused;
|
|
@@ -681,8 +679,8 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
681
679
|
let geoIso = null;
|
|
682
680
|
let geoUnmatched;
|
|
683
681
|
let geoUnmatchedDistinct;
|
|
684
|
-
if (geo && geo.column && geo.kind &&
|
|
685
|
-
const built =
|
|
682
|
+
if (geo && geo.column && geo.kind && Mn(geo.kind)) {
|
|
683
|
+
const built = In(rowObjs.map((r) => r[geo.column]), geo.kind);
|
|
686
684
|
geoIso = built.iso;
|
|
687
685
|
geoUnmatched = { count: built.totalRows - built.matchedRows, examples: built.unmatched.slice(0, 8) };
|
|
688
686
|
geoUnmatchedDistinct = built.unmatched.length;
|
|
@@ -693,11 +691,11 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
693
691
|
const row = rowObjs[r];
|
|
694
692
|
const a2 = new Array(cols.length + extra);
|
|
695
693
|
for (let c = 0; c < cols.length; c++) {
|
|
696
|
-
const
|
|
697
|
-
if (
|
|
698
|
-
a2[c] =
|
|
694
|
+
const v3 = row[colNames[c]];
|
|
695
|
+
if (v3 instanceof Date) {
|
|
696
|
+
a2[c] = v3.toISOString();
|
|
699
697
|
} else {
|
|
700
|
-
a2[c] =
|
|
698
|
+
a2[c] = v3 ?? null;
|
|
701
699
|
}
|
|
702
700
|
}
|
|
703
701
|
let k2 = cols.length;
|
|
@@ -722,8 +720,8 @@ function buildRenderPayload(cols, rowObjs, geo, point) {
|
|
|
722
720
|
function createMarkResolver(env) {
|
|
723
721
|
const { root, doc, log } = env;
|
|
724
722
|
const isElement = (t) => {
|
|
725
|
-
const
|
|
726
|
-
if (
|
|
723
|
+
const E3 = doc?.defaultView?.Element ?? globalThis.Element;
|
|
724
|
+
if (E3 && t instanceof E3) return true;
|
|
727
725
|
return !!t && typeof t.closest === "function" && typeof t.getAttribute === "function";
|
|
728
726
|
};
|
|
729
727
|
const viewStyle = (n) => {
|
|
@@ -742,26 +740,26 @@ function createMarkResolver(env) {
|
|
|
742
740
|
const so = parseFloat(el.getAttribute("stroke-opacity") || "1");
|
|
743
741
|
return s === "transparent" || s === "none" || so <= 0.01;
|
|
744
742
|
};
|
|
745
|
-
const distToPathCenterline = (el, x2,
|
|
743
|
+
const distToPathCenterline = (el, x2, y2) => {
|
|
746
744
|
const L3 = el.getTotalLength();
|
|
747
745
|
if (!(L3 > 0)) return Number.MAX_VALUE;
|
|
748
|
-
const
|
|
749
|
-
if (!
|
|
746
|
+
const m3 = el.getScreenCTM();
|
|
747
|
+
if (!m3) return Number.MAX_VALUE;
|
|
750
748
|
let best = Number.MAX_VALUE;
|
|
751
749
|
const N2 = 64;
|
|
752
750
|
for (let i = 0; i <= N2; i++) {
|
|
753
751
|
const pt = el.getPointAtLength(L3 * i / N2);
|
|
754
|
-
const dx =
|
|
755
|
-
const dy =
|
|
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;
|
|
756
754
|
const d2 = dx * dx + dy * dy;
|
|
757
755
|
if (d2 < best) best = d2;
|
|
758
756
|
}
|
|
759
757
|
return Math.sqrt(best);
|
|
760
758
|
};
|
|
761
|
-
const refineHitCorridor = (mark, x2,
|
|
759
|
+
const refineHitCorridor = (mark, x2, y2, sel) => {
|
|
762
760
|
try {
|
|
763
761
|
if (!mark || !isInvisibleStrokePath(mark) || !mark.getAttribute("data-row-idx")) return mark;
|
|
764
|
-
const stack = doc.elementsFromPoint(x2,
|
|
762
|
+
const stack = doc.elementsFromPoint(x2, y2);
|
|
765
763
|
const candidates = [];
|
|
766
764
|
for (const el of stack) {
|
|
767
765
|
if (!root.contains(el)) continue;
|
|
@@ -775,7 +773,7 @@ function createMarkResolver(env) {
|
|
|
775
773
|
let best = mark;
|
|
776
774
|
let bestD = Number.MAX_VALUE;
|
|
777
775
|
for (const el of candidates) {
|
|
778
|
-
const d2 = distToPathCenterline(el, x2,
|
|
776
|
+
const d2 = distToPathCenterline(el, x2, y2);
|
|
779
777
|
if (d2 < bestD) {
|
|
780
778
|
bestD = d2;
|
|
781
779
|
best = el;
|
|
@@ -797,9 +795,9 @@ function createMarkResolver(env) {
|
|
|
797
795
|
const findMark = (target, sel = ".d3-mark", ev) => {
|
|
798
796
|
if (!isElement(target)) return null;
|
|
799
797
|
const el = target;
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
return
|
|
798
|
+
const m3 = el.closest(sel);
|
|
799
|
+
if (m3 && ev) return refineHitCorridor(m3, ev.clientX, ev.clientY, sel);
|
|
800
|
+
return m3;
|
|
803
801
|
};
|
|
804
802
|
const rowIdxsFromMark = (el) => {
|
|
805
803
|
if (!el) return [];
|
|
@@ -812,9 +810,9 @@ function createMarkResolver(env) {
|
|
|
812
810
|
}
|
|
813
811
|
return out;
|
|
814
812
|
};
|
|
815
|
-
const penetrateOverlayAt = (x2,
|
|
813
|
+
const penetrateOverlayAt = (x2, y2, sel) => {
|
|
816
814
|
try {
|
|
817
|
-
const stack = doc.elementsFromPoint(x2,
|
|
815
|
+
const stack = doc.elementsFromPoint(x2, y2);
|
|
818
816
|
for (const el of stack) {
|
|
819
817
|
if (!root.contains(el) || !isElement(el)) continue;
|
|
820
818
|
const cand = el.matches(sel) ? el : el.closest(sel);
|
|
@@ -826,7 +824,7 @@ function createMarkResolver(env) {
|
|
|
826
824
|
}
|
|
827
825
|
return null;
|
|
828
826
|
};
|
|
829
|
-
const resolveByGeometry = (x2,
|
|
827
|
+
const resolveByGeometry = (x2, y2, sel) => {
|
|
830
828
|
try {
|
|
831
829
|
const cands = root.querySelectorAll(sel);
|
|
832
830
|
let best = null, bestArea = Number.MAX_VALUE;
|
|
@@ -835,7 +833,7 @@ function createMarkResolver(env) {
|
|
|
835
833
|
if (!el.getAttribute("data-row-idx")) continue;
|
|
836
834
|
const r = el.getBoundingClientRect ? el.getBoundingClientRect() : null;
|
|
837
835
|
if (!r || r.width <= 0 || r.height <= 0) continue;
|
|
838
|
-
if (x2 < r.left || x2 > r.right ||
|
|
836
|
+
if (x2 < r.left || x2 > r.right || y2 < r.top || y2 > r.bottom) continue;
|
|
839
837
|
const area = r.width * r.height;
|
|
840
838
|
if (area < bestArea) {
|
|
841
839
|
bestArea = area;
|
|
@@ -883,8 +881,8 @@ var D3_PLUGIN_PACKAGES = {
|
|
|
883
881
|
};
|
|
884
882
|
function requiredD3Plugins(code) {
|
|
885
883
|
const out = /* @__PURE__ */ new Set();
|
|
886
|
-
for (const
|
|
887
|
-
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]];
|
|
888
886
|
if (pkg) out.add(pkg);
|
|
889
887
|
}
|
|
890
888
|
return [...out].sort();
|
|
@@ -896,8 +894,8 @@ function explainRenderFailure(err, d3) {
|
|
|
896
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
|
|
897
895
|
);
|
|
898
896
|
}
|
|
899
|
-
const
|
|
900
|
-
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] ?? "";
|
|
901
899
|
const pkg = D3_PLUGIN_PACKAGES[name];
|
|
902
900
|
if (pkg) {
|
|
903
901
|
return new Error(
|
|
@@ -934,7 +932,7 @@ function createChartHost(container, config) {
|
|
|
934
932
|
let data = config.data;
|
|
935
933
|
{
|
|
936
934
|
const stamped = config.data?.meta?.hostContract;
|
|
937
|
-
const major = (
|
|
935
|
+
const major = (v3) => (v3 || "").split(".")[0];
|
|
938
936
|
if (stamped && major(stamped) !== major(HOST_CONTRACT_VERSION)) {
|
|
939
937
|
try {
|
|
940
938
|
(win?.console ?? console)?.warn(
|
|
@@ -985,10 +983,10 @@ function createChartHost(container, config) {
|
|
|
985
983
|
container.classList?.[active ? "add" : "remove"](SELECTION_ACTIVE_CLASS);
|
|
986
984
|
const wanted = new Set(sel ?? []);
|
|
987
985
|
const marks = container.querySelectorAll(`.${MARK_CLASS}[${ROW_IDX_ATTR}], .${LEGEND_MARK_CLASS}[${ROW_IDX_ATTR}]`);
|
|
988
|
-
for (const
|
|
989
|
-
const rows = parseRowIdxs(
|
|
990
|
-
const
|
|
991
|
-
|
|
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);
|
|
992
990
|
}
|
|
993
991
|
} catch {
|
|
994
992
|
}
|
|
@@ -1064,8 +1062,8 @@ function createChartHost(container, config) {
|
|
|
1064
1062
|
renderFn = compileRenderFn(config.code, win, doc, d3);
|
|
1065
1063
|
}
|
|
1066
1064
|
if (resolved.geo === void 0 && config.geoKind) {
|
|
1067
|
-
const
|
|
1068
|
-
if (
|
|
1065
|
+
const g2 = config.geoProvider?.(config.geoKind) ?? geoFromCache(config.geoKind);
|
|
1066
|
+
if (g2) resolved = { ...resolved, geo: g2 };
|
|
1069
1067
|
else if (!warnedGeo) {
|
|
1070
1068
|
warnedGeo = true;
|
|
1071
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",
|