svelteplot 0.2.9-pr-104.2 → 0.2.9-pr-104.3
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/helpers/scales.js +7 -3
- package/dist/marks/AxisX.svelte +1 -1
- package/dist/marks/Dot.svelte +0 -1
- package/dist/transforms/sort.d.ts +1 -1
- package/dist/transforms/sort.js +21 -13
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
package/dist/helpers/scales.js
CHANGED
|
@@ -55,9 +55,7 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
55
55
|
// we're deliberately checking for !== undefined and not for != null
|
|
56
56
|
// since the explicit sort transforms like shuffle will set the
|
|
57
57
|
// sort channel to null to we know that there's an explicit order
|
|
58
|
-
if (name === 'y')
|
|
59
|
-
console.log(mark.type, mark.options[IS_SORTED]);
|
|
60
|
-
if (mark.options[IS_SORTED] != null) {
|
|
58
|
+
if ((name === 'x' || name === 'y') && mark.options[IS_SORTED] != undefined) {
|
|
61
59
|
sortOrdinalDomain = false;
|
|
62
60
|
}
|
|
63
61
|
for (const channel of mark.channels) {
|
|
@@ -139,6 +137,12 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
139
|
}
|
|
140
|
+
if ((name === 'x' || name === 'y') && scaleOptions.sort) {
|
|
141
|
+
sortOrdinalDomain = true;
|
|
142
|
+
}
|
|
143
|
+
if ((name === 'x' || name === 'y') && scaleOptions.sort === false) {
|
|
144
|
+
sortOrdinalDomain = false;
|
|
145
|
+
}
|
|
142
146
|
// construct domain from data values
|
|
143
147
|
const valueArr = [...dataValues.values(), ...(scaleOptions.domain || [])].filter((d) => d != null);
|
|
144
148
|
const type = scaleOptions.type === 'auto'
|
package/dist/marks/AxisX.svelte
CHANGED
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
const ticks: RawValue[] = $derived(
|
|
100
100
|
data.length > 0
|
|
101
101
|
? // use custom tick values if user passed any as prop
|
|
102
|
-
data
|
|
102
|
+
Array.from(new Set(data))
|
|
103
103
|
: // use custom scale tick values if user passed any as plot scale option
|
|
104
104
|
autoTicks(
|
|
105
105
|
plot.scales.x.type,
|
package/dist/marks/Dot.svelte
CHANGED
|
@@ -5,7 +5,7 @@ export declare function sort({ data, ...channels }: TransformArg<DataRecord>, op
|
|
|
5
5
|
reverse?: boolean;
|
|
6
6
|
}): any;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* shuffles the data row order
|
|
9
9
|
*/
|
|
10
10
|
export declare function shuffle({ data, ...channels }: TransformArg<DataRow[]>, options?: {
|
|
11
11
|
seed?: number;
|
package/dist/transforms/sort.js
CHANGED
|
@@ -15,18 +15,24 @@ export function sort({ data, ...channels }, options = {}) {
|
|
|
15
15
|
sort.channel = sort.channel.substring(1);
|
|
16
16
|
sort.order = 'descending';
|
|
17
17
|
}
|
|
18
|
+
// if sort is a function that does not take exactly one argument, we treat it
|
|
19
|
+
// as comparator function, as you would pass to array.sort
|
|
20
|
+
const isComparator = typeof channels.sort === 'function' && channels.sort.length !== 1;
|
|
18
21
|
// sort data
|
|
19
22
|
return {
|
|
20
|
-
data:
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
? -1
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
data: isComparator
|
|
24
|
+
? data.toSorted(channels.sort)
|
|
25
|
+
: data
|
|
26
|
+
.map((d) => ({
|
|
27
|
+
...d,
|
|
28
|
+
[SORT_KEY]: resolveChannel('sort', d, { ...channels, sort })
|
|
29
|
+
}))
|
|
30
|
+
.toSorted((a, b) => (a[SORT_KEY] > b[SORT_KEY] ? 1 : a[SORT_KEY] < b[SORT_KEY] ? -1 : 0) *
|
|
31
|
+
(options.reverse ||
|
|
32
|
+
(isDataRecord(sort) && sort?.order === 'descending')
|
|
33
|
+
? -1
|
|
34
|
+
: 1))
|
|
35
|
+
.map(({ [SORT_KEY]: a, ...rest }) => rest),
|
|
30
36
|
...channels,
|
|
31
37
|
[IS_SORTED]: sort,
|
|
32
38
|
// set the sort channel to null to disable the implicit alphabetical
|
|
@@ -41,7 +47,7 @@ export function sort({ data, ...channels }, options = {}) {
|
|
|
41
47
|
};
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
|
-
*
|
|
50
|
+
* shuffles the data row order
|
|
45
51
|
*/
|
|
46
52
|
export function shuffle({ data, ...channels }, options = {}) {
|
|
47
53
|
const random = randomLcg(options.seed);
|
|
@@ -51,7 +57,8 @@ export function shuffle({ data, ...channels }, options = {}) {
|
|
|
51
57
|
...channels,
|
|
52
58
|
// set the sort channel to null to disable the implicit
|
|
53
59
|
// alphabetical ordering of ordinal domains
|
|
54
|
-
sort: null
|
|
60
|
+
sort: null,
|
|
61
|
+
[IS_SORTED]: true
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
64
|
/**
|
|
@@ -63,6 +70,7 @@ export function reverse({ data, ...channels }) {
|
|
|
63
70
|
...channels,
|
|
64
71
|
// set the sort channel to null to disable the implicit
|
|
65
72
|
// alphabetical ordering of ordinal domains
|
|
66
|
-
sort: null
|
|
73
|
+
sort: null,
|
|
74
|
+
[IS_SORTED]: true
|
|
67
75
|
};
|
|
68
76
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -512,7 +512,7 @@ export type BaseMarkProps = Partial<{
|
|
|
512
512
|
dy: ConstantAccessor<number>;
|
|
513
513
|
fill: ConstantAccessor<string>;
|
|
514
514
|
fillOpacity: ConstantAccessor<number>;
|
|
515
|
-
sort: string | ConstantAccessor<RawValue> | {
|
|
515
|
+
sort: string | ConstantAccessor<RawValue> | ((a: RawValue, b: RawValue) => number) | {
|
|
516
516
|
/** sort data using an already defined channel */
|
|
517
517
|
channel: string;
|
|
518
518
|
/** sort order */
|
|
@@ -583,7 +583,7 @@ export type BaseRectMarkProps = {
|
|
|
583
583
|
borderRadius?: BorderRadius;
|
|
584
584
|
};
|
|
585
585
|
export type Channels = Record<string, ChannelAccessor | ConstantAccessor<string | number | boolean | symbol>>;
|
|
586
|
-
export type TransformArg<K> = Channels & {
|
|
586
|
+
export type TransformArg<K> = Channels & BaseMarkProps & {
|
|
587
587
|
data: K[];
|
|
588
588
|
};
|
|
589
589
|
export type MapArg<K> = Channels & {
|