layerchart 2.0.0-next.0 → 2.0.0-next.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.
- package/dist/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +155 -0
- package/dist/components/AnnotationLine.svelte.d.ts +28 -0
- package/dist/components/AnnotationPoint.svelte +121 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +32 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +287 -174
- package/dist/components/Axis.svelte.d.ts +116 -0
- package/dist/components/Bar.svelte +163 -107
- package/dist/components/Bar.svelte.d.ts +48 -0
- package/dist/components/Bars.svelte +54 -68
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +31 -7
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +60 -15
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +47 -12
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +28 -13
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +226 -114
- package/dist/components/Grid.svelte.d.ts +70 -0
- package/dist/components/Group.svelte +132 -105
- package/dist/components/Group.svelte.d.ts +53 -0
- package/dist/components/Highlight.svelte +409 -307
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +96 -45
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +125 -46
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +143 -70
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +105 -62
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +437 -176
- package/dist/components/Text.svelte.d.ts +130 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +106 -75
- package/dist/components/Voronoi.svelte.d.ts +40 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +450 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +454 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +369 -314
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +334 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +55 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +321 -155
- package/dist/components/layout/Canvas.svelte.d.ts +104 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +246 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +409 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte.d.ts +18 -14
- package/dist/docs/Code.svelte.d.ts +26 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte.d.ts +27 -16
- package/dist/docs/Json.svelte.d.ts +20 -16
- package/dist/docs/Layout.svelte.d.ts +18 -13
- package/dist/docs/Link.svelte.d.ts +33 -21
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte.d.ts +21 -17
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +90 -0
- package/dist/utils/{scales.js → scales.svelte.js} +100 -39
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +8 -2
- package/dist/utils/ticks.js +28 -0
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +67 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +25 -24
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,39 +1,131 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { forceSimulation, type Force } from 'd3-force';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const { data } = chartContext();
|
|
6
|
-
|
|
7
|
-
// MARK: Public Props
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { forceSimulation, type Force, type Simulation, type SimulationNodeDatum } from 'd3-force';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
8
4
|
|
|
9
5
|
type Forces = Record<string, Force<any, any>>;
|
|
10
|
-
export let forces: Forces;
|
|
11
|
-
|
|
12
|
-
export let alpha: number = 1;
|
|
13
|
-
export let alphaTarget: number = 0;
|
|
14
|
-
export let alphaDecay: number = 1 - Math.pow(0.001, 1 / 300);
|
|
15
|
-
export let alphaMin: number = 0.001;
|
|
16
|
-
|
|
17
|
-
export let velocityDecay = 0.4;
|
|
18
6
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
export type LinkPosition = {
|
|
8
|
+
x1: number;
|
|
9
|
+
y1: number;
|
|
10
|
+
x2: number;
|
|
11
|
+
y2: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type ForceSimulationProps = {
|
|
15
|
+
/**
|
|
16
|
+
* Force simulation parameters
|
|
17
|
+
*/
|
|
18
|
+
forces: Forces;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* An array of links to be used for position calculation.
|
|
22
|
+
*/
|
|
23
|
+
links?: any[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Current alpha value of the simulation
|
|
27
|
+
* @default 1
|
|
28
|
+
*/
|
|
29
|
+
alpha?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Target alpha value for the simulation
|
|
33
|
+
* @default 0
|
|
34
|
+
*/
|
|
35
|
+
alphaTarget?: number;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Alpha decay rate per tick
|
|
39
|
+
* @default 1 - Math.pow(0.001, 1 / 300)
|
|
40
|
+
*/
|
|
41
|
+
alphaDecay?: number;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Minimum alpha value at which simulation stops
|
|
45
|
+
* @default 0.01
|
|
46
|
+
*/
|
|
47
|
+
alphaMin?: number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Velocity decay factor applied to nodes each tick
|
|
51
|
+
* @default 0.4
|
|
52
|
+
*/
|
|
53
|
+
velocityDecay?: number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Stop simulation
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
stopped?: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* If true, will only update nodes after simulation has completed
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
static?: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Clone nodes since simulation mutates original
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
cloneNodes?: boolean;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Callback function triggered when simulation starts
|
|
75
|
+
*/
|
|
76
|
+
onStart?: () => void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Callback function triggered on each simulation tick
|
|
80
|
+
*/
|
|
81
|
+
onTick?: (e: { alpha: number; alphaTarget: number }) => void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Callback function triggered when simulation ends
|
|
85
|
+
*/
|
|
86
|
+
onEnd?: () => void;
|
|
87
|
+
|
|
88
|
+
children?: Snippet<
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
nodes: any[];
|
|
92
|
+
simulation: Simulation<SimulationNodeDatum, undefined>;
|
|
93
|
+
linkPositions: LinkPosition[];
|
|
94
|
+
},
|
|
95
|
+
]
|
|
96
|
+
>;
|
|
97
|
+
};
|
|
98
|
+
</script>
|
|
25
99
|
|
|
26
|
-
|
|
27
|
-
|
|
100
|
+
<script lang="ts">
|
|
101
|
+
import { getChartContext } from './Chart.svelte';
|
|
102
|
+
import { watch } from 'runed';
|
|
103
|
+
|
|
104
|
+
let {
|
|
105
|
+
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,
|
|
112
|
+
stopped = false,
|
|
113
|
+
static: staticProp,
|
|
114
|
+
onStart: onStartProp = () => {},
|
|
115
|
+
onTick: onTickProp = () => {},
|
|
116
|
+
onEnd: onEndProp = () => {},
|
|
117
|
+
children,
|
|
118
|
+
cloneNodes = false,
|
|
119
|
+
}: ForceSimulationProps = $props();
|
|
120
|
+
|
|
121
|
+
const ctx = getChartContext();
|
|
28
122
|
|
|
29
|
-
|
|
30
|
-
export let ontick: ((e: { alpha: number; alphaTarget: number }) => void) | undefined = undefined;
|
|
31
|
-
// export let onchange: | (() => void) | undefined = undefined;
|
|
32
|
-
export let onend: (() => void) | undefined = undefined;
|
|
123
|
+
// MARK: Public Props
|
|
33
124
|
|
|
34
125
|
// MARK: Private Props
|
|
35
126
|
|
|
36
|
-
let nodes:
|
|
127
|
+
let nodes: SimulationNodeDatum[] = $state([]);
|
|
128
|
+
let linkPositions: LinkPosition[] = $state([]);
|
|
37
129
|
|
|
38
130
|
const simulation = forceSimulation().stop();
|
|
39
131
|
|
|
@@ -45,57 +137,71 @@
|
|
|
45
137
|
|
|
46
138
|
// MARK: Reactivity Effects
|
|
47
139
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
140
|
+
watch.pre(
|
|
141
|
+
() => stopped,
|
|
142
|
+
() => {
|
|
143
|
+
// Any time the `stopped` prop gets toggled we
|
|
144
|
+
// update the running state of the simulation:
|
|
145
|
+
if (stopped) {
|
|
146
|
+
pauseDynamicSimulation();
|
|
147
|
+
} else {
|
|
148
|
+
runOrResumeSimulation();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
watch.pre(
|
|
154
|
+
() => staticProp,
|
|
155
|
+
() => {
|
|
156
|
+
// Any time the `static` prop gets toggled we
|
|
157
|
+
// either attach or detach our internal event listeners:
|
|
158
|
+
if (staticProp) {
|
|
159
|
+
simulation.on('tick', null).on('end', null);
|
|
160
|
+
} else {
|
|
161
|
+
simulation.on('tick', onTick).on('end', onEnd);
|
|
162
|
+
}
|
|
51
163
|
|
|
52
|
-
if (stopped) {
|
|
53
|
-
pauseDynamicSimulation();
|
|
54
|
-
} else {
|
|
55
164
|
runOrResumeSimulation();
|
|
56
165
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
simulation
|
|
64
|
-
|
|
65
|
-
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
watch.pre(
|
|
169
|
+
() => ctx.data,
|
|
170
|
+
() => {
|
|
171
|
+
// Any time the `data` store gets changed we
|
|
172
|
+
// pass them to the internal d3 simulation object:
|
|
173
|
+
pushNodesToSimulation(ctx.data as any[]);
|
|
174
|
+
runOrResumeSimulation();
|
|
66
175
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
runOrResumeSimulation();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
$: {
|
|
79
|
-
// Any time the `forces` prop gets changed we
|
|
80
|
-
// pass them to the internal d3 simulation object:
|
|
81
|
-
pushForcesToSimulation(forces);
|
|
82
|
-
runOrResumeSimulation();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
$: {
|
|
86
|
-
// Any time the `alpha` prop gets changed we
|
|
87
|
-
// pass it to the internal d3 simulation object:
|
|
88
|
-
pushAlphaToSimulation(alpha);
|
|
89
|
-
|
|
90
|
-
// Only resume the simulation as long as `alpha`
|
|
91
|
-
// is above the cut-off threshold of `alphaMin`,
|
|
92
|
-
// otherwise our simulation will never terminate:
|
|
93
|
-
if (simulation.alpha() >= simulation.alphaMin()) {
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
watch.pre(
|
|
179
|
+
() => forces,
|
|
180
|
+
() => {
|
|
181
|
+
// Any time the `forces` prop gets changed we
|
|
182
|
+
// pass them to the internal d3 simulation object:
|
|
183
|
+
pushForcesToSimulation(forces);
|
|
94
184
|
runOrResumeSimulation();
|
|
95
185
|
}
|
|
96
|
-
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
watch.pre(
|
|
189
|
+
() => alpha,
|
|
190
|
+
() => {
|
|
191
|
+
// Any time the `alpha` prop gets changed we
|
|
192
|
+
// pass it to the internal d3 simulation object:
|
|
193
|
+
pushAlphaToSimulation(alpha);
|
|
194
|
+
|
|
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
|
+
}
|
|
201
|
+
}
|
|
202
|
+
);
|
|
97
203
|
|
|
98
|
-
|
|
204
|
+
watch.pre([() => alphaTarget, () => alphaMin, () => alphaDecay, () => velocityDecay], () => {
|
|
99
205
|
// Any time any of the the alpha props get changed we
|
|
100
206
|
// pass them all to the internal d3 simulation object
|
|
101
207
|
// (they are cheap, so passing them as a batch is fine!):
|
|
@@ -117,7 +223,7 @@
|
|
|
117
223
|
.velocityDecay(velocityDecay);
|
|
118
224
|
|
|
119
225
|
runOrResumeSimulation();
|
|
120
|
-
}
|
|
226
|
+
});
|
|
121
227
|
|
|
122
228
|
// MARK: Push State
|
|
123
229
|
|
|
@@ -126,31 +232,45 @@
|
|
|
126
232
|
}
|
|
127
233
|
|
|
128
234
|
function pushNodesToSimulation(nodes: any[]) {
|
|
129
|
-
simulation.nodes(
|
|
235
|
+
simulation.nodes(nodes);
|
|
130
236
|
}
|
|
131
237
|
|
|
132
238
|
function pushForcesToSimulation(forces: Forces) {
|
|
133
239
|
// Evict obsolete forces:
|
|
134
|
-
Object.keys(previousForces)
|
|
240
|
+
const names = Object.keys(previousForces);
|
|
241
|
+
for (const name of names) {
|
|
135
242
|
if (!(name in forces)) {
|
|
136
243
|
simulation.force(name, null);
|
|
137
244
|
}
|
|
138
|
-
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const entries = Object.entries(forces);
|
|
139
248
|
|
|
140
|
-
|
|
141
|
-
Object.entries(forces).forEach(([name, force]) => {
|
|
249
|
+
for (const [name, force] of entries) {
|
|
142
250
|
if (!(name in previousForces) || force !== previousForces[name]) {
|
|
143
251
|
simulation.force(name, force);
|
|
144
252
|
}
|
|
145
|
-
}
|
|
253
|
+
}
|
|
146
254
|
|
|
147
255
|
previousForces = forces;
|
|
148
256
|
}
|
|
149
257
|
|
|
258
|
+
function updateLinkPositions() {
|
|
259
|
+
// Keeping the link positions in sync with the simulation
|
|
260
|
+
// so we don't need to recalculate _all_ link positions on each tick
|
|
261
|
+
// which bogs down the simulation
|
|
262
|
+
linkPositions = links.map((link: any) => ({
|
|
263
|
+
x1: link.source.x ?? 0,
|
|
264
|
+
y1: link.source.y ?? 0,
|
|
265
|
+
x2: link.target.x ?? 0,
|
|
266
|
+
y2: link.target.y ?? 0,
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
|
|
150
270
|
// MARK: Pull State
|
|
151
271
|
|
|
152
272
|
function pullNodesFromSimulation() {
|
|
153
|
-
nodes = simulation.nodes();
|
|
273
|
+
nodes = cloneNodes ? structuredClone(simulation.nodes()) : simulation.nodes();
|
|
154
274
|
}
|
|
155
275
|
|
|
156
276
|
function pullAlphaFromSimulation() {
|
|
@@ -160,7 +280,7 @@
|
|
|
160
280
|
// MARK: Resume / Pause
|
|
161
281
|
|
|
162
282
|
function runOrResumeSimulation() {
|
|
163
|
-
if (
|
|
283
|
+
if (staticProp) {
|
|
164
284
|
runStaticSimulationToCompletion();
|
|
165
285
|
} else {
|
|
166
286
|
resumeDynamicSimulation();
|
|
@@ -173,7 +293,7 @@
|
|
|
173
293
|
return;
|
|
174
294
|
}
|
|
175
295
|
|
|
176
|
-
if (!
|
|
296
|
+
if (!staticProp) {
|
|
177
297
|
// Only static simulations are run to completion.
|
|
178
298
|
return;
|
|
179
299
|
}
|
|
@@ -212,7 +332,7 @@
|
|
|
212
332
|
return;
|
|
213
333
|
}
|
|
214
334
|
|
|
215
|
-
if (
|
|
335
|
+
if (staticProp) {
|
|
216
336
|
// Only dynamic simulations can be resumed.
|
|
217
337
|
return;
|
|
218
338
|
}
|
|
@@ -244,17 +364,15 @@
|
|
|
244
364
|
}
|
|
245
365
|
|
|
246
366
|
paused = false;
|
|
247
|
-
|
|
367
|
+
onStartProp();
|
|
248
368
|
}
|
|
249
369
|
|
|
250
370
|
function onTick() {
|
|
251
371
|
pullNodesFromSimulation();
|
|
252
372
|
pullAlphaFromSimulation();
|
|
373
|
+
updateLinkPositions();
|
|
253
374
|
|
|
254
|
-
|
|
255
|
-
alpha,
|
|
256
|
-
alphaTarget,
|
|
257
|
-
});
|
|
375
|
+
onTickProp({ alpha, alphaTarget });
|
|
258
376
|
}
|
|
259
377
|
|
|
260
378
|
function onEnd() {
|
|
@@ -264,8 +382,15 @@
|
|
|
264
382
|
}
|
|
265
383
|
|
|
266
384
|
paused = true;
|
|
267
|
-
|
|
385
|
+
onEndProp();
|
|
268
386
|
}
|
|
387
|
+
|
|
388
|
+
$effect(() => {
|
|
389
|
+
return () => {
|
|
390
|
+
simulation.stop();
|
|
391
|
+
simulation.on('tick', null).on('end', null);
|
|
392
|
+
};
|
|
393
|
+
});
|
|
269
394
|
</script>
|
|
270
395
|
|
|
271
|
-
|
|
396
|
+
{@render children?.({ nodes: nodes, simulation, linkPositions })}
|
|
@@ -1,37 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { type Force, type Simulation, type SimulationNodeDatum } from 'd3-force';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Forces = Record<string, Force<any, any>>;
|
|
4
|
+
export type LinkPosition = {
|
|
5
|
+
x1: number;
|
|
6
|
+
y1: number;
|
|
7
|
+
x2: number;
|
|
8
|
+
y2: number;
|
|
9
|
+
};
|
|
10
|
+
export type ForceSimulationProps = {
|
|
11
|
+
/**
|
|
12
|
+
* Force simulation parameters
|
|
13
|
+
*/
|
|
14
|
+
forces: Forces;
|
|
15
|
+
/**
|
|
16
|
+
* An array of links to be used for position calculation.
|
|
17
|
+
*/
|
|
18
|
+
links?: any[];
|
|
19
|
+
/**
|
|
20
|
+
* Current alpha value of the simulation
|
|
21
|
+
* @default 1
|
|
22
|
+
*/
|
|
23
|
+
alpha?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Target alpha value for the simulation
|
|
26
|
+
* @default 0
|
|
27
|
+
*/
|
|
28
|
+
alphaTarget?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Alpha decay rate per tick
|
|
31
|
+
* @default 1 - Math.pow(0.001, 1 / 300)
|
|
32
|
+
*/
|
|
33
|
+
alphaDecay?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Minimum alpha value at which simulation stops
|
|
36
|
+
* @default 0.01
|
|
37
|
+
*/
|
|
38
|
+
alphaMin?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Velocity decay factor applied to nodes each tick
|
|
41
|
+
* @default 0.4
|
|
42
|
+
*/
|
|
43
|
+
velocityDecay?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Stop simulation
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
stopped?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* If true, will only update nodes after simulation has completed
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
static?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Clone nodes since simulation mutates original
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
cloneNodes?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Callback function triggered when simulation starts
|
|
61
|
+
*/
|
|
62
|
+
onStart?: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* Callback function triggered on each simulation tick
|
|
65
|
+
*/
|
|
66
|
+
onTick?: (e: {
|
|
67
|
+
alpha: number;
|
|
68
|
+
alphaTarget: number;
|
|
69
|
+
}) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Callback function triggered when simulation ends
|
|
72
|
+
*/
|
|
73
|
+
onEnd?: () => void;
|
|
74
|
+
children?: Snippet<[
|
|
75
|
+
{
|
|
26
76
|
nodes: any[];
|
|
27
|
-
simulation:
|
|
28
|
-
|
|
29
|
-
|
|
77
|
+
simulation: Simulation<SimulationNodeDatum, undefined>;
|
|
78
|
+
linkPositions: LinkPosition[];
|
|
79
|
+
}
|
|
80
|
+
]>;
|
|
30
81
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export
|
|
34
|
-
export default class ForceSimulation extends SvelteComponentTyped<ForceSimulationProps, ForceSimulationEvents, ForceSimulationSlots> {
|
|
35
|
-
get cloneData(): NonNullable<boolean | undefined>;
|
|
36
|
-
}
|
|
37
|
-
export {};
|
|
82
|
+
declare const ForceSimulation: import("svelte").Component<ForceSimulationProps, {}, "alpha">;
|
|
83
|
+
type ForceSimulation = ReturnType<typeof ForceSimulation>;
|
|
84
|
+
export default ForceSimulation;
|
|
@@ -1,21 +1,41 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Without } from '../utils/types.js';
|
|
3
|
+
import Rect, { type RectProps, type RectPropsWithoutHTML } from './Rect.svelte';
|
|
4
|
+
|
|
5
|
+
export type FramePropsWithoutHTML = RectPropsWithoutHTML & {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to include padding area
|
|
8
|
+
*
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
full?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type FrameProps = Omit<
|
|
15
|
+
FramePropsWithoutHTML & Without<RectProps, FramePropsWithoutHTML>,
|
|
16
|
+
'width' | 'height'
|
|
17
|
+
>;
|
|
18
|
+
</script>
|
|
19
|
+
|
|
1
20
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
21
|
+
import { getChartContext } from './Chart.svelte';
|
|
22
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
4
23
|
|
|
5
|
-
|
|
24
|
+
let { ref: refProp = $bindable(), full = false, ...restProps }: FrameProps = $props();
|
|
6
25
|
|
|
7
|
-
|
|
8
|
-
|
|
26
|
+
let ref = $state<SVGRectElement>();
|
|
27
|
+
$effect.pre(() => {
|
|
28
|
+
refProp = ref;
|
|
29
|
+
});
|
|
9
30
|
|
|
10
|
-
|
|
11
|
-
export let element: SVGRectElement | undefined = undefined;
|
|
31
|
+
const ctx = getChartContext();
|
|
12
32
|
</script>
|
|
13
33
|
|
|
14
34
|
<Rect
|
|
15
|
-
x={full &&
|
|
16
|
-
y={full &&
|
|
17
|
-
width={
|
|
18
|
-
height={
|
|
19
|
-
bind:
|
|
20
|
-
{
|
|
35
|
+
x={full && ctx.padding?.left ? -ctx.padding.left : 0}
|
|
36
|
+
y={full && ctx.padding?.top ? -ctx.padding.top : 0}
|
|
37
|
+
width={ctx.width + (full ? (ctx.padding?.left ?? 0) + (ctx.padding?.right ?? 0) : 0)}
|
|
38
|
+
height={ctx.height + (full ? (ctx.padding?.top ?? 0) + (ctx.padding?.bottom ?? 0) : 0)}
|
|
39
|
+
bind:ref
|
|
40
|
+
{...extractLayerProps(restProps, 'frame')}
|
|
21
41
|
/>
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
slots: {};
|
|
1
|
+
import type { Without } from '../utils/types.js';
|
|
2
|
+
import { type RectProps, type RectPropsWithoutHTML } from './Rect.svelte';
|
|
3
|
+
export type FramePropsWithoutHTML = RectPropsWithoutHTML & {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to include padding area
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
full?: boolean;
|
|
12
10
|
};
|
|
13
|
-
export type FrameProps =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export default
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
11
|
+
export type FrameProps = Omit<FramePropsWithoutHTML & Without<RectProps, FramePropsWithoutHTML>, 'width' | 'height'>;
|
|
12
|
+
declare const Frame: import("svelte").Component<FrameProps, {}, "ref">;
|
|
13
|
+
type Frame = ReturnType<typeof Frame>;
|
|
14
|
+
export default Frame;
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import GeoPath, { type GeoPathProps } from './GeoPath.svelte';
|
|
3
|
+
import type { Without } from '../utils/types.js';
|
|
4
|
+
export type GeoCirclePropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* The radius of the circle in degrees.
|
|
7
|
+
* @default 90
|
|
8
|
+
*/
|
|
9
|
+
radius?: number;
|
|
3
10
|
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The center point of the circle in degrees ([longitude, latitude]).
|
|
13
|
+
* @default [0, 0]
|
|
14
|
+
*/
|
|
15
|
+
center?: [number, number];
|
|
6
16
|
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The precision of the circle in degrees.
|
|
19
|
+
* @default 6
|
|
20
|
+
*/
|
|
21
|
+
precision?: number;
|
|
22
|
+
};
|
|
9
23
|
|
|
10
|
-
|
|
11
|
-
|
|
24
|
+
export type GeoCircleProps = GeoCirclePropsWithoutHTML &
|
|
25
|
+
Without<GeoPathProps, GeoCirclePropsWithoutHTML>;
|
|
26
|
+
</script>
|
|
12
27
|
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import { geoCircle } from 'd3-geo';
|
|
30
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
15
31
|
|
|
16
|
-
|
|
17
|
-
export let onpointerenter: ComponentProps<typeof GeoPath>['onpointerenter'] = undefined;
|
|
18
|
-
export let onpointermove: ComponentProps<typeof GeoPath>['onpointermove'] = undefined;
|
|
19
|
-
export let onpointerleave: ComponentProps<typeof GeoPath>['onpointerleave'] = undefined;
|
|
32
|
+
let { radius = 90, center = [0, 0], precision = 6, ...restProps }: GeoCircleProps = $props();
|
|
20
33
|
|
|
21
|
-
|
|
34
|
+
const geojson = $derived(geoCircle().radius(radius).center(center).precision(precision)());
|
|
22
35
|
</script>
|
|
23
36
|
|
|
24
|
-
<GeoPath {geojson} {
|
|
37
|
+
<GeoPath {geojson} {...extractLayerProps(restProps, 'geo-circle')} />
|