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,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
|
|
@@ -218,7 +278,12 @@ function getBarsProps(s, i) {
|
|
|
218
278
|
{/if}
|
|
219
279
|
|
|
220
280
|
{#if rule}
|
|
221
|
-
<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?: ("
|
|
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">
|
|
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
|
|
@@ -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?: {
|
|
@@ -1,52 +1,102 @@
|
|
|
1
|
-
<script generics="TData">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export let
|
|
45
|
-
$:
|
|
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
|
-
|
|
49
|
-
$:
|
|
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>
|