layerchart 1.0.2 → 1.0.4
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/Area.svelte +26 -16
- package/dist/components/Link.svelte +3 -2
- package/dist/components/Points.svelte +3 -1
- package/dist/components/Spline.svelte +3 -2
- package/dist/components/TransformContext.svelte +4 -4
- package/dist/components/charts/AreaChart.svelte +11 -9
- package/dist/components/charts/LineChart.svelte +11 -9
- package/dist/components/tooltip/TooltipContext.svelte +1 -1
- package/dist/utils/object.js +2 -0
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import Spline from './Spline.svelte';
|
|
18
18
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
19
19
|
import { isScaleBand } from '../utils/scales.js';
|
|
20
|
+
import { flattenPathData } from '../utils/path.js';
|
|
20
21
|
import { getCanvasContext } from './layout/Canvas.svelte';
|
|
21
22
|
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
22
23
|
const {
|
|
@@ -78,24 +79,33 @@
|
|
|
78
79
|
|
|
79
80
|
/** Provide initial `0` horizontal baseline and initially hide/untrack scale changes so not reactive (only set on initial mount) */
|
|
80
81
|
function defaultPathData() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
if (!tweenedOptions) {
|
|
83
|
+
// If not tweened, return empty string (faster initial render)
|
|
84
|
+
return '';
|
|
85
|
+
} else if (pathData) {
|
|
86
|
+
// Flatten all `y` coordinates of pre-defined `pathData`
|
|
87
|
+
return flattenPathData(pathData, Math.min($yScale(0), $yRange[0]));
|
|
88
|
+
} else if ($config.x) {
|
|
89
|
+
// Only use default line if `x` accessor is defined (cartesian chart)
|
|
90
|
+
const path = $radial
|
|
91
|
+
? areaRadial()
|
|
92
|
+
.angle((d) => $xScale(xAccessor(d)))
|
|
93
|
+
.innerRadius((d) => Math.min($yScale(0), $yRange[0]))
|
|
94
|
+
.outerRadius((d) => Math.min($yScale(0), $yRange[0]))
|
|
95
|
+
: d3Area()
|
|
96
|
+
.x((d) => $xScale(xAccessor(d)) + xOffset)
|
|
97
|
+
.y0((d) => Math.min($yScale(0), $yRange[0]))
|
|
98
|
+
.y1((d) => Math.min($yScale(0), $yRange[0]));
|
|
99
|
+
|
|
100
|
+
path.defined(defined ?? ((d) => xAccessor(d) != null && y1Accessor(d) != null));
|
|
101
|
+
|
|
102
|
+
if (curve) path.curve(curve);
|
|
103
|
+
|
|
104
|
+
return path(data ?? $contextData);
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
const tweenedOptions = tweened
|
|
99
109
|
? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
|
|
100
110
|
: false;
|
|
101
111
|
$: tweened_d = motionStore(defaultPathData(), { tweened: tweenedOptions });
|
|
@@ -65,8 +65,9 @@
|
|
|
65
65
|
$: markerEndId = markerEnd || $$slots['markerEnd'] ? uniqueId('marker-') : '';
|
|
66
66
|
|
|
67
67
|
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const tweenedOptions = tweened
|
|
69
|
+
? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
|
|
70
|
+
: false;
|
|
70
71
|
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
71
72
|
|
|
72
73
|
$: {
|
|
@@ -143,6 +143,7 @@
|
|
|
143
143
|
x: xMax + getOffset(xMax, offsetX, $xScale) - ($config.r ? $rGet(d) : r),
|
|
144
144
|
y: y,
|
|
145
145
|
},
|
|
146
|
+
data: d,
|
|
146
147
|
};
|
|
147
148
|
} else if (Array.isArray(yValue)) {
|
|
148
149
|
/*
|
|
@@ -160,6 +161,7 @@
|
|
|
160
161
|
x: x,
|
|
161
162
|
y: yMax + getOffset(yMax, offsetY, $yScale),
|
|
162
163
|
},
|
|
164
|
+
data: d,
|
|
163
165
|
};
|
|
164
166
|
}
|
|
165
167
|
});
|
|
@@ -170,7 +172,7 @@
|
|
|
170
172
|
{#each _links as link}
|
|
171
173
|
<Link
|
|
172
174
|
data={link}
|
|
173
|
-
|
|
175
|
+
stroke={fill ?? ($config.c ? $cGet(link.data) : null)}
|
|
174
176
|
{...typeof links === 'object' ? links : null}
|
|
175
177
|
/>
|
|
176
178
|
{/each}
|
|
@@ -149,8 +149,9 @@
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
let d: string | null = '';
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
const tweenedOptions = tweened
|
|
153
|
+
? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
|
|
154
|
+
: false;
|
|
154
155
|
$: tweened_d = motionStore(defaultPathData(), { tweened: tweenedOptions });
|
|
155
156
|
$: {
|
|
156
157
|
const path = $radial
|
|
@@ -130,15 +130,15 @@
|
|
|
130
130
|
center: { x: number; y: number },
|
|
131
131
|
rect?: { width: number; height: number }
|
|
132
132
|
) {
|
|
133
|
-
|
|
133
|
+
const newScale = rect ? ($width < $height ? $width / rect.width : $height / rect.height) : 1;
|
|
134
134
|
|
|
135
135
|
$translate = {
|
|
136
|
-
x: $width / 2 - center.x,
|
|
137
|
-
y: $height / 2 - center.y,
|
|
136
|
+
x: $width / 2 - center.x * newScale,
|
|
137
|
+
y: $height / 2 - center.y * newScale,
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
if (rect) {
|
|
141
|
-
$scale =
|
|
141
|
+
$scale = newScale;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -433,15 +433,17 @@
|
|
|
433
433
|
onpointenter={() => (highlightSeriesKey = s.key)}
|
|
434
434
|
onpointleave={() => (highlightSeriesKey = null)}
|
|
435
435
|
{...props.highlight}
|
|
436
|
-
points={
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
436
|
+
points={props.highlight?.points == false
|
|
437
|
+
? false
|
|
438
|
+
: {
|
|
439
|
+
...highlightPointsProps,
|
|
440
|
+
fill: s.color,
|
|
441
|
+
class: cls(
|
|
442
|
+
'transition-opacity',
|
|
443
|
+
highlightSeriesKey && highlightSeriesKey !== s.key && 'opacity-10',
|
|
444
|
+
highlightPointsProps?.class
|
|
445
|
+
),
|
|
446
|
+
}}
|
|
445
447
|
/>
|
|
446
448
|
{/each}
|
|
447
449
|
</slot>
|
|
@@ -363,15 +363,17 @@
|
|
|
363
363
|
onpointenter={() => (highlightSeriesKey = s.key)}
|
|
364
364
|
onpointleave={() => (highlightSeriesKey = null)}
|
|
365
365
|
{...props.highlight}
|
|
366
|
-
points={
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
366
|
+
points={props.highlight?.points == false
|
|
367
|
+
? false
|
|
368
|
+
: {
|
|
369
|
+
...highlightPointsProps,
|
|
370
|
+
fill: s.color,
|
|
371
|
+
class: cls(
|
|
372
|
+
'transition-opacity',
|
|
373
|
+
highlightSeriesKey && highlightSeriesKey !== s.key && 'opacity-10',
|
|
374
|
+
highlightPointsProps?.class
|
|
375
|
+
),
|
|
376
|
+
}}
|
|
375
377
|
/>
|
|
376
378
|
{/each}
|
|
377
379
|
</slot>
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
const point = localPoint(e, containerNode);
|
|
193
193
|
|
|
194
194
|
if (
|
|
195
|
-
tooltipData
|
|
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 ||
|