@pioneer-code/pioneer-charts 22.2.4 → 22.2.5

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.
@@ -2268,11 +2268,16 @@ class PlaChartBuilder extends PcacChart {
2268
2268
  coincidentOf = new Map();
2269
2269
  fanOut = null;
2270
2270
  fanOutOffsets = new Map();
2271
+ /** The `.point` group under the cursor, between its mouseover and mouseout (see `leavePoint`). */
2272
+ hoveredPoint = null;
2271
2273
  dotClicked$ = this.dotClickedSource.asObservable();
2272
2274
  buildChart(chartElm, config, type) {
2273
2275
  if (!config?.data?.length) {
2274
2276
  return;
2275
2277
  }
2278
+ // A rebuild throws the hovered point away with everything else, and a removed element gets
2279
+ // no mouseout, so its tooltip is closed here (see `leavePoint`).
2280
+ this.leavePoint();
2276
2281
  this.config = JSON.parse(JSON.stringify(config));
2277
2282
  this.startData = range(this.config.data[0].data.length).map(() => ({
2278
2283
  key: '',
@@ -2298,6 +2303,11 @@ class PlaChartBuilder extends PcacChart {
2298
2303
  this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
2299
2304
  if (this.zoomEnabled) {
2300
2305
  this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
2306
+ // Zoom moves the points, not the mouse: the hovered one slides out from under a still
2307
+ // cursor (or is hidden outright, see `pointDisplay`), and either way the browser never
2308
+ // sends it a mouseout - its tooltip would stay up, and its dot stay grown, until the
2309
+ // cursor happened to cross it again. So the hover is ended here, on every zoom event.
2310
+ this.leavePoint();
2301
2311
  // A d3 zoom transform is always two-dimensional; only the enabled axes follow it and the
2302
2312
  // other keeps its original scale, so that component of the gesture is simply ignored.
2303
2313
  const newX = this.config.enableZoomX ? event.transform.rescaleX(this.scales.x) : this.scales.x;
@@ -2459,9 +2469,17 @@ class PlaChartBuilder extends PcacChart {
2459
2469
  attachZoomBehavior() {
2460
2470
  if (!this.zoomEnabled)
2461
2471
  return;
2462
- // Add a transparent rect to capture zoom events
2472
+ // A transparent rect so the empty plot area is a hit target too: a `<g>` has no area of its
2473
+ // own, so wheel/drag only reaches it through something painted. The rect is only ever that -
2474
+ // the behavior is attached once, to the group, and the rect's events bubble up to it. It used
2475
+ // to be `.call()`ed on both, and d3-zoom keeps its transform per element (`__zoom`): a wheel
2476
+ // over a point never passes through the rect (a sibling of the `.dots`, not an ancestor), so
2477
+ // only the group's transform advanced, and once the point had slid out from under the cursor
2478
+ // the next tick hit the rect - whose handler redrew from its own stale, near-identity
2479
+ // transform before the group's redrew from the real one, every tick, flickering the chart
2480
+ // between the two.
2463
2481
  //
2464
- // d3's `ZoomBehavior<Element, unknown>` vs. our concretely-typed `Selection<SVGRectElement|SVGGElement, ...>`
2482
+ // d3's `ZoomBehavior<Element, unknown>` vs. our concretely-typed `Selection<SVGGElement, ...>`
2465
2483
  // is a known D3+TS typings friction point: `.call()` structurally compares nested generic Selection
2466
2484
  // methods (`.merge()`, `.select()`, ...) and those never line up across two different concrete element
2467
2485
  // types, even though a zoom behavior works on any element at runtime. Narrow, local `any` escape hatch.
@@ -2469,13 +2487,8 @@ class PlaChartBuilder extends PcacChart {
2469
2487
  .attr('width', this.width)
2470
2488
  .attr('height', this.height)
2471
2489
  .attr('fill', 'none')
2472
- .attr('pointer-events', 'all')
2473
- .call(this.zoomBehavior)
2474
- .transition()
2475
- .duration(750);
2476
- this.svg.call(this.zoomBehavior)
2477
- .transition()
2478
- .duration(750);
2490
+ .attr('pointer-events', 'all');
2491
+ this.svg.call(this.zoomBehavior);
2479
2492
  }
2480
2493
  drawLineArea(config, type) {
2481
2494
  for (let i = 0; i < config.data.length; i++) {
@@ -2590,6 +2603,7 @@ class PlaChartBuilder extends PcacChart {
2590
2603
  .attr('transform', (d, i) => this.pointTransform(d, i, this.scales))
2591
2604
  .attr('display', (d, i) => this.pointDisplay(d, i, this.scales))
2592
2605
  .on('mouseover', function (event, d) {
2606
+ self.hoveredPoint = this;
2593
2607
  // `d` is the very element bound from `series.data` above, so identity lookup is exact.
2594
2608
  self.showTooltip(event, d, {
2595
2609
  index: series.data.indexOf(d),
@@ -2606,14 +2620,7 @@ class PlaChartBuilder extends PcacChart {
2606
2620
  .attr('r', 6)
2607
2621
  .attr('fill', self.colors[index]);
2608
2622
  })
2609
- .on('mouseout', function () {
2610
- self.hideTooltip();
2611
- select$1(this).select('.dot')
2612
- .transition()
2613
- .duration(duration / 3)
2614
- .attr('r', 4)
2615
- .attr('fill', '#fff');
2616
- })
2623
+ .on('mouseout', () => this.leavePoint())
2617
2624
  .on('click', (_event, d) => {
2618
2625
  this.dotClickedSource.next(d);
2619
2626
  });
@@ -2647,6 +2654,24 @@ class PlaChartBuilder extends PcacChart {
2647
2654
  .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
2648
2655
  }
2649
2656
  }
2657
+ /**
2658
+ * Ends the current hover, if there is one: hides the tooltip and shrinks the dot back. Shared by
2659
+ * the point's own mouseout and the zoom handler, which has to end a hover the browser won't
2660
+ * (the point moves, the cursor doesn't - see `buildChart`'s zoom callback).
2661
+ */
2662
+ leavePoint() {
2663
+ if (!this.hoveredPoint) {
2664
+ return;
2665
+ }
2666
+ const point = this.hoveredPoint;
2667
+ this.hoveredPoint = null;
2668
+ this.hideTooltip();
2669
+ select$1(point).select('.dot')
2670
+ .transition()
2671
+ .duration(this.transitionService.getTransitionDuration() / 3)
2672
+ .attr('r', 4)
2673
+ .attr('fill', '#fff');
2674
+ }
2650
2675
  /**
2651
2676
  * Where a point's group goes: its true coordinate, plus - for a fanned-out point - however far
2652
2677
  * its ring had to be shifted to stay inside the plot area at these scales. The shift is on the