svelteplot 0.2.10 → 0.3.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.
Files changed (49) hide show
  1. package/dist/Plot.svelte +2 -1
  2. package/dist/core/Plot.svelte +35 -18
  3. package/dist/marks/Area.svelte +13 -3
  4. package/dist/marks/AreaX.svelte +7 -3
  5. package/dist/marks/AreaX.svelte.d.ts +1 -6
  6. package/dist/marks/AreaY.svelte +7 -2
  7. package/dist/marks/AreaY.svelte.d.ts +1 -9
  8. package/dist/marks/Arrow.svelte +24 -7
  9. package/dist/marks/AxisX.svelte +19 -20
  10. package/dist/marks/AxisX.svelte.d.ts +1 -4
  11. package/dist/marks/AxisY.svelte +19 -20
  12. package/dist/marks/AxisY.svelte.d.ts +1 -4
  13. package/dist/marks/BarX.svelte +16 -2
  14. package/dist/marks/BarY.svelte +17 -3
  15. package/dist/marks/BoxX.svelte +25 -9
  16. package/dist/marks/BoxX.svelte.d.ts +3 -2
  17. package/dist/marks/BoxY.svelte +22 -10
  18. package/dist/marks/BoxY.svelte.d.ts +3 -3
  19. package/dist/marks/Brush.svelte +30 -10
  20. package/dist/marks/BrushX.svelte +8 -2
  21. package/dist/marks/BrushX.svelte.d.ts +1 -1
  22. package/dist/marks/BrushY.svelte +8 -2
  23. package/dist/marks/BrushY.svelte.d.ts +1 -1
  24. package/dist/marks/Cell.svelte +16 -2
  25. package/dist/marks/ColorLegend.svelte +2 -2
  26. package/dist/marks/Dot.svelte +9 -5
  27. package/dist/marks/Frame.svelte +23 -4
  28. package/dist/marks/Geo.svelte +14 -4
  29. package/dist/marks/Graticule.svelte +15 -5
  30. package/dist/marks/GridX.svelte +16 -2
  31. package/dist/marks/GridY.svelte +16 -2
  32. package/dist/marks/Line.svelte +22 -8
  33. package/dist/marks/Link.svelte +12 -4
  34. package/dist/marks/Pointer.svelte +12 -3
  35. package/dist/marks/Rect.svelte +16 -2
  36. package/dist/marks/RectX.svelte +16 -2
  37. package/dist/marks/RectY.svelte +16 -2
  38. package/dist/marks/RuleX.svelte +15 -2
  39. package/dist/marks/RuleY.svelte +15 -2
  40. package/dist/marks/Sphere.svelte +13 -2
  41. package/dist/marks/Spike.svelte +21 -11
  42. package/dist/marks/Text.svelte +22 -4
  43. package/dist/marks/TickX.svelte +15 -2
  44. package/dist/marks/TickY.svelte +15 -2
  45. package/dist/marks/Vector.svelte +13 -5
  46. package/dist/transforms/sort.d.ts +2 -2
  47. package/dist/types.d.ts +227 -75
  48. package/dist/ui/ExamplesGrid.svelte +1 -1
  49. package/package.json +1 -1
package/dist/Plot.svelte CHANGED
@@ -12,7 +12,7 @@
12
12
  <script lang="ts">
13
13
  import Plot from './core/Plot.svelte';
14
14
 
15
- import type { PlotOptions } from './types.js';
15
+ import type { PlotDefaults, PlotOptions } from './types.js';
16
16
 
17
17
  // implicit marks
18
18
  import AxisX from './marks/AxisX.svelte';
@@ -28,6 +28,7 @@
28
28
  import { autoScale, autoScaleColor } from './helpers/autoScales.js';
29
29
  import { namedProjection } from './helpers/autoProjection.js';
30
30
  import { isObject } from './helpers/index.js';
31
+ import { getContext } from 'svelte';
31
32
 
32
33
  let {
33
34
  header: userHeader,
@@ -51,22 +51,17 @@
51
51
  const maxMarginBottom = $derived(Math.max(...$autoMarginBottom.values()));
52
52
  const maxMarginTop = $derived(Math.max(...$autoMarginTop.values()));
53
53
 
54
+ const USER_DEFAULTS = getContext<Partial<PlotDefaults>>('svelteplot/defaults') || {};
55
+
54
56
  // default settings in the plot and marks can be overwritten by
55
57
  // defining the svelteplot/defaults context outside of Plot
56
58
  const DEFAULTS: PlotDefaults = {
57
- axisXAnchor: 'bottom',
58
- axisYAnchor: 'left',
59
- xTickSpacing: 80,
60
- yTickSpacing: 50,
61
59
  height: 350,
62
60
  initialWidth: 500,
63
61
  inset: 0,
64
62
  colorScheme: 'turbo',
65
63
  unknown: '#cccccc99',
66
- dotRadius: 3,
67
- frame: false,
68
- axes: true,
69
- grid: false,
64
+
70
65
  categoricalColorScheme: 'observable10',
71
66
  pointScaleHeight: 18,
72
67
  bandScaleHeight: 30,
@@ -77,7 +72,29 @@
77
72
  compactDisplay: 'short'
78
73
  },
79
74
  markerDotRadius: 3,
80
- ...getContext<Partial<PlotDefaults>>('svelteplot/defaults')
75
+ ...USER_DEFAULTS,
76
+ axisX: {
77
+ anchor: 'bottom',
78
+ implicit: true,
79
+ ...USER_DEFAULTS.axis,
80
+ ...USER_DEFAULTS.axisX
81
+ },
82
+ axisY: {
83
+ anchor: 'left',
84
+ implicit: true,
85
+ ...USER_DEFAULTS.axis,
86
+ ...USER_DEFAULTS.axisY
87
+ },
88
+ gridX: {
89
+ implicit: false,
90
+ ...USER_DEFAULTS.grid,
91
+ ...USER_DEFAULTS.gridX
92
+ },
93
+ gridY: {
94
+ implicit: false,
95
+ ...USER_DEFAULTS.grid,
96
+ ...USER_DEFAULTS.gridY
97
+ }
81
98
  };
82
99
 
83
100
  let {
@@ -390,16 +407,16 @@
390
407
  ? margins
391
408
  : Math.max(5, maxMarginBottom),
392
409
  inset: isOneDimensional ? 10 : DEFAULTS.inset,
393
- grid: DEFAULTS.grid,
394
- axes: DEFAULTS.axes,
395
- frame: DEFAULTS.frame,
410
+ grid: (DEFAULTS.gridX?.implicit ?? false) && (DEFAULTS.gridY?.implicit ?? false),
411
+ axes: (DEFAULTS.axisX?.implicit ?? false) && (DEFAULTS.axisY?.implicit ?? false),
412
+ frame: DEFAULTS.frame?.implicit ?? false,
396
413
  projection: null,
397
414
  aspectRatio: null,
398
415
  facet: {},
399
416
  padding: 0.1,
400
417
  x: {
401
418
  type: 'auto',
402
- axis: autoXAxis ? DEFAULTS.axisXAnchor : false,
419
+ axis: DEFAULTS.axisX.implicit && autoXAxis ? DEFAULTS.axisX.anchor : false,
403
420
  labelAnchor: 'auto',
404
421
  reverse: false,
405
422
  clamp: false,
@@ -408,13 +425,13 @@
408
425
  round: false,
409
426
  percent: false,
410
427
  align: 0.5,
411
- tickSpacing: DEFAULTS.xTickSpacing,
428
+ tickSpacing: DEFAULTS.axisX.tickSpacing ?? 80,
412
429
  tickFormat: 'auto',
413
- grid: false
430
+ grid: DEFAULTS.gridX.implicit ?? false
414
431
  },
415
432
  y: {
416
433
  type: 'auto',
417
- axis: autoYAxis ? DEFAULTS.axisYAnchor : false,
434
+ axis: DEFAULTS.axisY.implicit && autoYAxis ? DEFAULTS.axisY.anchor : false,
418
435
  labelAnchor: 'auto',
419
436
  reverse: false,
420
437
  clamp: false,
@@ -423,9 +440,9 @@
423
440
  round: false,
424
441
  percent: false,
425
442
  align: 0.5,
426
- tickSpacing: DEFAULTS.yTickSpacing,
443
+ tickSpacing: DEFAULTS.axisY.tickSpacing ?? 50,
427
444
  tickFormat: 'auto',
428
- grid: false
445
+ grid: DEFAULTS.gridY.implicit ?? false
429
446
  },
430
447
  opacity: {
431
448
  type: 'linear',
@@ -39,12 +39,22 @@
39
39
  ConstantAccessor,
40
40
  ChannelAccessor,
41
41
  ScaledDataRecord,
42
- LinkableMarkProps
42
+ LinkableMarkProps,
43
+ PlotDefaults
43
44
  } from '../types.js';
44
45
  import type { RawValue } from '../types.js';
45
46
  import type { StackOptions } from '../transforms/stack.js';
46
47
 
47
- let {
48
+ let markProps: AreaMarkProps = $props();
49
+
50
+ const DEFAULTS = {
51
+ fill: 'currentColor',
52
+ curve: 'linear',
53
+ tension: 0,
54
+ ...getContext<PlotDefaults>('svelteplot/_defaults').area
55
+ };
56
+
57
+ const {
48
58
  data,
49
59
  /** the curve */
50
60
  curve = 'linear',
@@ -52,7 +62,7 @@
52
62
  class: className = '',
53
63
  canvas = false,
54
64
  ...options
55
- }: AreaMarkProps = $props();
65
+ }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
56
66
 
57
67
  const { getPlotState } = getContext<PlotContext>('svelteplot');
58
68
  const plot = $derived(getPlotState());
@@ -7,15 +7,19 @@
7
7
  import { renameChannels } from '../transforms/rename.js';
8
8
  import { stackX } from '../transforms/stack.js';
9
9
  import { recordizeX } from '../transforms/recordize.js';
10
- import type { ChannelAccessor } from '../types.js';
10
+ import type { ChannelAccessor, PlotDefaults } from '../types.js';
11
+ import { getContext } from 'svelte';
11
12
 
12
13
  type AreaXProps = Omit<AreaMarkProps, 'y1' | 'y2'> & {
13
14
  x?: ChannelAccessor;
14
15
  y?: ChannelAccessor;
15
16
  };
16
17
 
17
- // we're discarding y1 and y2 props since they are not
18
- let { data, stack, ...options }: AreaXProps = $props();
18
+ let markProps: AreaMarkProps = $props();
19
+
20
+ const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaX;
21
+
22
+ const { data, stack, ...options }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
19
23
 
20
24
  const args = $derived(
21
25
  renameChannels<AreaXProps>(
@@ -1,13 +1,8 @@
1
1
  import { type AreaMarkProps } from './Area.svelte';
2
- import type { ChannelAccessor } from '../types.js';
3
- type AreaXProps = Omit<AreaMarkProps, 'y1' | 'y2'> & {
4
- x?: ChannelAccessor;
5
- y?: ChannelAccessor;
6
- };
7
2
  /**
8
3
  * Creates a horizontal area chart with x value and baseline. Areas are implicitly
9
4
  * stacked horizontally if just the x channel is defined.
10
5
  */
11
- declare const AreaX: import("svelte").Component<AreaXProps, {}, "">;
6
+ declare const AreaX: import("svelte").Component<AreaMarkProps, {}, "">;
12
7
  type AreaX = ReturnType<typeof AreaX>;
13
8
  export default AreaX;
@@ -7,7 +7,8 @@
7
7
  import { renameChannels } from '../transforms/rename.js';
8
8
  import { stackY } from '../transforms/stack.js';
9
9
  import { recordizeY } from '../transforms/recordize.js';
10
- import type { ChannelAccessor } from '../types.js';
10
+ import type { ChannelAccessor, PlotDefaults } from '../types.js';
11
+ import { getContext } from 'svelte';
11
12
 
12
13
  /**
13
14
  * AreaY mark foo
@@ -17,7 +18,11 @@
17
18
  y?: ChannelAccessor;
18
19
  };
19
20
 
20
- let { data, stack, ...options }: AreaYProps = $props();
21
+ let markProps: AreaMarkProps = $props();
22
+
23
+ const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaY;
24
+
25
+ const { data, stack, ...options }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
21
26
 
22
27
  const args = $derived(
23
28
  renameChannels<AreaYProps>(
@@ -1,16 +1,8 @@
1
1
  import { type AreaMarkProps } from './Area.svelte';
2
- import type { ChannelAccessor } from '../types.js';
3
- /**
4
- * AreaY mark foo
5
- */
6
- type AreaYProps = Omit<AreaMarkProps, 'x1' | 'x2'> & {
7
- x?: ChannelAccessor;
8
- y?: ChannelAccessor;
9
- };
10
2
  /**
11
3
  * Creates a vertical area chart with y value and baseline. Areas are implicitly
12
4
  * stacked vertically if just the y channel is defined.
13
5
  */
14
- declare const AreaY: import("svelte").Component<AreaYProps, {}, "">;
6
+ declare const AreaY: import("svelte").Component<AreaMarkProps, {}, "">;
15
7
  type AreaY = ReturnType<typeof AreaY>;
16
8
  export default AreaY;
@@ -38,14 +38,15 @@
38
38
  </script>
39
39
 
40
40
  <script lang="ts">
41
- import { getContext, type Snippet } from 'svelte';
41
+ import { getContext } from 'svelte';
42
42
  import type {
43
43
  PlotContext,
44
44
  DataRecord,
45
45
  BaseMarkProps,
46
46
  ConstantAccessor,
47
47
  ChannelAccessor,
48
- RawValue
48
+ RawValue,
49
+ PlotDefaults
49
50
  } from '../types.js';
50
51
  import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
51
52
  import { coalesce, maybeData, maybeNumber } from '../helpers/index.js';
@@ -55,7 +56,23 @@
55
56
  import { addEventHandlers } from './helpers/events.js';
56
57
  import GroupMultiple from './helpers/GroupMultiple.svelte';
57
58
 
58
- let { data = [{}], class: className = null, ...options }: ArrowMarkProps = $props();
59
+ let markProps: ArrowMarkProps = $props();
60
+
61
+ const DEFAULTS = {
62
+ headAngle: 60,
63
+ headLength: 8,
64
+ inset: 0,
65
+ ...getContext<PlotDefaults>('svelteplot/_defaults').arrow
66
+ };
67
+
68
+ const {
69
+ data = [{}],
70
+ class: className = '',
71
+ ...options
72
+ }: ArrowMarkProps = $derived({
73
+ ...DEFAULTS,
74
+ ...markProps
75
+ });
59
76
 
60
77
  const { getPlotState } = getContext<PlotContext>('svelteplot');
61
78
  const plot = $derived(getPlotState());
@@ -68,7 +85,7 @@
68
85
  : maybeData(data)
69
86
  );
70
87
 
71
- const args: ArrowProps = $derived(
88
+ const args: ArrowMarkProps = $derived(
72
89
  replaceChannels({ data: sorted, ...options }, { y: ['y1', 'y2'], x: ['x1', 'x2'] })
73
90
  );
74
91
  </script>
@@ -78,7 +95,7 @@
78
95
  required={['x1', 'x2', 'y1', 'y2']}
79
96
  channels={['x1', 'y1', 'x2', 'y2', 'opacity', 'stroke', 'strokeOpacity']}
80
97
  {...args}>
81
- {#snippet children({ mark, usedScales, scaledData })}
98
+ {#snippet children({ usedScales, scaledData })}
82
99
  {@const sweep = maybeSweep(args.sweep)}
83
100
  <GroupMultiple class="arrow" length={scaledData.length}>
84
101
  {#each scaledData as d, i (i)}
@@ -86,8 +103,8 @@
86
103
  {@const inset = resolveProp(args.inset, d.datum, 0)}
87
104
  {@const insetStart = resolveProp(args.insetStart, d.datum)}
88
105
  {@const insetEnd = resolveProp(args.insetEnd, d.datum)}
89
- {@const headAngle = resolveProp(args.headAngle, d.datum, 60)}
90
- {@const headLength = resolveProp(args.headLength, d.datum, 8)}
106
+ {@const headAngle = resolveProp(args.headAngle, d.datum)}
107
+ {@const headLength = resolveProp(args.headLength, d.datum)}
91
108
  {@const bend = resolveProp(args.bend, d.datum, 0)}
92
109
  {@const strokeWidth = resolveProp(args.strokeWidth, d.datum, 1)}
93
110
  {@const arrPath = arrowPath(
@@ -27,16 +27,11 @@
27
27
  ticks?: number | string | RawValue[];
28
28
  /** set to false or null to disable tick labels */
29
29
  text: boolean | null;
30
- } & XOR<
31
- {
32
- /** approximate number of ticks to be generated */
33
- tickCount?: number;
34
- },
35
- {
36
- /** approximate number of pixels between generated ticks */
37
- tickSpacing?: number;
38
- }
39
- >;
30
+ /** approximate number of ticks to be generated */
31
+ tickCount?: number;
32
+ /** approximate number of pixels between generated ticks */
33
+ tickSpacing?: number;
34
+ };
40
35
  </script>
41
36
 
42
37
  <script lang="ts">
@@ -49,32 +44,36 @@
49
44
  RawValue,
50
45
  ConstantAccessor,
51
46
  FacetContext,
52
- DefaultOptions
47
+ PlotDefaults,
48
+ ChannelName
53
49
  } from '../types.js';
54
50
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
55
51
  import { derived } from 'svelte/store';
56
52
  import { autoTicks } from '../helpers/autoTicks.js';
57
53
  import { resolveScaledStyles } from '../helpers/resolve.js';
58
54
 
59
- const DEFAULTS = {
55
+ let markProps: AxisXMarkProps = $props();
56
+
57
+ const DEFAULTS: Omit<AxisXMarkProps, 'data' | ChannelName> = {
60
58
  tickSize: 6,
61
59
  tickPadding: 3,
62
60
  tickFontSize: 11,
63
- axisXAnchor: 'bottom',
64
- ...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
61
+ anchor: 'bottom',
62
+ ...getContext<PlotDefaults>('svelteplot/_defaults').axis,
63
+ ...getContext<PlotDefaults>('svelteplot/_defaults').axisX
65
64
  };
66
65
 
67
- let {
66
+ const {
68
67
  ticks: magicTicks,
69
68
  data = Array.isArray(magicTicks) ? magicTicks : [],
70
69
  automatic = false,
71
70
  title,
72
- anchor = DEFAULTS.axisXAnchor as 'top' | 'bottom',
71
+ anchor,
73
72
  facetAnchor = 'auto',
74
73
  interval = typeof magicTicks === 'string' ? magicTicks : undefined,
75
- tickSize = DEFAULTS.tickSize,
76
- tickFontSize = DEFAULTS.tickFontSize,
77
- tickPadding = DEFAULTS.tickPadding,
74
+ tickSize,
75
+ tickFontSize,
76
+ tickPadding,
78
77
  labelAnchor,
79
78
  tickFormat,
80
79
  tickClass,
@@ -83,7 +82,7 @@
83
82
  tickSpacing,
84
83
  text = true,
85
84
  ...options
86
- }: AxisXMarkProps = $props();
85
+ }: AxisXMarkProps = $derived({ ...DEFAULTS, ...markProps });
87
86
 
88
87
  const { getPlotState } = getContext<PlotContext>('svelteplot');
89
88
  const plot = $derived(getPlotState());
@@ -1,4 +1,3 @@
1
- import type { XOR } from 'ts-essentials';
2
1
  export type AxisXMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'> & {
3
2
  data?: RawValue[];
4
3
  automatic?: boolean;
@@ -16,13 +15,11 @@ export type AxisXMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
16
15
  ticks?: number | string | RawValue[];
17
16
  /** set to false or null to disable tick labels */
18
17
  text: boolean | null;
19
- } & XOR<{
20
18
  /** approximate number of ticks to be generated */
21
19
  tickCount?: number;
22
- }, {
23
20
  /** approximate number of pixels between generated ticks */
24
21
  tickSpacing?: number;
25
- }>;
22
+ };
26
23
  import type { BaseMarkProps, RawValue, ConstantAccessor } from '../types.js';
27
24
  /** Renders a horizontal axis with labels and tick marks */
28
25
  declare const AxisX: import("svelte").Component<AxisXMarkProps, {}, "">;
@@ -28,16 +28,11 @@
28
28
  ticks?: number | string | RawValue[];
29
29
  /** set to false or null to disable tick labels */
30
30
  text: boolean | null;
31
- } & XOR<
32
- {
33
- /** approximate number of ticks to be generated */
34
- tickCount?: number;
35
- },
36
- {
37
- /** approximate number of pixels between generated ticks */
38
- tickSpacing?: number;
39
- }
40
- >;
31
+ /** approximate number of ticks to be generated */
32
+ tickCount?: number;
33
+ /** approximate number of pixels between generated ticks */
34
+ tickSpacing?: number;
35
+ };
41
36
  </script>
42
37
 
43
38
  <script lang="ts">
@@ -49,40 +44,44 @@
49
44
  BaseMarkProps,
50
45
  RawValue,
51
46
  FacetContext,
52
- DefaultOptions
47
+ PlotDefaults,
48
+ ChannelName
53
49
  } from '../types.js';
54
50
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
55
51
  import type { ConstantAccessor } from '../types.js';
56
52
  import { autoTicks } from '../helpers/autoTicks.js';
57
53
  import { resolveScaledStyles } from '../helpers/resolve.js';
58
54
 
59
- const DEFAULTS = {
55
+ let markProps: AxisYMarkProps = $props();
56
+
57
+ const DEFAULTS: Omit<AxisYMarkProps, 'data' | ChannelName> = {
60
58
  tickSize: 6,
61
59
  tickPadding: 3,
62
60
  tickFontSize: 11,
63
- axisYAnchor: 'left',
64
- ...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
61
+ anchor: 'left',
62
+ ...getContext<PlotDefaults>('svelteplot/_defaults').axis,
63
+ ...getContext<PlotDefaults>('svelteplot/_defaults').axisY
65
64
  };
66
65
 
67
- let {
66
+ const {
68
67
  ticks: magicTicks,
69
68
  data = Array.isArray(magicTicks) ? magicTicks : [],
70
69
  automatic = false,
71
70
  title,
72
- anchor = DEFAULTS.axisYAnchor as 'left' | 'right',
71
+ anchor,
73
72
  facetAnchor = 'auto',
74
73
  interval = typeof magicTicks === 'string' ? magicTicks : undefined,
75
74
  lineAnchor = 'center',
76
- tickSize = DEFAULTS.tickSize,
77
- tickFontSize = DEFAULTS.tickFontSize,
78
- tickPadding = DEFAULTS.tickPadding,
75
+ tickSize,
76
+ tickFontSize,
77
+ tickPadding,
79
78
  tickFormat,
80
79
  tickClass,
81
80
  tickCount = typeof magicTicks === 'number' ? magicTicks : undefined,
82
81
  tickSpacing,
83
82
  text = true,
84
83
  ...options
85
- }: AxisYMarkProps = $props();
84
+ }: AxisYMarkProps = $derived({ ...DEFAULTS, ...markProps });
86
85
 
87
86
  const { getPlotState } = getContext<PlotContext>('svelteplot');
88
87
  const plot = $derived(getPlotState());
@@ -1,4 +1,3 @@
1
- import type { XOR } from 'ts-essentials';
2
1
  export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'> & {
3
2
  data?: RawValue[];
4
3
  automatic?: boolean;
@@ -17,13 +16,11 @@ export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
17
16
  ticks?: number | string | RawValue[];
18
17
  /** set to false or null to disable tick labels */
19
18
  text: boolean | null;
20
- } & XOR<{
21
19
  /** approximate number of ticks to be generated */
22
20
  tickCount?: number;
23
- }, {
24
21
  /** approximate number of pixels between generated ticks */
25
22
  tickSpacing?: number;
26
- }>;
23
+ };
27
24
  import type { BaseMarkProps, RawValue } from '../types.js';
28
25
  import type { ConstantAccessor } from '../types.js';
29
26
  /** Renders a vertical axis with labels and tick marks */
@@ -8,7 +8,8 @@
8
8
  BaseMarkProps,
9
9
  BaseRectMarkProps,
10
10
  ChannelAccessor,
11
- LinkableMarkProps
11
+ LinkableMarkProps,
12
+ PlotDefaults
12
13
  } from '../types.js';
13
14
 
14
15
  export type BarXMarkProps = BaseMarkProps &
@@ -38,7 +39,20 @@
38
39
  import GroupMultiple from './helpers/GroupMultiple.svelte';
39
40
  import RectPath from './helpers/RectPath.svelte';
40
41
 
41
- let { data = [{}], class: className = null, stack, ...options }: BarXMarkProps = $props();
42
+ const DEFAULTS = {
43
+ fill: 'currentColor',
44
+ ...getContext<PlotDefaults>('svelteplot/_defaults').bar,
45
+ ...getContext<PlotDefaults>('svelteplot/_defaults').barX
46
+ };
47
+
48
+ let markProps: BarXMarkProps = $props();
49
+
50
+ const {
51
+ data = [{}],
52
+ class: className = null,
53
+ stack,
54
+ ...options
55
+ }: BarXMarkProps = $derived({ ...DEFAULTS, ...markProps });
42
56
 
43
57
  const { getPlotState } = getContext<PlotContext>('svelteplot');
44
58
  const plot = $derived(getPlotState());
@@ -8,7 +8,8 @@
8
8
  BaseMarkProps,
9
9
  BaseRectMarkProps,
10
10
  ChannelAccessor,
11
- DataRow
11
+ DataRow,
12
+ PlotDefaults
12
13
  } from '../types.js';
13
14
 
14
15
  export type BarYMarkProps = BaseMarkProps &
@@ -37,11 +38,24 @@
37
38
  import GroupMultiple from './helpers/GroupMultiple.svelte';
38
39
  import RectPath from './helpers/RectPath.svelte';
39
40
 
40
- let { data = [{}], class: className = null, stack, ...options }: BarYMarkProps = $props();
41
-
42
41
  const { getPlotState } = getContext<PlotContext>('svelteplot');
43
42
  const plot = $derived(getPlotState());
44
43
 
44
+ const DEFAULTS = {
45
+ fill: 'currentColor',
46
+ ...getContext<PlotDefaults>('svelteplot/_defaults').bar,
47
+ ...getContext<PlotDefaults>('svelteplot/_defaults').barY
48
+ };
49
+
50
+ let markProps: BarYMarkProps = $props();
51
+
52
+ const {
53
+ data = [{}],
54
+ class: className = null,
55
+ stack,
56
+ ...options
57
+ }: BarYMarkProps = $derived({ ...DEFAULTS, ...markProps });
58
+
45
59
  const args = $derived(
46
60
  stackY(
47
61
  intervalY(
@@ -1,23 +1,39 @@
1
1
  <!-- @component
2
2
  Creates a horizontal box plot for visualizing data distribution with quartiles and outliers
3
3
  -->
4
+ <script module lang="ts">
5
+ export type BoxXMarkProps = BoxYMarkProps;
6
+ </script>
7
+
4
8
  <script lang="ts">
5
9
  import GroupMultiple from './helpers/GroupMultiple.svelte';
6
- import type { BoxProps } from './BoxY.svelte';
10
+ import type { BoxYMarkProps } from './BoxY.svelte';
7
11
  import { BarX, TickX, RuleY, Dot, groupY } from '../index.js';
8
12
  import { resolveChannel } from '../helpers/resolve.js';
13
+ import { getContext } from 'svelte';
14
+ import type { PlotDefaults } from '../types.js';
9
15
 
10
- let {
16
+ let markProps: BoxXMarkProps = $props();
17
+ const DEFAULTS = {
18
+ tickMedian: true,
19
+ tickMinMax: false,
20
+ ...getContext<PlotDefaults>('svelteplot/_defaults').box,
21
+ ...getContext<PlotDefaults>('svelteplot/_defaults').boxX
22
+ };
23
+ const {
11
24
  data = [{}],
12
- x,
13
- y,
14
- rule,
15
25
  bar,
16
- tickMedian = true,
17
- tickMinMax = false,
26
+ rule,
27
+ tickMedian,
28
+ tickMinMax,
18
29
  dot,
19
- class: className = null
20
- }: BoxProps = $props();
30
+ x,
31
+ y,
32
+ class: className = ''
33
+ }: BoxXMarkProps = $derived({
34
+ ...DEFAULTS,
35
+ ...markProps
36
+ });
21
37
 
22
38
  const { data: grouped } = $derived(
23
39
  groupY(
@@ -1,5 +1,6 @@
1
- import type { BoxProps } from './BoxY.svelte';
1
+ export type BoxXMarkProps = BoxYMarkProps;
2
+ import type { BoxYMarkProps } from './BoxY.svelte';
2
3
  /** Creates a horizontal box plot for visualizing data distribution with quartiles and outliers */
3
- declare const BoxX: import("svelte").Component<BoxProps, {}, "">;
4
+ declare const BoxX: import("svelte").Component<BoxYMarkProps, {}, "">;
4
5
  type BoxX = ReturnType<typeof BoxX>;
5
6
  export default BoxX;