@d3plus/core 4.2.0 → 4.3.0

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.
Files changed (40) hide show
  1. package/README.md +374 -296
  2. package/es/src/charts/Geomap/emit.js +44 -4
  3. package/es/src/charts/Geomap/emit.js.map +1 -1
  4. package/es/src/charts/Geomap/index.js +30 -1
  5. package/es/src/charts/Geomap/index.js.map +1 -1
  6. package/es/src/charts/Plot/index.js +77 -2
  7. package/es/src/charts/Plot/index.js.map +1 -1
  8. package/es/src/charts/Plot/pipeline.js +24 -3
  9. package/es/src/charts/Plot/pipeline.js.map +1 -1
  10. package/es/src/charts/features/shapeEmit.js +3 -1
  11. package/es/src/charts/features/shapeEmit.js.map +1 -1
  12. package/es/src/charts/viz/Viz.js +63 -10
  13. package/es/src/charts/viz/Viz.js.map +1 -1
  14. package/es/src/charts/viz/interactionOpacity.js +4 -1
  15. package/es/src/charts/viz/interactionOpacity.js.map +1 -1
  16. package/es/src/charts/viz/vizDefaults.js +4 -1
  17. package/es/src/charts/viz/vizDefaults.js.map +1 -1
  18. package/es/src/charts/viz/vizRender.js +7 -3
  19. package/es/src/charts/viz/vizRender.js.map +1 -1
  20. package/es/src/charts/viz/vizTypes.js.map +1 -1
  21. package/es/src/shapes/Shape.js +12 -10
  22. package/es/src/shapes/Shape.js.map +1 -1
  23. package/es/src/shapes/hitAreaNode.js +31 -5
  24. package/es/src/shapes/hitAreaNode.js.map +1 -1
  25. package/es/src/shapes/interactionPoints.js +30 -0
  26. package/es/src/shapes/interactionPoints.js.map +1 -0
  27. package/package.json +9 -9
  28. package/types/src/charts/Plot/index.d.ts +22 -1
  29. package/types/src/charts/Plot/pipeline.d.ts +2 -1
  30. package/types/src/charts/viz/Viz.d.ts +31 -1
  31. package/types/src/charts/viz/vizTypes.d.ts +18 -0
  32. package/types/src/shapes/Shape.d.ts +2 -2
  33. package/types/src/shapes/hitAreaNode.d.ts +5 -4
  34. package/types/src/shapes/interactionPoints.d.ts +15 -0
  35. package/umd/d3plus-core.full.js +954 -275
  36. package/umd/d3plus-core.full.js.map +1 -1
  37. package/umd/d3plus-core.full.min.js +1285 -1099
  38. package/umd/d3plus-core.js +267 -39
  39. package/umd/d3plus-core.js.map +1 -1
  40. package/umd/d3plus-core.min.js +266 -170
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/core v4.2.0
2
+ @d3plus/core v4.3.0
3
3
  Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -2034,7 +2034,10 @@
2034
2034
  };
2035
2035
  let base = typeof paint.fill === "string" ? paint.fill : undefined;
2036
2036
  if (!base || base === "transparent" || base === "none") base = typeof paint.stroke === "string" ? paint.stroke : undefined;
2037
- const c = base ? d3Color.color(base) : null;
2037
+ // No visible paint to emphasize (e.g. an invisible hit-area node): leave it
2038
+ // untouched — darkening `transparent`/`none` would format to opaque black.
2039
+ if (!base || base === "transparent" || base === "none") return node;
2040
+ const c = d3Color.color(base);
2038
2041
  if (c) paint.stroke = c.darker(darken).formatHex();
2039
2042
  const w = typeof paint.strokeWidth === "number" && paint.strokeWidth ? paint.strokeWidth : 1;
2040
2043
  paint.strokeWidth = w * widthMult;
@@ -2792,12 +2795,38 @@
2792
2795
  the swatch↔hit-area crossing) but a DISTINCT `key`: the hit-area and the
2793
2796
  visible geometry are siblings, and the SVG keyed join can't hold two nodes
2794
2797
  under one key — sharing it made the geometry re-enter (collapse→grow) on every
2795
- redraw (a "pulse" on e.g. every timeline step). Returns null when no
2796
- rect-style hitArea is configured; Line's path-style hitArea is covered by its
2797
- own geometry.
2798
- */ function hitAreaNode(hitArea, d, i, aes, key, datum, name, transform) {
2798
+ redraw (a "pulse" on e.g. every timeline step). Returns null when no hitArea
2799
+ is configured. A path-style hitArea (Line: a fat, transparent stroke) reuses
2800
+ the resolved geometry `d`/`transform` so the hover target overlaps the
2801
+ visible line exactly while extending past its ~1px stroke.
2802
+ */ function hitAreaNode(hitArea, d, i, aes, key, datum, name, transform, geomD) {
2799
2803
  const bounds = typeof hitArea === "function" ? hitArea(d, i, aes) : hitArea;
2800
- if (!bounds || typeof bounds.width !== "number" || typeof bounds.height !== "number") return null;
2804
+ if (!bounds) return null;
2805
+ // Path-style hitArea (Line): widen the hover target to a fat transparent
2806
+ // stroke over the line's own geometry. `stroke: transparent` (not "none") is
2807
+ // painted, so it hit-tests across the full width on both backends.
2808
+ if (typeof bounds.width !== "number" && typeof geomD === "string") {
2809
+ const sw = typeof bounds["stroke-width"] === "number" ? bounds["stroke-width"] : 10;
2810
+ return {
2811
+ type: "path",
2812
+ d: geomD,
2813
+ key: `${key}::hit`,
2814
+ datum,
2815
+ index: i,
2816
+ shapeType: name,
2817
+ paint: {
2818
+ fill: "none",
2819
+ stroke: "transparent",
2820
+ strokeWidth: sw,
2821
+ vectorEffect: "non-scaling-stroke"
2822
+ },
2823
+ transform,
2824
+ aria: {
2825
+ hidden: true
2826
+ }
2827
+ };
2828
+ }
2829
+ if (typeof bounds.width !== "number" || typeof bounds.height !== "number") return null;
2801
2830
  return {
2802
2831
  type: "rect",
2803
2832
  x: typeof bounds.x === "number" ? bounds.x : -bounds.width / 2,
@@ -2818,6 +2847,35 @@
2818
2847
  };
2819
2848
  }
2820
2849
 
2850
+ /**
2851
+ For a nested shape datum (Line/Area, whose datum wraps many points) returns a
2852
+ spreadable scene-node fragment carrying each point's content-space position
2853
+ paired with its source datum, so the pointer bridge can report the point
2854
+ nearest the cursor rather than the whole-series aggregate. Points the
2855
+ `defined` accessor rejects, or whose position isn't finite (a missing value),
2856
+ are skipped — so the nearest match is always a real, defined point. Returns
2857
+ an empty object for non-nested data (spreads to nothing).
2858
+ */ function interactionPoints(d, x, y, defined) {
2859
+ if (!d.__d3plusShape__ || !Array.isArray(d.values)) return {};
2860
+ const values = d.values;
2861
+ const points = [];
2862
+ values.forEach((v, k)=>{
2863
+ if (typeof defined === "function" && defined(v, k) === false) return;
2864
+ const px = Number(x(v, k));
2865
+ const py = Number(y(v, k));
2866
+ if (!Number.isFinite(px) || !Number.isFinite(py)) return;
2867
+ points.push({
2868
+ x: px,
2869
+ y: py,
2870
+ datum: v,
2871
+ index: typeof v.i === "number" ? v.i : k
2872
+ });
2873
+ });
2874
+ return points.length ? {
2875
+ interactionPoints: points
2876
+ } : {};
2877
+ }
2878
+
2821
2879
  /** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back
2822
2880
  to the source datum, so a `sort` comparator sees the same object the other
2823
2881
  per-datum accessors receive. */ function unwrap(d) {
@@ -3326,15 +3384,12 @@
3326
3384
  Renders the current Shape to the page. If a *callback* is specified, it will be called once the shapes are done drawing.
3327
3385
  @param callback Optional callback invoked after rendering completes.
3328
3386
  */ /**
3329
- Resolves a style accessor for a data point, mirroring the nested-data logic
3330
- of _applyStyle so scene output matches DOM rendering.
3387
+ Resolves a style accessor. For a nested shape (Line/Area) the accessor gets
3388
+ the merged aggregate `d.data`/`d.i` — matching `_nestWrapper` + scene datum.
3331
3389
  @private
3332
3390
  */ _styleVal(fn, d, i) {
3333
3391
  if (typeof fn !== "function") return fn;
3334
- if (d.nested && d.key && d.values) {
3335
- const first = d.values[0];
3336
- return fn(first, this._data.indexOf(first));
3337
- }
3392
+ if (d.nested && d.key && d.values) return fn(d.data, d.i);
3338
3393
  return fn(d, i);
3339
3394
  }
3340
3395
  /**
@@ -3419,15 +3474,23 @@
3419
3474
  const key = this._nestWrapper(this.schema.id)(d, i);
3420
3475
  const datum = d.__d3plusShape__ ? d.data : d;
3421
3476
  const transform = this._sceneTransform(d, i);
3477
+ // Per-point positions (Line/Area) shared by the geometry and its hit area
3478
+ // so a hover anywhere on either resolves to the nearest point.
3479
+ const iPoints = interactionPoints(d, this.schema.x, this.schema.y, this.schema.defined);
3422
3480
  // Push the hit area (if any) before the geometry so it sits behind it.
3481
+ // Line's is a fat path built from the geometry `d`; Bar/legend etc. a rect.
3423
3482
  if (this.schema.hitArea) {
3424
- const ha = hitAreaNode(this.schema.hitArea, d, i, this._aes(d, i), key, datum, this._name, transform);
3483
+ const ha = hitAreaNode(this.schema.hitArea, d, i, this._aes(d, i), key, datum, this._name, transform, geom.d);
3425
3484
  // Share the datum's rank so the hit area stays paired just behind its
3426
3485
  // own geometry (equal `z`, kept in push order by the stable sort).
3427
3486
  if (ha) children.push(rank ? {
3428
3487
  ...ha,
3488
+ ...iPoints,
3429
3489
  z: rank[i]
3430
- } : ha);
3490
+ } : {
3491
+ ...ha,
3492
+ ...iPoints
3493
+ });
3431
3494
  }
3432
3495
  children.push({
3433
3496
  ...geom,
@@ -3441,6 +3504,7 @@
3441
3504
  role: strOrUndef(this._nestWrapper(this.schema.role)(d, i)),
3442
3505
  label: strOrUndef(this._nestWrapper(this.schema.ariaLabel)(d, i))
3443
3506
  },
3507
+ ...iPoints,
3444
3508
  ...rank ? {
3445
3509
  z: rank[i]
3446
3510
  } : {}
@@ -9467,7 +9531,10 @@
9467
9531
  }
9468
9532
  };
9469
9533
  const debouncedResize = debounce(applyResize, viz.schema.detectResizeDelay);
9470
- viz._resizeObserver = new ResizeObserver((entries)=>{
9534
+ // Guarded so a chart can be constructed in an environment without a DOM (e.g.
9535
+ // before `@d3plus/ssr` installs one). Auto-resize is a browser-only feature;
9536
+ // when absent, `_resizeObserver` stays undefined and its call sites skip it.
9537
+ viz._resizeObserver = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver((entries)=>{
9471
9538
  // The first real-size notification after `observe()` reports the
9472
9539
  // container's settled layout size, which on an auto-sized chart often
9473
9540
  // differs from the size the chart just measured pre-layout (the
@@ -10082,7 +10149,9 @@
10082
10149
  viz._visiblePoll = clearInterval(viz._visiblePoll);
10083
10150
  viz._resizePoll = clearTimeout(viz._resizePoll);
10084
10151
  viz._scrollPoll = clearTimeout(viz._scrollPoll);
10085
- d3Selection.select(viz.schema.scrollContainer).on(`scroll.${viz._uuid}`, null);
10152
+ // scrollContainer is "" when constructed without a window (headless/SSR);
10153
+ // there is nothing to unbind and select("") throws on an invalid selector.
10154
+ if (viz.schema.scrollContainer) d3Selection.select(viz.schema.scrollContainer).on(`scroll.${viz._uuid}`, null);
10086
10155
  }
10087
10156
  /**
10088
10157
  Installs the visibility/scroll detection that defers rendering until the
@@ -10183,9 +10252,9 @@
10183
10252
  if (viz._select.attr("opacity") === "0") viz._select.transition().duration(viz.schema.duration).attr("opacity", 1);
10184
10253
  }
10185
10254
  if (viz.schema.detectResize && (viz._autoWidth || viz._autoHeight)) {
10186
- viz._resizeObserver.observe(viz._select.node().parentNode);
10255
+ viz._resizeObserver?.observe(viz._select.node().parentNode);
10187
10256
  } else {
10188
- viz._resizeObserver.unobserve(viz._select.node().parentNode);
10257
+ viz._resizeObserver?.unobserve(viz._select.node().parentNode);
10189
10258
  }
10190
10259
  if (callback) setTimeout(()=>{
10191
10260
  callback();
@@ -10884,6 +10953,23 @@
10884
10953
  */ render(callback) {
10885
10954
  return vizRender(this, callback);
10886
10955
  }
10956
+ /**
10957
+ Serializes the most recently rendered output to an SVG string. Returns
10958
+ `""` if the chart has not been rendered yet. Both backends support this:
10959
+ the SVG backend returns its live `<svg>`, the canvas backend re-renders the
10960
+ retained scene through a throwaway SVG backend. Primarily used for
10961
+ server-side rendering (see `@d3plus/ssr`).
10962
+ */ toSVGString() {
10963
+ return this._sceneRenderer?.toSVGString?.() ?? "";
10964
+ }
10965
+ /**
10966
+ Returns the underlying canvas element of the most recent render when the
10967
+ canvas backend is active (`renderer("canvas")`), or `undefined` otherwise.
10968
+ Server-side callers cast this to their native canvas to encode a raster
10969
+ (see `@d3plus/ssr`).
10970
+ */ toCanvas() {
10971
+ return this._renderer === "canvas" ? this._sceneRenderer?.toCanvas?.() : undefined;
10972
+ }
10887
10973
  renderer(_) {
10888
10974
  if (!arguments.length) return this._renderer;
10889
10975
  this._renderer = _ === "canvas" ? "canvas" : "svg";
@@ -10947,10 +11033,14 @@
10947
11033
  if (this._sceneRenderer && typeof this._sceneRenderer.destroy === "function") this._sceneRenderer.destroy();
10948
11034
  const Ctor = kind === "canvas" ? render.CanvasRenderer : render.SvgRenderer;
10949
11035
  this._sceneRenderer = new Ctor();
11036
+ // `_scenePixelRatio`, when set (e.g. by @d3plus/ssr for hi-res PNG output),
11037
+ // fixes the canvas backing-store scale; otherwise the renderer falls back
11038
+ // to `devicePixelRatio`.
10950
11039
  this._sceneRenderer.mount({
10951
11040
  container: mountTarget,
10952
11041
  width: w,
10953
- height: h
11042
+ height: h,
11043
+ pixelRatio: this._scenePixelRatio
10954
11044
  });
10955
11045
  // Bridge renderer pointer events → viz.schema.on handlers. Without this,
10956
11046
  // tooltips never fire on the v4 scene-rendered path because
@@ -11034,6 +11124,25 @@
11034
11124
  if (tlGroup) host.appendChild(tlGroup);
11035
11125
  }
11036
11126
  }
11127
+ /**
11128
+ Resolves the `(d, i, x)` a picked scene node reports to interaction
11129
+ handlers (tooltip, click, user `on` handlers). `pick.datum` is the raw
11130
+ scene datum; for a Plot shape that's the wrapped record `{data, i}`, which
11131
+ handlers expect unwrapped to `(d.data, d.i, wrapped)`. The base does that
11132
+ unwrap; Plot overrides this to report the point nearest the cursor for
11133
+ multi-point shapes (Line/Area) so a series tooltip reflects the hovered
11134
+ x rather than the whole-series aggregate.
11135
+ @private
11136
+ */ _interactionDatum(pick, _event) {
11137
+ const rawDatum = pick.datum;
11138
+ const sourceDatum = rawDatum && rawDatum.data ? rawDatum.data : rawDatum;
11139
+ const sourceIndex = rawDatum && typeof rawDatum.i === "number" ? rawDatum.i : pick.index ?? 0;
11140
+ return {
11141
+ d: sourceDatum,
11142
+ i: sourceIndex,
11143
+ x: rawDatum
11144
+ };
11145
+ }
11037
11146
  /**
11038
11147
  Routes a renderer pointer event to the matching `viz.schema.on` handlers.
11039
11148
  Bridges the v4 scene-rendered path (SvgRenderer/CanvasRenderer), where
@@ -11105,12 +11214,12 @@
11105
11214
  const isLegendNode = nodeAny.interactionGroup === "legend" || (target && typeof target.closest === "function" ? !!target.closest('[data-key="viz-legend"]') : false);
11106
11215
  const suffix = isLegendNode ? "legend" : "shape";
11107
11216
  const handlerKey = `${event.type}.${suffix}`;
11108
- // Resolve the source datum + index. `pick.datum` is the raw scene datum
11109
- // (which Shape._sceneXxx populated). For Plot shapes that's the wrapped
11110
- // record; the handlers expect `(d.data, d.i, x, event)`.
11111
- const rawDatum = pick.datum;
11112
- const sourceDatum = rawDatum && rawDatum.data ? rawDatum.data : rawDatum;
11113
- const sourceIndex = rawDatum && typeof rawDatum.i === "number" ? rawDatum.i : pick.index ?? 0;
11217
+ // Resolve the datum + index this pick reports to handlers, ONCE, and reuse
11218
+ // it for every handler fired below so tooltip/click/user handlers agree on
11219
+ // which datum the pointer is over. The base unwraps the node's raw datum to
11220
+ // its source row; Plot overrides `_interactionDatum` to report the point
11221
+ // nearest the cursor for multi-point shapes (Line/Area).
11222
+ const { d: sourceDatum, i: sourceIndex, x: rawDatum } = this._interactionDatum(pick, event);
11114
11223
  const shapeType = typeof nodeAny.shapeType === "string" ? nodeAny.shapeType : null;
11115
11224
  this._lastScenePick = {
11116
11225
  d: sourceDatum,
@@ -11156,7 +11265,7 @@
11156
11265
  /**
11157
11266
  Tears down the visualization: disconnects the ResizeObserver and removes DOM event listeners. Call this when unmounting to avoid memory leaks.
11158
11267
  */ destroy() {
11159
- this._resizeObserver.disconnect();
11268
+ this._resizeObserver?.disconnect();
11160
11269
  this._tooltipClass.data([]).render();
11161
11270
  d3Selection.select("body").on(`touchstart.${this._uuid}`, null);
11162
11271
  // Clear the visibility/resize/scroll poll timers + scroll listener
@@ -11177,7 +11286,7 @@
11177
11286
  if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(this._sceneRepaintRAF);
11178
11287
  this._sceneRepaintRAF = undefined;
11179
11288
  }
11180
- d3Selection.select(this.schema.scrollContainer).on(`scroll.${this._uuid}`, null);
11289
+ if (this.schema.scrollContainer) d3Selection.select(this.schema.scrollContainer).on(`scroll.${this._uuid}`, null);
11181
11290
  // Destroy the active scene renderer (clears its own pointer-rect
11182
11291
  // listeners, overlay host, canvas/svg DOM, timers).
11183
11292
  if (this._sceneRenderer && typeof this._sceneRenderer.destroy === "function") {
@@ -11589,11 +11698,28 @@
11589
11698
  };
11590
11699
 
11591
11700
  /** d3-scale's scale constructors, indexed by the dynamic `scale<Type>` name. */ const scaleConstructors = scales__namespace;
11701
+ /**
11702
+ A plotted axis value that can't be turned into a pixel coordinate: a
11703
+ non-finite number (`NaN`/`±Infinity`), `null`, or the empty-array sentinel
11704
+ `merge` yields when a numeric column aggregates to no usable value. Any of
11705
+ these poisons the shape's transform or path `d` downstream — e.g.
11706
+ `translate(NaN,…)` or `…L268.75,NaN` — which the browser rejects. A bare
11707
+ `undefined` is NOT bad: it's how an unused secondary axis (x2/y2) reports
11708
+ "no value on this row".
11709
+ */ const isBadAxisValue = (v)=>v === null || typeof v === "number" && !Number.isFinite(v) || Array.isArray(v) && v.length === 0;
11710
+ /**
11711
+ A formatted row is plottable when its x/y — and any *defined* x2/y2 — are
11712
+ real coordinates. Rows failing this are dropped in `formatPlotData` before
11713
+ domains, stacking, and paint ever read `_formattedData`, so a NaN measure
11714
+ no longer widens a domain, stacks as 0, or emits a broken coordinate.
11715
+ Resolves d3plus/d3plus#776.
11716
+ */ const isPlottableRow = (d)=>!isBadAxisValue(d.x) && !isBadAxisValue(d.y) && (d.x2 === undefined || !isBadAxisValue(d.x2)) && (d.y2 === undefined || !isBadAxisValue(d.y2));
11592
11717
  /**
11593
11718
  `formatPlotData` — first stage of Plot's chart-specific pipeline. Detects
11594
11719
  time axes (sets viz._xTime / _x2Time / _yTime / _y2Time), maps the
11595
11720
  filtered data through `prepData` to produce the per-row PlotDatum shape
11596
- (x/y/x2/y2 + id + group + shape + lci/hci + discrete), and constructs
11721
+ (x/y/x2/y2 + id + group + shape + lci/hci + discrete), drops rows whose
11722
+ axis values can't be plotted (`isPlottableRow` — see #776), and constructs
11597
11723
  the `_sizeScaleD3` if `_size` is set.
11598
11724
 
11599
11725
  Pure compute. Returns `{formattedData, axisData, x2Exists, y2Exists}`
@@ -11634,8 +11760,8 @@
11634
11760
  newD.id = newD.shape === "Bar" ? `${newD.id}_${newD[viz.schema.discrete]}` : newD.id;
11635
11761
  return newD;
11636
11762
  };
11637
- const formattedData = viz._formattedData = viz._filteredData.map(prepData);
11638
- const axisData = viz._axisPersist ? viz._data.map(prepData) : formattedData;
11763
+ const formattedData = viz._formattedData = viz._filteredData.map(prepData).filter(isPlottableRow);
11764
+ const axisData = viz._axisPersist ? viz._data.map(prepData).filter(isPlottableRow) : formattedData;
11639
11765
  if (viz._size) {
11640
11766
  const rExtent = d3Array.extent(axisData, (d)=>viz._size(d.data));
11641
11767
  viz._sizeScaleD3 = scaleConstructors[`scale${viz.schema.sizeScale.charAt(0).toUpperCase()}${viz.schema.sizeScale.slice(1)}`]().domain(rExtent).range([
@@ -13181,7 +13307,9 @@
13181
13307
  areaConfig[`${key}0`] = (d)=>scaleFunction(confidence[0] ? d.lci : d[key]);
13182
13308
  areaConfig[`${key}1`] = (d)=>scaleFunction(confidence[1] ? d.hci : d[key]);
13183
13309
  const area = makeShape("Area").renderMode("compute").config(areaConfig).data(values);
13184
- const confidenceConfig = Object.assign(viz.schema.shapeConfig, viz._confidenceConfig);
13310
+ // Fresh object — must NOT mutate the shared `shapeConfig`, or the confidence
13311
+ // fill/fillOpacity leak onto every other shape and every later render.
13312
+ const confidenceConfig = Object.assign({}, viz.schema.shapeConfig, viz._confidenceConfig);
13185
13313
  area.config(dom.assign(shapeConfigFor(viz, "Line", confidenceConfig), shapeConfigFor(viz, "Area", confidenceConfig))).render();
13186
13314
  out.push(...collectComputed(area));
13187
13315
  }
@@ -13990,6 +14118,53 @@
13990
14118
  for (const evt of shapeEvents)shape.on(evt, forward(evt));
13991
14119
  for (const evt of classEvents)shape.on(evt, forward(evt));
13992
14120
  }
14121
+ /**
14122
+ For a multi-point shape (Line/Area) reports the point nearest the cursor
14123
+ along the discrete axis, so every mouse event (tooltip, click, user
14124
+ handlers) reflects the hovered x rather than the whole-series aggregate.
14125
+ Non-nested shapes and legend swatches fall through to the base (aggregate)
14126
+ behavior.
14127
+ @private
14128
+ */ _interactionDatum(pick, event) {
14129
+ const node = pick.node;
14130
+ const points = node && node.interactionPoints;
14131
+ if (node && node.interactionGroup !== "legend" && Array.isArray(points) && points.length && event && Array.isArray(event.point)) {
14132
+ const nearest = this._nearestInteractionPoint(points, event.point);
14133
+ if (nearest) {
14134
+ const wrapped = nearest.datum;
14135
+ return {
14136
+ d: wrapped && wrapped.data ? wrapped.data : wrapped,
14137
+ i: typeof wrapped.i === "number" ? wrapped.i : nearest.index,
14138
+ x: wrapped
14139
+ };
14140
+ }
14141
+ }
14142
+ return super._interactionDatum(pick, event);
14143
+ }
14144
+ /**
14145
+ Picks the interaction point closest to a surface-local cursor position
14146
+ along the discrete axis. `event.point` is post-zoom surface space while the
14147
+ points are in pre-zoom content space (they live under the `viz-zoom`
14148
+ group), so the cursor is un-zoomed by `_zoomTransform` before comparing.
14149
+ @private
14150
+ */ _nearestInteractionPoint(points, point) {
14151
+ const t = this._zoomTransform;
14152
+ const scale = t && t.scale ? t.scale : 1;
14153
+ const cx = (point[0] - (t ? t.x : 0)) / scale;
14154
+ const cy = (point[1] - (t ? t.y : 0)) / scale;
14155
+ const axis = this.schema.discrete === "y" ? "y" : "x";
14156
+ const target = axis === "y" ? cy : cx;
14157
+ let best = null;
14158
+ let bestDist = Infinity;
14159
+ for (const p of points){
14160
+ const dist = Math.abs(p[axis] - target);
14161
+ if (dist < bestDist) {
14162
+ bestDist = dist;
14163
+ best = p;
14164
+ }
14165
+ }
14166
+ return best;
14167
+ }
13993
14168
  /**
13994
14169
  Extends the draw behavior of the abstract Viz class.
13995
14170
  @private
@@ -14237,9 +14412,14 @@
14237
14412
  Line: false
14238
14413
  });
14239
14414
  this._confidenceConfig = {
14415
+ // A line's colour is its stroke, so the confidence band fills with that
14416
+ // same colour (at the reduced opacity below). Prefer a per-Line stroke
14417
+ // override, else the shared stroke accessor (the Line config itself sets
14418
+ // no `stroke` — the colour comes from the top-level `shapeConfig.stroke`).
14240
14419
  fill: (d, i)=>{
14241
- const c = typeof this.schema.shapeConfig.Line.stroke === "function" ? this.schema.shapeConfig.Line.stroke(d, i) : this.schema.shapeConfig.Line.stroke;
14242
- return c;
14420
+ const { Line, stroke } = this.schema.shapeConfig;
14421
+ const s = Line && Line.stroke !== undefined ? Line.stroke : stroke;
14422
+ return typeof s === "function" ? s(d, i) : s;
14243
14423
  },
14244
14424
  fillOpacity: constant(0.5)
14245
14425
  };
@@ -15044,10 +15224,12 @@
15044
15224
  const c = viz.ctx.geomapCtx;
15045
15225
  if (!c) return [];
15046
15226
  const out = [];
15047
- // Canvas backend: ensureZoomDom keeps its imperative ocean rect transparent
15048
- // (it lives in the overlaying compute <svg>), so paint the ocean into the
15049
- // scene here — first, beneath the geography — to match the SVG backend.
15050
- if (viz._renderer === "canvas") {
15227
+ // The ocean rect and basemap tiles normally live in the imperative geomap
15228
+ // <svg> (`_container`), outside the scene graph. That's fine on-screen, but a
15229
+ // server render serializes only the scene, so under SSR (`viz._ssr`) — and on
15230
+ // the canvas backend, whose compute <svg> keeps its ocean transparent — paint
15231
+ // them into the scene here, beneath the geography, so the output is complete.
15232
+ if (viz._renderer === "canvas" || viz._ssr) {
15051
15233
  const ocean = viz.schema.ocean;
15052
15234
  if (ocean && ocean !== "transparent") {
15053
15235
  const { width, height } = chartBounds(viz);
@@ -15064,6 +15246,27 @@
15064
15246
  });
15065
15247
  }
15066
15248
  }
15249
+ // Basemap tiles, pre-fetched + inlined as data URIs by @d3plus/ssr. Placed
15250
+ // above the ocean and below the geography, at the positions `_computeTileList`
15251
+ // derives from the fitted projection (same math as the live `_renderTiles`).
15252
+ const ssrTiles = viz._ssrTiles;
15253
+ if (ssrTiles && ssrTiles.size && typeof viz._computeTileList === "function") {
15254
+ for (const t of viz._computeTileList()){
15255
+ const href = ssrTiles.get(t.key);
15256
+ if (!href) continue;
15257
+ out.push({
15258
+ type: "image",
15259
+ key: `geomap-tile-${t.key}`,
15260
+ x: t.x,
15261
+ y: t.y,
15262
+ width: t.size,
15263
+ height: t.size,
15264
+ href,
15265
+ preserveAspectRatio: "none",
15266
+ interactive: false
15267
+ });
15268
+ }
15269
+ }
15067
15270
  if (c.topoData && c.topoData.length) {
15068
15271
  const pathConfig = shapeConfigFor(viz, "Path");
15069
15272
  for(let i = 0; i < c.topoData.length; i++){
@@ -15136,6 +15339,11 @@
15136
15339
  /** Installs `_renderTiles`, the per-instance method that mutates the tile group. */ function setupGeomapRenderTiles(viz) {
15137
15340
  // `_renderTiles` is a per-instance method that mutates the tile group.
15138
15341
  viz._renderTiles = function(transform = d3Zoom.zoomTransform((this._zoomEventTarget || this._container).node()), duration = 0) {
15342
+ // Under SSR the basemap is composited into the scene graph (see geomapEmit +
15343
+ // `_computeTileList`), so skip the imperative <image> tile layer entirely.
15344
+ // It wouldn't be serialized anyway, and its transform transition relies on
15345
+ // SVGGElement.transform.baseVal, which headless DOMs don't implement.
15346
+ if (this._ssr) return;
15139
15347
  let tileData = [];
15140
15348
  if (this.schema.tiles) {
15141
15349
  tileData = this._tileGen.extent(this._zoomBehavior.translateExtent()).scale(this.schema.projection.scale() * (2 * Math.PI) * transform.k).translate(transform.apply(this.schema.projection.translate()))();
@@ -15152,6 +15360,23 @@
15152
15360
  "c"
15153
15361
  ][Math.random() * 3 | 0]).replace("{z}", `${z}`).replace("{x}", `${x}`).replace("{y}", `${y}`)).attr("x", ([x])=>x * scale + tileData.translate[0] * scale - transform.x / transform.k).attr("y", ([, y])=>y * scale + tileData.translate[1] * scale - transform.y / transform.k);
15154
15362
  };
15363
+ // Static (identity-transform) tile list for server-side rendering: the tile
15364
+ // URLs + their positions in projection pixel space, so @d3plus/ssr can fetch
15365
+ // them and geomapEmit can place them as scene image nodes (both SVG string and
15366
+ // canvas output then include the basemap, with no network at view time).
15367
+ // Deterministic `{s}` = "a" so tiles are cacheable across renders.
15368
+ viz._computeTileList = function() {
15369
+ if (!this.schema.tiles) return [];
15370
+ const tileData = this._tileGen.extent(this._zoomBehavior.translateExtent()).scale(this.schema.projection.scale() * (2 * Math.PI)).translate(this.schema.projection.translate())();
15371
+ const size = tileData.scale;
15372
+ return tileData.map(([x, y, z])=>({
15373
+ key: `${x}-${y}-${z}`,
15374
+ url: this.schema.tileUrl.replace("{s}", "a").replace("{z}", `${z}`).replace("{x}", `${x}`).replace("{y}", `${y}`),
15375
+ x: x * size + tileData.translate[0] * size,
15376
+ y: y * size + tileData.translate[1] * size,
15377
+ size
15378
+ }));
15379
+ };
15155
15380
  }
15156
15381
  /** Wraps `_draw` to ensure the DOM zoom group + zoom wiring exist before drawing. */ function setupGeomapDraw(viz) {
15157
15382
  // Wrap _draw to ensure DOM zoom group + zoom wiring.
@@ -15223,7 +15448,10 @@
15223
15448
  const supDrawScene = viz._drawSceneToTarget.bind(viz);
15224
15449
  viz._drawSceneToTarget = function(durationOverride) {
15225
15450
  supDrawScene(durationOverride);
15226
- if (viz._renderer === "canvas" && viz._sceneRenderer && typeof viz._sceneRenderer.toCanvas === "function") {
15451
+ if (viz._renderer === "canvas" && // Under SSR the canvas is a headless native surface with no
15452
+ // addEventListener; there is no interaction to wire, so skip the
15453
+ // pointer/zoom rebind entirely.
15454
+ !viz._ssr && viz._sceneRenderer && typeof viz._sceneRenderer.toCanvas === "function") {
15227
15455
  const canvasNode = viz._sceneRenderer.toCanvas();
15228
15456
  if (canvasNode) {
15229
15457
  // The compute svg is absolutely positioned over the canvas; an svg root