svelteplot 0.5.1-pr-244.1 → 0.5.1-pr-245.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/core/Plot.svelte
CHANGED
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
margin: 'auto',
|
|
66
66
|
colorScheme: 'turbo',
|
|
67
67
|
unknown: '#cccccc99',
|
|
68
|
-
|
|
68
|
+
sortOrdinalDomains: true,
|
|
69
69
|
categoricalColorScheme: 'observable10',
|
|
70
70
|
pointScaleHeight: 18,
|
|
71
71
|
bandScaleHeight: 30,
|
|
@@ -365,7 +365,12 @@
|
|
|
365
365
|
initialOpts: Partial<PlotOptions>,
|
|
366
366
|
opts: PlotOptionsParameters
|
|
367
367
|
): PlotOptions {
|
|
368
|
-
return mergeDeep<PlotOptions>(
|
|
368
|
+
return mergeDeep<PlotOptions>(
|
|
369
|
+
{},
|
|
370
|
+
{ sortOrdinalDomains: DEFAULTS.sortOrdinalDomains },
|
|
371
|
+
smartDefaultPlotOptions(opts),
|
|
372
|
+
initialOpts
|
|
373
|
+
);
|
|
369
374
|
}
|
|
370
375
|
|
|
371
376
|
function maybeMargin(
|
package/dist/helpers/scales.d.ts
CHANGED
|
@@ -40,3 +40,4 @@ export declare function looksLikeANumber(input: string | number): boolean;
|
|
|
40
40
|
export declare function projectXY(scales: PlotScales, x: RawValue, y: RawValue, useXScale?: boolean, useYScale?: boolean): [number, number];
|
|
41
41
|
export declare function projectX(channel: 'x' | 'x1' | 'x2', scales: PlotScales, value: RawValue): number;
|
|
42
42
|
export declare function projectY(channel: 'y' | 'y1' | 'y2', scales: PlotScales, value: RawValue): number;
|
|
43
|
+
export declare function isOrdinalScale(scaleType: ScaleType): scaleType is "point" | "ordinal" | "band" | "categorical" | "threshold";
|
package/dist/helpers/scales.js
CHANGED
|
@@ -48,7 +48,7 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
48
48
|
let manualActiveMarks = 0;
|
|
49
49
|
const propNames = new Set();
|
|
50
50
|
const uniqueScaleProps = new Set();
|
|
51
|
-
let sortOrdinalDomain = true;
|
|
51
|
+
let sortOrdinalDomain = plotOptions.sortOrdinalDomains ?? true;
|
|
52
52
|
for (const mark of marks) {
|
|
53
53
|
// we only sort the scale domain alphabetically, if none of the
|
|
54
54
|
// marks that map to it are using the `sort` transform. Note that
|
|
@@ -152,11 +152,7 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
152
152
|
throw new Error(`Invalid scale type ${type} for scale
|
|
153
153
|
${name}. Valid types are ${[...VALID_SCALE_TYPES[name]].join(', ')}`);
|
|
154
154
|
}
|
|
155
|
-
const isOrdinal = type
|
|
156
|
-
type === 'point' ||
|
|
157
|
-
type === 'ordinal' ||
|
|
158
|
-
type === 'categorical' ||
|
|
159
|
-
type === 'threshold';
|
|
155
|
+
const isOrdinal = isOrdinalScale(type);
|
|
160
156
|
if (isOrdinal && sortOrdinalDomain) {
|
|
161
157
|
valueArr.sort(ascending);
|
|
162
158
|
}
|
|
@@ -351,3 +347,10 @@ export function projectY(channel, scales, value) {
|
|
|
351
347
|
? scales.y.fn.bandwidth()
|
|
352
348
|
: 0));
|
|
353
349
|
}
|
|
350
|
+
export function isOrdinalScale(scaleType) {
|
|
351
|
+
return (scaleType === 'band' ||
|
|
352
|
+
scaleType === 'point' ||
|
|
353
|
+
scaleType === 'ordinal' ||
|
|
354
|
+
scaleType === 'categorical' ||
|
|
355
|
+
scaleType === 'threshold');
|
|
356
|
+
}
|
package/dist/marks/BarX.svelte
CHANGED
package/dist/marks/BarY.svelte
CHANGED
package/dist/marks/Dot.svelte
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
import { addEventHandlers } from './helpers/events.js';
|
|
33
33
|
import Anchor from './helpers/Anchor.svelte';
|
|
34
34
|
import { getPlotDefaults } from '../hooks/plotDefaults.js';
|
|
35
|
+
import { isOrdinalScale } from '../helpers/scales.js';
|
|
35
36
|
|
|
36
37
|
const DEFAULTS = {
|
|
37
38
|
...getPlotDefaults().dot
|
|
@@ -60,7 +61,11 @@
|
|
|
60
61
|
recordizeXY({
|
|
61
62
|
data,
|
|
62
63
|
// sort by descending radius by default
|
|
63
|
-
...(options.r
|
|
64
|
+
...(options.r &&
|
|
65
|
+
!isOrdinalScale(plot.scales.x.type) &&
|
|
66
|
+
!isOrdinalScale(plot.scales.y.type)
|
|
67
|
+
? { sort: { channel: '-r' } }
|
|
68
|
+
: {}),
|
|
64
69
|
...options,
|
|
65
70
|
...(options.fill === true ? { fill: 'currentColor' } : {})
|
|
66
71
|
})
|
package/dist/types/plot.d.ts
CHANGED
|
@@ -112,6 +112,10 @@ export type PlotDefaults = {
|
|
|
112
112
|
* default dot radius for line markers, used in dot, circle, and circle-stroke markers
|
|
113
113
|
*/
|
|
114
114
|
markerDotRadius: number;
|
|
115
|
+
/**
|
|
116
|
+
* if set to true, ordinal domains will be sorted alphabetically
|
|
117
|
+
*/
|
|
118
|
+
sortOrdinalDomains: boolean;
|
|
115
119
|
/**
|
|
116
120
|
* default props for area marks, applied to area, areaX, and areaY marks
|
|
117
121
|
*/
|
|
@@ -467,5 +471,9 @@ export type PlotOptions = {
|
|
|
467
471
|
* pass a @emotion/css function to style plot using dynamic classes
|
|
468
472
|
*/
|
|
469
473
|
css: (d: string) => string | undefined;
|
|
474
|
+
/**
|
|
475
|
+
* if set to true, ordinal domains will be sorted alphabetically
|
|
476
|
+
*/
|
|
477
|
+
sortOrdinalDomains: boolean;
|
|
470
478
|
};
|
|
471
479
|
export {};
|