layerchart 0.54.0 → 0.54.1
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 +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +205 -155
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +45 -34
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +181 -110
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +295 -74
- package/dist/components/Chart.svelte.d.ts +17 -17
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +75 -48
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +81 -70
- package/dist/components/Legend.svelte +105 -74
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +29 -19
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +44 -22
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +50 -42
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +118 -96
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +235 -135
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +128 -77
- package/dist/components/charts/AreaChart.svelte.d.ts +1 -1
- package/dist/components/charts/BarChart.svelte +169 -104
- package/dist/components/charts/BarChart.svelte.d.ts +1 -1
- package/dist/components/charts/LineChart.svelte +87 -43
- package/dist/components/charts/LineChart.svelte.d.ts +1 -1
- package/dist/components/charts/PieChart.svelte +102 -52
- package/dist/components/charts/PieChart.svelte.d.ts +1 -1
- package/dist/components/charts/ScatterChart.svelte +73 -38
- package/dist/components/charts/ScatterChart.svelte.d.ts +1 -1
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +137 -91
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -249
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +39 -33
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +3 -3
- package/package.json +29 -30
|
@@ -1,162 +1,188 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// https://
|
|
7
|
-
// https://
|
|
8
|
-
// https://
|
|
9
|
-
|
|
10
|
-
// https://
|
|
11
|
-
// https://
|
|
12
|
-
|
|
13
|
-
// https://
|
|
14
|
-
// https://
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
TODO:
|
|
4
|
+
- [ ] Allow spring/tweened to be reactive (but ignore value)
|
|
5
|
+
*/
|
|
6
|
+
// https://caniuse.com/#feat=css-conic-gradients
|
|
7
|
+
// https://css-tricks.com/snippets/css/css-conic-gradient/
|
|
8
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/conic-gradient
|
|
9
|
+
|
|
10
|
+
// https://stackoverflow.com/questions/2465405/svg-angular-gradient
|
|
11
|
+
// https://stackoverflow.com/questions/18206361/svg-multiple-color-on-circle-stroke
|
|
12
|
+
|
|
13
|
+
// https://bl.ocks.org/mbostock/4163057
|
|
14
|
+
// https://github.com/d3/d3/issues/2427#issuecomment-100759055
|
|
15
|
+
// https://github.com/mnsht/gradient-path
|
|
16
|
+
|
|
17
|
+
// https://svelte.dev/repl/09711e43a1264ba18945d7db7cab9335?version=3.38.2
|
|
18
|
+
// https://codepen.io/simeydotme/pen/rrOEmO/
|
|
19
|
+
|
|
20
|
+
import { tick } from 'svelte';
|
|
21
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
22
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
23
|
+
import { arc as d3arc } from 'd3-shape';
|
|
24
|
+
import { scaleLinear } from 'd3-scale';
|
|
25
|
+
import { min, max } from 'd3-array';
|
|
26
|
+
|
|
27
|
+
import { chartContext } from './ChartContext.svelte';
|
|
28
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
29
|
+
import { degreesToRadians } from '../utils/math.js';
|
|
30
|
+
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
31
|
+
|
|
32
|
+
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
33
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
34
|
+
|
|
35
|
+
export let value = 0;
|
|
36
|
+
export let initialValue = value;
|
|
37
|
+
let tweened_value = motionStore(initialValue, { spring, tweened });
|
|
38
|
+
|
|
39
|
+
$: tick().then(() => {
|
|
28
40
|
tweened_value.set(value);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export let domain = [0, 100];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Range [min,max] in degrees. See also startAngle/endAngle
|
|
47
|
+
*/
|
|
48
|
+
export let range = [0, 360]; // degrees
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Start angle in radians
|
|
52
|
+
*/
|
|
53
|
+
export let startAngle: number | undefined = undefined;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* End angle in radians
|
|
57
|
+
*/
|
|
58
|
+
export let endAngle: number | undefined = undefined;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Define innerRadius. Defaults to yRange min
|
|
62
|
+
* • value >= 1: discrete value
|
|
63
|
+
* • value < 1: percent of `outerRadius`
|
|
64
|
+
* • value < 0: offset of `outerRadius`
|
|
65
|
+
*/
|
|
66
|
+
export let innerRadius: number | undefined = undefined;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Define outerRadius. Defaults to yRange max / 2 (ie. chart height / 2)
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* Define outerRadius. Defaults to yRange max (ie. chart height / 2)
|
|
73
|
+
* • value >= 1: discrete value
|
|
74
|
+
* • value < 1: percent of chart height / 2
|
|
75
|
+
* • value < 0: offset of chart height / 2
|
|
76
|
+
*/
|
|
77
|
+
export let outerRadius: number | undefined = undefined;
|
|
78
|
+
|
|
79
|
+
export let cornerRadius = 0;
|
|
80
|
+
export let padAngle = 0;
|
|
81
|
+
// export let padRadius = 0;
|
|
82
|
+
|
|
83
|
+
export let track: boolean | SVGAttributes<SVGPathElement> = false;
|
|
84
|
+
|
|
85
|
+
const { yRange } = chartContext();
|
|
86
|
+
|
|
87
|
+
$: scale = scaleLinear().domain(domain).range(range);
|
|
88
|
+
|
|
89
|
+
function getOuterRadius(outerRadius: number | undefined, chartRadius: number) {
|
|
67
90
|
if (!outerRadius) {
|
|
68
|
-
|
|
91
|
+
return chartRadius;
|
|
92
|
+
} else if (outerRadius > 1) {
|
|
93
|
+
// discrete value
|
|
94
|
+
return outerRadius;
|
|
95
|
+
} else if (outerRadius > 0) {
|
|
96
|
+
// percent of `chartRadius`
|
|
97
|
+
return chartRadius * outerRadius;
|
|
98
|
+
} else if (outerRadius < 0) {
|
|
99
|
+
// offset of `chartRadius`
|
|
100
|
+
return chartRadius + outerRadius;
|
|
101
|
+
} else {
|
|
102
|
+
// 0
|
|
103
|
+
return outerRadius;
|
|
69
104
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// percent of `chartRadius`
|
|
76
|
-
return chartRadius * outerRadius;
|
|
77
|
-
}
|
|
78
|
-
else if (outerRadius < 0) {
|
|
79
|
-
// offset of `chartRadius`
|
|
80
|
-
return chartRadius + outerRadius;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
// 0
|
|
84
|
-
return outerRadius;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
$: _outerRadius = getOuterRadius(outerRadius, (max($yRange) ?? 0) / 2);
|
|
88
|
-
function getInnerRadius(innerRadius, outerRadius) {
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
$: _outerRadius = getOuterRadius(outerRadius, (max<number>($yRange) ?? 0) / 2);
|
|
108
|
+
|
|
109
|
+
function getInnerRadius(innerRadius: number | undefined, outerRadius: number) {
|
|
89
110
|
if (innerRadius == null) {
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
else
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
// 0
|
|
106
|
-
return innerRadius;
|
|
111
|
+
return Math.min(...$yRange);
|
|
112
|
+
} else if (innerRadius > 1) {
|
|
113
|
+
// discrete value
|
|
114
|
+
return innerRadius;
|
|
115
|
+
} else if (innerRadius > 0) {
|
|
116
|
+
// percent of `outerRadius`
|
|
117
|
+
return outerRadius * innerRadius;
|
|
118
|
+
} else if (innerRadius < 0) {
|
|
119
|
+
// offset of `outerRadius`
|
|
120
|
+
return outerRadius + innerRadius;
|
|
121
|
+
} else {
|
|
122
|
+
// 0
|
|
123
|
+
return innerRadius;
|
|
107
124
|
}
|
|
108
|
-
}
|
|
109
|
-
$: _innerRadius = getInnerRadius(innerRadius, _outerRadius);
|
|
110
|
-
|
|
125
|
+
}
|
|
126
|
+
$: _innerRadius = getInnerRadius(innerRadius, _outerRadius);
|
|
127
|
+
|
|
128
|
+
$: arc = d3arc()
|
|
111
129
|
.innerRadius(_innerRadius)
|
|
112
130
|
.outerRadius(_outerRadius)
|
|
113
131
|
.startAngle(startAngle ?? degreesToRadians(range[0]))
|
|
114
132
|
.endAngle(endAngle ?? degreesToRadians(scale($tweened_value)))
|
|
115
133
|
.cornerRadius(cornerRadius)
|
|
116
|
-
.padAngle(padAngle);
|
|
117
|
-
// .padRadius(padRadius);
|
|
118
|
-
|
|
134
|
+
.padAngle(padAngle) as Function;
|
|
135
|
+
// .padRadius(padRadius);
|
|
136
|
+
|
|
137
|
+
$: trackArc = d3arc()
|
|
119
138
|
.innerRadius(_innerRadius)
|
|
120
139
|
.outerRadius(_outerRadius)
|
|
121
140
|
.startAngle(startAngle ?? degreesToRadians(range[0]))
|
|
122
141
|
.endAngle(endAngle ?? degreesToRadians(range[1]))
|
|
123
142
|
.cornerRadius(cornerRadius)
|
|
124
|
-
.padAngle(padAngle);
|
|
125
|
-
// .padRadius(padRadius);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
143
|
+
.padAngle(padAngle) as Function;
|
|
144
|
+
// .padRadius(padRadius);
|
|
145
|
+
|
|
146
|
+
// @ts-expect-error
|
|
147
|
+
$: trackArcCentroid = trackArc.centroid();
|
|
148
|
+
// $: console.log(trackArcCentroid)
|
|
149
|
+
|
|
150
|
+
let trackArcEl: SVGPathElement | undefined = undefined;
|
|
151
|
+
$: boundingBox = trackArcEl ? trackArcEl.getBBox() : ({} as DOMRect);
|
|
152
|
+
|
|
153
|
+
// $: labelArcCenterOffset = {
|
|
154
|
+
// x: outerRadius - boundingBox.width / 2,
|
|
155
|
+
// // x: 0,
|
|
156
|
+
// y: (outerRadius - boundingBox.height / 2) * -1,
|
|
157
|
+
// };
|
|
158
|
+
// $: console.log(labelArcCenterOffset)
|
|
159
|
+
|
|
160
|
+
// $: labelArcBottomOffset = {
|
|
161
|
+
// // x: outerRadius - boundingBox.width / 2,
|
|
162
|
+
// x: outerRadius - boundingBox.width / 2,
|
|
163
|
+
// // x: 0,
|
|
164
|
+
// // y: (outerRadius - boundingBox.height) * -1
|
|
165
|
+
// y: (outerRadius - boundingBox.height) * -1,
|
|
166
|
+
// };
|
|
167
|
+
// $: console.log(labelArcBottomOffset)
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Offset arc from center
|
|
171
|
+
*/
|
|
172
|
+
export let offset = 0;
|
|
173
|
+
$: angle = ((startAngle ?? 0) + (endAngle ?? 0)) / 2;
|
|
174
|
+
$: xOffset = Math.sin(angle) * offset;
|
|
175
|
+
$: yOffset = -Math.cos(angle) * offset;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Tooltip context to setup pointer events to show tooltip for related data. Must set `data` prop as well
|
|
179
|
+
*/
|
|
180
|
+
export let tooltip: TooltipContextValue | undefined = undefined;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Data to set when showing tooltip
|
|
184
|
+
*/
|
|
185
|
+
export let data: any = undefined;
|
|
160
186
|
</script>
|
|
161
187
|
|
|
162
188
|
{#if track}
|
|
@@ -1,82 +1,111 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { type ComponentProps } from 'svelte';
|
|
3
|
+
import type { tweened as tweenedStore } from 'svelte/motion';
|
|
4
|
+
import { type Area, area as d3Area, areaRadial } from 'd3-shape';
|
|
5
|
+
import type { CurveFactory } from 'd3-shape';
|
|
6
|
+
import { max, min } from 'd3-array';
|
|
7
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
8
|
+
|
|
9
|
+
import { cls } from '@layerstack/tailwind';
|
|
10
|
+
|
|
11
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
12
|
+
|
|
13
|
+
import { chartContext } from './ChartContext.svelte';
|
|
14
|
+
import Spline from './Spline.svelte';
|
|
15
|
+
import { accessor, type Accessor } from '../utils/common.js';
|
|
16
|
+
import { isScaleBand } from '../utils/scales.js';
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
data: contextData,
|
|
20
|
+
xScale,
|
|
21
|
+
yScale,
|
|
22
|
+
x: contextX,
|
|
23
|
+
y,
|
|
24
|
+
yDomain,
|
|
25
|
+
yRange,
|
|
26
|
+
config,
|
|
27
|
+
radial,
|
|
28
|
+
} = chartContext();
|
|
29
|
+
|
|
30
|
+
/** Override data instead of using context */
|
|
31
|
+
export let data: any = undefined;
|
|
32
|
+
|
|
33
|
+
/** Pass `<path d={...} />` explicitly instead of calculating from data / context */
|
|
34
|
+
export let pathData: string | undefined | null = undefined;
|
|
35
|
+
|
|
36
|
+
/** Override x accessor */
|
|
37
|
+
export let x: Accessor = undefined;
|
|
38
|
+
|
|
39
|
+
/** Override y0 accessor. Defaults to max($yRange) */
|
|
40
|
+
export let y0: Accessor = undefined;
|
|
41
|
+
/** Override y1 accessor. Defaults to y accessor */
|
|
42
|
+
export let y1: Accessor = undefined;
|
|
43
|
+
|
|
44
|
+
/** Interpolate path data using d3-interpolate-path */
|
|
45
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
46
|
+
|
|
47
|
+
export let clipPath: string | undefined = undefined;
|
|
48
|
+
|
|
49
|
+
export let curve: CurveFactory | undefined = undefined;
|
|
50
|
+
export let defined: Parameters<Area<any>['defined']>[0] | undefined = undefined;
|
|
51
|
+
|
|
52
|
+
/** Enable showing line */
|
|
53
|
+
export let line: boolean | Partial<ComponentProps<Spline>> = false;
|
|
54
|
+
|
|
55
|
+
const xAccessor = x ? accessor(x) : $contextX;
|
|
56
|
+
const y0Accessor = y0 ? accessor(y0) : (d: any) => min($yDomain);
|
|
57
|
+
const y1Accessor = y1 ? accessor(y1) : $y;
|
|
58
|
+
|
|
59
|
+
$: xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
|
|
60
|
+
$: yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
|
|
61
|
+
|
|
62
|
+
$: tweenedOptions = tweened
|
|
35
63
|
? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
|
|
36
64
|
: false;
|
|
37
|
-
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
38
|
-
$: {
|
|
65
|
+
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
66
|
+
$: {
|
|
39
67
|
const path = $radial
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let value = max($yRange)
|
|
68
|
+
? areaRadial()
|
|
69
|
+
.angle((d) => $xScale(xAccessor(d)))
|
|
70
|
+
.innerRadius((d) => $yScale(y0Accessor(d)))
|
|
71
|
+
.outerRadius((d) => $yScale(y1Accessor(d)))
|
|
72
|
+
: d3Area()
|
|
73
|
+
.x((d) => $xScale(xAccessor(d)) + xOffset)
|
|
74
|
+
.y0((d) => {
|
|
75
|
+
let value = max<number>($yRange)!;
|
|
48
76
|
if (y0) {
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
value = $yScale($y(d)[0]);
|
|
77
|
+
value = $yScale(y0Accessor(d));
|
|
78
|
+
} else if (Array.isArray($config.y) && $config.y[0] === 0) {
|
|
79
|
+
// Use first value if `y` defined as an array (ex. `<Chart y={[0,1]}>`)
|
|
80
|
+
// TODO: Would be nice if this also handled multi-series (<Chart y={['apples', 'bananas', 'oranges']}>) as well as delta values (<Chart y={['baseline', 'value']}>)
|
|
81
|
+
value = $yScale($y(d)[0]);
|
|
55
82
|
}
|
|
83
|
+
|
|
56
84
|
return value + yOffset;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let value = max($yRange)
|
|
85
|
+
})
|
|
86
|
+
.y1((d) => {
|
|
87
|
+
let value = max<number>($yRange)!;
|
|
60
88
|
if (y1) {
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Expect single value defined for `y` (ex. `<Chart y="value">`)
|
|
70
|
-
value = $yScale($y(d));
|
|
89
|
+
value = $yScale(y1Accessor(d));
|
|
90
|
+
} else if (Array.isArray($config.y) && $config.y[1] === 1) {
|
|
91
|
+
// Use second value if `y` defined as an array (ex. `<Chart y={[0,1]}>`)
|
|
92
|
+
// TODO: Would be nice if this also handled multi-series (<Chart y={['apples', 'bananas', 'oranges']}>) as well as delta values (<Chart y={['baseline', 'value']}>)
|
|
93
|
+
value = $yScale($y(d)[1]);
|
|
94
|
+
} else {
|
|
95
|
+
// Expect single value defined for `y` (ex. `<Chart y="value">`)
|
|
96
|
+
value = $yScale($y(d));
|
|
71
97
|
}
|
|
98
|
+
|
|
72
99
|
return value + yOffset;
|
|
73
|
-
|
|
100
|
+
});
|
|
101
|
+
|
|
74
102
|
path.defined(defined ?? ((d) => xAccessor(d) != null && y1Accessor(d) != null));
|
|
75
|
-
|
|
76
|
-
|
|
103
|
+
|
|
104
|
+
if (curve) path.curve(curve);
|
|
105
|
+
|
|
77
106
|
const d = pathData ?? path(data ?? $contextData);
|
|
78
107
|
tweened_d.set(d ?? '');
|
|
79
|
-
}
|
|
108
|
+
}
|
|
80
109
|
</script>
|
|
81
110
|
|
|
82
111
|
{#if line}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import { type ComponentProps } from 'svelte';
|
|
3
3
|
import type { tweened as tweenedStore } from 'svelte/motion';
|
|
4
|
+
import { type Area } from 'd3-shape';
|
|
4
5
|
import type { CurveFactory } from 'd3-shape';
|
|
5
6
|
import Spline from './Spline.svelte';
|
|
6
7
|
import { type Accessor } from '../utils/common.js';
|