svelteplot 0.4.2-pr-193.0 → 0.4.2-pr-194.0
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/Mark.svelte +4 -2
- package/dist/helpers/resolve.js +4 -4
- package/dist/marks/RuleX.svelte +1 -1
- package/dist/marks/RuleX.svelte.d.ts +1 -1
- package/dist/transforms/recordize.d.ts +9 -7
- package/dist/transforms/recordize.js +23 -24
- package/dist/types/channel.d.ts +1 -1
- package/dist/types/data.d.ts +2 -0
- package/dist/types/index.d.ts +6 -6
- package/package.json +1 -1
package/dist/Mark.svelte
CHANGED
|
@@ -135,11 +135,12 @@
|
|
|
135
135
|
const resolvedData: ResolvedDataRecord<Datum>[] = $derived(
|
|
136
136
|
data
|
|
137
137
|
.map((d, i) => ({ ...d, [INDEX]: i }))
|
|
138
|
-
.flatMap((row) => {
|
|
138
|
+
.flatMap((row, index) => {
|
|
139
139
|
const channels = options as Record<ChannelName, ChannelAccessor<Datum>>;
|
|
140
140
|
if (!testFacet(row, channels) || !testFilter(row, channels)) return [];
|
|
141
141
|
const out: ResolvedDataRecord<Datum> = {
|
|
142
|
-
datum: row
|
|
142
|
+
datum: row,
|
|
143
|
+
index
|
|
143
144
|
};
|
|
144
145
|
for (const [channel] of Object.entries(CHANNEL_SCALE) as [
|
|
145
146
|
ScaledChannelName,
|
|
@@ -208,6 +209,7 @@
|
|
|
208
209
|
resolvedData.flatMap((row) => {
|
|
209
210
|
const out: ScaledDataRecord<Datum> = {
|
|
210
211
|
datum: row.datum,
|
|
212
|
+
index: row[INDEX],
|
|
211
213
|
valid: true
|
|
212
214
|
};
|
|
213
215
|
// compute dx/dy
|
package/dist/helpers/resolve.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CHANNEL_SCALE } from '../constants.js';
|
|
1
|
+
import { CHANNEL_SCALE, INDEX } from '../constants.js';
|
|
2
2
|
import isDataRecord from './isDataRecord.js';
|
|
3
3
|
import isRawValue from './isRawValue.js';
|
|
4
4
|
import { isValid } from './index.js';
|
|
@@ -11,7 +11,7 @@ export function resolveProp(accessor, datum, _defaultValue = null) {
|
|
|
11
11
|
// so we're passing the original value to accessor functions instead of our wrapped record
|
|
12
12
|
return datum == null
|
|
13
13
|
? accessor()
|
|
14
|
-
: accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum);
|
|
14
|
+
: accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum, datum[INDEX]);
|
|
15
15
|
}
|
|
16
16
|
else if ((typeof accessor === 'string' || typeof accessor === 'symbol') &&
|
|
17
17
|
datum &&
|
|
@@ -51,7 +51,7 @@ function resolve(datum, accessor, channel, scale) {
|
|
|
51
51
|
// datum[RAW_VALUE] exists if an array of raw values was used as dataset and got
|
|
52
52
|
// "recordized" by the recordize transform. We want to hide this wrapping to the user
|
|
53
53
|
// so we're passing the original value to accessor functions instead of our wrapped record
|
|
54
|
-
return accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum);
|
|
54
|
+
return accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum, datum?.[INDEX]);
|
|
55
55
|
// use accessor string
|
|
56
56
|
if ((typeof accessor === 'string' || typeof accessor === 'symbol') &&
|
|
57
57
|
datum[accessor] !== undefined)
|
|
@@ -69,7 +69,7 @@ function resolve(datum, accessor, channel, scale) {
|
|
|
69
69
|
else {
|
|
70
70
|
// return single value or accessor
|
|
71
71
|
return typeof accessor === 'function'
|
|
72
|
-
? accessor(datum)
|
|
72
|
+
? accessor(datum, datum?.[INDEX])
|
|
73
73
|
: accessor !== null && isRawValue(accessor)
|
|
74
74
|
? accessor
|
|
75
75
|
: !Array.isArray(datum) && (scale === 'x' || scale === 'y')
|
package/dist/marks/RuleX.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
-->
|
|
4
4
|
<script lang="ts" generics="Datum = DataRecord | RawValue">
|
|
5
5
|
interface RuleXMarkProps extends Omit<BaseMarkProps<Datum>, 'fill' | 'fillOpacity'> {
|
|
6
|
-
data
|
|
6
|
+
data?: Datum[];
|
|
7
7
|
x?: ChannelAccessor<Datum>;
|
|
8
8
|
y1?: ChannelAccessor<Datum>;
|
|
9
9
|
y2?: ChannelAccessor<Datum>;
|
|
@@ -60,7 +60,7 @@ declare class __sveltets_Render<Datum = DataRecord | RawValue> {
|
|
|
60
60
|
class: string | null;
|
|
61
61
|
cursor: ConstantAccessor<import("csstype").Property.Cursor, Datum>;
|
|
62
62
|
}>, "fill" | "fillOpacity"> & {
|
|
63
|
-
data
|
|
63
|
+
data?: Datum[] | undefined;
|
|
64
64
|
x?: ChannelAccessor<Datum>;
|
|
65
65
|
y1?: ChannelAccessor<Datum>;
|
|
66
66
|
y2?: ChannelAccessor<Datum>;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { TransformArgsRow, TransformArgsRecord } from '../types/index.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const X: unique symbol;
|
|
3
|
+
export declare const Y: unique symbol;
|
|
3
4
|
export declare const RAW_VALUE: unique symbol;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function indexData<T extends object>(data: T[]): (T & {})[];
|
|
6
|
+
export declare function recordizeX<T>({ data, ...channels }: TransformArgsRow<T>, { withIndex }?: {
|
|
5
7
|
withIndex: boolean;
|
|
6
|
-
}): TransformArgsRecord
|
|
7
|
-
export declare function recordizeY({ data, ...channels }: TransformArgsRow
|
|
8
|
+
}): TransformArgsRecord<T>;
|
|
9
|
+
export declare function recordizeY<T>({ data, ...channels }: TransformArgsRow<T>, { withIndex }?: {
|
|
8
10
|
withIndex: boolean;
|
|
9
|
-
}): TransformArgsRecord
|
|
11
|
+
}): TransformArgsRecord<T>;
|
|
10
12
|
/**
|
|
11
13
|
* This transform is used to allow users to pass an [[x0, y0], [x1, y1], ...] array
|
|
12
14
|
* as dataset to marks that support it. It transforms the arrays into records, so
|
|
13
15
|
* the rest of our code doesn't have to deal with this case anymore.
|
|
14
16
|
*/
|
|
15
|
-
export declare function recordizeXY({ data, ...channels }: TransformArgsRow): TransformArgsRecord
|
|
16
|
-
export declare function recordize({ data, ...channels }: TransformArgsRow): TransformArgsRecord
|
|
17
|
+
export declare function recordizeXY<T>({ data, ...channels }: TransformArgsRow<T>): TransformArgsRecord<T>;
|
|
18
|
+
export declare function recordize<T>({ data, ...channels }: TransformArgsRow<T>): TransformArgsRecord<T>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import isDataRecord from '../helpers/isDataRecord.js';
|
|
2
|
-
|
|
2
|
+
import { INDEX } from '../constants';
|
|
3
|
+
export const X = Symbol('x');
|
|
4
|
+
export const Y = Symbol('y');
|
|
3
5
|
export const RAW_VALUE = Symbol('originalValue');
|
|
6
|
+
export function indexData(data) {
|
|
7
|
+
return data.map((d, i) => ({ ...d, [INDEX]: i }));
|
|
8
|
+
}
|
|
4
9
|
/*
|
|
5
10
|
* This transform takes an array of raw values as input and returns data records
|
|
6
11
|
* in which the values are interpreted as x channel and their index as y
|
|
@@ -10,16 +15,15 @@ export function recordizeX({ data, ...channels }, { withIndex } = { withIndex: t
|
|
|
10
15
|
if (dataIsRawValueArray) {
|
|
11
16
|
return {
|
|
12
17
|
data: data.map((value, index) => ({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[RAW_VALUE]: value
|
|
18
|
+
[RAW_VALUE]: value,
|
|
19
|
+
[INDEX]: index
|
|
16
20
|
})),
|
|
17
21
|
...channels,
|
|
18
22
|
x: RAW_VALUE,
|
|
19
23
|
...(withIndex ? { y: INDEX } : {})
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
|
-
return { data: data, ...channels };
|
|
26
|
+
return { data: indexData(data), ...channels };
|
|
23
27
|
}
|
|
24
28
|
/*
|
|
25
29
|
* This transform takes an array of raw values as input and returns data records
|
|
@@ -32,22 +36,15 @@ export function recordizeY({ data, ...channels }, { withIndex } = { withIndex: t
|
|
|
32
36
|
if (dataIsRawValueArray) {
|
|
33
37
|
return {
|
|
34
38
|
data: Array.from(data).map((value, index) => ({
|
|
35
|
-
|
|
39
|
+
[INDEX]: index,
|
|
36
40
|
[RAW_VALUE]: value
|
|
37
41
|
})),
|
|
38
42
|
...channels,
|
|
39
|
-
...(withIndex ? { x:
|
|
43
|
+
...(withIndex ? { x: INDEX } : {}),
|
|
40
44
|
y: RAW_VALUE
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
|
-
return {
|
|
44
|
-
data: Array.from(data).map((d, index) => ({
|
|
45
|
-
...d,
|
|
46
|
-
...(withIndex ? { __index: index } : {})
|
|
47
|
-
})),
|
|
48
|
-
x: '__index',
|
|
49
|
-
...channels
|
|
50
|
-
};
|
|
47
|
+
return { data: indexData(data), ...channels };
|
|
51
48
|
}
|
|
52
49
|
/**
|
|
53
50
|
* This transform is used to allow users to pass an [[x0, y0], [x1, y1], ...] array
|
|
@@ -62,28 +59,30 @@ export function recordizeXY({ data, ...channels }) {
|
|
|
62
59
|
channels.x === undefined &&
|
|
63
60
|
channels.y === undefined) {
|
|
64
61
|
return {
|
|
65
|
-
data: data.map(([x, y, ...rest]) => ({
|
|
62
|
+
data: data.map(([x, y, ...rest], i) => ({
|
|
66
63
|
[RAW_VALUE]: [x, y, ...rest],
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
[INDEX]: i,
|
|
65
|
+
[X]: x,
|
|
66
|
+
[Y]: y
|
|
69
67
|
})),
|
|
70
68
|
...channels,
|
|
71
|
-
x:
|
|
72
|
-
y:
|
|
69
|
+
x: X,
|
|
70
|
+
y: Y
|
|
73
71
|
};
|
|
74
72
|
}
|
|
75
|
-
return { data, ...channels };
|
|
73
|
+
return { data: data, ...channels };
|
|
76
74
|
}
|
|
77
75
|
export function recordize({ data, ...channels }) {
|
|
78
76
|
if (!data)
|
|
79
77
|
return { data, ...channels };
|
|
80
78
|
if (!isDataRecord(data[0])) {
|
|
81
79
|
return {
|
|
82
|
-
data: data.map((d) => ({
|
|
83
|
-
[RAW_VALUE]: d
|
|
80
|
+
data: data.map((d, i) => ({
|
|
81
|
+
[RAW_VALUE]: d,
|
|
82
|
+
[INDEX]: i
|
|
84
83
|
})),
|
|
85
84
|
...channels
|
|
86
85
|
};
|
|
87
86
|
}
|
|
88
|
-
return { data, ...channels };
|
|
87
|
+
return { data: indexData(data), ...channels };
|
|
89
88
|
}
|
package/dist/types/channel.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type ChannelAccessor<T = Record<string | symbol, RawValue>> = ChannelValu
|
|
|
6
6
|
/** you can bypass the scale by passing null */
|
|
7
7
|
scale: boolean | null;
|
|
8
8
|
};
|
|
9
|
-
export type ChannelValue<T = Record<string | symbol, RawValue>> = RawValue | keyof T | ((d: T) => RawValue) | null | undefined;
|
|
9
|
+
export type ChannelValue<T = Record<string | symbol, RawValue>> = RawValue | keyof T | ((d: T, index: number) => RawValue) | null | undefined;
|
|
10
10
|
export type ScaledChannelName = 'fill' | 'fillOpacity' | 'opacity' | 'r' | 'length' | 'stroke' | 'strokeOpacity' | 'symbol' | 'fx' | 'fy' | 'x' | 'x1' | 'x2' | 'y' | 'y1' | 'y2';
|
|
11
11
|
export type ScaledChannelType<T extends ScaledChannelName> = T extends 'fill' | 'stroke' | 'symbol' ? string : number;
|
|
12
12
|
export type ChannelName = ScaledChannelName | 'z' | 'sort' | 'filter' | 'interval';
|
package/dist/types/data.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type RawValue = number | Date | boolean | string | symbol;
|
|
|
3
3
|
export type DataRecord<T = Record<string | symbol, RawValue>> = T;
|
|
4
4
|
export type ResolvedDataRecord<T = Record<string | symbol, RawValue>> = Partial<Record<ScaledChannelName, any>> & {
|
|
5
5
|
datum: DataRecord<T>;
|
|
6
|
+
index: number;
|
|
6
7
|
};
|
|
7
8
|
export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<{
|
|
8
9
|
[K in ScaledChannelName]?: ScaledChannelType<K>;
|
|
@@ -11,5 +12,6 @@ export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<{
|
|
|
11
12
|
dy: number;
|
|
12
13
|
datum: DataRecord<T>;
|
|
13
14
|
valid: Boolean;
|
|
15
|
+
index: number;
|
|
14
16
|
};
|
|
15
17
|
export type DataRow<T = Record<string | symbol, RawValue>> = DataRecord<T> | RawValue | [number, number] | null;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Snippet } from 'svelte';
|
|
|
2
2
|
import type { Writable } from 'svelte/store';
|
|
3
3
|
import type { MarkerShape } from '../marks/helpers/Marker.svelte';
|
|
4
4
|
import type { Channels, ScaledChannelName } from './channel.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { RawValue } from './data.js';
|
|
6
6
|
import type { BaseMarkProps } from './mark.js';
|
|
7
7
|
export type GenericMarkOptions = Record<string | symbol, any>;
|
|
8
8
|
export type CurveName = 'basis' | 'basis-closed' | 'basis-open' | 'bundle' | 'bump-x' | 'bump-y' | 'cardinal' | 'cardinal-closed' | 'cardinal-open' | 'catmull-rom' | 'catmull-rom-closed' | 'catmull-rom-open' | 'linear' | 'linear-closed' | 'monotone-x' | 'monotone-y' | 'natural' | 'step' | 'step-after' | 'step-before';
|
|
@@ -24,18 +24,18 @@ export type MarkerOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
marker?: boolean | MarkerShape | Snippet;
|
|
26
26
|
};
|
|
27
|
-
export type ConstantAccessor<K, T = Record<string | symbol, RawValue>> = K | ((d: T) => K) | null | undefined;
|
|
27
|
+
export type ConstantAccessor<K, T = Record<string | symbol, RawValue>> = K | ((d: T, index: number) => K) | null | undefined;
|
|
28
28
|
export type TransformArg<T> = Channels<T> & BaseMarkProps<T> & {
|
|
29
29
|
data: T[];
|
|
30
30
|
};
|
|
31
31
|
export type MapArg<T> = Channels<T> & {
|
|
32
32
|
data: T[];
|
|
33
33
|
};
|
|
34
|
-
export type TransformArgsRow = Partial<Channels
|
|
35
|
-
data:
|
|
34
|
+
export type TransformArgsRow<T extends RawValue & object> = Partial<Channels<T>> & {
|
|
35
|
+
data: T[];
|
|
36
36
|
};
|
|
37
|
-
export type TransformArgsRecord = Partial<Channels
|
|
38
|
-
data:
|
|
37
|
+
export type TransformArgsRecord<T extends object> = Partial<Channels<T>> & {
|
|
38
|
+
data: T[];
|
|
39
39
|
};
|
|
40
40
|
export type AutoMarginStores = {
|
|
41
41
|
autoMarginTop: Writable<Map<string, number>>;
|