svelteplot 0.8.1-pr-298.3 → 0.8.1-pr-298.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/marks/BoxY.svelte
CHANGED
|
@@ -12,7 +12,18 @@
|
|
|
12
12
|
/**
|
|
13
13
|
* Custom sort order for grouped box plot data
|
|
14
14
|
*/
|
|
15
|
-
sort?:
|
|
15
|
+
sort?:
|
|
16
|
+
| 'min'
|
|
17
|
+
| 'max'
|
|
18
|
+
| 'median'
|
|
19
|
+
| 'p25'
|
|
20
|
+
| 'p75'
|
|
21
|
+
| '-min'
|
|
22
|
+
| '-max'
|
|
23
|
+
| '-median'
|
|
24
|
+
| '-p25'
|
|
25
|
+
| '-p75'
|
|
26
|
+
| ((d: Datum) => RawValue);
|
|
16
27
|
/**
|
|
17
28
|
* Options for the rule marks that represent the min/max range
|
|
18
29
|
*/
|
|
@@ -7,7 +7,7 @@ declare function $$render<Datum extends DataRecord>(): {
|
|
|
7
7
|
/**
|
|
8
8
|
* Custom sort order for grouped box plot data
|
|
9
9
|
*/
|
|
10
|
-
sort?: "min" | "max" | "median" | "p25" | "p75" | ((d: Datum) => RawValue);
|
|
10
|
+
sort?: "min" | "max" | "median" | "p25" | "p75" | "-min" | "-max" | "-median" | "-p25" | "-p75" | ((d: Datum) => RawValue);
|
|
11
11
|
/**
|
|
12
12
|
* Options for the rule marks that represent the min/max range
|
|
13
13
|
*/
|
|
@@ -167,11 +167,13 @@
|
|
|
167
167
|
|
|
168
168
|
if (!sort) return boxes.map(stripSortRef);
|
|
169
169
|
|
|
170
|
+
const [sort_, direction] = maybeSort(sort);
|
|
171
|
+
|
|
170
172
|
const sortAccessor =
|
|
171
173
|
typeof sort === 'function'
|
|
172
174
|
? (d) => sort(d[SORT_REF])
|
|
173
175
|
: (d) => {
|
|
174
|
-
switch (
|
|
176
|
+
switch (sort_) {
|
|
175
177
|
case 'min':
|
|
176
178
|
return d[MIN];
|
|
177
179
|
case 'max':
|
|
@@ -186,13 +188,28 @@
|
|
|
186
188
|
}
|
|
187
189
|
};
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
console.log({ sort_, direction });
|
|
190
192
|
|
|
191
193
|
return boxes
|
|
192
|
-
.toSorted(
|
|
194
|
+
.toSorted(
|
|
195
|
+
(a, b) =>
|
|
196
|
+
compareValues(sortAccessor(a), sortAccessor(b)) *
|
|
197
|
+
direction *
|
|
198
|
+
(orientation === 'x' ? -1 : 1)
|
|
199
|
+
)
|
|
193
200
|
.map(stripSortRef);
|
|
194
201
|
});
|
|
195
202
|
|
|
203
|
+
function maybeSort(
|
|
204
|
+
sort: string | ((d: Datum) => RawValue) | undefined
|
|
205
|
+
): [string | ((d: Datum) => RawValue), 1 | -1] {
|
|
206
|
+
if (typeof sort !== 'string') return [sort, 1];
|
|
207
|
+
if (sort.startsWith('-')) {
|
|
208
|
+
return [sort.slice(1), -1];
|
|
209
|
+
}
|
|
210
|
+
return [sort, 1];
|
|
211
|
+
}
|
|
212
|
+
|
|
196
213
|
const valueSymbol = $derived(orientation === 'y' ? Y : X);
|
|
197
214
|
const groupSymbol = $derived(orientation === 'y' ? X : Y);
|
|
198
215
|
const length = $derived(className ? 2 : grouped.length);
|