layerchart 0.98.1 → 0.98.2

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.
@@ -128,6 +128,7 @@
128
128
 
129
129
  let isHoveringTooltip = false;
130
130
  let hideTimeoutId: NodeJS.Timeout;
131
+ let tooltipContextNode: HTMLDivElement;
131
132
 
132
133
  $: bisectX = bisector((d: any) => {
133
134
  const value = $x(d);
@@ -187,20 +188,15 @@
187
188
  return;
188
189
  }
189
190
 
190
- const referenceNode = (e.target as Element).closest('.layercake-container')!;
191
- const point = localPoint(e, referenceNode);
192
- const pointerX = point?.x ?? 0;
193
- const pointerY = point?.y ?? 0;
191
+ const containerNode = (e.target as Element).closest('.layercake-container')!;
192
+ const point = localPoint(e, containerNode);
194
193
 
195
194
  if (
196
- // @ts-expect-error
197
- pointerX < e.currentTarget?.offsetLeft ||
198
- // @ts-expect-error
199
- pointerX > e.currentTarget?.offsetLeft + e.currentTarget?.offsetWidth ||
200
- // @ts-expect-error
201
- pointerY < e.currentTarget?.offsetTop ||
202
- // @ts-expect-error
203
- pointerY > e.currentTarget?.offsetTop + e.currentTarget?.offsetHeight
195
+ mode !== 'manual' &&
196
+ (point.x < tooltipContextNode.offsetLeft ||
197
+ point.x > tooltipContextNode.offsetLeft + tooltipContextNode.offsetWidth ||
198
+ point.y < tooltipContextNode.offsetTop ||
199
+ point.y > tooltipContextNode.offsetTop + tooltipContextNode.offsetHeight)
204
200
  ) {
205
201
  // Ignore if within padding of chart
206
202
  hideTooltip();
@@ -215,10 +211,10 @@
215
211
  let xValueAtPoint: any;
216
212
  if ($radial) {
217
213
  // Assume radial is always centered
218
- const { radians } = cartesianToPolar(pointerX - $width / 2, pointerY - $height / 2);
214
+ const { radians } = cartesianToPolar(point.x - $width / 2, point.y - $height / 2);
219
215
  xValueAtPoint = scaleInvert($xScale, radians);
220
216
  } else {
221
- xValueAtPoint = scaleInvert($xScale, pointerX - $padding.left);
217
+ xValueAtPoint = scaleInvert($xScale, point.x - $padding.left);
222
218
  }
223
219
 
224
220
  const index = bisectX($flatData, xValueAtPoint, 1);
@@ -230,7 +226,7 @@
230
226
 
231
227
  case 'bisect-y': {
232
228
  // `y` value at pointer coordinate
233
- const yValueAtPoint = scaleInvert($yScale, pointerY - $padding.top);
229
+ const yValueAtPoint = scaleInvert($yScale, point.y - $padding.top);
234
230
 
235
231
  const index = bisectY($flatData, yValueAtPoint, 1);
236
232
  const previousValue = $flatData[index - 1];
@@ -241,8 +237,8 @@
241
237
 
242
238
  case 'bisect-band': {
243
239
  // `x` and `y` values at pointer coordinate
244
- const xValueAtPoint = scaleInvert($xScale, pointerX);
245
- const yValueAtPoint = scaleInvert($yScale, pointerY);
240
+ const xValueAtPoint = scaleInvert($xScale, point.x);
241
+ const yValueAtPoint = scaleInvert($yScale, point.y);
246
242
 
247
243
  if (isScaleBand($xScale)) {
248
244
  // Find point closest to pointer within the x band
@@ -269,7 +265,7 @@
269
265
  }
270
266
 
271
267
  case 'quadtree': {
272
- tooltipData = quadtree.find(pointerX, pointerY, radius);
268
+ tooltipData = quadtree.find(point.x, point.y, radius);
273
269
  break;
274
270
  }
275
271
  }
@@ -282,8 +278,8 @@
282
278
 
283
279
  $tooltip = {
284
280
  ...$tooltip,
285
- x: pointerX,
286
- y: pointerY,
281
+ x: point.x,
282
+ y: point.y,
287
283
  data: tooltipData,
288
284
  };
289
285
  } else {
@@ -427,6 +423,7 @@
427
423
  onclick(e, { data: $tooltip?.data });
428
424
  }
429
425
  }}
426
+ bind:this={tooltipContextNode}
430
427
  >
431
428
  <!-- Rendering slot within TooltipContext to allow pointer events to bubble up (ex. Brush) -->
432
429
  <div
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "0.98.1",
7
+ "version": "0.98.2",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.12",
10
10
  "@mdi/js": "^7.4.47",