svelteplot 0.4.8-pr-225.0 → 0.4.8-pr-227.1

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.
@@ -30,6 +30,7 @@
30
30
  import { computeScales, projectXY } from '../helpers/scales.js';
31
31
  import { CHANNEL_SCALE, SCALES } from '../constants.js';
32
32
  import { getPlotDefaults, setPlotDefaults } from '../hooks/plotDefaults.js';
33
+ import { maybeNumber } from '../helpers/index.js';
33
34
 
34
35
  // automatic margins can be applied by the marks, registered
35
36
  // with their respective unique identifier as keys
@@ -214,7 +215,7 @@
214
215
  // - for one-dimensional scales using the x scale we set a fixed height
215
216
  // - for y band-scales we use the number of items in the y domain
216
217
  const height = $derived(
217
- plotOptions.height === 'auto'
218
+ maybeNumber(plotOptions.height) === null || plotOptions.height === 'auto'
218
219
  ? Math.round(
219
220
  preScales.projection && preScales.projection.aspectRatio
220
221
  ? ((plotWidth * preScales.projection.aspectRatio) / xFacetCount) *
@@ -242,7 +243,7 @@
242
243
  )
243
244
  : typeof plotOptions.height === 'function'
244
245
  ? plotOptions.height(plotWidth)
245
- : plotOptions.height
246
+ : maybeNumber(plotOptions.height)
246
247
  );
247
248
 
248
249
  const plotHeight = $derived(height - plotOptions.marginTop - plotOptions.marginBottom);
@@ -9,7 +9,7 @@ export declare function randomId(): string;
9
9
  export declare function isSnippet(value: unknown): value is Snippet;
10
10
  export declare function isValid(value: RawValue | undefined): value is number | Date | string;
11
11
  export declare function isObject<T>(option: object | T): option is object;
12
- export declare function maybeNumber(value: RawValue | null): number | null;
12
+ export declare function maybeNumber(value: any): number | null;
13
13
  export declare const constant: <T>(x: T) => () => T;
14
14
  export declare const POSITION_CHANNELS: Set<ChannelName>;
15
15
  export declare function parseInset(inset: number | string, width: number): number;
@@ -31,8 +31,17 @@ export function isObject(option) {
31
31
  // doesn't work with Proxies
32
32
  return (typeof option === 'object' && !isDate(option) && !Array.isArray(option) && option !== null);
33
33
  }
34
+ const NUMERIC = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
34
35
  export function maybeNumber(value) {
35
- return value != null ? +value : null;
36
+ if (typeof value === 'number' && Number.isFinite(value))
37
+ return value;
38
+ if (typeof value === 'string') {
39
+ // only accept numeric strings
40
+ if (NUMERIC.test(value.trim())) {
41
+ return parseFloat(value);
42
+ }
43
+ }
44
+ return null;
36
45
  }
37
46
  export const constant = (x) => () => x;
38
47
  export const POSITION_CHANNELS = new Set(['x', 'x1', 'x2', 'y', 'y1', 'y2']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.4.8-pr-225.0",
3
+ "version": "0.4.8-pr-227.1",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",