layerchart 2.0.0-next.15 → 2.0.0-next.16
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.
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
} from 'd3-force';
|
|
9
9
|
import type { Snippet } from 'svelte';
|
|
10
10
|
|
|
11
|
-
type Forces
|
|
11
|
+
export type Forces<
|
|
12
|
+
NodeDatum extends SimulationNodeDatum,
|
|
13
|
+
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
|
|
14
|
+
> = Record<string, Force<NodeDatum, LinkDatum>>;
|
|
12
15
|
|
|
13
16
|
export type Data<TNode = any, TLink = any> = {
|
|
14
17
|
nodes: TNode[];
|
|
@@ -22,7 +25,35 @@
|
|
|
22
25
|
y2: number;
|
|
23
26
|
}>;
|
|
24
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Default initial alpha value of the simulation.
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_ALPHA: number = 1;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default target alpha value for the simulation.
|
|
35
|
+
*/
|
|
36
|
+
export const DEFAULT_ALPHA_TARGET: number = 0;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Default alpha decay rate per tick.
|
|
40
|
+
*
|
|
41
|
+
* Formula: `1 - Math.pow(0.001, 1 / 300)`.
|
|
42
|
+
*/
|
|
43
|
+
export const DEFAULT_ALPHA_DECAY: number = 1 - Math.pow(0.001, 1 / 300);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Default minimum alpha value at which simulation stops.
|
|
47
|
+
*/
|
|
48
|
+
export const DEFAULT_ALPHA_MIN: number = 0.01;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Default velocity decay factor applied to nodes each tick.
|
|
52
|
+
*/
|
|
53
|
+
export const DEFAULT_VELOCITY_DECAY: number = 0.4;
|
|
54
|
+
|
|
25
55
|
type NodeDatumFor<NodeDatum> = Prettify<NodeDatum & SimulationNodeDatum>;
|
|
56
|
+
|
|
26
57
|
type LinkDatumFor<NodeDatum, LinkDatum> = Prettify<
|
|
27
58
|
LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>
|
|
28
59
|
>;
|
|
@@ -32,11 +63,14 @@
|
|
|
32
63
|
LinkDatumFor<NodeDatum, LinkDatum>
|
|
33
64
|
>;
|
|
34
65
|
|
|
35
|
-
export type ForceSimulationProps<
|
|
66
|
+
export type ForceSimulationProps<
|
|
67
|
+
NodeDatum extends SimulationNodeDatum,
|
|
68
|
+
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,
|
|
69
|
+
> = {
|
|
36
70
|
/**
|
|
37
71
|
* Force simulation parameters
|
|
38
72
|
*/
|
|
39
|
-
forces: Forces
|
|
73
|
+
forces: Forces<NodeDatum, LinkDatum>;
|
|
40
74
|
|
|
41
75
|
/**
|
|
42
76
|
* An object with arrays of nodes and links,
|
|
@@ -46,31 +80,31 @@
|
|
|
46
80
|
|
|
47
81
|
/**
|
|
48
82
|
* Current alpha value of the simulation
|
|
49
|
-
* @default
|
|
83
|
+
* @default DEFAULT_ALPHA
|
|
50
84
|
*/
|
|
51
85
|
alpha?: number;
|
|
52
86
|
|
|
53
87
|
/**
|
|
54
88
|
* Target alpha value for the simulation
|
|
55
|
-
* @default
|
|
89
|
+
* @default DEFAULT_ALPHA_TARGET
|
|
56
90
|
*/
|
|
57
91
|
alphaTarget?: number;
|
|
58
92
|
|
|
59
93
|
/**
|
|
60
94
|
* Alpha decay rate per tick
|
|
61
|
-
* @default
|
|
95
|
+
* @default DEFAULT_ALPHA_DECAY
|
|
62
96
|
*/
|
|
63
97
|
alphaDecay?: number;
|
|
64
98
|
|
|
65
99
|
/**
|
|
66
100
|
* Minimum alpha value at which simulation stops
|
|
67
|
-
* @default
|
|
101
|
+
* @default DEFAULT_ALPHA_MIN
|
|
68
102
|
*/
|
|
69
103
|
alphaMin?: number;
|
|
70
104
|
|
|
71
105
|
/**
|
|
72
106
|
* Velocity decay factor applied to nodes each tick
|
|
73
|
-
* @default
|
|
107
|
+
* @default DEFAULT_VELOCITY_DECAY
|
|
74
108
|
*/
|
|
75
109
|
velocityDecay?: number;
|
|
76
110
|
|
|
@@ -120,18 +154,22 @@
|
|
|
120
154
|
};
|
|
121
155
|
</script>
|
|
122
156
|
|
|
123
|
-
<script
|
|
157
|
+
<script
|
|
158
|
+
lang="ts"
|
|
159
|
+
generics="NodeDatum extends SimulationNodeDatum,
|
|
160
|
+
LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined,"
|
|
161
|
+
>
|
|
124
162
|
import { watch } from 'runed';
|
|
125
163
|
import type { Prettify } from '@layerstack/utils';
|
|
126
164
|
|
|
127
165
|
let {
|
|
128
166
|
forces,
|
|
129
167
|
data,
|
|
130
|
-
alpha = $bindable(
|
|
131
|
-
alphaTarget =
|
|
132
|
-
alphaDecay =
|
|
133
|
-
alphaMin =
|
|
134
|
-
velocityDecay =
|
|
168
|
+
alpha = $bindable(DEFAULT_ALPHA),
|
|
169
|
+
alphaTarget = DEFAULT_ALPHA_TARGET,
|
|
170
|
+
alphaDecay = DEFAULT_ALPHA_DECAY,
|
|
171
|
+
alphaMin = DEFAULT_ALPHA_MIN,
|
|
172
|
+
velocityDecay = DEFAULT_VELOCITY_DECAY,
|
|
135
173
|
stopped = false,
|
|
136
174
|
static: staticProp,
|
|
137
175
|
onStart: onStartProp = () => {},
|
|
@@ -159,7 +197,7 @@
|
|
|
159
197
|
|
|
160
198
|
// d3.Simulation does not provide a `.forces()` getter, so we need to
|
|
161
199
|
// keep track of previous forces ourselves, for diffing against `forces`.
|
|
162
|
-
let previousForces: Forces = {};
|
|
200
|
+
let previousForces: Forces<NodeDatum, LinkDatum> = {};
|
|
163
201
|
|
|
164
202
|
let paused: boolean = true;
|
|
165
203
|
|
|
@@ -263,7 +301,7 @@
|
|
|
263
301
|
simulation.nodes(nodes);
|
|
264
302
|
}
|
|
265
303
|
|
|
266
|
-
function pushForcesToSimulation(forces: Forces) {
|
|
304
|
+
function pushForcesToSimulation(forces: Forces<NodeDatum, LinkDatum>) {
|
|
267
305
|
// Evict obsolete forces:
|
|
268
306
|
const names = Object.keys(previousForces);
|
|
269
307
|
for (const name of names) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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<
|
|
3
|
+
export type Forces<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = Record<string, Force<NodeDatum, LinkDatum>>;
|
|
4
4
|
export type Data<TNode = any, TLink = any> = {
|
|
5
5
|
nodes: TNode[];
|
|
6
6
|
links?: TLink[];
|
|
@@ -11,14 +11,36 @@ export type LinkPosition = Prettify<{
|
|
|
11
11
|
x2: number;
|
|
12
12
|
y2: number;
|
|
13
13
|
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Default initial alpha value of the simulation.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_ALPHA: number;
|
|
18
|
+
/**
|
|
19
|
+
* Default target alpha value for the simulation.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_ALPHA_TARGET: number;
|
|
22
|
+
/**
|
|
23
|
+
* Default alpha decay rate per tick.
|
|
24
|
+
*
|
|
25
|
+
* Formula: `1 - Math.pow(0.001, 1 / 300)`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_ALPHA_DECAY: number;
|
|
28
|
+
/**
|
|
29
|
+
* Default minimum alpha value at which simulation stops.
|
|
30
|
+
*/
|
|
31
|
+
export declare const DEFAULT_ALPHA_MIN: number;
|
|
32
|
+
/**
|
|
33
|
+
* Default velocity decay factor applied to nodes each tick.
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_VELOCITY_DECAY: number;
|
|
14
36
|
type NodeDatumFor<NodeDatum> = Prettify<NodeDatum & SimulationNodeDatum>;
|
|
15
37
|
type LinkDatumFor<NodeDatum, LinkDatum> = Prettify<LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>>;
|
|
16
38
|
type SimulationFor<NodeDatum, LinkDatum> = Simulation<NodeDatumFor<NodeDatum>, LinkDatumFor<NodeDatum, LinkDatum>>;
|
|
17
|
-
export type ForceSimulationProps<NodeDatum, LinkDatum> = {
|
|
39
|
+
export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
18
40
|
/**
|
|
19
41
|
* Force simulation parameters
|
|
20
42
|
*/
|
|
21
|
-
forces: Forces
|
|
43
|
+
forces: Forces<NodeDatum, LinkDatum>;
|
|
22
44
|
/**
|
|
23
45
|
* An object with arrays of nodes and links,
|
|
24
46
|
* to be used for position calculation.
|
|
@@ -26,27 +48,27 @@ export type ForceSimulationProps<NodeDatum, LinkDatum> = {
|
|
|
26
48
|
data: Data<NodeDatum, LinkDatum>;
|
|
27
49
|
/**
|
|
28
50
|
* Current alpha value of the simulation
|
|
29
|
-
* @default
|
|
51
|
+
* @default DEFAULT_ALPHA
|
|
30
52
|
*/
|
|
31
53
|
alpha?: number;
|
|
32
54
|
/**
|
|
33
55
|
* Target alpha value for the simulation
|
|
34
|
-
* @default
|
|
56
|
+
* @default DEFAULT_ALPHA_TARGET
|
|
35
57
|
*/
|
|
36
58
|
alphaTarget?: number;
|
|
37
59
|
/**
|
|
38
60
|
* Alpha decay rate per tick
|
|
39
|
-
* @default
|
|
61
|
+
* @default DEFAULT_ALPHA_DECAY
|
|
40
62
|
*/
|
|
41
63
|
alphaDecay?: number;
|
|
42
64
|
/**
|
|
43
65
|
* Minimum alpha value at which simulation stops
|
|
44
|
-
* @default
|
|
66
|
+
* @default DEFAULT_ALPHA_MIN
|
|
45
67
|
*/
|
|
46
68
|
alphaMin?: number;
|
|
47
69
|
/**
|
|
48
70
|
* Velocity decay factor applied to nodes each tick
|
|
49
|
-
* @default
|
|
71
|
+
* @default DEFAULT_VELOCITY_DECAY
|
|
50
72
|
*/
|
|
51
73
|
velocityDecay?: number;
|
|
52
74
|
/**
|
|
@@ -89,7 +111,7 @@ export type ForceSimulationProps<NodeDatum, LinkDatum> = {
|
|
|
89
111
|
]>;
|
|
90
112
|
};
|
|
91
113
|
import type { Prettify } from '@layerstack/utils';
|
|
92
|
-
declare class __sveltets_Render<NodeDatum, LinkDatum
|
|
114
|
+
declare class __sveltets_Render<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
|
|
93
115
|
props(): ForceSimulationProps<NodeDatum, LinkDatum>;
|
|
94
116
|
events(): {};
|
|
95
117
|
slots(): {};
|
|
@@ -97,12 +119,12 @@ declare class __sveltets_Render<NodeDatum, LinkDatum = undefined> {
|
|
|
97
119
|
exports(): {};
|
|
98
120
|
}
|
|
99
121
|
interface $$IsomorphicComponent {
|
|
100
|
-
new <NodeDatum, LinkDatum
|
|
122
|
+
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']>> & {
|
|
101
123
|
$$bindings?: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['bindings']>;
|
|
102
124
|
} & ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
|
|
103
|
-
<NodeDatum, LinkDatum
|
|
125
|
+
<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(internal: unknown, props: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']> & {}): ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
|
|
104
126
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
105
127
|
}
|
|
106
128
|
declare const ForceSimulation: $$IsomorphicComponent;
|
|
107
|
-
type ForceSimulation<NodeDatum, LinkDatum
|
|
129
|
+
type ForceSimulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = InstanceType<typeof ForceSimulation<NodeDatum, LinkDatum>>;
|
|
108
130
|
export default ForceSimulation;
|
package/package.json
CHANGED