layerchart 0.41.6 → 0.43.0
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 +27 -20
- package/dist/components/Arc.svelte.d.ts +2 -2
- package/dist/components/Area.svelte +11 -7
- package/dist/components/Area.svelte.d.ts +3 -3
- package/dist/components/AreaStack.svelte +3 -2
- package/dist/components/Axis.svelte +38 -41
- package/dist/components/Axis.svelte.d.ts +5 -4
- package/dist/components/Bar.svelte +6 -5
- package/dist/components/Bar.svelte.d.ts +3 -2
- package/dist/components/Bars.svelte +5 -4
- package/dist/components/Bars.svelte.d.ts +3 -2
- package/dist/components/Bounds.svelte +7 -5
- package/dist/components/Bounds.svelte.d.ts +8 -8
- package/dist/components/Brush.svelte +8 -6
- package/dist/components/Brush.svelte.d.ts +2 -2
- package/dist/components/Calendar.svelte +4 -3
- package/dist/components/Chart.svelte +72 -86
- package/dist/components/Chart.svelte.d.ts +216 -24
- package/dist/components/ChartClipPath.svelte +6 -6
- package/dist/components/ChartContext.svelte +19 -0
- package/dist/components/ChartContext.svelte.d.ts +89 -0
- package/dist/components/Circle.svelte +1 -0
- package/dist/components/ClipPath.svelte +1 -0
- package/dist/components/ForceSimulation.svelte +182 -25
- package/dist/components/ForceSimulation.svelte.d.ts +11 -1
- package/dist/components/Frame.svelte +8 -7
- package/dist/components/Frame.svelte.d.ts +1 -1
- package/dist/components/GeoCircle.svelte.d.ts +1 -2
- package/dist/components/GeoContext.svelte +2 -1
- package/dist/components/GeoContext.svelte.d.ts +5 -5
- package/dist/components/GeoEdgeFade.svelte +2 -5
- package/dist/components/GeoPath.svelte +9 -5
- package/dist/components/GeoPath.svelte.d.ts +7 -4
- package/dist/components/GeoPoint.svelte +0 -1
- package/dist/components/GeoSpline.svelte +2 -11
- package/dist/components/GeoTile.svelte +3 -1
- package/dist/components/Group.svelte +4 -2
- package/dist/components/Highlight.svelte +16 -10
- package/dist/components/Highlight.svelte.d.ts +16 -15
- package/dist/components/HitCanvas.svelte +5 -2
- package/dist/components/HitCanvas.svelte.d.ts +1 -1
- package/dist/components/Hull.svelte +6 -3
- package/dist/components/Labels.svelte +5 -4
- package/dist/components/Labels.svelte.d.ts +0 -1
- package/dist/components/Legend.svelte +4 -4
- package/dist/components/Legend.svelte.d.ts +2 -2
- package/dist/components/Line.svelte +1 -0
- package/dist/components/Link.svelte +3 -1
- package/dist/components/Pack.svelte +4 -3
- package/dist/components/Partition.svelte +3 -3
- package/dist/components/Partition.svelte.d.ts +2 -1
- package/dist/components/Pie.svelte +7 -6
- package/dist/components/Pie.svelte.d.ts +2 -4
- package/dist/components/Point.svelte +2 -2
- package/dist/components/Points.svelte +4 -3
- package/dist/components/RadialGradient.svelte +2 -2
- package/dist/components/RadialGradient.svelte.d.ts +0 -1
- package/dist/components/Rect.svelte +1 -0
- package/dist/components/Rule.svelte +3 -3
- package/dist/components/Sankey.svelte +9 -3
- package/dist/components/Sankey.svelte.d.ts +2 -2
- package/dist/components/Spline.svelte +9 -6
- package/dist/components/Spline.svelte.d.ts +2 -2
- package/dist/components/Text.svelte +1 -2
- package/dist/components/Threshold.svelte +2 -2
- package/dist/components/Threshold.svelte.d.ts +2 -2
- package/dist/components/TileImage.svelte +4 -1
- package/dist/components/Tooltip.svelte +3 -3
- package/dist/components/TooltipContext.svelte +46 -15
- package/dist/components/TooltipContext.svelte.d.ts +1 -1
- package/dist/components/TooltipItem.svelte.d.ts +1 -1
- package/dist/components/TransformContext.svelte +17 -6
- package/dist/components/TransformControls.svelte +1 -0
- package/dist/components/Tree.svelte +4 -3
- package/dist/components/Tree.svelte.d.ts +3 -3
- package/dist/components/Treemap.svelte +11 -12
- package/dist/components/Treemap.svelte.d.ts +6 -6
- package/dist/components/Voronoi.svelte +8 -3
- package/dist/components/layout/Canvas.svelte +5 -3
- package/dist/components/layout/Html.svelte +3 -3
- package/dist/components/layout/Svg.svelte +6 -3
- package/dist/docs/Code.svelte +2 -3
- package/dist/docs/GeoDebug.svelte +4 -4
- package/dist/docs/Link.svelte +2 -4
- package/dist/docs/Link.svelte.d.ts +14 -5
- package/dist/docs/Preview.svelte +1 -1
- package/dist/docs/TilesetField.svelte +1 -1
- package/dist/docs/TilesetField.svelte.d.ts +1 -1
- package/dist/docs/ViewSourceButton.svelte +4 -4
- package/dist/docs/ViewSourceButton.svelte.d.ts +5 -3
- package/dist/stores/motionStore.d.ts +2 -2
- package/dist/stores/motionStore.js +4 -2
- package/dist/utils/array.d.ts +5 -0
- package/dist/utils/array.js +7 -0
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/common.js +18 -0
- package/dist/utils/genData.d.ts +23 -23
- package/dist/utils/genData.js +3 -2
- package/dist/utils/geo.d.ts +3 -3
- package/dist/utils/geo.js +2 -0
- package/dist/utils/graph.d.ts +1 -1
- package/dist/utils/graph.js +3 -3
- package/dist/utils/hierarchy.d.ts +1 -1
- package/dist/utils/hierarchy.js +1 -0
- package/dist/utils/rect.d.ts +5 -3
- package/dist/utils/rect.js +7 -11
- package/dist/utils/scales.d.ts +21 -12
- package/dist/utils/scales.js +3 -1
- package/dist/utils/stack.d.ts +5 -2
- package/dist/utils/stack.js +20 -7
- package/dist/utils/threshold.js +1 -0
- package/dist/utils/treemap.d.ts +5 -2
- package/dist/utils/treemap.js +1 -1
- package/package.json +6 -3
|
@@ -1,49 +1,206 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { createEventDispatcher } from 'svelte';
|
|
2
2
|
import { forceSimulation } from 'd3-force';
|
|
3
|
-
|
|
3
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
|
+
const { data } = chartContext();
|
|
5
|
+
const dispatch = createEventDispatcher();
|
|
4
6
|
export let forces;
|
|
5
7
|
export let alpha = 1;
|
|
6
8
|
export let alphaTarget = 0;
|
|
7
9
|
export let alphaDecay = 1 - Math.pow(0.001, 1 / 300);
|
|
8
10
|
export let alphaMin = 0.001;
|
|
9
11
|
export let velocityDecay = 0.4;
|
|
10
|
-
/**
|
|
11
|
-
export let
|
|
12
|
+
/** Stop simulation */
|
|
13
|
+
export let stopped = false;
|
|
12
14
|
let _static = false;
|
|
13
15
|
/** If true, will only update nodes after simulation has completed */
|
|
14
16
|
export { _static as static };
|
|
15
|
-
|
|
17
|
+
/** Clone data since simulation mutates original */
|
|
18
|
+
export const cloneData = false;
|
|
19
|
+
// MARK: Private Props
|
|
20
|
+
let nodes = [];
|
|
21
|
+
const simulation = forceSimulation().stop();
|
|
22
|
+
// d3.Simulation does not provide a `.forces()` getter, so we need to
|
|
23
|
+
// keep track of previous forces ourselves, for diffing against `forces`.
|
|
24
|
+
let previousForces = {};
|
|
25
|
+
let paused = true;
|
|
26
|
+
// MARK: Reactivity Effects
|
|
27
|
+
$: {
|
|
28
|
+
// Any time the `stopped` prop gets toggled we
|
|
29
|
+
// update the running state of the simulation:
|
|
30
|
+
if (stopped) {
|
|
31
|
+
pauseDynamicSimulation();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
runOrResumeSimulation();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
$: {
|
|
38
|
+
// Any time the `static` prop gets toggled we
|
|
39
|
+
// either attach or detach our internal event listeners:
|
|
40
|
+
if (_static) {
|
|
41
|
+
simulation.on('tick', null).on('end', null);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
simulation.on('tick', onTick).on('end', onEnd);
|
|
45
|
+
}
|
|
46
|
+
runOrResumeSimulation();
|
|
47
|
+
}
|
|
48
|
+
$: {
|
|
49
|
+
// Any time the `$data` store gets changed we
|
|
50
|
+
// pass them to the internal d3 simulation object:
|
|
51
|
+
pushNodesToSimulation($data);
|
|
52
|
+
runOrResumeSimulation();
|
|
53
|
+
}
|
|
16
54
|
$: {
|
|
55
|
+
// Any time the `forces` prop gets changed we
|
|
56
|
+
// pass them to the internal d3 simulation object:
|
|
57
|
+
pushForcesToSimulation(forces);
|
|
58
|
+
runOrResumeSimulation();
|
|
59
|
+
}
|
|
60
|
+
$: {
|
|
61
|
+
// Any time the `alpha` prop gets changed we
|
|
62
|
+
// pass it to the internal d3 simulation object:
|
|
63
|
+
pushAlphaToSimulation(alpha);
|
|
64
|
+
// Only resume the simulation as long as `alpha`
|
|
65
|
+
// is above the cut-off threshold of `alphaMin`,
|
|
66
|
+
// otherwise our simulation will never terminate:
|
|
67
|
+
if (simulation.alpha() >= simulation.alphaMin()) {
|
|
68
|
+
runOrResumeSimulation();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
$: {
|
|
72
|
+
// Any time any of the the alpha props get changed we
|
|
73
|
+
// pass them all to the internal d3 simulation object
|
|
74
|
+
// (they are cheap, so passing them as a batch is fine!):
|
|
75
|
+
// We read `simulation.alpha()` instead of `alpha` here, so
|
|
76
|
+
// Svelte does not trigger this block on any change to `alpha`:
|
|
77
|
+
let alphaValue = simulation.alpha();
|
|
78
|
+
if (alphaTarget > alphaValue && alphaValue < alphaMin) {
|
|
79
|
+
// Lift `alpha` from below `alphaMin` in order to give the simulation
|
|
80
|
+
// a chance to get revived if an `alphaTarget > alpha` is provided:
|
|
81
|
+
alphaValue = alphaMin;
|
|
82
|
+
}
|
|
17
83
|
simulation
|
|
18
|
-
.alpha(
|
|
84
|
+
.alpha(alphaValue)
|
|
19
85
|
.alphaTarget(alphaTarget)
|
|
20
86
|
.alphaMin(alphaMin)
|
|
21
87
|
.alphaDecay(alphaDecay)
|
|
22
|
-
.velocityDecay(velocityDecay)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
88
|
+
.velocityDecay(velocityDecay);
|
|
89
|
+
runOrResumeSimulation();
|
|
90
|
+
}
|
|
91
|
+
// MARK: Push State
|
|
92
|
+
function pushAlphaToSimulation(alpha) {
|
|
93
|
+
simulation.alpha(alpha);
|
|
94
|
+
}
|
|
95
|
+
function pushNodesToSimulation(nodes) {
|
|
96
|
+
simulation.nodes(cloneData ? structuredClone(nodes) : nodes);
|
|
97
|
+
}
|
|
98
|
+
function pushForcesToSimulation(forces) {
|
|
99
|
+
// Evict obsolete forces:
|
|
100
|
+
Object.keys(previousForces).forEach((name) => {
|
|
101
|
+
if (!(name in forces)) {
|
|
102
|
+
simulation.force(name, null);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
// Add new or overwrite existing forces:
|
|
106
|
+
Object.entries(forces).forEach(([name, force]) => {
|
|
107
|
+
if (!(name in previousForces) || force !== previousForces[name]) {
|
|
29
108
|
simulation.force(name, force);
|
|
30
|
-
});
|
|
31
|
-
for (let i = 0, n = Math.ceil(Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay())); i < n; ++i) {
|
|
32
|
-
simulation.tick();
|
|
33
109
|
}
|
|
34
|
-
|
|
110
|
+
});
|
|
111
|
+
previousForces = forces;
|
|
112
|
+
}
|
|
113
|
+
// MARK: Pull State
|
|
114
|
+
function pullNodesFromSimulation() {
|
|
115
|
+
nodes = simulation.nodes();
|
|
116
|
+
}
|
|
117
|
+
function pullAlphaFromSimulation() {
|
|
118
|
+
alpha = simulation.alpha();
|
|
119
|
+
}
|
|
120
|
+
// MARK: Resume / Pause
|
|
121
|
+
function runOrResumeSimulation() {
|
|
122
|
+
if (_static) {
|
|
123
|
+
runStaticSimulationToCompletion();
|
|
35
124
|
}
|
|
36
125
|
else {
|
|
37
|
-
|
|
38
|
-
Object.entries(forces).forEach(([name, force]) => {
|
|
39
|
-
simulation.force(name, force);
|
|
40
|
-
});
|
|
126
|
+
resumeDynamicSimulation();
|
|
41
127
|
}
|
|
42
128
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
129
|
+
function runStaticSimulationToCompletion() {
|
|
130
|
+
if (stopped) {
|
|
131
|
+
// If a simulation is marked as stopped, then it should not get started.
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!_static) {
|
|
135
|
+
// Only static simulations are run to completion.
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!paused) {
|
|
139
|
+
// Pause any possibly still running dynamic simulation:
|
|
140
|
+
pauseDynamicSimulation();
|
|
141
|
+
}
|
|
142
|
+
const ticks = Math.ceil(Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay()));
|
|
143
|
+
pushAlphaToSimulation(1.0);
|
|
144
|
+
onStart();
|
|
145
|
+
for (let i = 0; i < ticks; ++i) {
|
|
146
|
+
simulation.tick();
|
|
147
|
+
}
|
|
148
|
+
pullNodesFromSimulation();
|
|
149
|
+
pullAlphaFromSimulation();
|
|
150
|
+
onEnd();
|
|
151
|
+
}
|
|
152
|
+
function resumeDynamicSimulation() {
|
|
153
|
+
if (!paused) {
|
|
154
|
+
// No need to restart an already running simulation.
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (stopped) {
|
|
158
|
+
// If a simulation is marked as stopped, then it should not get resumed.
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (_static) {
|
|
162
|
+
// Only dynamic simulations can be resumed.
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
onStart();
|
|
166
|
+
simulation.restart();
|
|
167
|
+
// No need to call `onEnd();` for dynamic simulations
|
|
168
|
+
// as the simulation itself takes care of firing `on:end`,
|
|
169
|
+
// which then gets calls `onEnd();` for us.
|
|
170
|
+
}
|
|
171
|
+
function pauseDynamicSimulation() {
|
|
172
|
+
if (paused) {
|
|
173
|
+
// No need to pause an already paused simulation.
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
simulation.stop();
|
|
177
|
+
onEnd();
|
|
178
|
+
}
|
|
179
|
+
// MARK: Event Listeners
|
|
180
|
+
function onStart() {
|
|
181
|
+
if (!paused) {
|
|
182
|
+
// Avoid double-emissions of `start` event due to race conditions.
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
paused = false;
|
|
186
|
+
dispatch('start');
|
|
187
|
+
}
|
|
188
|
+
function onTick() {
|
|
189
|
+
pullNodesFromSimulation();
|
|
190
|
+
pullAlphaFromSimulation();
|
|
191
|
+
dispatch('tick', {
|
|
192
|
+
alpha,
|
|
193
|
+
alphaTarget,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function onEnd() {
|
|
197
|
+
if (paused) {
|
|
198
|
+
// Avoid double-emissions of `end` event due to race conditions.
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
paused = true;
|
|
202
|
+
dispatch('end');
|
|
203
|
+
}
|
|
47
204
|
</script>
|
|
48
205
|
|
|
49
206
|
<slot {nodes} {simulation} />
|
|
@@ -8,10 +8,19 @@ declare const __propDef: {
|
|
|
8
8
|
alphaDecay?: number;
|
|
9
9
|
alphaMin?: number;
|
|
10
10
|
velocityDecay?: number;
|
|
11
|
-
/**
|
|
11
|
+
/** Stop simulation */ stopped?: boolean;
|
|
12
12
|
/** If true, will only update nodes after simulation has completed */ static?: boolean;
|
|
13
|
+
/** Clone data since simulation mutates original */ cloneData?: boolean;
|
|
13
14
|
};
|
|
14
15
|
events: {
|
|
16
|
+
start: CustomEvent<null>;
|
|
17
|
+
tick: CustomEvent<{
|
|
18
|
+
alpha: number;
|
|
19
|
+
alphaTarget: number;
|
|
20
|
+
}>;
|
|
21
|
+
change: CustomEvent<null>;
|
|
22
|
+
end: CustomEvent<null>;
|
|
23
|
+
} & {
|
|
15
24
|
[evt: string]: CustomEvent<any>;
|
|
16
25
|
};
|
|
17
26
|
slots: {
|
|
@@ -25,5 +34,6 @@ export type ForceSimulationProps = typeof __propDef.props;
|
|
|
25
34
|
export type ForceSimulationEvents = typeof __propDef.events;
|
|
26
35
|
export type ForceSimulationSlots = typeof __propDef.slots;
|
|
27
36
|
export default class ForceSimulation extends SvelteComponentTyped<ForceSimulationProps, ForceSimulationEvents, ForceSimulationSlots> {
|
|
37
|
+
get cloneData(): NonNullable<boolean | undefined>;
|
|
28
38
|
}
|
|
29
39
|
export {};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
const { width, height, padding } =
|
|
1
|
+
<script>import { chartContext } from './ChartContext.svelte';
|
|
2
|
+
const { width, height, padding } = chartContext();
|
|
3
3
|
/** Include padding area */
|
|
4
4
|
export let full = false;
|
|
5
5
|
/** Access underlying `<rect>` element */
|
|
6
|
-
export let rectEl;
|
|
6
|
+
export let rectEl = undefined;
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
9
10
|
<rect
|
|
10
|
-
x={full ? -$padding.left : 0}
|
|
11
|
-
y={full ? -$padding.top : 0}
|
|
12
|
-
width={$width + (full ? $padding
|
|
13
|
-
height={$height + (full ? $padding
|
|
11
|
+
x={full && $padding?.left ? -$padding.left : 0}
|
|
12
|
+
y={full && $padding?.top ? -$padding.top : 0}
|
|
13
|
+
width={$width + (full ? ($padding?.left ?? 0) + ($padding?.right ?? 0) : 0)}
|
|
14
|
+
height={$height + (full ? ($padding?.top ?? 0) + ($padding?.bottom ?? 0) : 0)}
|
|
14
15
|
on:click
|
|
15
16
|
on:pointerdown
|
|
16
17
|
on:dblclick
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import GeoPath from './GeoPath.svelte';
|
|
3
2
|
declare const __propDef: {
|
|
4
3
|
props: {
|
|
5
4
|
[x: string]: any;
|
|
@@ -11,7 +10,7 @@ declare const __propDef: {
|
|
|
11
10
|
pointermove: PointerEvent;
|
|
12
11
|
pointerleave: PointerEvent;
|
|
13
12
|
click: CustomEvent<{
|
|
14
|
-
geoPath:
|
|
13
|
+
geoPath: ReturnType<typeof import("..").geoCurvePath>;
|
|
15
14
|
event: MouseEvent;
|
|
16
15
|
}>;
|
|
17
16
|
} & {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script context="module">import { getContext, setContext } from 'svelte';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
3
|
import {} from 'd3-geo';
|
|
4
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
5
|
import { transformContext } from './TransformContext.svelte';
|
|
5
6
|
export const geoContextKey = Symbol();
|
|
6
7
|
export function geoContext() {
|
|
@@ -11,7 +12,7 @@ function setGeoContext(geo) {
|
|
|
11
12
|
}
|
|
12
13
|
</script>
|
|
13
14
|
|
|
14
|
-
<script>const { width, height } =
|
|
15
|
+
<script>const { width, height } = chartContext();
|
|
15
16
|
/** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */
|
|
16
17
|
export let projection = undefined;
|
|
17
18
|
export let fitGeojson = undefined;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import { type Writable } from 'svelte/store';
|
|
3
|
-
import { type
|
|
3
|
+
import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
|
|
4
4
|
export declare const geoContextKey: unique symbol;
|
|
5
|
-
export type GeoContext = Writable<GeoProjection
|
|
5
|
+
export type GeoContext = Writable<GeoProjection>;
|
|
6
6
|
export declare function geoContext(): GeoContext;
|
|
7
7
|
declare const __propDef: {
|
|
8
8
|
props: {
|
|
9
|
-
/** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */ projection?: (() => GeoProjection
|
|
9
|
+
/** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */ projection?: (() => GeoProjection) | undefined;
|
|
10
10
|
fitGeojson?: GeoPermissibleObjects | undefined;
|
|
11
11
|
/** By default, the map fills to fit the $width and $height. If instead you want a fixed-aspect ratio, like for a server-side rendered map, set that here. */ fixedAspectRatio?: number | undefined;
|
|
12
12
|
clipAngle?: number | undefined;
|
|
@@ -25,14 +25,14 @@ declare const __propDef: {
|
|
|
25
25
|
/** Apply TransformContext to the selected properties. Typically `translate` or `rotate` are mutually selected */ applyTransform?: ("scale" | "translate" | "rotate")[];
|
|
26
26
|
reflectX?: boolean | undefined;
|
|
27
27
|
reflectY?: boolean | undefined;
|
|
28
|
-
/** Exposed to allow binding in Chart */ geo?: Writable<GeoProjection
|
|
28
|
+
/** Exposed to allow binding in Chart */ geo?: Writable<GeoProjection>;
|
|
29
29
|
};
|
|
30
30
|
events: {
|
|
31
31
|
[evt: string]: CustomEvent<any>;
|
|
32
32
|
};
|
|
33
33
|
slots: {
|
|
34
34
|
default: {
|
|
35
|
-
projection: GeoProjection
|
|
35
|
+
projection: GeoProjection;
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { scaleLinear } from 'd3-scale';
|
|
1
|
+
<script>import { scaleLinear } from 'd3-scale';
|
|
3
2
|
import { geoDistance } from 'd3-geo';
|
|
4
3
|
import { geoContext } from './GeoContext.svelte';
|
|
5
4
|
export let link;
|
|
6
|
-
const { width, height } = getContext('LayerCake');
|
|
7
5
|
const geo = geoContext();
|
|
8
6
|
const fade = scaleLinear().domain([-0.1, 0]).range([0, 0.1]);
|
|
9
7
|
const clamper = scaleLinear().domain([0, 1]).range([0, 1]).clamp(true);
|
|
10
|
-
|
|
11
|
-
$: center = $geo.invert($geo.translate());
|
|
8
|
+
$: center = $geo.invert?.($geo.translate()) ?? [0, 0];
|
|
12
9
|
$: source = link.source;
|
|
13
10
|
$: target = link.target;
|
|
14
11
|
$: startDistance = 1.57 - geoDistance(source, center);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>import { createEventDispatcher, getContext } from 'svelte';
|
|
2
2
|
import { geoTransform as d3geoTransform, } from 'd3-geo';
|
|
3
3
|
import { cls } from 'svelte-ux';
|
|
4
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
5
|
import { geoContext } from './GeoContext.svelte';
|
|
5
6
|
import { curveLinearClosed } from 'd3-shape';
|
|
6
7
|
import { geoCurvePath } from '../utils/geo.js';
|
|
@@ -27,7 +28,7 @@ export let curve = curveLinearClosed;
|
|
|
27
28
|
let className = undefined;
|
|
28
29
|
export { className as class };
|
|
29
30
|
const dispatch = createEventDispatcher();
|
|
30
|
-
const { containerWidth, containerHeight, padding } =
|
|
31
|
+
const { containerWidth, containerHeight, padding } = chartContext();
|
|
31
32
|
const canvas = getContext('canvas');
|
|
32
33
|
const geo = geoContext();
|
|
33
34
|
/**
|
|
@@ -58,25 +59,28 @@ $: if (renderContext === 'canvas' && $ctx) {
|
|
|
58
59
|
$ctx.beginPath();
|
|
59
60
|
// Set the context here since setting it in `$: geoPath` is a circular reference
|
|
60
61
|
geoPath = geoCurvePath(_projection, curve, $ctx);
|
|
61
|
-
|
|
62
|
+
if (geojson) {
|
|
63
|
+
geoPath(geojson);
|
|
64
|
+
}
|
|
62
65
|
$ctx.fillStyle =
|
|
63
66
|
fill ??
|
|
64
67
|
(computedStyles.fill !== DEFAULT_FILL ? computedStyles.fill : undefined) ??
|
|
65
68
|
'transparent';
|
|
66
69
|
$ctx.fill();
|
|
67
|
-
$ctx.lineWidth = strokeWidth;
|
|
70
|
+
$ctx.lineWidth = Number(strokeWidth ?? 0);
|
|
68
71
|
$ctx.strokeStyle =
|
|
69
|
-
stroke ?? computedStyles.stroke === 'none' ? 'transparent' : computedStyles.stroke;
|
|
72
|
+
stroke ?? computedStyles.stroke === 'none' ? 'transparent' : computedStyles.stroke ?? '';
|
|
70
73
|
$ctx.stroke();
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
</script>
|
|
74
77
|
|
|
78
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
75
79
|
{#if renderContext === 'svg'}
|
|
76
80
|
<slot {geoPath}>
|
|
77
81
|
<path
|
|
78
82
|
{...$$restProps}
|
|
79
|
-
d={geoPath(geojson)}
|
|
83
|
+
d={geojson ? geoPath(geojson) : ''}
|
|
80
84
|
{fill}
|
|
81
85
|
{stroke}
|
|
82
86
|
stroke-width={strokeWidth}
|
|
@@ -2,11 +2,14 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
import { type GeoIdentityTransform, type GeoPermissibleObjects, type GeoProjection, type GeoTransformPrototype } from 'd3-geo';
|
|
3
3
|
import type { TooltipContextValue } from './TooltipContext.svelte';
|
|
4
4
|
import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
5
|
+
import { geoCurvePath } from '../utils/geo.js';
|
|
5
6
|
declare const __propDef: {
|
|
6
7
|
props: {
|
|
7
8
|
[x: string]: any;
|
|
8
|
-
geojson?: GeoPermissibleObjects;
|
|
9
|
-
render?: ((ctx: CanvasRenderingContext2D,
|
|
9
|
+
geojson?: GeoPermissibleObjects | null | undefined;
|
|
10
|
+
render?: ((ctx: CanvasRenderingContext2D, options: {
|
|
11
|
+
geoPath: ReturnType<typeof geoCurvePath>;
|
|
12
|
+
}) => any) | undefined;
|
|
10
13
|
fill?: string | undefined;
|
|
11
14
|
stroke?: string | undefined;
|
|
12
15
|
strokeWidth?: number | string | undefined;
|
|
@@ -21,7 +24,7 @@ declare const __propDef: {
|
|
|
21
24
|
pointerleave: PointerEvent;
|
|
22
25
|
pointerdown: PointerEvent;
|
|
23
26
|
click: CustomEvent<{
|
|
24
|
-
geoPath:
|
|
27
|
+
geoPath: ReturnType<typeof geoCurvePath>;
|
|
25
28
|
event: MouseEvent;
|
|
26
29
|
}>;
|
|
27
30
|
} & {
|
|
@@ -29,7 +32,7 @@ declare const __propDef: {
|
|
|
29
32
|
};
|
|
30
33
|
slots: {
|
|
31
34
|
default: {
|
|
32
|
-
geoPath: (
|
|
35
|
+
geoPath: import("d3-geo").GeoPath<unknown, GeoPermissibleObjects>;
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
38
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { curveNatural } from 'd3-shape';
|
|
1
|
+
<script>import { curveNatural } from 'd3-shape';
|
|
3
2
|
import { geoOrthographic, geoInterpolate } from 'd3-geo';
|
|
4
3
|
import { geoContext } from './GeoContext.svelte';
|
|
5
4
|
import Spline from './Spline.svelte';
|
|
@@ -16,7 +15,6 @@ export let loft = 1.0;
|
|
|
16
15
|
* @type {CurveFactory | CurveFactoryLineOnly | undefined}
|
|
17
16
|
*/
|
|
18
17
|
export let curve = curveNatural;
|
|
19
|
-
const { width, height } = getContext('LayerCake');
|
|
20
18
|
const geo = geoContext();
|
|
21
19
|
$: loftedProjection = geoOrthographic()
|
|
22
20
|
.translate($geo.translate())
|
|
@@ -27,11 +25,4 @@ $: target = $geo(link.target);
|
|
|
27
25
|
$: middle = loftedProjection(geoInterpolate(link.source, link.target)(0.5));
|
|
28
26
|
</script>
|
|
29
27
|
|
|
30
|
-
<Spline
|
|
31
|
-
data={[source, middle, target]}
|
|
32
|
-
x={(d) => d[0]}
|
|
33
|
-
y={(d) => d[1]}
|
|
34
|
-
defined={(d) => $geo.invert(d)}
|
|
35
|
-
{curve}
|
|
36
|
-
{...$$restProps}
|
|
37
|
-
/>
|
|
28
|
+
<Spline data={[source, middle, target]} x={(d) => d[0]} y={(d) => d[1]} {curve} {...$$restProps} />
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
|
+
// @ts-expect-error
|
|
2
3
|
import { tile as d3Tile } from 'd3-tile';
|
|
4
|
+
import { chartContext } from './ChartContext.svelte';
|
|
3
5
|
import { geoContext } from './GeoContext.svelte';
|
|
4
6
|
import Group from './Group.svelte';
|
|
5
7
|
import TileImage from './TileImage.svelte';
|
|
@@ -8,7 +10,7 @@ export let zoomDelta = 0;
|
|
|
8
10
|
export let tileSize = 256;
|
|
9
11
|
export let disableCache = false;
|
|
10
12
|
export let debug = false;
|
|
11
|
-
const { containerWidth, containerHeight, padding } =
|
|
13
|
+
const { containerWidth, containerHeight, padding } = chartContext();
|
|
12
14
|
const canvas = getContext('canvas');
|
|
13
15
|
const geo = geoContext();
|
|
14
16
|
$: center = $geo([0, 0]) ?? [0, 0];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { tick } from 'svelte';
|
|
2
|
+
import { chartContext } from './ChartContext.svelte';
|
|
2
3
|
import { motionStore } from '../stores/motionStore.js';
|
|
3
|
-
const { width, height } =
|
|
4
|
+
const { width, height } = chartContext();
|
|
4
5
|
/**
|
|
5
6
|
* Translate x
|
|
6
7
|
*/
|
|
@@ -33,6 +34,7 @@ $: if (center || x != null || y != null) {
|
|
|
33
34
|
}
|
|
34
35
|
</script>
|
|
35
36
|
|
|
37
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
36
38
|
<g
|
|
37
39
|
{transform}
|
|
38
40
|
{...$$restProps}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import {} from 'svelte';
|
|
2
2
|
import { max, min } from 'd3-array';
|
|
3
3
|
import { cls, notNull } from 'svelte-ux';
|
|
4
|
-
import {
|
|
4
|
+
import { chartContext } from './ChartContext.svelte';
|
|
5
5
|
import Circle from './Circle.svelte';
|
|
6
6
|
import Line from './Line.svelte';
|
|
7
7
|
import Bar from './Bar.svelte';
|
|
8
8
|
import Rect from './Rect.svelte';
|
|
9
9
|
import { tooltipContext } from './TooltipContext.svelte';
|
|
10
|
-
|
|
10
|
+
import { isScaleBand } from '../utils/scales.js';
|
|
11
|
+
const { flatData, x, xDomain, xScale, xRange, xGet, y, yDomain, yScale, yRange, yGet, rGet, config, } = chartContext();
|
|
11
12
|
const tooltip = tooltipContext();
|
|
12
13
|
/** Highlight specific data (annotate), espect uses tooltip data */
|
|
13
14
|
export let data = undefined;
|
|
@@ -173,6 +174,7 @@ $: if (highlightData) {
|
|
|
173
174
|
{..._area}
|
|
174
175
|
{...typeof area === 'object' ? area : null}
|
|
175
176
|
class={cls(
|
|
177
|
+
// @ts-expect-error
|
|
176
178
|
!area.fill && 'fill-surface-content/5',
|
|
177
179
|
typeof area === 'object' ? area.class : null
|
|
178
180
|
)}
|
|
@@ -185,14 +187,18 @@ $: if (highlightData) {
|
|
|
185
187
|
<slot name="bar" {bar}>
|
|
186
188
|
<Bar
|
|
187
189
|
spring={motion}
|
|
188
|
-
x={typeof bar === 'object' ? bar.x :
|
|
189
|
-
y={typeof bar === 'object' ? bar.y :
|
|
190
|
-
inset={typeof bar === 'object' ? bar.inset :
|
|
191
|
-
stroke={typeof bar === 'object' ? bar.stroke :
|
|
192
|
-
strokeWidth={typeof bar === 'object' ? bar.strokeWidth :
|
|
193
|
-
radius={typeof bar === 'object' ? bar.radius :
|
|
190
|
+
x={typeof bar === 'object' ? bar.x : undefined}
|
|
191
|
+
y={typeof bar === 'object' ? bar.y : undefined}
|
|
192
|
+
inset={typeof bar === 'object' ? bar.inset : undefined}
|
|
193
|
+
stroke={typeof bar === 'object' ? bar.stroke : undefined}
|
|
194
|
+
strokeWidth={typeof bar === 'object' ? bar.strokeWidth : undefined}
|
|
195
|
+
radius={typeof bar === 'object' ? bar.radius : undefined}
|
|
194
196
|
bar={highlightData}
|
|
195
|
-
class={cls(
|
|
197
|
+
class={cls(
|
|
198
|
+
// @ts-expect-error
|
|
199
|
+
!bar.fill && 'fill-primary',
|
|
200
|
+
typeof bar === 'object' ? bar.class : null
|
|
201
|
+
)}
|
|
196
202
|
on:click
|
|
197
203
|
/>
|
|
198
204
|
</slot>
|
|
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
import { type ComponentProps } from 'svelte';
|
|
3
3
|
import Circle from './Circle.svelte';
|
|
4
4
|
import Line from './Line.svelte';
|
|
5
|
+
import Bar from './Bar.svelte';
|
|
5
6
|
import Rect from './Rect.svelte';
|
|
6
7
|
declare const __propDef: {
|
|
7
8
|
props: {
|
|
@@ -10,7 +11,7 @@ declare const __propDef: {
|
|
|
10
11
|
/** Show points and pass props to Circles */ points?: boolean | Partial<ComponentProps<Circle>>;
|
|
11
12
|
/** Show lines and pass props to Lines */ lines?: boolean | Partial<ComponentProps<Line>>;
|
|
12
13
|
/** Show area and pass props to Rect */ area?: boolean | Partial<ComponentProps<Rect>>;
|
|
13
|
-
/** Show bar and pass props to Rect */ bar?: boolean | Partial<ComponentProps<
|
|
14
|
+
/** Show bar and pass props to Rect */ bar?: boolean | Partial<ComponentProps<Bar>>;
|
|
14
15
|
/** Set to false to disable spring transitions */ motion?: boolean;
|
|
15
16
|
};
|
|
16
17
|
events: {
|
|
@@ -30,20 +31,20 @@ declare const __propDef: {
|
|
|
30
31
|
bar: {
|
|
31
32
|
bar: boolean | Partial<{
|
|
32
33
|
[x: string]: any;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
y?:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
bar: Object;
|
|
35
|
+
x?: import("../utils/common").Accessor;
|
|
36
|
+
y?: import("../utils/common").Accessor;
|
|
37
|
+
fill?: string | undefined;
|
|
38
|
+
stroke?: string;
|
|
39
|
+
strokeWidth?: number;
|
|
40
|
+
radius?: number;
|
|
41
|
+
rounded?: "all" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
42
|
+
inset?: number;
|
|
43
|
+
groupBy?: string | undefined;
|
|
44
|
+
groupPaddingInner?: number;
|
|
45
|
+
groupPaddingOuter?: number;
|
|
46
|
+
spring?: ComponentProps<Rect>["spring"];
|
|
47
|
+
tweened?: ComponentProps<Rect>["tweened"];
|
|
47
48
|
}>;
|
|
48
49
|
};
|
|
49
50
|
lines: {
|