layerchart 1.0.0 → 1.0.2
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/Spline.svelte +4 -1
- package/dist/components/charts/AreaChart.svelte +10 -3
- package/dist/components/charts/BarChart.svelte +9 -3
- package/dist/components/charts/LineChart.svelte +10 -3
- package/dist/components/charts/PieChart.svelte +24 -10
- package/dist/components/charts/PieChart.svelte.d.ts +4 -0
- package/dist/components/charts/ScatterChart.svelte +10 -3
- package/dist/components/layout/Canvas.svelte +8 -10
- package/dist/components/tooltip/TooltipContext.svelte +1 -1
- package/package.json +1 -1
|
@@ -124,7 +124,10 @@
|
|
|
124
124
|
|
|
125
125
|
/** Provide initial `0` horizontal baseline and initially hide/untrack scale changes so not reactive (only set on initial mount) */
|
|
126
126
|
function defaultPathData() {
|
|
127
|
-
if (
|
|
127
|
+
if (!tweenedOptions) {
|
|
128
|
+
// If not tweened, return empty string (faster initial render)
|
|
129
|
+
return '';
|
|
130
|
+
} else if (pathData) {
|
|
128
131
|
// Flatten all `y` coordinates of pre-defined `pathData`
|
|
129
132
|
return flattenPathData(pathData, Math.min($yScale(0), $yRange[0]));
|
|
130
133
|
} else if ($config.x) {
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
export let props: {
|
|
104
104
|
area?: Partial<ComponentProps<Area>>;
|
|
105
105
|
brush?: Partial<ComponentProps<BrushContext>>;
|
|
106
|
+
canvas?: Partial<ComponentProps<Canvas>>;
|
|
106
107
|
grid?: Partial<ComponentProps<Grid>>;
|
|
107
108
|
highlight?: Partial<ComponentProps<Highlight>>;
|
|
108
109
|
labels?: Partial<ComponentProps<Labels>>;
|
|
@@ -110,6 +111,7 @@
|
|
|
110
111
|
line?: Partial<ComponentProps<Line>>;
|
|
111
112
|
points?: Partial<ComponentProps<Points>>;
|
|
112
113
|
rule?: Partial<ComponentProps<Rule>>;
|
|
114
|
+
svg?: Partial<ComponentProps<Svg>>;
|
|
113
115
|
tooltip?: {
|
|
114
116
|
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
115
117
|
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
@@ -173,7 +175,7 @@
|
|
|
173
175
|
highlightSeriesKey = seriesKey;
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
$: getAreaProps = (s: (typeof series)[number], i: number) => {
|
|
177
179
|
const lineProps = {
|
|
178
180
|
...props.line,
|
|
179
181
|
...(typeof props.area?.line === 'object' ? props.area.line : null),
|
|
@@ -217,7 +219,7 @@
|
|
|
217
219
|
};
|
|
218
220
|
|
|
219
221
|
return areaProps;
|
|
220
|
-
}
|
|
222
|
+
};
|
|
221
223
|
|
|
222
224
|
function getPointsProps(s: (typeof series)[number], i: number) {
|
|
223
225
|
const pointsProps: ComponentProps<Points> = {
|
|
@@ -350,7 +352,12 @@
|
|
|
350
352
|
<slot {...slotProps}>
|
|
351
353
|
<slot name="belowContext" {...slotProps} />
|
|
352
354
|
|
|
353
|
-
<svelte:component
|
|
355
|
+
<svelte:component
|
|
356
|
+
this={renderContext === 'canvas' ? Canvas : Svg}
|
|
357
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
358
|
+
center={radial}
|
|
359
|
+
{debug}
|
|
360
|
+
>
|
|
354
361
|
<slot name="grid" {...slotProps}>
|
|
355
362
|
{#if grid}
|
|
356
363
|
<Grid x={radial} y {...typeof grid === 'object' ? grid : null} {...props.grid} />
|
|
@@ -135,12 +135,14 @@
|
|
|
135
135
|
export let props: {
|
|
136
136
|
xAxis?: Partial<ComponentProps<Axis>>;
|
|
137
137
|
yAxis?: Partial<ComponentProps<Axis>>;
|
|
138
|
+
canvas?: Partial<ComponentProps<Canvas>>;
|
|
138
139
|
grid?: Partial<ComponentProps<Grid>>;
|
|
139
140
|
rule?: Partial<ComponentProps<Rule>>;
|
|
140
141
|
bars?: Partial<ComponentProps<Bars>>;
|
|
141
142
|
legend?: Partial<ComponentProps<Legend>>;
|
|
142
143
|
highlight?: Partial<ComponentProps<Highlight>>;
|
|
143
144
|
labels?: Partial<ComponentProps<Labels>>;
|
|
145
|
+
svg?: Partial<ComponentProps<Svg>>;
|
|
144
146
|
tooltip?: {
|
|
145
147
|
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
146
148
|
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
@@ -203,7 +205,7 @@
|
|
|
203
205
|
highlightSeriesKey = seriesKey;
|
|
204
206
|
}
|
|
205
207
|
|
|
206
|
-
|
|
208
|
+
$: getBarsProps = (s: (typeof series)[number], i: number) => {
|
|
207
209
|
const isFirst = i == 0;
|
|
208
210
|
const isLast = i == visibleSeries.length - 1;
|
|
209
211
|
|
|
@@ -252,7 +254,7 @@
|
|
|
252
254
|
};
|
|
253
255
|
|
|
254
256
|
return barsProps;
|
|
255
|
-
}
|
|
257
|
+
};
|
|
256
258
|
|
|
257
259
|
function getLabelsProps(s: (typeof series)[number], i: number) {
|
|
258
260
|
const labelsProps: ComponentProps<Labels> = {
|
|
@@ -356,7 +358,11 @@
|
|
|
356
358
|
<slot {...slotProps}>
|
|
357
359
|
<slot name="belowContext" {...slotProps} />
|
|
358
360
|
|
|
359
|
-
<svelte:component
|
|
361
|
+
<svelte:component
|
|
362
|
+
this={renderContext === 'canvas' ? Canvas : Svg}
|
|
363
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
364
|
+
{debug}
|
|
365
|
+
>
|
|
360
366
|
<slot name="grid" {...slotProps}>
|
|
361
367
|
{#if grid}
|
|
362
368
|
<Grid
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
|
|
95
95
|
export let props: {
|
|
96
96
|
brush?: Partial<ComponentProps<BrushContext>>;
|
|
97
|
+
canvas?: Partial<ComponentProps<Canvas>>;
|
|
97
98
|
grid?: Partial<ComponentProps<Grid>>;
|
|
98
99
|
highlight?: Partial<ComponentProps<Highlight>>;
|
|
99
100
|
labels?: Partial<ComponentProps<Labels>>;
|
|
@@ -101,6 +102,7 @@
|
|
|
101
102
|
points?: Partial<ComponentProps<Points>>;
|
|
102
103
|
rule?: Partial<ComponentProps<Rule>>;
|
|
103
104
|
spline?: Partial<ComponentProps<Spline>>;
|
|
105
|
+
svg?: Partial<ComponentProps<Svg>>;
|
|
104
106
|
tooltip?: {
|
|
105
107
|
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
106
108
|
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
@@ -139,7 +141,7 @@
|
|
|
139
141
|
highlightSeriesKey = seriesKey;
|
|
140
142
|
}
|
|
141
143
|
|
|
142
|
-
|
|
144
|
+
$: getSplineProps = (s: (typeof series)[number], i: number) => {
|
|
143
145
|
const splineProps: ComponentProps<Spline> = {
|
|
144
146
|
data: s.data,
|
|
145
147
|
y: s.value ?? (s.data ? undefined : s.key),
|
|
@@ -159,7 +161,7 @@
|
|
|
159
161
|
};
|
|
160
162
|
|
|
161
163
|
return splineProps;
|
|
162
|
-
}
|
|
164
|
+
};
|
|
163
165
|
|
|
164
166
|
function getPointsProps(s: (typeof series)[number], i: number) {
|
|
165
167
|
const pointsProps: ComponentProps<Points> = {
|
|
@@ -280,7 +282,12 @@
|
|
|
280
282
|
<slot {...slotProps}>
|
|
281
283
|
<slot name="belowContext" {...slotProps} />
|
|
282
284
|
|
|
283
|
-
<svelte:component
|
|
285
|
+
<svelte:component
|
|
286
|
+
this={renderContext === 'canvas' ? Canvas : Svg}
|
|
287
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
288
|
+
center={radial}
|
|
289
|
+
{debug}
|
|
290
|
+
>
|
|
284
291
|
<slot name="grid" {...slotProps}>
|
|
285
292
|
{#if grid}
|
|
286
293
|
<Grid x={radial} y {...typeof grid === 'object' ? grid : null} {...props.grid} />
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import * as Tooltip from '../tooltip/index.js';
|
|
16
16
|
|
|
17
17
|
import { accessor, chartDataArray, type Accessor } from '../../utils/common.js';
|
|
18
|
+
import { asAny } from '../../utils/types.js';
|
|
18
19
|
|
|
19
20
|
interface $$Props extends ComponentProps<Chart<TData>> {
|
|
20
21
|
cornerRadius?: typeof cornerRadius;
|
|
@@ -52,6 +53,10 @@
|
|
|
52
53
|
export let value: Accessor<TData> = 'value';
|
|
53
54
|
$: valueAccessor = accessor(value);
|
|
54
55
|
|
|
56
|
+
/** Color accessor*/
|
|
57
|
+
export let c: Accessor<TData> = key;
|
|
58
|
+
$: cAccessor = accessor(c);
|
|
59
|
+
|
|
55
60
|
/** Maximum possible value, useful when `data` is single item */
|
|
56
61
|
export let maxValue: number | undefined = undefined;
|
|
57
62
|
|
|
@@ -115,6 +120,8 @@
|
|
|
115
120
|
group?: Partial<ComponentProps<Group>>;
|
|
116
121
|
arc?: Partial<ComponentProps<Arc>>;
|
|
117
122
|
legend?: Partial<ComponentProps<Legend>>;
|
|
123
|
+
canvas?: Partial<ComponentProps<Canvas>>;
|
|
124
|
+
svg?: Partial<ComponentProps<Svg>>;
|
|
118
125
|
tooltip?: {
|
|
119
126
|
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
120
127
|
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
@@ -169,18 +176,20 @@
|
|
|
169
176
|
data={visibleData}
|
|
170
177
|
x={value}
|
|
171
178
|
y={key}
|
|
172
|
-
c
|
|
179
|
+
{c}
|
|
173
180
|
cDomain={chartData.map(keyAccessor)}
|
|
174
181
|
cRange={seriesColors.length
|
|
175
182
|
? seriesColors
|
|
176
|
-
:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
183
|
+
: c !== key
|
|
184
|
+
? chartData.map((d) => cAccessor(d))
|
|
185
|
+
: [
|
|
186
|
+
'hsl(var(--color-primary))',
|
|
187
|
+
'hsl(var(--color-secondary))',
|
|
188
|
+
'hsl(var(--color-info))',
|
|
189
|
+
'hsl(var(--color-success))',
|
|
190
|
+
'hsl(var(--color-warning))',
|
|
191
|
+
'hsl(var(--color-danger))',
|
|
192
|
+
]}
|
|
184
193
|
padding={{ bottom: legend === true ? 32 : 0 }}
|
|
185
194
|
{...$$restProps}
|
|
186
195
|
tooltip={props.tooltip?.context}
|
|
@@ -217,7 +226,12 @@
|
|
|
217
226
|
<slot {...slotProps}>
|
|
218
227
|
<slot name="belowContext" {...slotProps} />
|
|
219
228
|
|
|
220
|
-
<svelte:component
|
|
229
|
+
<svelte:component
|
|
230
|
+
this={renderContext === 'canvas' ? Canvas : Svg}
|
|
231
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
232
|
+
{center}
|
|
233
|
+
{debug}
|
|
234
|
+
>
|
|
221
235
|
<slot name="belowMarks" {...slotProps} />
|
|
222
236
|
|
|
223
237
|
<slot name="marks" {...slotProps}>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import { type ComponentProps } from 'svelte';
|
|
3
3
|
import Arc from '../Arc.svelte';
|
|
4
|
+
import Canvas from '../layout/Canvas.svelte';
|
|
4
5
|
import Group from '../Group.svelte';
|
|
5
6
|
import Legend from '../Legend.svelte';
|
|
6
7
|
import Pie from '../Pie.svelte';
|
|
8
|
+
import Svg from '../layout/Svg.svelte';
|
|
7
9
|
import * as Tooltip from '../tooltip/index.js';
|
|
8
10
|
import { type Accessor } from '../../utils/common.js';
|
|
9
11
|
declare class __sveltets_Render<TData> {
|
|
@@ -294,6 +296,8 @@ declare class __sveltets_Render<TData> {
|
|
|
294
296
|
group?: Partial<ComponentProps<Group>>;
|
|
295
297
|
arc?: Partial<ComponentProps<Arc>>;
|
|
296
298
|
legend?: Partial<ComponentProps<Legend>>;
|
|
299
|
+
canvas?: Partial<ComponentProps<Canvas>>;
|
|
300
|
+
svg?: Partial<ComponentProps<Svg>>;
|
|
297
301
|
tooltip?: {
|
|
298
302
|
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
299
303
|
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
defaultChartPadding,
|
|
26
26
|
type Accessor,
|
|
27
27
|
} from '../../utils/common.js';
|
|
28
|
+
import { asAny } from '../../utils/types.js';
|
|
28
29
|
|
|
29
30
|
interface $$Props extends ComponentProps<Chart<TData>> {
|
|
30
31
|
axis?: typeof axis;
|
|
@@ -72,6 +73,7 @@
|
|
|
72
73
|
|
|
73
74
|
export let props: {
|
|
74
75
|
brush?: Partial<ComponentProps<BrushContext>>;
|
|
76
|
+
canvas?: Partial<ComponentProps<Canvas>>;
|
|
75
77
|
debug?: typeof debug;
|
|
76
78
|
grid?: Partial<ComponentProps<Grid>>;
|
|
77
79
|
highlight?: Partial<ComponentProps<Highlight>>;
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
points?: Partial<ComponentProps<Points>>;
|
|
81
83
|
profile?: typeof profile;
|
|
82
84
|
rule?: Partial<ComponentProps<Rule>>;
|
|
85
|
+
svg?: Partial<ComponentProps<Svg>>;
|
|
83
86
|
tooltip?: {
|
|
84
87
|
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
85
88
|
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
@@ -120,7 +123,7 @@
|
|
|
120
123
|
highlightSeriesKey = seriesKey ?? null;
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
$: getPointsProps = (s: (typeof series)[number], i: number) => {
|
|
124
127
|
const pointsProps: ComponentProps<Points> = {
|
|
125
128
|
data: s.data,
|
|
126
129
|
stroke: s.color,
|
|
@@ -137,7 +140,7 @@
|
|
|
137
140
|
};
|
|
138
141
|
|
|
139
142
|
return pointsProps;
|
|
140
|
-
}
|
|
143
|
+
};
|
|
141
144
|
|
|
142
145
|
function getLabelsProps(s: (typeof series)[number], i: number) {
|
|
143
146
|
const labelsProps: ComponentProps<Labels> = {
|
|
@@ -246,7 +249,11 @@
|
|
|
246
249
|
<slot {...slotProps}>
|
|
247
250
|
<slot name="belowContext" {...slotProps} />
|
|
248
251
|
|
|
249
|
-
<svelte:component
|
|
252
|
+
<svelte:component
|
|
253
|
+
this={renderContext === 'canvas' ? Canvas : Svg}
|
|
254
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
255
|
+
{debug}
|
|
256
|
+
>
|
|
250
257
|
<slot name="grid" {...slotProps}>
|
|
251
258
|
{#if grid}
|
|
252
259
|
<Grid x y {...typeof grid === 'object' ? grid : null} {...props.grid} />
|
|
@@ -118,19 +118,17 @@
|
|
|
118
118
|
activeCanvas = true;
|
|
119
119
|
const component = getPointerComponent(e);
|
|
120
120
|
|
|
121
|
-
if (
|
|
122
|
-
// TODO: Should
|
|
121
|
+
if (component != lastActiveComponent) {
|
|
122
|
+
// TODO: Should `pointerleave`/`pointerout` and `pointerenter`/`pointerover` be handled differently?
|
|
123
|
+
if (lastActiveComponent) {
|
|
124
|
+
lastActiveComponent.events?.pointerleave?.(e);
|
|
125
|
+
lastActiveComponent.events?.pointerout?.(e);
|
|
126
|
+
}
|
|
127
|
+
|
|
123
128
|
component?.events?.pointerenter?.(e);
|
|
124
129
|
component?.events?.pointerover?.(e);
|
|
125
|
-
} else if (lastActiveComponent != component) {
|
|
126
|
-
// TODO: Should these be handled differently
|
|
127
|
-
lastActiveComponent?.events?.pointerleave?.(e);
|
|
128
|
-
lastActiveComponent?.events?.pointerout?.(e);
|
|
129
|
-
|
|
130
|
-
component?.events?.pointermove?.(e);
|
|
131
|
-
} else {
|
|
132
|
-
component?.events?.pointermove?.(e);
|
|
133
130
|
}
|
|
131
|
+
component?.events?.pointermove?.(e);
|
|
134
132
|
|
|
135
133
|
lastActiveComponent = component;
|
|
136
134
|
}
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
const point = localPoint(e, containerNode);
|
|
193
193
|
|
|
194
194
|
if (
|
|
195
|
-
mode !== 'manual'
|
|
195
|
+
tooltipData === null && // mode !== 'manual' but support annotations
|
|
196
196
|
(point.x < tooltipContextNode.offsetLeft ||
|
|
197
197
|
point.x > tooltipContextNode.offsetLeft + tooltipContextNode.offsetWidth ||
|
|
198
198
|
point.y < tooltipContextNode.offsetTop ||
|