layerchart 2.0.0-next.16 → 2.0.0-next.17
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/Arc.svelte +2 -2
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Blur.svelte.d.ts +2 -5
- package/dist/components/Connector.svelte +2 -2
- package/dist/components/Connector.svelte.d.ts +1 -1
- package/dist/components/Ellipse.svelte +187 -0
- package/dist/components/Ellipse.svelte.d.ts +64 -0
- package/dist/components/ForceSimulation.svelte +68 -22
- package/dist/components/ForceSimulation.svelte.d.ts +24 -11
- package/dist/components/GeoPath.svelte +5 -4
- package/dist/components/GeoPoint.svelte +1 -2
- package/dist/components/GeoSpline.svelte +4 -4
- package/dist/components/GeoSpline.svelte.d.ts +1 -1
- package/dist/components/MonthPath.svelte +11 -8
- package/dist/components/MonthPath.svelte.d.ts +4 -3
- package/dist/components/Polygon.svelte +285 -0
- package/dist/components/Polygon.svelte.d.ts +115 -0
- package/dist/components/Spline.svelte +29 -17
- package/dist/components/Spline.svelte.d.ts +12 -4
- package/dist/components/Treemap.svelte +63 -26
- package/dist/components/Treemap.svelte.d.ts +11 -11
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/layout/Layer.svelte +6 -4
- package/dist/components/layout/Layer.svelte.d.ts +6 -4
- package/dist/components/tooltip/TooltipList.svelte +1 -1
- package/dist/utils/canvas.js +15 -0
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.js +30 -0
- package/dist/utils/shape.d.ts +43 -0
- package/dist/utils/shape.js +59 -0
- package/dist/utils/treemap.d.ts +1 -1
- package/package.json +1 -1
|
@@ -401,13 +401,13 @@
|
|
|
401
401
|
<Spline
|
|
402
402
|
pathData={trackArc()}
|
|
403
403
|
stroke="none"
|
|
404
|
-
bind:
|
|
404
|
+
bind:pathRef={trackRef}
|
|
405
405
|
{...extractLayerProps(track, 'arc-track')}
|
|
406
406
|
/>
|
|
407
407
|
{/if}
|
|
408
408
|
|
|
409
409
|
<Spline
|
|
410
|
-
bind:
|
|
410
|
+
bind:pathRef={ref}
|
|
411
411
|
pathData={arc()}
|
|
412
412
|
transform="translate({xOffset}, {yOffset})"
|
|
413
413
|
{fill}
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The default children snippet which provides
|
|
17
|
-
* the id
|
|
17
|
+
* the id for the filter.
|
|
18
18
|
*/
|
|
19
|
-
children?: Snippet
|
|
19
|
+
children?: Snippet;
|
|
20
20
|
};
|
|
21
21
|
</script>
|
|
22
22
|
|
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
|
|
43
43
|
{#if children}
|
|
44
44
|
<g filter="url(#{id})" class={layerClass('blur-g')}>
|
|
45
|
-
{@render children(
|
|
45
|
+
{@render children()}
|
|
46
46
|
</g>
|
|
47
47
|
{/if}
|
|
48
|
+
{:else if children}
|
|
49
|
+
{@render children()}
|
|
48
50
|
{/if}
|
|
@@ -11,12 +11,9 @@ export type BlurProps = {
|
|
|
11
11
|
stdDeviation?: number;
|
|
12
12
|
/**
|
|
13
13
|
* The default children snippet which provides
|
|
14
|
-
* the id
|
|
14
|
+
* the id for the filter.
|
|
15
15
|
*/
|
|
16
|
-
children?: Snippet
|
|
17
|
-
id: string;
|
|
18
|
-
url: string;
|
|
19
|
-
}]>;
|
|
16
|
+
children?: Snippet;
|
|
20
17
|
};
|
|
21
18
|
import type { Snippet } from 'svelte';
|
|
22
19
|
declare const Blur: import("svelte").Component<BlurProps, {}, "">;
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
type = 'rounded',
|
|
83
83
|
radius = 20,
|
|
84
84
|
curve = curveLinear,
|
|
85
|
-
|
|
85
|
+
pathRef = $bindable(),
|
|
86
86
|
pathData: pathDataProp,
|
|
87
87
|
marker,
|
|
88
88
|
markerStart,
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
|
|
138
138
|
<Spline
|
|
139
139
|
pathData={motionPath.current}
|
|
140
|
-
bind:
|
|
140
|
+
bind:pathRef
|
|
141
141
|
marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
|
|
142
142
|
marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
|
|
143
143
|
marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
|
|
@@ -46,6 +46,6 @@ import { type CurveFactory } from 'd3-shape';
|
|
|
46
46
|
import { type ConnectorCoords, type ConnectorSweep, type ConnectorType } from '../utils/connectorUtils.js';
|
|
47
47
|
import { type SplineProps, type SplinePropsWithoutHTML } from './Spline.svelte';
|
|
48
48
|
import type { Without } from '../utils/types.js';
|
|
49
|
-
declare const Connector: import("svelte").Component<ConnectorProps, {}, "
|
|
49
|
+
declare const Connector: import("svelte").Component<ConnectorProps, {}, "pathRef">;
|
|
50
50
|
type Connector = ReturnType<typeof Connector>;
|
|
51
51
|
export default Connector;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
|
+
|
|
4
|
+
export type EllipsePropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* The center x position of the ellipse.
|
|
7
|
+
*
|
|
8
|
+
* @default 0
|
|
9
|
+
*/
|
|
10
|
+
cx?: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The initial center x position of the ellipse.
|
|
14
|
+
*
|
|
15
|
+
* @default cx
|
|
16
|
+
*/
|
|
17
|
+
initialCx?: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The center y position of the ellipse.
|
|
21
|
+
*
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
cy?: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The initial center y position of the ellipse.
|
|
28
|
+
*
|
|
29
|
+
* @default cy
|
|
30
|
+
*/
|
|
31
|
+
initialCy?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The radius of the ellipse on the x-axis.
|
|
35
|
+
*
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
rx?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The initial radius of the ellipse on the x-axis.
|
|
42
|
+
*
|
|
43
|
+
* @default rx
|
|
44
|
+
*/
|
|
45
|
+
initialRx?: number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The radius of the ellipse on the y-axis.
|
|
49
|
+
*
|
|
50
|
+
* @default 1
|
|
51
|
+
*/
|
|
52
|
+
ry?: number;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The initial radius of the ellipse on the y-axis.
|
|
56
|
+
*
|
|
57
|
+
* @default ry
|
|
58
|
+
*/
|
|
59
|
+
initialRy?: number;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A bindable reference to the `<ellipse>` element
|
|
63
|
+
*
|
|
64
|
+
* @bindable
|
|
65
|
+
*/
|
|
66
|
+
ref?: SVGEllipseElement;
|
|
67
|
+
|
|
68
|
+
motion?: MotionProp;
|
|
69
|
+
} & CommonStyleProps;
|
|
70
|
+
|
|
71
|
+
export type EllipseProps = EllipsePropsWithoutHTML &
|
|
72
|
+
Without<SVGAttributes<Element>, EllipsePropsWithoutHTML>;
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<script lang="ts">
|
|
76
|
+
import { cls } from '@layerstack/tailwind';
|
|
77
|
+
import { merge } from 'lodash-es';
|
|
78
|
+
|
|
79
|
+
import { getRenderContext } from './Chart.svelte';
|
|
80
|
+
import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
|
|
81
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
82
|
+
import { renderEllipse, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
83
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
84
|
+
import { createKey } from '../utils/key.svelte.js';
|
|
85
|
+
import { layerClass } from '../utils/attributes.js';
|
|
86
|
+
|
|
87
|
+
let {
|
|
88
|
+
cx = 0,
|
|
89
|
+
initialCx: initialCxProp,
|
|
90
|
+
cy = 0,
|
|
91
|
+
initialCy: initialCyProp,
|
|
92
|
+
rx = 1,
|
|
93
|
+
initialRx: initialRxProp,
|
|
94
|
+
ry = 1,
|
|
95
|
+
initialRy: initialRyProp,
|
|
96
|
+
motion,
|
|
97
|
+
fill,
|
|
98
|
+
fillOpacity,
|
|
99
|
+
stroke,
|
|
100
|
+
strokeWidth,
|
|
101
|
+
opacity,
|
|
102
|
+
class: className,
|
|
103
|
+
ref: refProp = $bindable(),
|
|
104
|
+
...restProps
|
|
105
|
+
}: EllipseProps = $props();
|
|
106
|
+
|
|
107
|
+
let ref = $state<SVGEllipseElement>();
|
|
108
|
+
|
|
109
|
+
$effect.pre(() => {
|
|
110
|
+
refProp = ref;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const initialCx = initialCxProp ?? cx;
|
|
114
|
+
const initialCy = initialCyProp ?? cy;
|
|
115
|
+
const initialRx = initialRxProp ?? rx;
|
|
116
|
+
const initialRy = initialRyProp ?? ry;
|
|
117
|
+
|
|
118
|
+
const renderCtx = getRenderContext();
|
|
119
|
+
|
|
120
|
+
const motionCx = createMotion(initialCx, () => cx, motion);
|
|
121
|
+
const motionCy = createMotion(initialCy, () => cy, motion);
|
|
122
|
+
const motionRx = createMotion(initialRx, () => rx, motion);
|
|
123
|
+
const motionRy = createMotion(initialRy, () => ry, motion);
|
|
124
|
+
|
|
125
|
+
function render(
|
|
126
|
+
ctx: CanvasRenderingContext2D,
|
|
127
|
+
styleOverrides: ComputedStylesOptions | undefined
|
|
128
|
+
) {
|
|
129
|
+
renderEllipse(
|
|
130
|
+
ctx,
|
|
131
|
+
{ cx: motionCx.current, cy: motionCy.current, rx: motionRx.current, ry: motionRy.current },
|
|
132
|
+
styleOverrides
|
|
133
|
+
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
134
|
+
: {
|
|
135
|
+
styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
|
|
136
|
+
classes: className,
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
142
|
+
const fillKey = createKey(() => fill);
|
|
143
|
+
const strokeKey = createKey(() => stroke);
|
|
144
|
+
|
|
145
|
+
if (renderCtx === 'canvas') {
|
|
146
|
+
registerCanvasComponent({
|
|
147
|
+
name: 'Ellipse',
|
|
148
|
+
render,
|
|
149
|
+
events: {
|
|
150
|
+
click: restProps.onclick,
|
|
151
|
+
pointerdown: restProps.onpointerdown,
|
|
152
|
+
pointerenter: restProps.onpointerenter,
|
|
153
|
+
pointermove: restProps.onpointermove,
|
|
154
|
+
pointerleave: restProps.onpointerleave,
|
|
155
|
+
},
|
|
156
|
+
deps: () => [
|
|
157
|
+
motionCx.current,
|
|
158
|
+
motionCy.current,
|
|
159
|
+
motionRx.current,
|
|
160
|
+
motionRy.current,
|
|
161
|
+
fillKey.current,
|
|
162
|
+
fillOpacity,
|
|
163
|
+
strokeKey.current,
|
|
164
|
+
strokeWidth,
|
|
165
|
+
opacity,
|
|
166
|
+
className,
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
</script>
|
|
171
|
+
|
|
172
|
+
{#if renderCtx === 'svg'}
|
|
173
|
+
<ellipse
|
|
174
|
+
bind:this={ref}
|
|
175
|
+
cx={motionCx.current}
|
|
176
|
+
cy={motionCy.current}
|
|
177
|
+
rx={motionRx.current}
|
|
178
|
+
ry={motionRy.current}
|
|
179
|
+
{fill}
|
|
180
|
+
fill-opacity={fillOpacity}
|
|
181
|
+
{stroke}
|
|
182
|
+
stroke-width={strokeWidth}
|
|
183
|
+
{opacity}
|
|
184
|
+
class={cls(layerClass('ellipse'), fill == null && 'fill-surface-content', className)}
|
|
185
|
+
{...restProps}
|
|
186
|
+
/>
|
|
187
|
+
{/if}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
2
|
+
export type EllipsePropsWithoutHTML = {
|
|
3
|
+
/**
|
|
4
|
+
* The center x position of the ellipse.
|
|
5
|
+
*
|
|
6
|
+
* @default 0
|
|
7
|
+
*/
|
|
8
|
+
cx?: number;
|
|
9
|
+
/**
|
|
10
|
+
* The initial center x position of the ellipse.
|
|
11
|
+
*
|
|
12
|
+
* @default cx
|
|
13
|
+
*/
|
|
14
|
+
initialCx?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The center y position of the ellipse.
|
|
17
|
+
*
|
|
18
|
+
* @default 0
|
|
19
|
+
*/
|
|
20
|
+
cy?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The initial center y position of the ellipse.
|
|
23
|
+
*
|
|
24
|
+
* @default cy
|
|
25
|
+
*/
|
|
26
|
+
initialCy?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The radius of the ellipse on the x-axis.
|
|
29
|
+
*
|
|
30
|
+
* @default 1
|
|
31
|
+
*/
|
|
32
|
+
rx?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The initial radius of the ellipse on the x-axis.
|
|
35
|
+
*
|
|
36
|
+
* @default rx
|
|
37
|
+
*/
|
|
38
|
+
initialRx?: number;
|
|
39
|
+
/**
|
|
40
|
+
* The radius of the ellipse on the y-axis.
|
|
41
|
+
*
|
|
42
|
+
* @default 1
|
|
43
|
+
*/
|
|
44
|
+
ry?: number;
|
|
45
|
+
/**
|
|
46
|
+
* The initial radius of the ellipse on the y-axis.
|
|
47
|
+
*
|
|
48
|
+
* @default ry
|
|
49
|
+
*/
|
|
50
|
+
initialRy?: number;
|
|
51
|
+
/**
|
|
52
|
+
* A bindable reference to the `<ellipse>` element
|
|
53
|
+
*
|
|
54
|
+
* @bindable
|
|
55
|
+
*/
|
|
56
|
+
ref?: SVGEllipseElement;
|
|
57
|
+
motion?: MotionProp;
|
|
58
|
+
} & CommonStyleProps;
|
|
59
|
+
export type EllipseProps = EllipsePropsWithoutHTML & Without<SVGAttributes<Element>, EllipsePropsWithoutHTML>;
|
|
60
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
61
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
62
|
+
declare const Ellipse: import("svelte").Component<EllipseProps, {}, "ref">;
|
|
63
|
+
type Ellipse = ReturnType<typeof Ellipse>;
|
|
64
|
+
export default Ellipse;
|
|
@@ -18,12 +18,41 @@
|
|
|
18
18
|
links?: TLink[];
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export type LinkPosition =
|
|
21
|
+
export type LinkPosition = {
|
|
22
22
|
x1: number;
|
|
23
23
|
y1: number;
|
|
24
24
|
x2: number;
|
|
25
25
|
y2: number;
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type OnStartEvent<
|
|
29
|
+
NodeDatum extends SimulationNodeDatum,
|
|
30
|
+
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
|
|
31
|
+
> = {
|
|
32
|
+
alpha: number;
|
|
33
|
+
alphaTarget: number;
|
|
34
|
+
simulation: SimulationFor<NodeDatum, LinkDatum>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type OnTickEvent<
|
|
38
|
+
NodeDatum extends SimulationNodeDatum,
|
|
39
|
+
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
|
|
40
|
+
> = {
|
|
41
|
+
alpha: number;
|
|
42
|
+
alphaTarget: number;
|
|
43
|
+
nodes: NodeDatumFor<NodeDatum>[];
|
|
44
|
+
links: LinkDatumFor<NodeDatum, LinkDatum>[];
|
|
45
|
+
simulation: SimulationFor<NodeDatum, LinkDatum>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type OnEndEvent<
|
|
49
|
+
NodeDatum extends SimulationNodeDatum,
|
|
50
|
+
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
|
|
51
|
+
> = {
|
|
52
|
+
alpha: number;
|
|
53
|
+
alphaTarget: number;
|
|
54
|
+
simulation: SimulationFor<NodeDatum, LinkDatum>;
|
|
55
|
+
};
|
|
27
56
|
|
|
28
57
|
/**
|
|
29
58
|
* Default initial alpha value of the simulation.
|
|
@@ -52,11 +81,10 @@
|
|
|
52
81
|
*/
|
|
53
82
|
export const DEFAULT_VELOCITY_DECAY: number = 0.4;
|
|
54
83
|
|
|
55
|
-
type NodeDatumFor<NodeDatum> =
|
|
84
|
+
type NodeDatumFor<NodeDatum> = NodeDatum & SimulationNodeDatum;
|
|
56
85
|
|
|
57
|
-
type LinkDatumFor<NodeDatum, LinkDatum> =
|
|
58
|
-
|
|
59
|
-
>;
|
|
86
|
+
type LinkDatumFor<NodeDatum, LinkDatum> = LinkDatum &
|
|
87
|
+
SimulationLinkDatum<NodeDatumFor<NodeDatum>>;
|
|
60
88
|
|
|
61
89
|
type SimulationFor<NodeDatum, LinkDatum> = Simulation<
|
|
62
90
|
NodeDatumFor<NodeDatum>,
|
|
@@ -129,17 +157,17 @@
|
|
|
129
157
|
/**
|
|
130
158
|
* Callback function triggered when simulation starts
|
|
131
159
|
*/
|
|
132
|
-
onStart?: () => void;
|
|
160
|
+
onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
133
161
|
|
|
134
162
|
/**
|
|
135
163
|
* Callback function triggered on each simulation tick
|
|
136
164
|
*/
|
|
137
|
-
onTick?: (e:
|
|
165
|
+
onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
138
166
|
|
|
139
167
|
/**
|
|
140
168
|
* Callback function triggered when simulation ends
|
|
141
169
|
*/
|
|
142
|
-
onEnd?: () => void;
|
|
170
|
+
onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
143
171
|
|
|
144
172
|
children?: Snippet<
|
|
145
173
|
[
|
|
@@ -160,7 +188,6 @@
|
|
|
160
188
|
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,"
|
|
161
189
|
>
|
|
162
190
|
import { watch } from 'runed';
|
|
163
|
-
import type { Prettify } from '@layerstack/utils';
|
|
164
191
|
|
|
165
192
|
let {
|
|
166
193
|
forces,
|
|
@@ -172,9 +199,9 @@
|
|
|
172
199
|
velocityDecay = DEFAULT_VELOCITY_DECAY,
|
|
173
200
|
stopped = false,
|
|
174
201
|
static: staticProp,
|
|
175
|
-
onStart: onStartProp
|
|
176
|
-
onTick: onTickProp
|
|
177
|
-
onEnd: onEndProp
|
|
202
|
+
onStart: onStartProp,
|
|
203
|
+
onTick: onTickProp,
|
|
204
|
+
onEnd: onEndProp,
|
|
178
205
|
children,
|
|
179
206
|
cloneNodes = false,
|
|
180
207
|
}: ForceSimulationProps<NodeDatum, LinkDatum> = $props();
|
|
@@ -258,12 +285,8 @@
|
|
|
258
285
|
// pass it to the internal d3 simulation object:
|
|
259
286
|
pushAlphaToSimulation(alpha);
|
|
260
287
|
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
// otherwise our simulation will never terminate:
|
|
264
|
-
if (simulation.alpha() >= simulation.alphaMin()) {
|
|
265
|
-
runOrResumeSimulation();
|
|
266
|
-
}
|
|
288
|
+
// Then we attempt to resume the simulation:
|
|
289
|
+
runOrResumeSimulation();
|
|
267
290
|
}
|
|
268
291
|
);
|
|
269
292
|
|
|
@@ -404,6 +427,13 @@
|
|
|
404
427
|
return;
|
|
405
428
|
}
|
|
406
429
|
|
|
430
|
+
if (simulation.alpha() < simulation.alphaMin()) {
|
|
431
|
+
// Only resume the simulation as long as `alpha`
|
|
432
|
+
// is above the cut-off threshold of `alphaMin`,
|
|
433
|
+
// otherwise our simulation will never terminate:
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
407
437
|
onStart();
|
|
408
438
|
simulation.restart();
|
|
409
439
|
|
|
@@ -431,7 +461,12 @@
|
|
|
431
461
|
}
|
|
432
462
|
|
|
433
463
|
paused = false;
|
|
434
|
-
|
|
464
|
+
|
|
465
|
+
onStartProp?.({
|
|
466
|
+
alpha,
|
|
467
|
+
alphaTarget,
|
|
468
|
+
simulation,
|
|
469
|
+
});
|
|
435
470
|
}
|
|
436
471
|
|
|
437
472
|
function onTick() {
|
|
@@ -439,7 +474,13 @@
|
|
|
439
474
|
pullAlphaFromSimulation();
|
|
440
475
|
updateLinkPositions();
|
|
441
476
|
|
|
442
|
-
onTickProp({
|
|
477
|
+
onTickProp?.({
|
|
478
|
+
alpha,
|
|
479
|
+
alphaTarget,
|
|
480
|
+
nodes: simulatedNodes,
|
|
481
|
+
links: simulatedLinks,
|
|
482
|
+
simulation,
|
|
483
|
+
});
|
|
443
484
|
}
|
|
444
485
|
|
|
445
486
|
function onEnd() {
|
|
@@ -449,7 +490,12 @@
|
|
|
449
490
|
}
|
|
450
491
|
|
|
451
492
|
paused = true;
|
|
452
|
-
|
|
493
|
+
|
|
494
|
+
onEndProp?.({
|
|
495
|
+
alpha,
|
|
496
|
+
alphaTarget,
|
|
497
|
+
simulation,
|
|
498
|
+
});
|
|
453
499
|
}
|
|
454
500
|
|
|
455
501
|
$effect(() => {
|
|
@@ -5,12 +5,29 @@ export type Data<TNode = any, TLink = any> = {
|
|
|
5
5
|
nodes: TNode[];
|
|
6
6
|
links?: TLink[];
|
|
7
7
|
};
|
|
8
|
-
export type LinkPosition =
|
|
8
|
+
export type LinkPosition = {
|
|
9
9
|
x1: number;
|
|
10
10
|
y1: number;
|
|
11
11
|
x2: number;
|
|
12
12
|
y2: number;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
export type OnStartEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
15
|
+
alpha: number;
|
|
16
|
+
alphaTarget: number;
|
|
17
|
+
simulation: SimulationFor<NodeDatum, LinkDatum>;
|
|
18
|
+
};
|
|
19
|
+
export type OnTickEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
20
|
+
alpha: number;
|
|
21
|
+
alphaTarget: number;
|
|
22
|
+
nodes: NodeDatumFor<NodeDatum>[];
|
|
23
|
+
links: LinkDatumFor<NodeDatum, LinkDatum>[];
|
|
24
|
+
simulation: SimulationFor<NodeDatum, LinkDatum>;
|
|
25
|
+
};
|
|
26
|
+
export type OnEndEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
27
|
+
alpha: number;
|
|
28
|
+
alphaTarget: number;
|
|
29
|
+
simulation: SimulationFor<NodeDatum, LinkDatum>;
|
|
30
|
+
};
|
|
14
31
|
/**
|
|
15
32
|
* Default initial alpha value of the simulation.
|
|
16
33
|
*/
|
|
@@ -33,8 +50,8 @@ export declare const DEFAULT_ALPHA_MIN: number;
|
|
|
33
50
|
* Default velocity decay factor applied to nodes each tick.
|
|
34
51
|
*/
|
|
35
52
|
export declare const DEFAULT_VELOCITY_DECAY: number;
|
|
36
|
-
type NodeDatumFor<NodeDatum> =
|
|
37
|
-
type LinkDatumFor<NodeDatum, LinkDatum> =
|
|
53
|
+
type NodeDatumFor<NodeDatum> = NodeDatum & SimulationNodeDatum;
|
|
54
|
+
type LinkDatumFor<NodeDatum, LinkDatum> = LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>;
|
|
38
55
|
type SimulationFor<NodeDatum, LinkDatum> = Simulation<NodeDatumFor<NodeDatum>, LinkDatumFor<NodeDatum, LinkDatum>>;
|
|
39
56
|
export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
40
57
|
/**
|
|
@@ -89,18 +106,15 @@ export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatu
|
|
|
89
106
|
/**
|
|
90
107
|
* Callback function triggered when simulation starts
|
|
91
108
|
*/
|
|
92
|
-
onStart?: () => void;
|
|
109
|
+
onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
93
110
|
/**
|
|
94
111
|
* Callback function triggered on each simulation tick
|
|
95
112
|
*/
|
|
96
|
-
onTick?: (e:
|
|
97
|
-
alpha: number;
|
|
98
|
-
alphaTarget: number;
|
|
99
|
-
}) => void;
|
|
113
|
+
onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
100
114
|
/**
|
|
101
115
|
* Callback function triggered when simulation ends
|
|
102
116
|
*/
|
|
103
|
-
onEnd?: () => void;
|
|
117
|
+
onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
104
118
|
children?: Snippet<[
|
|
105
119
|
{
|
|
106
120
|
nodes: NodeDatumFor<NodeDatum>[];
|
|
@@ -110,7 +124,6 @@ export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatu
|
|
|
110
124
|
}
|
|
111
125
|
]>;
|
|
112
126
|
};
|
|
113
|
-
import type { Prettify } from '@layerstack/utils';
|
|
114
127
|
declare class __sveltets_Render<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
|
|
115
128
|
props(): ForceSimulationProps<NodeDatum, LinkDatum>;
|
|
116
129
|
events(): {};
|
|
@@ -157,10 +157,11 @@
|
|
|
157
157
|
name: 'GeoPath',
|
|
158
158
|
render,
|
|
159
159
|
events: {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
// Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
|
|
161
|
+
click: onclick ? _onClick : undefined,
|
|
162
|
+
pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
|
|
163
|
+
pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
|
|
164
|
+
pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
|
|
164
165
|
pointerdown: restProps.onpointerdown,
|
|
165
166
|
touchmove: restProps.ontouchmove,
|
|
166
167
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import
|
|
4
|
-
import Circle, { type CircleProps, type CirclePropsWithoutHTML } from './Circle.svelte';
|
|
3
|
+
import Circle, { type CircleProps } from './Circle.svelte';
|
|
5
4
|
import type { Without } from '../utils/types.js';
|
|
6
5
|
|
|
7
6
|
export type GeoPointPropsWithoutHTML = {
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
link,
|
|
43
43
|
loft = 1.0,
|
|
44
44
|
curve = curveNatural,
|
|
45
|
-
|
|
45
|
+
pathRef: pathRefProp = $bindable(),
|
|
46
46
|
...restProps
|
|
47
47
|
}: GeoSplineProps = $props();
|
|
48
48
|
|
|
49
|
-
let
|
|
49
|
+
let pathRef = $state<SVGPathElement>();
|
|
50
50
|
$effect.pre(() => {
|
|
51
|
-
|
|
51
|
+
pathRefProp = pathRef;
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
const geoCtx = getGeoContext();
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
</script>
|
|
77
77
|
|
|
78
78
|
<Spline
|
|
79
|
-
bind:
|
|
79
|
+
bind:pathRef
|
|
80
80
|
data={[source, middle, target]}
|
|
81
81
|
x={(d) => d[0]}
|
|
82
82
|
y={(d) => d[1]}
|
|
@@ -27,6 +27,6 @@ export type GeoSplinePropsWithoutHTML = {
|
|
|
27
27
|
curve?: CurveFactory | CurveFactoryLineOnly;
|
|
28
28
|
};
|
|
29
29
|
export type GeoSplineProps = GeoSplinePropsWithoutHTML & Without<SplineProps, GeoSplinePropsWithoutHTML>;
|
|
30
|
-
declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "
|
|
30
|
+
declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "pathRef">;
|
|
31
31
|
type GeoSpline = ReturnType<typeof GeoSpline>;
|
|
32
32
|
export default GeoSpline;
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @bindable
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
pathRef?: SVGPathElement;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
export type MonthPathProps = MonthPathPropsWithoutHTML &
|
|
27
|
-
|
|
27
|
+
// we omit the spline props to avoid conflicts with attribute names since we are
|
|
28
|
+
// passing them through to `<Spline />`
|
|
29
|
+
Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML & SplinePropsWithoutHTML>;
|
|
28
30
|
</script>
|
|
29
31
|
|
|
30
32
|
<script lang="ts">
|
|
@@ -32,18 +34,19 @@
|
|
|
32
34
|
import { endOfMonth } from 'date-fns';
|
|
33
35
|
import { cls } from '@layerstack/tailwind';
|
|
34
36
|
import { layerClass } from '../utils/attributes.js';
|
|
37
|
+
import Spline, { type SplinePropsWithoutHTML } from './Spline.svelte';
|
|
35
38
|
|
|
36
39
|
let {
|
|
37
40
|
date,
|
|
38
41
|
cellSize: cellSizeProp,
|
|
39
|
-
|
|
42
|
+
pathRef: pathRefProp = $bindable(),
|
|
40
43
|
class: className,
|
|
41
44
|
...restProps
|
|
42
45
|
}: MonthPathProps = $props();
|
|
43
46
|
|
|
44
|
-
let
|
|
47
|
+
let pathRef = $state<SVGPathElement>();
|
|
45
48
|
$effect.pre(() => {
|
|
46
|
-
|
|
49
|
+
pathRefProp = pathRef;
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
const cellSize = $derived(
|
|
@@ -68,9 +71,9 @@
|
|
|
68
71
|
`);
|
|
69
72
|
</script>
|
|
70
73
|
|
|
71
|
-
<
|
|
72
|
-
bind:
|
|
73
|
-
|
|
74
|
+
<Spline
|
|
75
|
+
bind:pathRef
|
|
76
|
+
{pathData}
|
|
74
77
|
fill="none"
|
|
75
78
|
class={cls(layerClass('month-path'), 'stroke-surface-content/20', className)}
|
|
76
79
|
{...restProps}
|