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