svelteplot 0.10.3-pr-404.0 → 0.10.3-pr-405.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 +13 -8
- package/dist/hooks/plotDefaults.js +31 -1
- package/dist/types/plot.d.ts +4 -4
- package/package.json +1 -1
package/dist/core/Plot.svelte
CHANGED
|
@@ -59,6 +59,11 @@
|
|
|
59
59
|
|
|
60
60
|
// default settings in the plot and marks can be overwritten by
|
|
61
61
|
// defining the svelteplot/defaults context outside of Plot
|
|
62
|
+
const asGridDefaults = (opts: PlotDefaults['grid'] | undefined) =>
|
|
63
|
+
opts === true ? { implicit: true } : opts == null ? {} : opts;
|
|
64
|
+
const isImplicit = (opts: { implicit?: boolean } | true | undefined) =>
|
|
65
|
+
opts === true ? true : (opts?.implicit ?? false);
|
|
66
|
+
|
|
62
67
|
const DEFAULTS: PlotDefaults = {
|
|
63
68
|
height: 350,
|
|
64
69
|
initialWidth: 500,
|
|
@@ -93,13 +98,13 @@
|
|
|
93
98
|
},
|
|
94
99
|
gridX: {
|
|
95
100
|
implicit: false,
|
|
96
|
-
...USER_DEFAULTS.grid,
|
|
97
|
-
...USER_DEFAULTS.gridX
|
|
101
|
+
...asGridDefaults(USER_DEFAULTS.grid),
|
|
102
|
+
...asGridDefaults(USER_DEFAULTS.gridX)
|
|
98
103
|
},
|
|
99
104
|
gridY: {
|
|
100
105
|
implicit: false,
|
|
101
|
-
...USER_DEFAULTS.grid,
|
|
102
|
-
...USER_DEFAULTS.gridY
|
|
106
|
+
...asGridDefaults(USER_DEFAULTS.grid),
|
|
107
|
+
...asGridDefaults(USER_DEFAULTS.gridY)
|
|
103
108
|
}
|
|
104
109
|
};
|
|
105
110
|
|
|
@@ -444,9 +449,9 @@
|
|
|
444
449
|
marginTop: maybeMargin(margin, 'top', DEFAULTS.margin, autoMargins),
|
|
445
450
|
marginBottom: maybeMargin(margin, 'bottom', DEFAULTS.margin, autoMargins),
|
|
446
451
|
inset: isOneDimensional ? 10 : DEFAULTS.inset,
|
|
447
|
-
grid: (DEFAULTS.gridX
|
|
452
|
+
grid: isImplicit(DEFAULTS.gridX) && isImplicit(DEFAULTS.gridY),
|
|
448
453
|
axes: (DEFAULTS.axisX?.implicit ?? false) && (DEFAULTS.axisY?.implicit ?? false),
|
|
449
|
-
frame: DEFAULTS.frame
|
|
454
|
+
frame: isImplicit(DEFAULTS.frame),
|
|
450
455
|
projection: null,
|
|
451
456
|
aspectRatio: null,
|
|
452
457
|
facet: {},
|
|
@@ -464,7 +469,7 @@
|
|
|
464
469
|
align: 0.5,
|
|
465
470
|
tickSpacing: DEFAULTS.axisX.tickSpacing ?? 80,
|
|
466
471
|
tickFormat: 'auto',
|
|
467
|
-
grid: DEFAULTS.gridX
|
|
472
|
+
grid: isImplicit(DEFAULTS.gridX)
|
|
468
473
|
},
|
|
469
474
|
y: {
|
|
470
475
|
type: 'auto',
|
|
@@ -479,7 +484,7 @@
|
|
|
479
484
|
align: 0.5,
|
|
480
485
|
tickSpacing: DEFAULTS.axisY.tickSpacing ?? 50,
|
|
481
486
|
tickFormat: 'auto',
|
|
482
|
-
grid: DEFAULTS.gridY
|
|
487
|
+
grid: isImplicit(DEFAULTS.gridY)
|
|
483
488
|
},
|
|
484
489
|
opacity: {
|
|
485
490
|
type: 'linear',
|
|
@@ -3,7 +3,8 @@ const PLOT_DEFAULTS_KEY = Symbol('svelteplot/defaults');
|
|
|
3
3
|
/** sets default options for all Plot components in this component tree, merging with any existing defaults from parent contexts */
|
|
4
4
|
export function setPlotDefaults(plotDefaults) {
|
|
5
5
|
const existingDefaults = getPlotDefaults();
|
|
6
|
-
const
|
|
6
|
+
const normalizedDefaults = normalizePlotDefaults(plotDefaults, existingDefaults);
|
|
7
|
+
const mergedDefaults = { ...existingDefaults, ...normalizedDefaults };
|
|
7
8
|
setContext(PLOT_DEFAULTS_KEY, mergedDefaults);
|
|
8
9
|
}
|
|
9
10
|
/** retrieves the current plot defaults from the Svelte context, or an empty object if none have been set */
|
|
@@ -16,3 +17,32 @@ export function getPlotDefaults() {
|
|
|
16
17
|
getContext('svelteplot/defaults'))
|
|
17
18
|
: {};
|
|
18
19
|
}
|
|
20
|
+
function normalizePlotDefaults(plotDefaults, existingDefaults) {
|
|
21
|
+
const grid = normalizeGridDefaults(plotDefaults.grid, existingDefaults.grid);
|
|
22
|
+
const gridX = normalizeGridDefaults(plotDefaults.gridX, existingDefaults.gridX);
|
|
23
|
+
const gridY = normalizeGridDefaults(plotDefaults.gridY, existingDefaults.gridY);
|
|
24
|
+
const frame = normalizeFrameDefaults(plotDefaults.frame, existingDefaults.frame);
|
|
25
|
+
return {
|
|
26
|
+
...plotDefaults,
|
|
27
|
+
...(grid !== undefined ? { grid } : {}),
|
|
28
|
+
...(gridX !== undefined ? { gridX } : {}),
|
|
29
|
+
...(gridY !== undefined ? { gridY } : {}),
|
|
30
|
+
...(frame !== undefined ? { frame } : {})
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function normalizeGridDefaults(input, existing) {
|
|
34
|
+
if (input !== true)
|
|
35
|
+
return input;
|
|
36
|
+
return {
|
|
37
|
+
...(typeof existing === 'object' ? existing : {}),
|
|
38
|
+
implicit: true
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function normalizeFrameDefaults(input, existing) {
|
|
42
|
+
if (input !== true)
|
|
43
|
+
return input;
|
|
44
|
+
return {
|
|
45
|
+
...(typeof existing === 'object' ? existing : {}),
|
|
46
|
+
implicit: true
|
|
47
|
+
};
|
|
48
|
+
}
|
package/dist/types/plot.d.ts
CHANGED
|
@@ -210,7 +210,7 @@ export type PlotDefaults = {
|
|
|
210
210
|
*/
|
|
211
211
|
frame: Partial<ComponentProps<typeof Frame> & {
|
|
212
212
|
implicit: boolean;
|
|
213
|
-
}
|
|
213
|
+
}> | true;
|
|
214
214
|
/**
|
|
215
215
|
* default props for geo marks
|
|
216
216
|
*/
|
|
@@ -224,19 +224,19 @@ export type PlotDefaults = {
|
|
|
224
224
|
*/
|
|
225
225
|
grid: Partial<Omit<ComponentProps<typeof GridX>, IgnoreDefaults> & {
|
|
226
226
|
implicit: boolean;
|
|
227
|
-
}
|
|
227
|
+
}> | true;
|
|
228
228
|
/**
|
|
229
229
|
* default props for gridX marks
|
|
230
230
|
*/
|
|
231
231
|
gridX: Partial<Omit<ComponentProps<typeof GridX>, IgnoreDefaults> & {
|
|
232
232
|
implicit: boolean;
|
|
233
|
-
}
|
|
233
|
+
}> | true;
|
|
234
234
|
/**
|
|
235
235
|
* default props for gridY marks
|
|
236
236
|
*/
|
|
237
237
|
gridY: Partial<Omit<ComponentProps<typeof GridY>, IgnoreDefaults> & {
|
|
238
238
|
implicit: boolean;
|
|
239
|
-
}
|
|
239
|
+
}> | true;
|
|
240
240
|
/**
|
|
241
241
|
* default props for image marks
|
|
242
242
|
*/
|