svelteplot 0.5.3-pr-255.1 → 0.5.3-pr-255.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/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/index.js';
15
+ import type { PlotOptions, RawValue, ScaleOptions } from './types/index.js';
16
16
 
17
17
  // implicit marks
18
18
  import AxisX from './marks/AxisX.svelte';
@@ -62,12 +62,20 @@
62
62
  const scales = $derived(
63
63
  Object.fromEntries(
64
64
  ['x', 'y', 'r', 'color', 'opacity', 'symbol', 'length', 'fx', 'fy'].map((scale) => {
65
- const scaleOpts = restOptions[scale] || {};
65
+ const scaleOpts = maybeScaleOptions(restOptions[scale]);
66
66
  const scaleFn = scaleOpts.scale || (scale === 'color' ? autoScaleColor : autoScale);
67
67
  return [scale, { ...scaleOpts, scale: scaleFn }];
68
68
  })
69
69
  )
70
70
  );
71
+
72
+ function maybeScaleOptions(
73
+ scaleOptions: undefined | false | RawValue[] | object
74
+ ): Partial<ScaleOptions> | undefined {
75
+ if (scaleOptions === false) return { axis: false };
76
+ if (Array.isArray(scaleOptions)) return { domain: scaleOptions };
77
+ return scaleOptions || {};
78
+ }
71
79
  </script>
72
80
 
73
81
  {#snippet header()}
@@ -114,7 +114,7 @@
114
114
  class: className = '',
115
115
  css = DEFAULTS.css,
116
116
  width: fixedWidth,
117
- ...initialOpts
117
+ ...initialOptions
118
118
  }: Partial<PlotOptions> = $props();
119
119
 
120
120
  let width = $state(DEFAULTS.initialWidth);
@@ -164,7 +164,7 @@
164
164
  );
165
165
 
166
166
  const explicitDomains = $derived(
167
- new Set(SCALES.filter((scale) => !!initialOpts[scale]?.domain))
167
+ new Set(SCALES.filter((scale) => !!initialOptions[scale]?.domain))
168
168
  );
169
169
 
170
170
  // one-dimensional plots have different automatic margins and heights
@@ -173,12 +173,12 @@
173
173
  // construct the plot options from the user-defined options (top-level props) as well
174
174
  // as extending them from smart context-aware defaults
175
175
  const plotOptions = $derived(
176
- extendPlotOptions(initialOpts, {
176
+ extendPlotOptions(initialOptions, {
177
177
  explicitScales,
178
178
  explicitDomains,
179
- hasProjection: !!initialOpts.projection,
180
- margin: initialOpts.margin,
181
- inset: initialOpts.inset
179
+ hasProjection: !!initialOptions.projection,
180
+ margin: initialOptions.margin,
181
+ inset: initialOptions.inset
182
182
  })
183
183
  );
184
184
 
@@ -369,7 +369,7 @@
369
369
  {},
370
370
  { sortOrdinalDomains: DEFAULTS.sortOrdinalDomains },
371
371
  smartDefaultPlotOptions(opts),
372
- initialOpts
372
+ initialOptions
373
373
  );
374
374
  }
375
375
 
@@ -88,7 +88,7 @@
88
88
  // generate id used for registering margins
89
89
  const id = randomId();
90
90
 
91
- const { autoMarginTop, autoMarginBottom } =
91
+ const { autoMarginTop, autoMarginBottom, autoMarginLeft, autoMarginRight } =
92
92
  getContext<AutoMarginStores>('svelteplot/autoMargins');
93
93
 
94
94
  let tickTextElements = $state([] as SVGTextElement[]);
@@ -125,6 +125,14 @@
125
125
  return tickObjects as ScaledDataRecord[];
126
126
  });
127
127
 
128
+ $effect(() => {
129
+ // just add some minimal horizontal margins for axis ticks
130
+ untrack(() => $autoMarginLeft);
131
+ untrack(() => $autoMarginRight);
132
+ $autoMarginLeft.set(id, 5);
133
+ $autoMarginRight.set(id, 10);
134
+ });
135
+
128
136
  $effect(() => {
129
137
  untrack(() => [$autoMarginTop, $autoMarginBottom]);
130
138
  if (!text) return;
@@ -163,6 +171,8 @@
163
171
  return () => {
164
172
  if ($autoMarginBottom.has(id)) $autoMarginBottom.delete(id);
165
173
  if ($autoMarginTop.has(id)) $autoMarginTop.delete(id);
174
+ if ($autoMarginLeft.has(id)) $autoMarginLeft.delete(id);
175
+ if ($autoMarginRight.has(id)) $autoMarginRight.delete(id);
166
176
  };
167
177
  });
168
178
  </script>
@@ -1,7 +1,7 @@
1
1
  import type { ComponentProps } from 'svelte';
2
2
  import type { ColorScheme } from './colorScheme.js';
3
3
  import type { GeoProjection } from 'd3-geo';
4
- import type { ChannelAccessor, ChannelName, ColorScaleOptions, DataRecord, LegendScaleOptions, PlotScales, ScaleOptions, XScaleOptions, YScaleOptions } from './index.js';
4
+ import type { ChannelAccessor, ChannelName, ColorScaleOptions, DataRecord, LegendScaleOptions, PlotScales, RawValue, ScaleOptions, XScaleOptions, YScaleOptions } from './index.js';
5
5
  import type { Snippet } from 'svelte';
6
6
  import type { Area, AreaX, AreaY, Arrow, AxisX, AxisY, BarX, BarY, BoxX, BoxY, Brush, BrushX, BrushY, Cell, DifferenceY, Dot, Frame, Geo, Graticule, GridX, GridY, Image, Line, Link, Pointer, Rect, RectX, RectY, RuleX, RuleY, Sphere, Spike, Text, TickX, TickY, Vector } from '../marks/index.js';
7
7
  import type WaffleX from '../marks/WaffleX.svelte';
@@ -423,11 +423,11 @@ export type PlotOptions = {
423
423
  /**
424
424
  * Options for the shared x scale.
425
425
  */
426
- x: Partial<XScaleOptions>;
426
+ x: Partial<XScaleOptions> | false | RawValue[];
427
427
  /**
428
428
  * Options for the shared y scale
429
429
  */
430
- y: Partial<YScaleOptions>;
430
+ y: Partial<YScaleOptions> | false | RawValue[];
431
431
  /**
432
432
  * Options for the shared radius scale
433
433
  */
@@ -436,8 +436,8 @@ export type PlotOptions = {
436
436
  opacity: Partial<ScaleOptions>;
437
437
  symbol: Partial<LegendScaleOptions>;
438
438
  length: Partial<ScaleOptions>;
439
- fx: Partial<XScaleOptions>;
440
- fy: Partial<YScaleOptions>;
439
+ fx: Partial<XScaleOptions> | false | RawValue[];
440
+ fy: Partial<YScaleOptions> | false | RawValue[];
441
441
  children: Snippet<[
442
442
  {
443
443
  width: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.5.3-pr-255.1",
3
+ "version": "0.5.3-pr-255.3",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",