layerchart 2.0.0-next.3 → 2.0.0-next.30

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.
Files changed (108) hide show
  1. package/dist/components/AnnotationPoint.svelte +16 -9
  2. package/dist/components/AnnotationRange.svelte +3 -3
  3. package/dist/components/Arc.svelte +2 -2
  4. package/dist/components/Axis.svelte +63 -14
  5. package/dist/components/Axis.svelte.d.ts +12 -2
  6. package/dist/components/Blur.svelte +5 -3
  7. package/dist/components/Blur.svelte.d.ts +2 -5
  8. package/dist/components/BrushContext.svelte +1 -1
  9. package/dist/components/Calendar.svelte +10 -6
  10. package/dist/components/Calendar.svelte.d.ts +2 -1
  11. package/dist/components/Chart.svelte +2 -2
  12. package/dist/components/Connector.svelte +2 -2
  13. package/dist/components/Connector.svelte.d.ts +1 -1
  14. package/dist/components/Ellipse.svelte +187 -0
  15. package/dist/components/Ellipse.svelte.d.ts +64 -0
  16. package/dist/components/ForceSimulation.svelte +168 -50
  17. package/dist/components/ForceSimulation.svelte.d.ts +80 -21
  18. package/dist/components/GeoPath.svelte +12 -5
  19. package/dist/components/GeoPoint.svelte +1 -2
  20. package/dist/components/GeoSpline.svelte +4 -4
  21. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  22. package/dist/components/Group.svelte +2 -2
  23. package/dist/components/Highlight.svelte +2 -2
  24. package/dist/components/Hull.svelte +1 -1
  25. package/dist/components/Labels.svelte +3 -2
  26. package/dist/components/Labels.svelte.d.ts +2 -2
  27. package/dist/components/Legend.svelte +19 -12
  28. package/dist/components/Legend.svelte.d.ts +5 -5
  29. package/dist/components/MonthPath.svelte +14 -11
  30. package/dist/components/MonthPath.svelte.d.ts +4 -3
  31. package/dist/components/Polygon.svelte +285 -0
  32. package/dist/components/Polygon.svelte.d.ts +115 -0
  33. package/dist/components/RadialGradient.svelte +1 -3
  34. package/dist/components/Spline.svelte +30 -18
  35. package/dist/components/Spline.svelte.d.ts +12 -4
  36. package/dist/components/Text.svelte +62 -60
  37. package/dist/components/Text.svelte.d.ts +6 -0
  38. package/dist/components/TransformControls.svelte +16 -20
  39. package/dist/components/Treemap.svelte +63 -26
  40. package/dist/components/Treemap.svelte.d.ts +11 -11
  41. package/dist/components/Voronoi.svelte +51 -33
  42. package/dist/components/Voronoi.svelte.d.ts +3 -1
  43. package/dist/components/charts/ArcChart.svelte +5 -3
  44. package/dist/components/charts/AreaChart.svelte +11 -11
  45. package/dist/components/charts/BarChart.svelte +64 -53
  46. package/dist/components/charts/DefaultTooltip.svelte +1 -1
  47. package/dist/components/charts/LineChart.svelte +10 -6
  48. package/dist/components/charts/PieChart.svelte +5 -3
  49. package/dist/components/charts/ScatterChart.svelte +2 -3
  50. package/dist/components/charts/utils.svelte.d.ts +2 -2
  51. package/dist/components/charts/utils.svelte.js +5 -1
  52. package/dist/components/index.d.ts +4 -0
  53. package/dist/components/index.js +5 -1
  54. package/dist/components/layout/Canvas.svelte +67 -49
  55. package/dist/components/layout/Canvas.svelte.d.ts +6 -0
  56. package/dist/components/layout/Layer.svelte +6 -4
  57. package/dist/components/layout/Layer.svelte.d.ts +6 -4
  58. package/dist/components/tooltip/Tooltip.svelte +14 -7
  59. package/dist/components/tooltip/TooltipContext.svelte +78 -34
  60. package/dist/components/tooltip/TooltipContext.svelte.d.ts +3 -3
  61. package/dist/components/tooltip/TooltipHeader.svelte +5 -4
  62. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
  63. package/dist/components/tooltip/TooltipItem.svelte +5 -4
  64. package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
  65. package/dist/components/tooltip/TooltipList.svelte +1 -1
  66. package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
  67. package/dist/docs/Blockquote.svelte +6 -4
  68. package/dist/docs/Blockquote.svelte.d.ts +4 -19
  69. package/dist/docs/Code.svelte +20 -12
  70. package/dist/docs/Code.svelte.d.ts +9 -23
  71. package/dist/docs/Header1.svelte +4 -2
  72. package/dist/docs/Header1.svelte.d.ts +4 -28
  73. package/dist/docs/Json.svelte +11 -3
  74. package/dist/docs/Json.svelte.d.ts +9 -21
  75. package/dist/docs/Layout.svelte +10 -7
  76. package/dist/docs/Layout.svelte.d.ts +4 -19
  77. package/dist/docs/Link.svelte +7 -3
  78. package/dist/docs/Link.svelte.d.ts +4 -38
  79. package/dist/docs/Preview.svelte +6 -3
  80. package/dist/docs/TilesetField.svelte +20 -19
  81. package/dist/docs/TilesetField.svelte.d.ts +5 -22
  82. package/dist/docs/ViewSourceButton.svelte +9 -6
  83. package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
  84. package/dist/utils/arcText.svelte.js +4 -4
  85. package/dist/utils/array.d.ts +11 -0
  86. package/dist/utils/array.js +23 -0
  87. package/dist/utils/array.test.d.ts +1 -0
  88. package/dist/utils/array.test.js +200 -0
  89. package/dist/utils/canvas.d.ts +77 -0
  90. package/dist/utils/canvas.js +105 -41
  91. package/dist/utils/genData.d.ts +14 -0
  92. package/dist/utils/genData.js +24 -6
  93. package/dist/utils/index.d.ts +1 -0
  94. package/dist/utils/index.js +1 -0
  95. package/dist/utils/path.d.ts +10 -0
  96. package/dist/utils/path.js +30 -0
  97. package/dist/utils/scales.svelte.d.ts +3 -2
  98. package/dist/utils/scales.svelte.js +7 -3
  99. package/dist/utils/shape.d.ts +43 -0
  100. package/dist/utils/shape.js +59 -0
  101. package/dist/utils/string.d.ts +49 -0
  102. package/dist/utils/string.js +4 -2
  103. package/dist/utils/ticks.d.ts +15 -4
  104. package/dist/utils/ticks.js +140 -159
  105. package/dist/utils/ticks.test.js +6 -16
  106. package/dist/utils/treemap.d.ts +1 -1
  107. package/package.json +27 -25
  108. package/dist/utils/object.js +0 -2
@@ -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;
@@ -1,8 +1,22 @@
1
1
  <script lang="ts" module>
2
- import { forceSimulation, type Force, type Simulation, type SimulationNodeDatum } from 'd3-force';
2
+ import {
3
+ forceSimulation,
4
+ type Force,
5
+ type Simulation,
6
+ type SimulationLinkDatum,
7
+ type SimulationNodeDatum,
8
+ } from 'd3-force';
3
9
  import type { Snippet } from 'svelte';
4
10
 
5
- type Forces = Record<string, Force<any, any>>;
11
+ export type Forces<
12
+ NodeDatum extends SimulationNodeDatum,
13
+ LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
14
+ > = Record<string, Force<NodeDatum, LinkDatum>>;
15
+
16
+ export type Data<TNode = any, TLink = any> = {
17
+ nodes: TNode[];
18
+ links?: TLink[];
19
+ };
6
20
 
7
21
  export type LinkPosition = {
8
22
  x1: number;
@@ -11,44 +25,114 @@
11
25
  y2: number;
12
26
  };
13
27
 
14
- export type ForceSimulationProps = {
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
+ };
56
+
57
+ /**
58
+ * Default initial alpha value of the simulation.
59
+ */
60
+ export const DEFAULT_ALPHA: number = 1;
61
+
62
+ /**
63
+ * Default target alpha value for the simulation.
64
+ */
65
+ export const DEFAULT_ALPHA_TARGET: number = 0;
66
+
67
+ /**
68
+ * Default alpha decay rate per tick.
69
+ *
70
+ * Formula: `1 - Math.pow(0.001, 1 / 300)`.
71
+ */
72
+ export const DEFAULT_ALPHA_DECAY: number = 1 - Math.pow(0.001, 1 / 300);
73
+
74
+ /**
75
+ * Default minimum alpha value at which simulation stops.
76
+ */
77
+ export const DEFAULT_ALPHA_MIN: number = 0.01;
78
+
79
+ /**
80
+ * Default velocity decay factor applied to nodes each tick.
81
+ */
82
+ export const DEFAULT_VELOCITY_DECAY: number = 0.4;
83
+
84
+ type NodeDatumFor<NodeDatum> = NodeDatum & SimulationNodeDatum;
85
+
86
+ type LinkDatumFor<NodeDatum, LinkDatum> = LinkDatum &
87
+ SimulationLinkDatum<NodeDatumFor<NodeDatum>>;
88
+
89
+ type SimulationFor<NodeDatum, LinkDatum> = Simulation<
90
+ NodeDatumFor<NodeDatum>,
91
+ LinkDatumFor<NodeDatum, LinkDatum>
92
+ >;
93
+
94
+ export type ForceSimulationProps<
95
+ NodeDatum extends SimulationNodeDatum,
96
+ LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
97
+ > = {
15
98
  /**
16
99
  * Force simulation parameters
17
100
  */
18
- forces: Forces;
101
+ forces: Forces<NodeDatum, LinkDatum>;
19
102
 
20
103
  /**
21
- * An array of links to be used for position calculation.
104
+ * An object with arrays of nodes and links,
105
+ * to be used for position calculation.
22
106
  */
23
- links?: any[];
107
+ data: Data<NodeDatum, LinkDatum>;
24
108
 
25
109
  /**
26
110
  * Current alpha value of the simulation
27
- * @default 1
111
+ * @default DEFAULT_ALPHA
28
112
  */
29
113
  alpha?: number;
30
114
 
31
115
  /**
32
116
  * Target alpha value for the simulation
33
- * @default 0
117
+ * @default DEFAULT_ALPHA_TARGET
34
118
  */
35
119
  alphaTarget?: number;
36
120
 
37
121
  /**
38
122
  * Alpha decay rate per tick
39
- * @default 1 - Math.pow(0.001, 1 / 300)
123
+ * @default DEFAULT_ALPHA_DECAY
40
124
  */
41
125
  alphaDecay?: number;
42
126
 
43
127
  /**
44
128
  * Minimum alpha value at which simulation stops
45
- * @default 0.01
129
+ * @default DEFAULT_ALPHA_MIN
46
130
  */
47
131
  alphaMin?: number;
48
132
 
49
133
  /**
50
134
  * Velocity decay factor applied to nodes each tick
51
- * @default 0.4
135
+ * @default DEFAULT_VELOCITY_DECAY
52
136
  */
53
137
  velocityDecay?: number;
54
138
 
@@ -73,65 +157,74 @@
73
157
  /**
74
158
  * Callback function triggered when simulation starts
75
159
  */
76
- onStart?: () => void;
160
+ onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
77
161
 
78
162
  /**
79
163
  * Callback function triggered on each simulation tick
80
164
  */
81
- onTick?: (e: { alpha: number; alphaTarget: number }) => void;
165
+ onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
82
166
 
83
167
  /**
84
168
  * Callback function triggered when simulation ends
85
169
  */
86
- onEnd?: () => void;
170
+ onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
87
171
 
88
172
  children?: Snippet<
89
173
  [
90
174
  {
91
- nodes: any[];
92
- simulation: Simulation<SimulationNodeDatum, undefined>;
175
+ nodes: NodeDatumFor<NodeDatum>[];
176
+ links: LinkDatumFor<NodeDatum, LinkDatum>[];
93
177
  linkPositions: LinkPosition[];
178
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
94
179
  },
95
180
  ]
96
181
  >;
97
182
  };
98
183
  </script>
99
184
 
100
- <script lang="ts">
101
- import { getChartContext } from './Chart.svelte';
185
+ <script
186
+ lang="ts"
187
+ generics="NodeDatum extends SimulationNodeDatum,
188
+ LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,"
189
+ >
102
190
  import { watch } from 'runed';
103
191
 
104
192
  let {
105
193
  forces,
106
- links = [],
107
- alpha = $bindable(1),
108
- alphaTarget = 0,
109
- alphaDecay = 1 - Math.pow(0.001, 1 / 300),
110
- alphaMin = 0.001,
111
- velocityDecay = 0.4,
194
+ data,
195
+ alpha = $bindable(DEFAULT_ALPHA),
196
+ alphaTarget = DEFAULT_ALPHA_TARGET,
197
+ alphaDecay = DEFAULT_ALPHA_DECAY,
198
+ alphaMin = DEFAULT_ALPHA_MIN,
199
+ velocityDecay = DEFAULT_VELOCITY_DECAY,
112
200
  stopped = false,
113
201
  static: staticProp,
114
- onStart: onStartProp = () => {},
115
- onTick: onTickProp = () => {},
116
- onEnd: onEndProp = () => {},
202
+ onStart: onStartProp,
203
+ onTick: onTickProp,
204
+ onEnd: onEndProp,
117
205
  children,
118
206
  cloneNodes = false,
119
- }: ForceSimulationProps = $props();
120
-
121
- const ctx = getChartContext();
207
+ }: ForceSimulationProps<NodeDatum, LinkDatum> = $props();
122
208
 
123
209
  // MARK: Public Props
124
210
 
125
211
  // MARK: Private Props
126
212
 
127
- let nodes: SimulationNodeDatum[] = $state([]);
128
213
  let linkPositions: LinkPosition[] = $state([]);
214
+ let simulatedNodes: NodeDatumFor<NodeDatum>[] = $state([]);
215
+ let simulatedLinks: LinkDatumFor<NodeDatum, LinkDatum>[] = $derived(
216
+ (data.links ?? []) as LinkDatumFor<NodeDatum, LinkDatum>[]
217
+ );
129
218
 
130
- const simulation = forceSimulation().stop();
219
+ // This casting is unfortunately necessary, due to unfortunate
220
+ // overloading choices made, over at `@typed/d3-force`:
221
+ const simulation: SimulationFor<NodeDatum, LinkDatum> = (
222
+ forceSimulation() as SimulationFor<NodeDatum, LinkDatum>
223
+ ).stop();
131
224
 
132
225
  // d3.Simulation does not provide a `.forces()` getter, so we need to
133
226
  // keep track of previous forces ourselves, for diffing against `forces`.
134
- let previousForces: Forces = {};
227
+ let previousForces: Forces<NodeDatum, LinkDatum> = {};
135
228
 
136
229
  let paused: boolean = true;
137
230
 
@@ -166,11 +259,11 @@
166
259
  );
167
260
 
168
261
  watch.pre(
169
- () => ctx.data,
262
+ () => data,
170
263
  () => {
171
- // Any time the `data` store gets changed we
172
- // pass them to the internal d3 simulation object:
173
- pushNodesToSimulation(ctx.data as any[]);
264
+ // Any time the `nodes` prop, or the `data` store gets changed
265
+ // we pass them to the internal d3 simulation object:
266
+ pushNodesToSimulation(data.nodes);
174
267
  runOrResumeSimulation();
175
268
  }
176
269
  );
@@ -192,12 +285,8 @@
192
285
  // pass it to the internal d3 simulation object:
193
286
  pushAlphaToSimulation(alpha);
194
287
 
195
- // Only resume the simulation as long as `alpha`
196
- // is above the cut-off threshold of `alphaMin`,
197
- // otherwise our simulation will never terminate:
198
- if (simulation.alpha() >= simulation.alphaMin()) {
199
- runOrResumeSimulation();
200
- }
288
+ // Then we attempt to resume the simulation:
289
+ runOrResumeSimulation();
201
290
  }
202
291
  );
203
292
 
@@ -235,7 +324,7 @@
235
324
  simulation.nodes(nodes);
236
325
  }
237
326
 
238
- function pushForcesToSimulation(forces: Forces) {
327
+ function pushForcesToSimulation(forces: Forces<NodeDatum, LinkDatum>) {
239
328
  // Evict obsolete forces:
240
329
  const names = Object.keys(previousForces);
241
330
  for (const name of names) {
@@ -259,7 +348,7 @@
259
348
  // Keeping the link positions in sync with the simulation
260
349
  // so we don't need to recalculate _all_ link positions on each tick
261
350
  // which bogs down the simulation
262
- linkPositions = links.map((link: any) => ({
351
+ linkPositions = simulatedLinks.map((link: any) => ({
263
352
  x1: link.source.x ?? 0,
264
353
  y1: link.source.y ?? 0,
265
354
  x2: link.target.x ?? 0,
@@ -270,7 +359,8 @@
270
359
  // MARK: Pull State
271
360
 
272
361
  function pullNodesFromSimulation() {
273
- nodes = cloneNodes ? structuredClone(simulation.nodes()) : simulation.nodes();
362
+ const simulationNodes = simulation.nodes();
363
+ simulatedNodes = cloneNodes ? structuredClone(simulationNodes) : simulationNodes;
274
364
  }
275
365
 
276
366
  function pullAlphaFromSimulation() {
@@ -337,6 +427,13 @@
337
427
  return;
338
428
  }
339
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
+
340
437
  onStart();
341
438
  simulation.restart();
342
439
 
@@ -364,7 +461,12 @@
364
461
  }
365
462
 
366
463
  paused = false;
367
- onStartProp();
464
+
465
+ onStartProp?.({
466
+ alpha,
467
+ alphaTarget,
468
+ simulation,
469
+ });
368
470
  }
369
471
 
370
472
  function onTick() {
@@ -372,7 +474,13 @@
372
474
  pullAlphaFromSimulation();
373
475
  updateLinkPositions();
374
476
 
375
- onTickProp({ alpha, alphaTarget });
477
+ onTickProp?.({
478
+ alpha,
479
+ alphaTarget,
480
+ nodes: simulatedNodes,
481
+ links: simulatedLinks,
482
+ simulation,
483
+ });
376
484
  }
377
485
 
378
486
  function onEnd() {
@@ -382,7 +490,12 @@
382
490
  }
383
491
 
384
492
  paused = true;
385
- onEndProp();
493
+
494
+ onEndProp?.({
495
+ alpha,
496
+ alphaTarget,
497
+ simulation,
498
+ });
386
499
  }
387
500
 
388
501
  $effect(() => {
@@ -393,4 +506,9 @@
393
506
  });
394
507
  </script>
395
508
 
396
- {@render children?.({ nodes: nodes, simulation, linkPositions })}
509
+ {@render children?.({
510
+ nodes: simulatedNodes,
511
+ links: simulatedLinks,
512
+ simulation,
513
+ linkPositions,
514
+ })}
@@ -1,44 +1,91 @@
1
- import { type Force, type Simulation, type SimulationNodeDatum } from 'd3-force';
1
+ import { type Force, type Simulation, type SimulationLinkDatum, type SimulationNodeDatum } from 'd3-force';
2
2
  import type { Snippet } from 'svelte';
3
- type Forces = Record<string, Force<any, any>>;
3
+ export type Forces<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = Record<string, Force<NodeDatum, LinkDatum>>;
4
+ export type Data<TNode = any, TLink = any> = {
5
+ nodes: TNode[];
6
+ links?: TLink[];
7
+ };
4
8
  export type LinkPosition = {
5
9
  x1: number;
6
10
  y1: number;
7
11
  x2: number;
8
12
  y2: number;
9
13
  };
10
- export type ForceSimulationProps = {
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
+ };
31
+ /**
32
+ * Default initial alpha value of the simulation.
33
+ */
34
+ export declare const DEFAULT_ALPHA: number;
35
+ /**
36
+ * Default target alpha value for the simulation.
37
+ */
38
+ export declare const DEFAULT_ALPHA_TARGET: number;
39
+ /**
40
+ * Default alpha decay rate per tick.
41
+ *
42
+ * Formula: `1 - Math.pow(0.001, 1 / 300)`.
43
+ */
44
+ export declare const DEFAULT_ALPHA_DECAY: number;
45
+ /**
46
+ * Default minimum alpha value at which simulation stops.
47
+ */
48
+ export declare const DEFAULT_ALPHA_MIN: number;
49
+ /**
50
+ * Default velocity decay factor applied to nodes each tick.
51
+ */
52
+ export declare const DEFAULT_VELOCITY_DECAY: number;
53
+ type NodeDatumFor<NodeDatum> = NodeDatum & SimulationNodeDatum;
54
+ type LinkDatumFor<NodeDatum, LinkDatum> = LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>;
55
+ type SimulationFor<NodeDatum, LinkDatum> = Simulation<NodeDatumFor<NodeDatum>, LinkDatumFor<NodeDatum, LinkDatum>>;
56
+ export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
11
57
  /**
12
58
  * Force simulation parameters
13
59
  */
14
- forces: Forces;
60
+ forces: Forces<NodeDatum, LinkDatum>;
15
61
  /**
16
- * An array of links to be used for position calculation.
62
+ * An object with arrays of nodes and links,
63
+ * to be used for position calculation.
17
64
  */
18
- links?: any[];
65
+ data: Data<NodeDatum, LinkDatum>;
19
66
  /**
20
67
  * Current alpha value of the simulation
21
- * @default 1
68
+ * @default DEFAULT_ALPHA
22
69
  */
23
70
  alpha?: number;
24
71
  /**
25
72
  * Target alpha value for the simulation
26
- * @default 0
73
+ * @default DEFAULT_ALPHA_TARGET
27
74
  */
28
75
  alphaTarget?: number;
29
76
  /**
30
77
  * Alpha decay rate per tick
31
- * @default 1 - Math.pow(0.001, 1 / 300)
78
+ * @default DEFAULT_ALPHA_DECAY
32
79
  */
33
80
  alphaDecay?: number;
34
81
  /**
35
82
  * Minimum alpha value at which simulation stops
36
- * @default 0.01
83
+ * @default DEFAULT_ALPHA_MIN
37
84
  */
38
85
  alphaMin?: number;
39
86
  /**
40
87
  * Velocity decay factor applied to nodes each tick
41
- * @default 0.4
88
+ * @default DEFAULT_VELOCITY_DECAY
42
89
  */
43
90
  velocityDecay?: number;
44
91
  /**
@@ -59,26 +106,38 @@ export type ForceSimulationProps = {
59
106
  /**
60
107
  * Callback function triggered when simulation starts
61
108
  */
62
- onStart?: () => void;
109
+ onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
63
110
  /**
64
111
  * Callback function triggered on each simulation tick
65
112
  */
66
- onTick?: (e: {
67
- alpha: number;
68
- alphaTarget: number;
69
- }) => void;
113
+ onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
70
114
  /**
71
115
  * Callback function triggered when simulation ends
72
116
  */
73
- onEnd?: () => void;
117
+ onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
74
118
  children?: Snippet<[
75
119
  {
76
- nodes: any[];
77
- simulation: Simulation<SimulationNodeDatum, undefined>;
120
+ nodes: NodeDatumFor<NodeDatum>[];
121
+ links: LinkDatumFor<NodeDatum, LinkDatum>[];
78
122
  linkPositions: LinkPosition[];
123
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
79
124
  }
80
125
  ]>;
81
126
  };
82
- declare const ForceSimulation: import("svelte").Component<ForceSimulationProps, {}, "alpha">;
83
- type ForceSimulation = ReturnType<typeof ForceSimulation>;
127
+ declare class __sveltets_Render<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
128
+ props(): ForceSimulationProps<NodeDatum, LinkDatum>;
129
+ events(): {};
130
+ slots(): {};
131
+ bindings(): "alpha";
132
+ exports(): {};
133
+ }
134
+ interface $$IsomorphicComponent {
135
+ new <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['events']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['slots']>> & {
136
+ $$bindings?: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['bindings']>;
137
+ } & ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
138
+ <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(internal: unknown, props: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']> & {}): ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
139
+ z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
140
+ }
141
+ declare const ForceSimulation: $$IsomorphicComponent;
142
+ type ForceSimulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = InstanceType<typeof ForceSimulation<NodeDatum, LinkDatum>>;
84
143
  export default ForceSimulation;
@@ -5,6 +5,7 @@
5
5
  import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
6
6
  import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
7
7
  import {
8
+ geoPath as d3GeoPath,
8
9
  geoTransform as d3geoTransform,
9
10
  type GeoIdentityTransform,
10
11
  type GeoPermissibleObjects,
@@ -105,6 +106,10 @@
105
106
  const geoPath = $derived.by(() => {
106
107
  geojson;
107
108
  if (!projection) return;
109
+ // Only use geoCurvePath for custom curves (performance impact)
110
+ if (curve === curveLinearClosed) {
111
+ return d3GeoPath(projection);
112
+ }
108
113
  return geoCurvePath(projection, curve);
109
114
  });
110
115
 
@@ -157,16 +162,18 @@
157
162
  name: 'GeoPath',
158
163
  render,
159
164
  events: {
160
- click: _onClick,
161
- pointerenter: _onPointerEnter,
162
- pointermove: _onPointerMove,
163
- pointerleave: _onPointerLeave,
165
+ // Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
166
+ click: onclick ? _onClick : undefined,
167
+ pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
168
+ pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
169
+ pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
164
170
  pointerdown: restProps.onpointerdown,
165
171
  touchmove: restProps.ontouchmove,
166
172
  },
167
173
  deps: () => [
168
- geojson,
169
174
  projection,
175
+ geojson,
176
+ curve,
170
177
  fillKey.current,
171
178
  strokeKey.current,
172
179
  strokeWidth,
@@ -1,7 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from 'svelte';
3
- import type { SVGAttributes } from 'svelte/elements';
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
- splineRef: splineRefProp = $bindable(),
45
+ pathRef: pathRefProp = $bindable(),
46
46
  ...restProps
47
47
  }: GeoSplineProps = $props();
48
48
 
49
- let splineRef = $state<SVGPathElement>();
49
+ let pathRef = $state<SVGPathElement>();
50
50
  $effect.pre(() => {
51
- splineRefProp = splineRef;
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:splineRef
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, {}, "splineRef">;
30
+ declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "pathRef">;
31
31
  type GeoSpline = ReturnType<typeof GeoSpline>;
32
32
  export default GeoSpline;
@@ -100,7 +100,7 @@
100
100
  initialY: initialYProp,
101
101
  center = false,
102
102
  preventTouchMove = false,
103
- opacity = 1,
103
+ opacity = undefined,
104
104
  motion,
105
105
  transitionIn: transitionInProp,
106
106
  transitionInParams: transitionInParamsProp,
@@ -144,7 +144,7 @@
144
144
  name: 'Group',
145
145
  render: (ctx) => {
146
146
  const currentGlobalAlpha = ctx.globalAlpha;
147
- ctx.globalAlpha = opacity;
147
+ ctx.globalAlpha = opacity ?? 1;
148
148
 
149
149
  ctx.translate(motionX.current ?? 0, motionY.current ?? 0);
150
150