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.
Files changed (99) 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 +181 -110
  10. package/dist/components/Calendar.svelte +51 -38
  11. package/dist/components/Chart.svelte +295 -74
  12. package/dist/components/Chart.svelte.d.ts +17 -17
  13. package/dist/components/ChartClipPath.svelte +8 -5
  14. package/dist/components/ChartContext.svelte +243 -93
  15. package/dist/components/ChartContext.svelte.d.ts +15 -23
  16. package/dist/components/Circle.svelte +25 -16
  17. package/dist/components/CircleClipPath.svelte +16 -10
  18. package/dist/components/ClipPath.svelte +11 -7
  19. package/dist/components/ColorRamp.svelte +12 -10
  20. package/dist/components/ForceSimulation.svelte +185 -116
  21. package/dist/components/Frame.svelte +10 -6
  22. package/dist/components/GeoCircle.svelte +15 -9
  23. package/dist/components/GeoContext.svelte +109 -62
  24. package/dist/components/GeoEdgeFade.svelte +20 -14
  25. package/dist/components/GeoPath.svelte +107 -69
  26. package/dist/components/GeoPoint.svelte +32 -18
  27. package/dist/components/GeoSpline.svelte +30 -22
  28. package/dist/components/GeoTile.svelte +40 -30
  29. package/dist/components/GeoVisible.svelte +10 -7
  30. package/dist/components/Graticule.svelte +14 -8
  31. package/dist/components/Grid.svelte +75 -48
  32. package/dist/components/Group.svelte +43 -31
  33. package/dist/components/Highlight.svelte +284 -243
  34. package/dist/components/HitCanvas.svelte +75 -42
  35. package/dist/components/Hull.svelte +40 -20
  36. package/dist/components/Labels.svelte +81 -70
  37. package/dist/components/Legend.svelte +105 -74
  38. package/dist/components/Legend.svelte.d.ts +1 -1
  39. package/dist/components/Line.svelte +29 -19
  40. package/dist/components/LinearGradient.svelte +21 -15
  41. package/dist/components/Link.svelte +44 -22
  42. package/dist/components/MonthPath.svelte +23 -16
  43. package/dist/components/MotionPath.svelte +34 -25
  44. package/dist/components/Pack.svelte +21 -14
  45. package/dist/components/Partition.svelte +35 -20
  46. package/dist/components/Pattern.svelte +8 -6
  47. package/dist/components/Pie.svelte +76 -57
  48. package/dist/components/Point.svelte +11 -7
  49. package/dist/components/Points.svelte +178 -143
  50. package/dist/components/RadialGradient.svelte +25 -18
  51. package/dist/components/Rect.svelte +33 -19
  52. package/dist/components/RectClipPath.svelte +16 -11
  53. package/dist/components/Rule.svelte +50 -42
  54. package/dist/components/Sankey.svelte +55 -30
  55. package/dist/components/Spline.svelte +118 -96
  56. package/dist/components/Text.svelte +137 -104
  57. package/dist/components/Threshold.svelte +18 -7
  58. package/dist/components/TileImage.svelte +56 -50
  59. package/dist/components/TransformContext.svelte +235 -135
  60. package/dist/components/TransformControls.svelte +57 -29
  61. package/dist/components/TransformControls.svelte.d.ts +1 -1
  62. package/dist/components/Tree.svelte +33 -23
  63. package/dist/components/Treemap.svelte +69 -41
  64. package/dist/components/Voronoi.svelte +55 -28
  65. package/dist/components/charts/AreaChart.svelte +128 -77
  66. package/dist/components/charts/AreaChart.svelte.d.ts +1 -1
  67. package/dist/components/charts/BarChart.svelte +169 -104
  68. package/dist/components/charts/BarChart.svelte.d.ts +1 -1
  69. package/dist/components/charts/LineChart.svelte +87 -43
  70. package/dist/components/charts/LineChart.svelte.d.ts +1 -1
  71. package/dist/components/charts/PieChart.svelte +102 -52
  72. package/dist/components/charts/PieChart.svelte.d.ts +1 -1
  73. package/dist/components/charts/ScatterChart.svelte +73 -38
  74. package/dist/components/charts/ScatterChart.svelte.d.ts +1 -1
  75. package/dist/components/layout/Canvas.svelte +63 -43
  76. package/dist/components/layout/Html.svelte +28 -18
  77. package/dist/components/layout/Svg.svelte +47 -32
  78. package/dist/components/tooltip/Tooltip.svelte +137 -91
  79. package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
  80. package/dist/components/tooltip/TooltipContext.svelte +315 -249
  81. package/dist/components/tooltip/TooltipHeader.svelte +9 -3
  82. package/dist/components/tooltip/TooltipItem.svelte +17 -9
  83. package/dist/components/tooltip/TooltipList.svelte +2 -1
  84. package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
  85. package/dist/docs/Blockquote.svelte +4 -3
  86. package/dist/docs/Code.svelte +15 -8
  87. package/dist/docs/CurveMenuField.svelte +17 -12
  88. package/dist/docs/GeoDebug.svelte +13 -9
  89. package/dist/docs/Header1.svelte +2 -1
  90. package/dist/docs/Json.svelte +6 -4
  91. package/dist/docs/Layout.svelte +6 -6
  92. package/dist/docs/PathDataMenuField.svelte +52 -44
  93. package/dist/docs/Preview.svelte +39 -33
  94. package/dist/docs/TilesetField.svelte +80 -62
  95. package/dist/docs/TransformDebug.svelte +8 -5
  96. package/dist/docs/ViewSourceButton.svelte +13 -9
  97. package/dist/stores/motionStore.d.ts +1 -1
  98. package/dist/utils/scales.d.ts +3 -3
  99. package/package.json +29 -30
@@ -1,118 +1,178 @@
1
- <script generics="TData">import {} from 'svelte';
2
- import { scaleBand, scaleOrdinal, scaleLinear } from 'd3-scale';
3
- import { stack, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape';
4
- import { sum } from 'd3-array';
5
- import { format } from '@layerstack/utils';
6
- import Axis from '../Axis.svelte';
7
- import Bars from '../Bars.svelte';
8
- import Chart from '../Chart.svelte';
9
- import Grid from '../Grid.svelte';
10
- import Highlight from '../Highlight.svelte';
11
- import Labels from '../Labels.svelte';
12
- import Legend from '../Legend.svelte';
13
- import Rule from '../Rule.svelte';
14
- import Svg from '../layout/Svg.svelte';
15
- import * as Tooltip from '../tooltip/index.js';
16
- import { accessor, chartDataArray } from '../../utils/common.js';
17
- export let data = [];
18
- export let x = undefined;
19
- export let y = undefined;
20
- export let orientation = 'vertical';
21
- $: isVertical = orientation === 'vertical';
22
- export let series = [
1
+ <script lang="ts" generics="TData">
2
+ import { type ComponentProps } from 'svelte';
3
+ import { scaleBand, scaleOrdinal, scaleLinear } from 'd3-scale';
4
+ import { stack, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape';
5
+ import { sum } from 'd3-array';
6
+ import { format } from '@layerstack/utils';
7
+
8
+ import Axis from '../Axis.svelte';
9
+ import Bars from '../Bars.svelte';
10
+ import Chart from '../Chart.svelte';
11
+ import Grid from '../Grid.svelte';
12
+ import Highlight from '../Highlight.svelte';
13
+ import Labels from '../Labels.svelte';
14
+ import Legend from '../Legend.svelte';
15
+ import Rule from '../Rule.svelte';
16
+ import Svg from '../layout/Svg.svelte';
17
+ import * as Tooltip from '../tooltip/index.js';
18
+
19
+ import { accessor, chartDataArray, type Accessor } from '../../utils/common.js';
20
+
21
+ type ChartProps = ComponentProps<Chart<TData>>;
22
+
23
+ interface $$Props extends ChartProps {
24
+ axis?: typeof axis;
25
+ grid?: typeof grid;
26
+ bandPadding?: typeof bandPadding;
27
+ groupPadding?: typeof groupPadding;
28
+ labels?: typeof labels;
29
+ legend?: typeof legend;
30
+ orientation?: typeof orientation;
31
+ props?: typeof props;
32
+ rule?: typeof rule;
33
+ series?: typeof series;
34
+ seriesLayout?: typeof seriesLayout;
35
+ }
36
+
37
+ export let data: $$Props['data'] = [];
38
+ export let x: Accessor<TData> = undefined;
39
+ export let y: Accessor<TData> = undefined;
40
+
41
+ export let orientation: 'vertical' | 'horizontal' = 'vertical';
42
+ $: isVertical = orientation === 'vertical';
43
+
44
+ export let series: {
45
+ key: string;
46
+ label?: string;
47
+ value?: Accessor<TData>;
48
+ /** Provider series data, else uses chart data (with value/key accessor) */
49
+ data?: TData[];
50
+ color?: string;
51
+ props?: Partial<ComponentProps<Bars>>;
52
+ }[] = [
23
53
  {
24
- key: 'default',
25
- value: orientation === 'vertical' ? y : x,
54
+ key: 'default',
55
+ value: orientation === 'vertical' ? y : x,
26
56
  },
27
- ];
28
- $: isDefaultSeries = series.length === 1 && series[0].key === 'default';
29
- /** Determine how to layout series. Overlap (default), stack, or group side by side */
30
- export let seriesLayout = 'overlap';
31
- $: stackSeries = seriesLayout.startsWith('stack');
32
- $: groupSeries = seriesLayout === 'group';
33
- export let axis = true;
34
- export let rule = true;
35
- export let grid = true;
36
- export let labels = false;
37
- export let legend = false;
38
- /** Padding between primary x or y bands/bars, applied to scaleBand().padding() */
39
- export let bandPadding = 0.4;
40
- /** Padding between group/series items when using 'seriesLayout="group"', applied to scaleBand().padding() */
41
- export let groupPadding = 0;
42
- $: xScale = isVertical ? scaleBand().padding(bandPadding) : scaleLinear();
43
- $: xBaseline = isVertical ? undefined : 0;
44
- $: yScale = isVertical ? scaleLinear() : scaleBand().padding(bandPadding);
45
- $: yBaseline = isVertical ? 0 : undefined;
46
- let x1Scale;
47
- let x1Domain;
48
- let x1Range;
49
- let y1Scale;
50
- let y1Domain;
51
- let y1Range;
52
- $: if (seriesLayout === 'group') {
57
+ ];
58
+ $: isDefaultSeries = series.length === 1 && series[0].key === 'default';
59
+
60
+ /** Determine how to layout series. Overlap (default), stack, or group side by side */
61
+ export let seriesLayout: 'overlap' | 'group' | 'stack' | 'stackExpand' | 'stackDiverging' =
62
+ 'overlap';
63
+ $: stackSeries = seriesLayout.startsWith('stack');
64
+ $: groupSeries = seriesLayout === 'group';
65
+
66
+ export let axis: ComponentProps<Axis> | 'x' | 'y' | boolean = true;
67
+ export let rule: ComponentProps<Rule> | boolean = true;
68
+ export let grid: ComponentProps<Grid> | boolean = true;
69
+ export let labels: ComponentProps<Labels> | boolean = false;
70
+ export let legend: ComponentProps<Legend> | boolean = false;
71
+
72
+ /** Padding between primary x or y bands/bars, applied to scaleBand().padding() */
73
+ export let bandPadding = 0.4;
74
+ /** Padding between group/series items when using 'seriesLayout="group"', applied to scaleBand().padding() */
75
+ export let groupPadding = 0;
76
+
77
+ $: xScale = isVertical ? scaleBand().padding(bandPadding) : scaleLinear();
78
+ $: xBaseline = isVertical ? undefined : 0;
79
+
80
+ $: yScale = isVertical ? scaleLinear() : scaleBand().padding(bandPadding);
81
+ $: yBaseline = isVertical ? 0 : undefined;
82
+
83
+ let x1Scale: ChartProps['x1Scale'];
84
+ let x1Domain: ChartProps['x1Domain'];
85
+ let x1Range: ChartProps['x1Range'];
86
+
87
+ let y1Scale: ChartProps['y1Scale'];
88
+ let y1Domain: ChartProps['y1Domain'];
89
+ let y1Range: ChartProps['y1Range'];
90
+
91
+ $: if (seriesLayout === 'group') {
53
92
  if (isVertical) {
54
- x1Scale = scaleBand().padding(groupPadding);
55
- x1Domain = series.map((s) => s.key);
56
- x1Range = ({ xScale }) => [0, xScale.bandwidth?.()];
57
- }
58
- else {
59
- y1Scale = scaleBand().padding(groupPadding);
60
- y1Domain = series.map((s) => s.key);
61
- y1Range = ({ yScale }) => [0, yScale.bandwidth?.()];
93
+ x1Scale = scaleBand().padding(groupPadding);
94
+ x1Domain = series.map((s) => s.key);
95
+ x1Range = ({ xScale }) => [0, xScale.bandwidth?.()];
96
+ } else {
97
+ y1Scale = scaleBand().padding(groupPadding);
98
+ y1Domain = series.map((s) => s.key);
99
+ y1Range = ({ yScale }) => [0, yScale.bandwidth?.()];
62
100
  }
63
- }
64
- export let props = {};
65
- $: allSeriesData = series
66
- .flatMap((s) => s.data?.map((d) => {
67
- return { seriesKey: s.key, ...d };
68
- }))
69
- .filter((d) => d);
70
- $: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data));
71
- $: if (stackSeries) {
101
+ }
102
+
103
+ export let props: {
104
+ xAxis?: Partial<ComponentProps<Axis>>;
105
+ yAxis?: Partial<ComponentProps<Axis>>;
106
+ grid?: Partial<ComponentProps<Grid>>;
107
+ rule?: Partial<ComponentProps<Rule>>;
108
+ bars?: Partial<ComponentProps<Bars>>;
109
+ legend?: Partial<ComponentProps<Legend>>;
110
+ highlight?: Partial<ComponentProps<Highlight>>;
111
+ labels?: Partial<ComponentProps<Labels>>;
112
+ } = {};
113
+
114
+ $: allSeriesData = series
115
+ .flatMap((s) =>
116
+ s.data?.map((d) => {
117
+ return { seriesKey: s.key, ...d };
118
+ })
119
+ )
120
+ .filter((d) => d) as Array<TData & { stackData?: any }>;
121
+
122
+ $: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data)) as Array<
123
+ TData & { stackData?: any }
124
+ >;
125
+
126
+ $: if (stackSeries) {
72
127
  const seriesKeys = series.map((s) => s.key);
73
128
  // const stackData = stack().keys(seriesKeys)(chartDataArray(data)) as any[];
74
- const offset = seriesLayout === 'stackExpand'
129
+
130
+ const offset =
131
+ seriesLayout === 'stackExpand'
75
132
  ? stackOffsetExpand
76
133
  : seriesLayout === 'stackDiverging'
77
- ? stackOffsetDiverging
78
- : stackOffsetNone;
134
+ ? stackOffsetDiverging
135
+ : stackOffsetNone;
79
136
  const stackData = stack()
80
- .keys(seriesKeys)
81
- .value((d, key) => {
82
- const s = series.find((d) => d.key === key);
83
- return accessor(s.value ?? s.key)(d);
84
- })
85
- .offset(offset)(chartDataArray(data));
137
+ .keys(seriesKeys)
138
+ .value((d, key) => {
139
+ const s = series.find((d) => d.key === key)!;
140
+ return accessor(s.value ?? s.key)(d as any);
141
+ })
142
+ .offset(offset)(chartDataArray(data)) as any[];
143
+
86
144
  chartData = chartData.map((d, i) => {
87
- return {
88
- ...d,
89
- stackData: stackData.map((sd) => sd[i]),
90
- };
145
+ return {
146
+ ...d,
147
+ stackData: stackData.map((sd) => sd[i]),
148
+ };
91
149
  });
92
- }
93
- function getBarsProps(s, i) {
94
- const barsProps = {
95
- data: s.data,
96
- x: !isVertical
97
- ? stackSeries
98
- ? (d) => d.stackData[i]
99
- : (s.value ?? (s.data ? undefined : s.key))
100
- : undefined,
101
- y: isVertical
102
- ? stackSeries
103
- ? (d) => d.stackData[i]
104
- : (s.value ?? (s.data ? undefined : s.key))
105
- : undefined,
106
- x1: isVertical && groupSeries ? (d) => s.value ?? s.key : undefined,
107
- y1: !isVertical && groupSeries ? (d) => s.value ?? s.key : undefined,
108
- radius: 4,
109
- strokeWidth: 1,
110
- fill: s.color,
111
- ...props.bars,
112
- ...s.props,
150
+ }
151
+
152
+ function getBarsProps(s: (typeof series)[number], i: number) {
153
+ const barsProps: ComponentProps<Bars> = {
154
+ data: s.data,
155
+ x: !isVertical
156
+ ? stackSeries
157
+ ? (d) => d.stackData[i]
158
+ : (s.value ?? (s.data ? undefined : s.key))
159
+ : undefined,
160
+ y: isVertical
161
+ ? stackSeries
162
+ ? (d) => d.stackData[i]
163
+ : (s.value ?? (s.data ? undefined : s.key))
164
+ : undefined,
165
+ x1: isVertical && groupSeries ? (d) => s.value ?? s.key : undefined,
166
+ y1: !isVertical && groupSeries ? (d) => s.value ?? s.key : undefined,
167
+ radius: 4,
168
+ strokeWidth: 1,
169
+ fill: s.color,
170
+ ...props.bars,
171
+ ...s.props,
113
172
  };
173
+
114
174
  return barsProps;
115
- }
175
+ }
116
176
  </script>
117
177
 
118
178
  <Chart
@@ -218,7 +278,12 @@ function getBarsProps(s, i) {
218
278
  {/if}
219
279
 
220
280
  {#if rule}
221
- <Rule x={0} y={0} {...typeof rule === 'object' ? rule : null} {...props.rule} />
281
+ <Rule
282
+ x={isVertical ? false : 0}
283
+ y={isVertical ? 0 : false}
284
+ {...typeof rule === 'object' ? rule : null}
285
+ {...props.rule}
286
+ />
222
287
  {/if}
223
288
  {/if}
224
289
  </slot>
@@ -270,7 +335,7 @@ function getBarsProps(s, i) {
270
335
  <Tooltip.Item
271
336
  label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
272
337
  value={valueAccessor(data)}
273
- color={s.color ?? cScale(c(data))}
338
+ color={s.color ?? cScale?.(c(data))}
274
339
  {format}
275
340
  valueAlign="right"
276
341
  />
@@ -254,7 +254,7 @@ declare class __sveltets_Render<TData> {
254
254
  tickValues?: any[] | undefined;
255
255
  tickFontSize?: number | undefined;
256
256
  tickLength?: number | undefined;
257
- placement?: ("left" | "right" | "center" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
257
+ placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
258
258
  orientation?: ("horizontal" | "vertical") | undefined;
259
259
  variant?: ("ramp" | "swatches") | undefined;
260
260
  classes?: {
@@ -1,49 +1,93 @@
1
- <script generics="TData">import {} from 'svelte';
2
- import { scaleLinear, scaleOrdinal, scaleTime } from 'd3-scale';
3
- import { format } from '@layerstack/utils';
4
- import Axis from '../Axis.svelte';
5
- import Chart from '../Chart.svelte';
6
- import Grid from '../Grid.svelte';
7
- import Highlight from '../Highlight.svelte';
8
- import Labels from '../Labels.svelte';
9
- import Legend from '../Legend.svelte';
10
- import Points from '../Points.svelte';
11
- import Rule from '../Rule.svelte';
12
- import Spline from '../Spline.svelte';
13
- import Svg from '../layout/Svg.svelte';
14
- import * as Tooltip from '../tooltip/index.js';
15
- import { accessor, chartDataArray } from '../../utils/common.js';
16
- export let data = [];
17
- export let x = undefined;
18
- export let y = undefined;
19
- /** Use radial instead of cartesian coordinates, mapping `x` to `angle` and `y`` to radial. Radial lines are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */
20
- export let radial = false;
21
- export let series = [{ key: 'default', value: y, color: 'hsl(var(--color-primary))' }];
22
- $: isDefaultSeries = series.length === 1 && series[0].key === 'default';
23
- export let axis = true;
24
- export let rule = true;
25
- export let grid = true;
26
- export let labels = false;
27
- export let legend = false;
28
- export let points = false;
29
- export let props = {};
30
- $: allSeriesData = series
1
+ <script lang="ts" generics="TData">
2
+ import { type ComponentProps } from 'svelte';
3
+ import { scaleLinear, scaleOrdinal, scaleTime } from 'd3-scale';
4
+ import { format } from '@layerstack/utils';
5
+
6
+ import Axis from '../Axis.svelte';
7
+ import Chart from '../Chart.svelte';
8
+ import Grid from '../Grid.svelte';
9
+ import Highlight from '../Highlight.svelte';
10
+ import Labels from '../Labels.svelte';
11
+ import Legend from '../Legend.svelte';
12
+ import Points from '../Points.svelte';
13
+ import Rule from '../Rule.svelte';
14
+ import Spline from '../Spline.svelte';
15
+ import Svg from '../layout/Svg.svelte';
16
+ import * as Tooltip from '../tooltip/index.js';
17
+
18
+ import { accessor, chartDataArray, type Accessor } from '../../utils/common.js';
19
+
20
+ interface $$Props extends ComponentProps<Chart<TData>> {
21
+ axis?: typeof axis;
22
+ grid?: typeof grid;
23
+ labels?: typeof labels;
24
+ legend?: typeof legend;
25
+ points?: typeof points;
26
+ props?: typeof props;
27
+ rule?: typeof rule;
28
+ series?: typeof series;
29
+ }
30
+
31
+ export let data: $$Props['data'] = [];
32
+ export let x: Accessor<TData> = undefined;
33
+ export let y: Accessor<TData> = undefined;
34
+
35
+ /** Use radial instead of cartesian coordinates, mapping `x` to `angle` and `y`` to radial. Radial lines are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */
36
+ export let radial = false;
37
+
38
+ export let series: {
39
+ key: string | number;
40
+ label?: string;
41
+ value?: Accessor<TData>;
42
+ /** Provider series data, else uses chart data (with value/key accessor) */
43
+ data?: TData[];
44
+ color?: string;
45
+ props?: Partial<ComponentProps<Spline>>;
46
+ }[] = [{ key: 'default', value: y, color: 'hsl(var(--color-primary))' }];
47
+ $: isDefaultSeries = series.length === 1 && series[0].key === 'default';
48
+
49
+ export let axis: ComponentProps<Axis> | 'x' | 'y' | boolean = true;
50
+ export let rule: ComponentProps<Rule> | boolean = true;
51
+ export let grid: ComponentProps<Grid> | boolean = true;
52
+ export let labels: ComponentProps<Labels> | boolean = false;
53
+ export let legend: ComponentProps<Legend> | boolean = false;
54
+ export let points: ComponentProps<Points> | boolean = false;
55
+
56
+ export let props: {
57
+ xAxis?: Partial<ComponentProps<Axis>>;
58
+ yAxis?: Partial<ComponentProps<Axis>>;
59
+ grid?: Partial<ComponentProps<Grid>>;
60
+ rule?: Partial<ComponentProps<Rule>>;
61
+ spline?: Partial<ComponentProps<Spline>>;
62
+ legend?: Partial<ComponentProps<Legend>>;
63
+ highlight?: Partial<ComponentProps<Highlight>>;
64
+ labels?: Partial<ComponentProps<Labels>>;
65
+ points?: Partial<ComponentProps<Points>>;
66
+ } = {};
67
+
68
+ $: allSeriesData = series
31
69
  .flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
32
- .filter((d) => d);
33
- $: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data));
34
- // Default xScale based on first data's `x` value
35
- $: xScale = accessor(x)(chartData[0]) instanceof Date ? scaleTime() : scaleLinear();
36
- function getSplineProps(s, i) {
37
- const splineProps = {
38
- data: s.data,
39
- y: s.value ?? (s.data ? undefined : s.key),
40
- class: 'stroke-2',
41
- stroke: s.color,
42
- ...props.spline,
43
- ...s.props,
70
+ .filter((d) => d) as Array<TData & { stackData?: any }>;
71
+
72
+ $: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data)) as Array<
73
+ TData & { stackData?: any }
74
+ >;
75
+
76
+ // Default xScale based on first data's `x` value
77
+ $: xScale = accessor(x)(chartData[0]) instanceof Date ? scaleTime() : scaleLinear();
78
+
79
+ function getSplineProps(s: (typeof series)[number], i: number) {
80
+ const splineProps: ComponentProps<Spline> = {
81
+ data: s.data,
82
+ y: s.value ?? (s.data ? undefined : s.key),
83
+ class: 'stroke-2',
84
+ stroke: s.color,
85
+ ...props.spline,
86
+ ...s.props,
44
87
  };
88
+
45
89
  return splineProps;
46
- }
90
+ }
47
91
  </script>
48
92
 
49
93
  <Chart
@@ -253,7 +253,7 @@ declare class __sveltets_Render<TData> {
253
253
  tickValues?: any[] | undefined;
254
254
  tickFontSize?: number | undefined;
255
255
  tickLength?: number | undefined;
256
- placement?: ("left" | "right" | "center" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
256
+ placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
257
257
  orientation?: ("horizontal" | "vertical") | undefined;
258
258
  variant?: ("ramp" | "swatches") | undefined;
259
259
  classes?: {
@@ -1,52 +1,102 @@
1
- <script generics="TData">import {} from 'svelte';
2
- import { sum } from 'd3-array';
3
- import { format } from '@layerstack/utils';
4
- import Arc from '../Arc.svelte';
5
- import Chart from '../Chart.svelte';
6
- import Group from '../Group.svelte';
7
- import Legend from '../Legend.svelte';
8
- import Pie from '../Pie.svelte';
9
- import Svg from '../layout/Svg.svelte';
10
- import * as Tooltip from '../tooltip/index.js';
11
- import { accessor, chartDataArray } from '../../utils/common.js';
12
- export let data = [];
13
- /** Key accessor */
14
- export let key = 'key';
15
- $: keyAccessor = accessor(key);
16
- /** Label accessor */
17
- export let label = 'label';
18
- $: labelAccessor = accessor(label);
19
- /** Value accessor */
20
- export let value = 'value';
21
- $: valueAccessor = accessor(value);
22
- /** Maximum possible value, useful when `data` is single item */
23
- export let maxValue = undefined;
24
- export let series = [{ key: 'default', value: value /*, color: 'hsl(var(--color-primary))'*/ }];
25
- export let legend = false;
26
- /**
27
- * Range [min,max] in degrees. See also startAngle/endAngle
28
- */
29
- export let range = [0, 360];
30
- /**
31
- * Define innerRadius.
32
- * value >= 1: discrete value
33
- * value > 0: percent of `outerRadius`
34
- * value < 0: offset of `outerRadius`
35
- * default: yRange min
36
- */
37
- export let innerRadius = undefined;
38
- /**
39
- * Define outerRadius. Defaults to yRange max/2 (ie. chart height / 2)
40
- */
41
- export let outerRadius = undefined;
42
- export let cornerRadius = 0;
43
- export let padAngle = 0;
44
- export let props = {};
45
- $: allSeriesData = series
1
+ <script lang="ts" generics="TData">
2
+ import { type ComponentProps } from 'svelte';
3
+ import { sum } from 'd3-array';
4
+ import { format } from '@layerstack/utils';
5
+
6
+ import Arc from '../Arc.svelte';
7
+ import Chart from '../Chart.svelte';
8
+ import Group from '../Group.svelte';
9
+ import Legend from '../Legend.svelte';
10
+ import Pie from '../Pie.svelte';
11
+ import Svg from '../layout/Svg.svelte';
12
+ import * as Tooltip from '../tooltip/index.js';
13
+
14
+ import { accessor, chartDataArray, type Accessor } from '../../utils/common.js';
15
+
16
+ type ChartProps = ComponentProps<Chart<TData>>;
17
+
18
+ interface $$Props extends ChartProps {
19
+ cornerRadius?: typeof cornerRadius;
20
+ innerRadius?: typeof innerRadius;
21
+ key?: typeof key;
22
+ label?: typeof label;
23
+ legend?: typeof legend;
24
+ maxValue?: typeof maxValue;
25
+ outerRadius?: typeof outerRadius;
26
+ padAngle?: typeof padAngle;
27
+ props?: typeof props;
28
+ range?: typeof range;
29
+ series?: typeof series;
30
+ value?: typeof label;
31
+ }
32
+
33
+ export let data: ChartProps['data'] = [];
34
+
35
+ /** Key accessor */
36
+ export let key: Accessor<TData> = 'key';
37
+ $: keyAccessor = accessor(key);
38
+
39
+ /** Label accessor */
40
+ export let label: Accessor<TData> = 'label';
41
+ $: labelAccessor = accessor(label);
42
+
43
+ /** Value accessor */
44
+ export let value: Accessor<TData> = 'value';
45
+ $: valueAccessor = accessor(value);
46
+
47
+ /** Maximum possible value, useful when `data` is single item */
48
+ export let maxValue: number | undefined = undefined;
49
+
50
+ export let series: {
51
+ key: string | number;
52
+ label?: string;
53
+ value?: Accessor<TData>;
54
+ /** Provider series data, else uses chart data (with value/key accessor) */
55
+ data?: TData[];
56
+ /** Maximum possible value, useful when `data` is single item */
57
+ maxValue?: number;
58
+ color?: string;
59
+ props?: Partial<ComponentProps<Arc>>;
60
+ }[] = [{ key: 'default', value: value /*, color: 'hsl(var(--color-primary))'*/ }];
61
+
62
+ export let legend: ComponentProps<Legend> | boolean = false;
63
+
64
+ /**
65
+ * Range [min,max] in degrees. See also startAngle/endAngle
66
+ */
67
+ export let range = [0, 360];
68
+
69
+ /**
70
+ * Define innerRadius.
71
+ * value >= 1: discrete value
72
+ * value > 0: percent of `outerRadius`
73
+ * value < 0: offset of `outerRadius`
74
+ * default: yRange min
75
+ */
76
+ export let innerRadius: number | undefined = undefined;
77
+
78
+ /**
79
+ * Define outerRadius. Defaults to yRange max/2 (ie. chart height / 2)
80
+ */
81
+ export let outerRadius: number | undefined = undefined;
82
+
83
+ export let cornerRadius = 0;
84
+ export let padAngle = 0;
85
+
86
+ export let props: {
87
+ pie?: Partial<ComponentProps<Pie>>;
88
+ group?: Partial<ComponentProps<Group>>;
89
+ arc?: Partial<ComponentProps<Arc>>;
90
+ legend?: Partial<ComponentProps<Legend>>;
91
+ } = {};
92
+
93
+ $: allSeriesData = series
46
94
  .flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
47
- .filter((d) => d);
48
- $: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data));
49
- $: seriesColors = series.map((s) => s.color).filter((d) => d != null);
95
+ .filter((d) => d) as Array<TData>;
96
+
97
+ $: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data)) as Array<TData>;
98
+
99
+ $: seriesColors = series.map((s) => s.color).filter((d) => d != null);
50
100
  </script>
51
101
 
52
102
  <Chart
@@ -110,8 +160,8 @@ $: seriesColors = series.map((s) => s.color).filter((d) => d != null);
110
160
  outerRadius={(outerRadius ?? 0) < 0 ? i * (outerRadius ?? 0) : outerRadius}
111
161
  {cornerRadius}
112
162
  {padAngle}
113
- fill={s.color ?? cScale(c(d))}
114
- track={{ fill: s.color ?? cScale(c(d)), 'fill-opacity': 0.1 }}
163
+ fill={s.color ?? cScale?.(c(d))}
164
+ track={{ fill: s.color ?? cScale?.(c(d)), 'fill-opacity': 0.1 }}
115
165
  {tooltip}
116
166
  data={d}
117
167
  {...props.arc}
@@ -136,7 +186,7 @@ $: seriesColors = series.map((s) => s.color).filter((d) => d != null);
136
186
  {innerRadius}
137
187
  {cornerRadius}
138
188
  {padAngle}
139
- fill={cScale(c(arc.data))}
189
+ fill={cScale?.(c(arc.data))}
140
190
  data={arc.data}
141
191
  {tooltip}
142
192
  {...props.arc}
@@ -173,7 +223,7 @@ $: seriesColors = series.map((s) => s.color).filter((d) => d != null);
173
223
  <Tooltip.Item
174
224
  label={labelAccessor(data) || keyAccessor(data)}
175
225
  value={valueAccessor(data)}
176
- color={cScale(c(data))}
226
+ color={cScale?.(c(data))}
177
227
  {format}
178
228
  />
179
229
  </Tooltip.List>