layerchart 0.40.1 → 0.40.3
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.
|
@@ -113,7 +113,7 @@ onMount(() => {
|
|
|
113
113
|
let:data
|
|
114
114
|
let:flatData
|
|
115
115
|
>
|
|
116
|
-
<!-- Apply fitGeojson using TransformContext instead of GeoContext if `applyTransform` is used -->
|
|
116
|
+
<!-- Apply `fitGeojson` using TransformContext instead of GeoContext if `applyTransform` is used -->
|
|
117
117
|
{@const initialTransform =
|
|
118
118
|
geo?.applyTransform && geo?.fitGeojson && geo?.projection
|
|
119
119
|
? geoFitObjectTransform(geo.projection(), [width, height], geo.fitGeojson)
|
|
@@ -26,7 +26,7 @@ import Voronoi from './Voronoi.svelte';
|
|
|
26
26
|
import { localPoint } from '../utils/event.js';
|
|
27
27
|
import { isScaleBand, scaleInvert } from '../utils/scales.js';
|
|
28
28
|
import { quadtreeRects } from '../utils/quadtree.js';
|
|
29
|
-
const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, height, padding } = getContext('LayerCake');
|
|
29
|
+
const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, height, containerWidth, containerHeight, padding, } = getContext('LayerCake');
|
|
30
30
|
/*
|
|
31
31
|
TODO: Defaults to consider (if possible to detect scale type, which might not be possible)
|
|
32
32
|
- scaleTime / scaleLinear: bisect
|
|
@@ -124,8 +124,22 @@ function showTooltip(e, tooltipData) {
|
|
|
124
124
|
// TODO: When using bisect-x/y/band, values should be sorted. Tyipcally are for `x`, but not `y` (and band depends on if x or y scale)
|
|
125
125
|
if (tooltipData == null) {
|
|
126
126
|
switch (mode) {
|
|
127
|
-
case '
|
|
128
|
-
|
|
127
|
+
case 'bisect-x': {
|
|
128
|
+
// `x` value at pointer coordinate
|
|
129
|
+
const xValueAtPoint = scaleInvert($xScale, localX - $padding.left);
|
|
130
|
+
const index = bisectX($flatData, xValueAtPoint, 1);
|
|
131
|
+
const previousValue = $flatData[index - 1];
|
|
132
|
+
const currentValue = $flatData[index];
|
|
133
|
+
tooltipData = findData(previousValue, currentValue, xValueAtPoint, $x);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'bisect-y': {
|
|
137
|
+
// `y` value at pointer coordinate
|
|
138
|
+
const yValueAtPoint = scaleInvert($yScale, localY - $padding.top);
|
|
139
|
+
const index = bisectY($flatData, yValueAtPoint, 1);
|
|
140
|
+
const previousValue = $flatData[index - 1];
|
|
141
|
+
const currentValue = $flatData[index];
|
|
142
|
+
tooltipData = findData(previousValue, currentValue, yValueAtPoint, $y);
|
|
129
143
|
break;
|
|
130
144
|
}
|
|
131
145
|
case 'bisect-band': {
|
|
@@ -153,22 +167,8 @@ function showTooltip(e, tooltipData) {
|
|
|
153
167
|
}
|
|
154
168
|
break;
|
|
155
169
|
}
|
|
156
|
-
case '
|
|
157
|
-
|
|
158
|
-
const xValueAtPoint = scaleInvert($xScale, localX - $padding.left);
|
|
159
|
-
const index = bisectX($flatData, xValueAtPoint, 1);
|
|
160
|
-
const previousValue = $flatData[index - 1];
|
|
161
|
-
const currentValue = $flatData[index];
|
|
162
|
-
tooltipData = findData(previousValue, currentValue, xValueAtPoint, $x);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
case 'bisect-y': {
|
|
166
|
-
// `y` value at pointer coordinate
|
|
167
|
-
const yValueAtPoint = scaleInvert($yScale, localY - $padding.top);
|
|
168
|
-
const index = bisectY($flatData, yValueAtPoint, 1);
|
|
169
|
-
const previousValue = $flatData[index - 1];
|
|
170
|
-
const currentValue = $flatData[index];
|
|
171
|
-
tooltipData = findData(previousValue, currentValue, yValueAtPoint, $y);
|
|
170
|
+
case 'quadtree': {
|
|
171
|
+
tooltipData = quadtree.find(localX, localY, radius);
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -273,82 +273,85 @@ $: if (mode === 'bounds' || mode === 'band') {
|
|
|
273
273
|
})
|
|
274
274
|
.sort(sortFunc('x'));
|
|
275
275
|
}
|
|
276
|
+
$: triggerPointEvents = ['bisect-x', 'bisect-y', 'bisect-band', 'quadtree'].includes(mode);
|
|
276
277
|
</script>
|
|
277
278
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
279
|
+
<div
|
|
280
|
+
style:width="{$width}px"
|
|
281
|
+
style:height="{$height}px"
|
|
282
|
+
style:top="{$padding.top}px"
|
|
283
|
+
style:left="{$padding.left}px"
|
|
284
|
+
class={cls(
|
|
285
|
+
'tooltip-trigger absolute touch-none',
|
|
286
|
+
debug && triggerPointEvents && 'bg-danger/10 outline outline-danger'
|
|
287
|
+
)}
|
|
288
|
+
on:pointerenter={triggerPointEvents ? showTooltip : undefined}
|
|
289
|
+
on:pointermove={triggerPointEvents ? showTooltip : undefined}
|
|
290
|
+
on:pointerleave={triggerPointEvents ? hideTooltip : undefined}
|
|
291
|
+
on:click={(e) => {
|
|
292
|
+
if (triggerPointEvents) {
|
|
292
293
|
onClick({ data: $tooltip?.data });
|
|
293
|
-
}
|
|
294
|
+
}
|
|
295
|
+
}}
|
|
296
|
+
>
|
|
297
|
+
<!-- Rendering slot within tooltip-trigger allows pointer events to bubble up (ex. Brush) -->
|
|
298
|
+
<div
|
|
299
|
+
class="absolute"
|
|
300
|
+
style:width="{$containerWidth}px"
|
|
301
|
+
style:height="{$containerHeight}px"
|
|
302
|
+
style:top="{-$padding.top}px"
|
|
303
|
+
style:left="{-$padding.left}px"
|
|
294
304
|
>
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
{
|
|
301
|
-
|
|
302
|
-
<Svg>
|
|
303
|
-
<Voronoi
|
|
304
|
-
on:pointerenter={(e) => showTooltip(e.detail.event, e.detail.data)}
|
|
305
|
-
on:pointermove={(e) => showTooltip(e.detail.event, e.detail.data)}
|
|
306
|
-
on:pointerleave={hideTooltip}
|
|
307
|
-
on:click={(e) => {
|
|
308
|
-
onClick({ data: e.detail.data });
|
|
309
|
-
}}
|
|
310
|
-
classes={{ path: cls(debug && 'fill-danger/10 stroke-danger') }}
|
|
311
|
-
/>
|
|
312
|
-
</Svg>
|
|
313
|
-
{:else if mode === 'bounds' || mode === 'band'}
|
|
314
|
-
<slot tooltip={$tooltip} />
|
|
315
|
-
<Svg>
|
|
316
|
-
<g class="tooltip-rects">
|
|
317
|
-
{#each rects as rect}
|
|
318
|
-
<rect
|
|
319
|
-
x={rect.x}
|
|
320
|
-
y={rect.y}
|
|
321
|
-
width={rect.width}
|
|
322
|
-
height={rect.height}
|
|
323
|
-
class={cls(debug ? 'fill-danger/10 stroke-danger' : 'fill-transparent')}
|
|
324
|
-
on:pointerenter={(e) => showTooltip(e, rect.data)}
|
|
325
|
-
on:pointermove={(e) => showTooltip(e, rect.data)}
|
|
305
|
+
<slot tooltip={$tooltip} />
|
|
306
|
+
|
|
307
|
+
{#if mode === 'voronoi'}
|
|
308
|
+
<Svg>
|
|
309
|
+
<Voronoi
|
|
310
|
+
on:pointerenter={(e) => showTooltip(e.detail.event, e.detail.data)}
|
|
311
|
+
on:pointermove={(e) => showTooltip(e.detail.event, e.detail.data)}
|
|
326
312
|
on:pointerleave={hideTooltip}
|
|
327
313
|
on:click={(e) => {
|
|
328
|
-
onClick({ data:
|
|
314
|
+
onClick({ data: e.detail.data });
|
|
329
315
|
}}
|
|
316
|
+
classes={{ path: cls(debug && 'fill-danger/10 stroke-danger') }}
|
|
330
317
|
/>
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
{
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
</
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
318
|
+
</Svg>
|
|
319
|
+
{:else if mode === 'bounds' || mode === 'band'}
|
|
320
|
+
<Svg>
|
|
321
|
+
<g class="tooltip-rects">
|
|
322
|
+
{#each rects as rect}
|
|
323
|
+
<rect
|
|
324
|
+
x={rect.x}
|
|
325
|
+
y={rect.y}
|
|
326
|
+
width={rect.width}
|
|
327
|
+
height={rect.height}
|
|
328
|
+
class={cls(debug ? 'fill-danger/10 stroke-danger' : 'fill-transparent')}
|
|
329
|
+
on:pointerenter={(e) => showTooltip(e, rect.data)}
|
|
330
|
+
on:pointermove={(e) => showTooltip(e, rect.data)}
|
|
331
|
+
on:pointerleave={hideTooltip}
|
|
332
|
+
on:click={(e) => {
|
|
333
|
+
onClick({ data: rect.data });
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
{/each}
|
|
337
|
+
</g>
|
|
338
|
+
</Svg>
|
|
339
|
+
{:else if mode === 'quadtree' && debug}
|
|
340
|
+
<Svg pointerEvents={false}>
|
|
341
|
+
<ChartClipPath>
|
|
342
|
+
<g class="tooltip-quadtree">
|
|
343
|
+
{#each quadtreeRects(quadtree, false) as rect}
|
|
344
|
+
<rect
|
|
345
|
+
x={rect.x}
|
|
346
|
+
y={rect.y}
|
|
347
|
+
width={rect.width}
|
|
348
|
+
height={rect.height}
|
|
349
|
+
class={cls(debug ? 'fill-danger/10 stroke-danger' : 'fill-transparent')}
|
|
350
|
+
/>
|
|
351
|
+
{/each}
|
|
352
|
+
</g>
|
|
353
|
+
</ChartClipPath>
|
|
354
|
+
</Svg>
|
|
355
|
+
{/if}
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|