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.
- 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 +269 -112
- package/dist/components/Brush.svelte.d.ts +7 -0
- 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 +65 -19
- package/dist/components/Line.svelte.d.ts +13 -1
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +94 -22
- package/dist/components/Link.svelte.d.ts +17 -1
- package/dist/components/Marker.svelte +81 -0
- package/dist/components/Marker.svelte.d.ts +28 -0
- 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 +167 -96
- package/dist/components/Spline.svelte.d.ts +15 -0
- 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 +138 -87
- package/dist/components/charts/AreaChart.svelte.d.ts +4 -4
- package/dist/components/charts/BarChart.svelte +179 -114
- package/dist/components/charts/BarChart.svelte.d.ts +4 -4
- package/dist/components/charts/LineChart.svelte +97 -53
- package/dist/components/charts/LineChart.svelte.d.ts +4 -4
- package/dist/components/charts/PieChart.svelte +104 -54
- package/dist/components/charts/PieChart.svelte.d.ts +3 -3
- package/dist/components/charts/ScatterChart.svelte +83 -48
- package/dist/components/charts/ScatterChart.svelte.d.ts +4 -4
- 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,118 +1,178 @@
|
|
|
1
|
-
<script generics="TData">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
54
|
+
key: 'default',
|
|
55
|
+
value: orientation === 'vertical' ? y : x,
|
|
26
56
|
},
|
|
27
|
-
];
|
|
28
|
-
$: isDefaultSeries = series.length === 1 && series[0].key === 'default';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export let
|
|
37
|
-
export let
|
|
38
|
-
|
|
39
|
-
export let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
129
|
+
|
|
130
|
+
const offset =
|
|
131
|
+
seriesLayout === 'stackExpand'
|
|
75
132
|
? stackOffsetExpand
|
|
76
133
|
: seriesLayout === 'stackDiverging'
|
|
77
|
-
|
|
78
|
-
|
|
134
|
+
? stackOffsetDiverging
|
|
135
|
+
: stackOffsetNone;
|
|
79
136
|
const stackData = stack()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const s = series.find((d) => d.key === key)
|
|
83
|
-
return accessor(s.value ?? s.key)(d);
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
145
|
+
return {
|
|
146
|
+
...d,
|
|
147
|
+
stackData: stackData.map((sd) => sd[i]),
|
|
148
|
+
};
|
|
91
149
|
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
|
@@ -185,6 +245,16 @@ function getBarsProps(s, i) {
|
|
|
185
245
|
{/if}
|
|
186
246
|
</slot>
|
|
187
247
|
|
|
248
|
+
<slot name="belowMarks" {...slotProps} />
|
|
249
|
+
|
|
250
|
+
<slot name="marks" {...slotProps}>
|
|
251
|
+
{#each series as s, i}
|
|
252
|
+
<Bars {...getBarsProps(s, i)} />
|
|
253
|
+
{/each}
|
|
254
|
+
</slot>
|
|
255
|
+
|
|
256
|
+
<slot name="aboveMarks" {...slotProps} />
|
|
257
|
+
|
|
188
258
|
<slot name="axis" {...slotProps}>
|
|
189
259
|
{#if axis}
|
|
190
260
|
{#if axis !== 'x'}
|
|
@@ -218,21 +288,16 @@ function getBarsProps(s, i) {
|
|
|
218
288
|
{/if}
|
|
219
289
|
|
|
220
290
|
{#if rule}
|
|
221
|
-
<Rule
|
|
291
|
+
<Rule
|
|
292
|
+
x={isVertical ? false : 0}
|
|
293
|
+
y={isVertical ? 0 : false}
|
|
294
|
+
{...typeof rule === 'object' ? rule : null}
|
|
295
|
+
{...props.rule}
|
|
296
|
+
/>
|
|
222
297
|
{/if}
|
|
223
298
|
{/if}
|
|
224
299
|
</slot>
|
|
225
300
|
|
|
226
|
-
<slot name="below-marks" {...slotProps} />
|
|
227
|
-
|
|
228
|
-
<slot name="marks" {...slotProps}>
|
|
229
|
-
{#each series as s, i}
|
|
230
|
-
<Bars {...getBarsProps(s, i)} />
|
|
231
|
-
{/each}
|
|
232
|
-
</slot>
|
|
233
|
-
|
|
234
|
-
<slot name="above-marks" {...slotProps} />
|
|
235
|
-
|
|
236
301
|
<slot name="highlight" {...slotProps}>
|
|
237
302
|
<Highlight area {...props.highlight} />
|
|
238
303
|
</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?: ("
|
|
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?: {
|
|
@@ -301,10 +301,10 @@ declare class __sveltets_Render<TData> {
|
|
|
301
301
|
slots(): {
|
|
302
302
|
default: any;
|
|
303
303
|
grid: any;
|
|
304
|
-
|
|
305
|
-
'below-marks': any;
|
|
304
|
+
belowMarks: any;
|
|
306
305
|
marks: any;
|
|
307
|
-
|
|
306
|
+
aboveMarks: any;
|
|
307
|
+
axis: any;
|
|
308
308
|
highlight: any;
|
|
309
309
|
legend: any;
|
|
310
310
|
tooltip: any;
|
|
@@ -1,49 +1,93 @@
|
|
|
1
|
-
<script generics="TData">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
@@ -95,6 +139,16 @@ function getSplineProps(s, i) {
|
|
|
95
139
|
{/if}
|
|
96
140
|
</slot>
|
|
97
141
|
|
|
142
|
+
<slot name="belowMarks" {...slotProps} />
|
|
143
|
+
|
|
144
|
+
<slot name="marks" {...slotProps}>
|
|
145
|
+
{#each series as s, i}
|
|
146
|
+
<Spline {...getSplineProps(s, i)} />
|
|
147
|
+
{/each}
|
|
148
|
+
</slot>
|
|
149
|
+
|
|
150
|
+
<slot name="aboveMarks" {...slotProps} />
|
|
151
|
+
|
|
98
152
|
<slot name="axis" {...slotProps}>
|
|
99
153
|
{#if axis}
|
|
100
154
|
{#if axis !== 'x'}
|
|
@@ -121,16 +175,6 @@ function getSplineProps(s, i) {
|
|
|
121
175
|
{/if}
|
|
122
176
|
</slot>
|
|
123
177
|
|
|
124
|
-
<slot name="below-marks" {...slotProps} />
|
|
125
|
-
|
|
126
|
-
<slot name="marks" {...slotProps}>
|
|
127
|
-
{#each series as s, i}
|
|
128
|
-
<Spline {...getSplineProps(s, i)} />
|
|
129
|
-
{/each}
|
|
130
|
-
</slot>
|
|
131
|
-
|
|
132
|
-
<slot name="above-marks" {...slotProps} />
|
|
133
|
-
|
|
134
178
|
{#if points}
|
|
135
179
|
{#each series as s}
|
|
136
180
|
<Points
|
|
@@ -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?: ("
|
|
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?: {
|
|
@@ -312,10 +312,10 @@ declare class __sveltets_Render<TData> {
|
|
|
312
312
|
slots(): {
|
|
313
313
|
default: any;
|
|
314
314
|
grid: any;
|
|
315
|
-
|
|
316
|
-
'below-marks': any;
|
|
315
|
+
belowMarks: any;
|
|
317
316
|
marks: any;
|
|
318
|
-
|
|
317
|
+
aboveMarks: any;
|
|
318
|
+
axis: any;
|
|
319
319
|
highlight: any;
|
|
320
320
|
legend: any;
|
|
321
321
|
tooltip: any;
|