layerchart 0.59.0 → 0.59.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/Bars.svelte +4 -1
- package/dist/components/Bars.svelte.d.ts +1 -0
- package/dist/components/Labels.svelte +17 -11
- package/dist/components/Labels.svelte.d.ts +8 -1
- package/dist/components/Spline.svelte +23 -13
- package/dist/components/charts/AreaChart.svelte +2 -2
- package/dist/components/charts/AreaChart.svelte.d.ts +1 -0
- package/dist/components/charts/BarChart.svelte +1 -1
- package/dist/components/charts/BarChart.svelte.d.ts +1 -0
- package/dist/components/charts/LineChart.svelte +2 -2
- package/dist/components/charts/LineChart.svelte.d.ts +1 -0
- package/dist/components/charts/PieChart.svelte +1 -1
- package/dist/components/charts/PieChart.svelte.d.ts +2 -1
- package/dist/components/charts/ScatterChart.svelte +1 -1
- package/dist/components/charts/ScatterChart.svelte.d.ts +1 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +20 -0
- package/package.json +5 -3
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
/** Inset the rect for amount of padding. Useful with multiple bars (bullet, overlap, etc) */
|
|
42
42
|
export let inset = 0;
|
|
43
43
|
|
|
44
|
+
/** Define unique value for {#each} `(key)` expressions to improve transitions. `index` position used by default */
|
|
45
|
+
export let key: (d: any, index: number) => any = (d, i) => i;
|
|
46
|
+
|
|
44
47
|
export let spring: ComponentProps<Rect>['spring'] = undefined;
|
|
45
48
|
export let tweened: ComponentProps<Rect>['tweened'] = undefined;
|
|
46
49
|
|
|
@@ -49,7 +52,7 @@
|
|
|
49
52
|
|
|
50
53
|
<g class="Bars">
|
|
51
54
|
<slot>
|
|
52
|
-
{#each _data as d, i}
|
|
55
|
+
{#each _data as d, i (key(d, i))}
|
|
53
56
|
<Bar
|
|
54
57
|
bar={d}
|
|
55
58
|
{x}
|
|
@@ -15,6 +15,7 @@ declare const __propDef: {
|
|
|
15
15
|
radius?: number | undefined;
|
|
16
16
|
fill?: string | undefined;
|
|
17
17
|
inset?: number | undefined;
|
|
18
|
+
key?: ((d: any, index: number) => any) | undefined;
|
|
18
19
|
spring?: ComponentProps<Rect>["spring"];
|
|
19
20
|
tweened?: ComponentProps<Rect>["tweened"];
|
|
20
21
|
};
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
export let offset = placement === 'center' ? 0 : 4;
|
|
19
19
|
export let format: FormatType | undefined = undefined;
|
|
20
20
|
|
|
21
|
+
/** Define unique value for {#each} `(key)` expressions to improve transitions. `index` position used by default */
|
|
22
|
+
export let key: (d: any, index: number) => any = (d, i) => i;
|
|
23
|
+
|
|
21
24
|
$: getTextProps = (point: Point): ComponentProps<Text> => {
|
|
22
25
|
// Used for positioning
|
|
23
26
|
const pointValue = isScaleBand($yScale) ? point.xValue : point.yValue;
|
|
@@ -88,17 +91,20 @@
|
|
|
88
91
|
|
|
89
92
|
<g class="Labels">
|
|
90
93
|
<Points let:points>
|
|
91
|
-
{#each points as point}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
{#each points as point, i (key(point.data, i))}
|
|
95
|
+
{@const textProps = getTextProps(point)}
|
|
96
|
+
<slot data={point} {textProps}>
|
|
97
|
+
<Text
|
|
98
|
+
class={cls(
|
|
99
|
+
'text-xs',
|
|
100
|
+
placement === 'inside'
|
|
101
|
+
? 'fill-surface-300 stroke-surface-content'
|
|
102
|
+
: 'fill-surface-content stroke-surface-100'
|
|
103
|
+
)}
|
|
104
|
+
{...textProps}
|
|
105
|
+
{...$$restProps}
|
|
106
|
+
/>
|
|
107
|
+
</slot>
|
|
102
108
|
{/each}
|
|
103
109
|
</Points>
|
|
104
110
|
</g>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import { type FormatType } from '@layerstack/utils';
|
|
3
|
+
import { type Point } from './Points.svelte';
|
|
3
4
|
import { type Accessor } from '../utils/common.js';
|
|
4
5
|
declare const __propDef: {
|
|
5
6
|
props: {
|
|
@@ -8,11 +9,17 @@ declare const __propDef: {
|
|
|
8
9
|
placement?: ("inside" | "outside" | "center") | undefined;
|
|
9
10
|
offset?: number | undefined;
|
|
10
11
|
format?: FormatType | undefined;
|
|
12
|
+
key?: ((d: any, index: number) => any) | undefined;
|
|
11
13
|
};
|
|
12
14
|
events: {
|
|
13
15
|
[evt: string]: CustomEvent<any>;
|
|
14
16
|
};
|
|
15
|
-
slots: {
|
|
17
|
+
slots: {
|
|
18
|
+
default: {
|
|
19
|
+
data: Point;
|
|
20
|
+
textProps: any;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
16
23
|
};
|
|
17
24
|
export type LabelsProps = typeof __propDef.props;
|
|
18
25
|
export type LabelsEvents = typeof __propDef.events;
|
|
@@ -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 = '';
|
|
@@ -195,7 +195,7 @@
|
|
|
195
195
|
<slot name="belowMarks" {...slotProps} />
|
|
196
196
|
|
|
197
197
|
<slot name="marks" {...slotProps}>
|
|
198
|
-
{#each series as s, i}
|
|
198
|
+
{#each series as s, i (s.key)}
|
|
199
199
|
<Area {...getAreaProps(s, i)} />
|
|
200
200
|
{/each}
|
|
201
201
|
</slot>
|
|
@@ -247,7 +247,7 @@
|
|
|
247
247
|
{/if}
|
|
248
248
|
|
|
249
249
|
<slot name="highlight" {...slotProps}>
|
|
250
|
-
{#each series as s, i}
|
|
250
|
+
{#each series as s, i (s.key)}
|
|
251
251
|
<Highlight
|
|
252
252
|
y={stackSeries ? (d) => d.stackData[i][1] : (s.value ?? s.key)}
|
|
253
253
|
points={{ fill: s.color }}
|
|
@@ -242,6 +242,7 @@ declare class __sveltets_Render<TData> {
|
|
|
242
242
|
placement?: ("inside" | "outside" | "center") | undefined;
|
|
243
243
|
offset?: number | undefined;
|
|
244
244
|
format?: import("@layerstack/utils").FormatType | undefined;
|
|
245
|
+
key?: ((d: any, index: number) => any) | undefined;
|
|
245
246
|
};
|
|
246
247
|
legend?: boolean | {
|
|
247
248
|
[x: string]: any;
|
|
@@ -242,6 +242,7 @@ declare class __sveltets_Render<TData> {
|
|
|
242
242
|
placement?: ("inside" | "outside" | "center") | undefined;
|
|
243
243
|
offset?: number | undefined;
|
|
244
244
|
format?: import("@layerstack/utils").FormatType | undefined;
|
|
245
|
+
key?: ((d: any, index: number) => any) | undefined;
|
|
245
246
|
};
|
|
246
247
|
legend?: boolean | {
|
|
247
248
|
[x: string]: any;
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
<slot name="belowMarks" {...slotProps} />
|
|
143
143
|
|
|
144
144
|
<slot name="marks" {...slotProps}>
|
|
145
|
-
{#each series as s, i}
|
|
145
|
+
{#each series as s, i (s.key)}
|
|
146
146
|
<Spline {...getSplineProps(s, i)} />
|
|
147
147
|
{/each}
|
|
148
148
|
</slot>
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
{/if}
|
|
193
193
|
|
|
194
194
|
<slot name="highlight" {...slotProps}>
|
|
195
|
-
{#each series as s, i}
|
|
195
|
+
{#each series as s, i (s.key)}
|
|
196
196
|
<Highlight
|
|
197
197
|
data={s.data}
|
|
198
198
|
y={s.value ?? s.key}
|
|
@@ -241,6 +241,7 @@ declare class __sveltets_Render<TData> {
|
|
|
241
241
|
placement?: ("inside" | "outside" | "center") | undefined;
|
|
242
242
|
offset?: number | undefined;
|
|
243
243
|
format?: import("@layerstack/utils").FormatType | undefined;
|
|
244
|
+
key?: ((d: any, index: number) => any) | undefined;
|
|
244
245
|
};
|
|
245
246
|
legend?: boolean | {
|
|
246
247
|
[x: string]: any;
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
center={['left', 'right'].includes(placement) ? 'y' : undefined}
|
|
165
165
|
{...props.group}
|
|
166
166
|
>
|
|
167
|
-
{#each series as s, i}
|
|
167
|
+
{#each series as s, i (s.key)}
|
|
168
168
|
{@const singleArc = s.data?.length === 1 || chartData.length === 1}
|
|
169
169
|
{#if singleArc}
|
|
170
170
|
{@const d = s.data?.[0] || chartData[0]}
|
|
@@ -217,7 +217,8 @@ declare class __sveltets_Render<TData> {
|
|
|
217
217
|
label?: string;
|
|
218
218
|
tick?: string;
|
|
219
219
|
swatches?: string;
|
|
220
|
-
swatch
|
|
220
|
+
swatch
|
|
221
|
+
/** Key accessor */ ? /** Key accessor */: string;
|
|
221
222
|
} | undefined;
|
|
222
223
|
};
|
|
223
224
|
maxValue?: number | undefined;
|
|
@@ -240,6 +240,7 @@ declare class __sveltets_Render<TData> {
|
|
|
240
240
|
placement?: ("inside" | "outside" | "center") | undefined;
|
|
241
241
|
offset?: number | undefined;
|
|
242
242
|
format?: import("@layerstack/utils").FormatType | undefined;
|
|
243
|
+
key?: ((d: any, index: number) => any) | undefined;
|
|
243
244
|
};
|
|
244
245
|
legend?: boolean | {
|
|
245
246
|
[x: string]: any;
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "techniq/layerchart",
|
|
7
|
-
"version": "0.59.
|
|
7
|
+
"version": "0.59.2",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@changesets/cli": "^2.27.9",
|
|
10
10
|
"@mdi/js": "^7.4.47",
|
|
@@ -104,11 +104,13 @@
|
|
|
104
104
|
"exports": {
|
|
105
105
|
".": {
|
|
106
106
|
"types": "./dist/index.d.ts",
|
|
107
|
-
"svelte": "./dist/index.js"
|
|
107
|
+
"svelte": "./dist/index.js",
|
|
108
|
+
"default": "./dist/index.js"
|
|
108
109
|
},
|
|
109
110
|
"./utils/*": {
|
|
110
111
|
"types": "./dist/utils/*.d.ts",
|
|
111
|
-
"svelte": "./dist/utils/*.js"
|
|
112
|
+
"svelte": "./dist/utils/*.js",
|
|
113
|
+
"default": "./dist/utils/*.js"
|
|
112
114
|
}
|
|
113
115
|
},
|
|
114
116
|
"files": [
|