layerchart 0.59.0 → 0.59.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/Spline.svelte +23 -13
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +20 -0
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import { motionStore } from '../stores/motionStore.js';
|
|
21
21
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
22
22
|
import { isScaleBand } from '../utils/scales.js';
|
|
23
|
+
import { flattenPathData } from '../utils/path.js';
|
|
23
24
|
|
|
24
25
|
const {
|
|
25
26
|
data: contextData,
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
y: contextY,
|
|
30
31
|
yRange,
|
|
31
32
|
radial,
|
|
33
|
+
config,
|
|
32
34
|
} = chartContext();
|
|
33
35
|
|
|
34
36
|
/** Override data instead of using context */
|
|
@@ -100,19 +102,27 @@
|
|
|
100
102
|
|
|
101
103
|
/** Provide initial `0` horizontal baseline and initially hide/untrack scale changes so not reactive (only set on initial mount) */
|
|
102
104
|
function defaultPathData() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
105
|
+
if (pathData) {
|
|
106
|
+
// Flatten all `y` coordinates of pre-defined `pathData`
|
|
107
|
+
return flattenPathData(pathData, Math.min($yScale(0), $yRange[0]));
|
|
108
|
+
} else if ($config.x) {
|
|
109
|
+
// Only use default line if `x` accessor is defined (cartesian chart)
|
|
110
|
+
const path = $radial
|
|
111
|
+
? lineRadial()
|
|
112
|
+
.angle((d) => $xScale(xAccessor(d)))
|
|
113
|
+
.radius((d) => Math.min($yScale(0), $yRange[0]))
|
|
114
|
+
: d3Line()
|
|
115
|
+
.x((d) => $xScale(xAccessor(d)) + xOffset)
|
|
116
|
+
.y((d) => Math.min($yScale(0), $yRange[0]));
|
|
117
|
+
|
|
118
|
+
path.defined(defined ?? ((d) => xAccessor(d) != null && yAccessor(d) != null));
|
|
119
|
+
|
|
120
|
+
if (curve) path.curve(curve);
|
|
121
|
+
|
|
122
|
+
return path(data ?? $contextData);
|
|
123
|
+
} else {
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
116
126
|
}
|
|
117
127
|
|
|
118
128
|
let d: string | null = '';
|
package/dist/utils/path.d.ts
CHANGED
package/dist/utils/path.js
CHANGED
|
@@ -22,3 +22,23 @@ export function circlePath(dimensions) {
|
|
|
22
22
|
a ${r},${r} 0 1,${sweep} -${r * 2},0
|
|
23
23
|
`;
|
|
24
24
|
}
|
|
25
|
+
/** Flatten all `y` coordinates to `0` */
|
|
26
|
+
export function flattenPathData(pathData, yOverride = 0) {
|
|
27
|
+
let result = pathData;
|
|
28
|
+
// Match commands with y-coordinates, and replace `y` coordinate with `0` (or override such as `yScale(0)`)
|
|
29
|
+
result = result.replace(/([MLTQCSAZ])(-?\d*\.?\d+),(-?\d*\.?\d+)/g, (match, command, x, y) => {
|
|
30
|
+
return `${command}${x},${yOverride}`;
|
|
31
|
+
});
|
|
32
|
+
// Replace all vertical line commands (ex. `v123`) with `0` height
|
|
33
|
+
result = result.replace(/([v])(-?\d*\.?\d+)/g, (match, command, l) => {
|
|
34
|
+
return `${command}${0}`;
|
|
35
|
+
});
|
|
36
|
+
// TODO: Flatten all elliptical arc commands (ex. `a4,4 0 0 1 4,4`) with `0` height
|
|
37
|
+
// result = result.replace(
|
|
38
|
+
// /a(\d+),(\d+) (\d+) (\d+) (\d+) (\d+),(\d+)/g,
|
|
39
|
+
// (match, rx, ry, rot, large, sweep, x, y) => {
|
|
40
|
+
// return `a${rx},0 ${rot} ${large} ${sweep} ${x},0`;
|
|
41
|
+
// }
|
|
42
|
+
// );
|
|
43
|
+
return result;
|
|
44
|
+
}
|