layerchart 0.97.0 → 0.97.1
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/components/BrushContext.svelte +4 -5
- package/dist/components/Chart.svelte.d.ts +4 -2
- package/dist/components/Group.svelte +2 -1
- package/dist/components/TransformContext.svelte +2 -9
- package/dist/components/layout/Canvas.svelte +2 -3
- package/dist/components/tooltip/TooltipContext.svelte +2 -3
- package/package.json +7 -7
- package/dist/utils/event.d.ts +0 -4
- package/dist/utils/event.js +0 -44
|
@@ -42,13 +42,12 @@
|
|
|
42
42
|
|
|
43
43
|
<script lang="ts">
|
|
44
44
|
import { extent, min, max } from 'd3-array';
|
|
45
|
-
import { clamp } from '@layerstack/utils';
|
|
45
|
+
import { clamp, localPoint } from '@layerstack/utils';
|
|
46
46
|
import { cls } from '@layerstack/tailwind';
|
|
47
47
|
import { Logger } from '@layerstack/utils';
|
|
48
48
|
|
|
49
49
|
import { chartContext } from './ChartContext.svelte';
|
|
50
50
|
|
|
51
|
-
import { localPoint } from '../utils/event.js';
|
|
52
51
|
import type { DomainType } from '../utils/scales.js';
|
|
53
52
|
import { add } from '../utils/math.js';
|
|
54
53
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
@@ -143,7 +142,7 @@
|
|
|
143
142
|
logger.debug('drag start');
|
|
144
143
|
e.stopPropagation();
|
|
145
144
|
|
|
146
|
-
const startPoint = localPoint(
|
|
145
|
+
const startPoint = localPoint(e, rootEl);
|
|
147
146
|
|
|
148
147
|
if (
|
|
149
148
|
startPoint &&
|
|
@@ -165,7 +164,7 @@
|
|
|
165
164
|
onbrushstart({ xDomain, yDomain });
|
|
166
165
|
|
|
167
166
|
const onPointerMove = (e: PointerEvent) => {
|
|
168
|
-
const currentPoint = localPoint(
|
|
167
|
+
const currentPoint = localPoint(e, rootEl);
|
|
169
168
|
fn(start, {
|
|
170
169
|
x: $xScale.invert?.(currentPoint?.x ?? 0),
|
|
171
170
|
y: $yScale.invert?.(currentPoint?.y ?? 0),
|
|
@@ -175,7 +174,7 @@
|
|
|
175
174
|
};
|
|
176
175
|
|
|
177
176
|
const onPointerUp = (e: PointerEvent) => {
|
|
178
|
-
const currentPoint = localPoint(
|
|
177
|
+
const currentPoint = localPoint(e, rootEl);
|
|
179
178
|
const xPointDelta = Math.abs((startPoint?.x ?? 0) - (currentPoint?.x ?? 0));
|
|
180
179
|
const yPointDelta = Math.abs((startPoint?.y ?? 0) - (currentPoint?.y ?? 0));
|
|
181
180
|
|
|
@@ -225,7 +225,7 @@ declare class __sveltets_Render<TData> {
|
|
|
225
225
|
mode?: "none" | "canvas" | "manual";
|
|
226
226
|
translateOnScale?: boolean;
|
|
227
227
|
spring?: boolean | Parameters<typeof import("../stores/motionStore").motionStore>[1]["spring"];
|
|
228
|
-
tweened?: boolean | Parameters<typeof import("../stores/motionStore").motionStore>[1]["tweened"];
|
|
228
|
+
tweened?: boolean | Parameters<typeof import("../stores/motionStore").motionStore>[1] /** Override the default r range of `[1, 25]` by setting an array or function with argument `({ width, height})` that returns an array. Setting this prop overrides `rReverse`. This can also be a list of numbers or strings for scales with discrete ranges like [scaleThreshold](https://github.com/d3/d3-scale#threshold-scales) or [scaleQuantize](https://github.com/d3/d3-scale#quantize-scales). */["tweened"];
|
|
229
229
|
processTranslate?: (x: number, y: number, deltaX: number, deltaY: number, scale: number) => {
|
|
230
230
|
x: number;
|
|
231
231
|
y: number;
|
|
@@ -302,7 +302,9 @@ declare class __sveltets_Render<TData> {
|
|
|
302
302
|
}) => void;
|
|
303
303
|
onbrushstart?: (detail: {
|
|
304
304
|
xDomain?: DomainType;
|
|
305
|
-
yDomain
|
|
305
|
+
yDomain
|
|
306
|
+
/** Exposed via bind: to support `bind:brushContext` for external access (ex. `brushContext.xDomain) */
|
|
307
|
+
?: DomainType;
|
|
306
308
|
}) => void;
|
|
307
309
|
onbrushend?: (detail: {
|
|
308
310
|
xDomain?: DomainType;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onDestroy, tick } from 'svelte';
|
|
3
3
|
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
4
|
+
import { cls } from '@layerstack/tailwind';
|
|
4
5
|
|
|
5
6
|
import { getRenderContext } from './Chart.svelte';
|
|
6
7
|
import { chartContext } from './ChartContext.svelte';
|
|
7
8
|
import { motionStore } from '../stores/motionStore.js';
|
|
8
9
|
import { getCanvasContext } from './layout/Canvas.svelte';
|
|
9
|
-
|
|
10
10
|
const { width, height } = chartContext();
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
<div
|
|
117
117
|
style:transform
|
|
118
118
|
{...$$restProps}
|
|
119
|
+
class={cls('absolute', $$restProps.class)}
|
|
119
120
|
on:click={onclick}
|
|
120
121
|
on:dblclick={ondblclick}
|
|
121
122
|
on:pointerenter={onpointerenter}
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
<script lang="ts">
|
|
57
57
|
import { chartContext } from './ChartContext.svelte';
|
|
58
58
|
import { motionStore, type MotionOptions, motionFinishHandler } from '../stores/motionStore.js';
|
|
59
|
+
import { localPoint } from '@layerstack/utils';
|
|
59
60
|
|
|
60
61
|
const { width, height } = chartContext();
|
|
61
62
|
|
|
@@ -162,7 +163,7 @@
|
|
|
162
163
|
ondragstart?.();
|
|
163
164
|
}
|
|
164
165
|
|
|
165
|
-
function onPointerMove(e: PointerEvent) {
|
|
166
|
+
function onPointerMove(e: PointerEvent & { currentTarget: HTMLDivElement }) {
|
|
166
167
|
if (!pointerDown) return;
|
|
167
168
|
|
|
168
169
|
e.preventDefault(); // Stop text selection
|
|
@@ -178,7 +179,6 @@
|
|
|
178
179
|
|
|
179
180
|
if ($dragging) {
|
|
180
181
|
e.stopPropagation(); // Stop tooltip from trigging (along with `capture: true`)
|
|
181
|
-
// @ts-expect-error
|
|
182
182
|
e.currentTarget?.setPointerCapture(e.pointerId);
|
|
183
183
|
|
|
184
184
|
setTranslate(
|
|
@@ -281,13 +281,6 @@
|
|
|
281
281
|
scaling.handle(scale.set(value, options));
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
function localPoint(e: PointerEvent | MouseEvent | WheelEvent) {
|
|
285
|
-
return {
|
|
286
|
-
x: e.offsetX,
|
|
287
|
-
y: e.offsetY,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
284
|
$: center = { x: $width / 2, y: $height / 2 };
|
|
292
285
|
|
|
293
286
|
$: viewportCenter = {
|
|
@@ -38,14 +38,13 @@
|
|
|
38
38
|
<script lang="ts">
|
|
39
39
|
import { onMount, onDestroy } from 'svelte';
|
|
40
40
|
import { cls } from '@layerstack/tailwind';
|
|
41
|
-
import { Logger } from '@layerstack/utils';
|
|
41
|
+
import { Logger, localPoint } from '@layerstack/utils';
|
|
42
42
|
|
|
43
43
|
import { setRenderContext } from '../Chart.svelte';
|
|
44
44
|
import { chartContext } from '../ChartContext.svelte';
|
|
45
45
|
import { transformContext } from '../TransformContext.svelte';
|
|
46
46
|
import { getPixelColor, scaleCanvas, type ComputedStylesOptions } from '../../utils/canvas.js';
|
|
47
47
|
import { getColorStr, rgbColorGenerator } from '../../utils/color.js';
|
|
48
|
-
import { localPoint } from '../../utils/event.js';
|
|
49
48
|
const { width, height, containerWidth, containerHeight, padding } = chartContext();
|
|
50
49
|
|
|
51
50
|
/** The `<canvas>` tag. Useful for bindings. */
|
|
@@ -104,7 +103,7 @@
|
|
|
104
103
|
const componentByColor = new Map<string, ComponentRender>();
|
|
105
104
|
|
|
106
105
|
function getPointerComponent(e: PointerEvent | MouseEvent | TouchEvent) {
|
|
107
|
-
const { x, y } = localPoint(e
|
|
106
|
+
const { x, y } = localPoint(e);
|
|
108
107
|
const color = getPixelColor(hitCanvasContext!, x, y);
|
|
109
108
|
const colorKey = getColorStr(color);
|
|
110
109
|
const component = componentByColor.get(colorKey);
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
import { writable } from 'svelte/store';
|
|
48
48
|
import { bisector, max, min } from 'd3-array';
|
|
49
49
|
import { quadtree as d3Quadtree, type Quadtree } from 'd3-quadtree';
|
|
50
|
-
import { sortFunc } from '@layerstack/utils';
|
|
50
|
+
import { sortFunc, localPoint } from '@layerstack/utils';
|
|
51
51
|
import { cls } from '@layerstack/tailwind';
|
|
52
52
|
|
|
53
53
|
import Svg from './../layout/Svg.svelte';
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
import ChartClipPath from './../ChartClipPath.svelte';
|
|
56
56
|
import Voronoi from './../Voronoi.svelte';
|
|
57
57
|
|
|
58
|
-
import { localPoint } from '../../utils/event.js';
|
|
59
58
|
import { isScaleBand, scaleInvert } from '../../utils/scales.js';
|
|
60
59
|
import { cartesianToPolar } from '../../utils/math.js';
|
|
61
60
|
import { quadtreeRects } from '../../utils/quadtree.js';
|
|
@@ -189,7 +188,7 @@
|
|
|
189
188
|
}
|
|
190
189
|
|
|
191
190
|
const referenceNode = (e.target as Element).closest('.layercake-container')!;
|
|
192
|
-
const point = localPoint(
|
|
191
|
+
const point = localPoint(e, referenceNode);
|
|
193
192
|
const pointerX = point?.x ?? 0;
|
|
194
193
|
const pointerY = point?.y ?? 0;
|
|
195
194
|
|
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.97.
|
|
7
|
+
"version": "0.97.1",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@changesets/cli": "^2.27.12",
|
|
10
10
|
"@mdi/js": "^7.4.47",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"autoprefixer": "^10.4.20",
|
|
42
42
|
"marked": "^15.0.7",
|
|
43
43
|
"mdsvex": "^0.12.3",
|
|
44
|
-
"posthog-js": "^1.217.
|
|
44
|
+
"posthog-js": "^1.217.2",
|
|
45
45
|
"prettier": "^3.5.0",
|
|
46
46
|
"prettier-plugin-svelte": "^3.3.3",
|
|
47
47
|
"prism-svelte": "^0.5.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"rehype-slug": "^6.0.0",
|
|
51
51
|
"shapefile": "^0.6.6",
|
|
52
52
|
"solar-calculator": "^0.3.0",
|
|
53
|
-
"svelte": "5.
|
|
53
|
+
"svelte": "5.20.0",
|
|
54
54
|
"svelte-check": "^4.1.4",
|
|
55
55
|
"svelte-json-tree": "^2.2.0",
|
|
56
56
|
"svelte-ux": "^0.90.1",
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"type": "module",
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@dagrejs/dagre": "^1.1.4",
|
|
71
|
-
"@layerstack/svelte-actions": "^0.0.
|
|
72
|
-
"@layerstack/svelte-stores": "^0.0.
|
|
73
|
-
"@layerstack/tailwind": "^0.0.
|
|
74
|
-
"@layerstack/utils": "^0.0
|
|
71
|
+
"@layerstack/svelte-actions": "^0.0.12",
|
|
72
|
+
"@layerstack/svelte-stores": "^0.0.11",
|
|
73
|
+
"@layerstack/tailwind": "^0.0.12",
|
|
74
|
+
"@layerstack/utils": "^0.1.0",
|
|
75
75
|
"d3-array": "^3.2.4",
|
|
76
76
|
"d3-color": "^3.1.0",
|
|
77
77
|
"d3-delaunay": "^6.0.4",
|
package/dist/utils/event.d.ts
DELETED
package/dist/utils/event.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isSVGElement, isSVGGraphicsElement, isSVGSVGElement, isTouchEvent, } from '@layerstack/utils';
|
|
2
|
-
// See: https://github.com/airbnb/visx/blob/master/packages/visx-event/src/localPointGeneric.ts
|
|
3
|
-
// TODO: Matches event.layerX/Y, but are deprecated (https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/layerX).
|
|
4
|
-
// Similar and could be replaced by event.offsetX/Y (but not identical)
|
|
5
|
-
export function localPoint(node, event) {
|
|
6
|
-
if (!node || !event)
|
|
7
|
-
return null;
|
|
8
|
-
const coords = getPointFromEvent(event);
|
|
9
|
-
// find top-most SVG
|
|
10
|
-
const svg = isSVGElement(node) ? node.ownerSVGElement : node;
|
|
11
|
-
const screenCTM = isSVGGraphicsElement(svg) ? svg.getScreenCTM() : null;
|
|
12
|
-
if (isSVGSVGElement(svg) && screenCTM) {
|
|
13
|
-
let point = svg.createSVGPoint();
|
|
14
|
-
point.x = coords.x;
|
|
15
|
-
point.y = coords.y;
|
|
16
|
-
point = point.matrixTransform(screenCTM.inverse());
|
|
17
|
-
return {
|
|
18
|
-
x: point.x,
|
|
19
|
-
y: point.y,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// fall back to bounding box
|
|
23
|
-
const rect = node.getBoundingClientRect();
|
|
24
|
-
return {
|
|
25
|
-
x: coords.x - rect.left - node.clientLeft,
|
|
26
|
-
y: coords.y - rect.top - node.clientTop,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function getPointFromEvent(event) {
|
|
30
|
-
if (!event)
|
|
31
|
-
return { x: 0, y: 0 };
|
|
32
|
-
if (isTouchEvent(event)) {
|
|
33
|
-
return event.changedTouches.length > 0
|
|
34
|
-
? {
|
|
35
|
-
x: event.changedTouches[0].clientX,
|
|
36
|
-
y: event.changedTouches[0].clientY,
|
|
37
|
-
}
|
|
38
|
-
: { x: 0, y: 0 };
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
x: event.clientX,
|
|
42
|
-
y: event.clientY,
|
|
43
|
-
};
|
|
44
|
-
}
|