svelteplot 0.4.5-pr-208.6 → 0.4.5-pr-208.8

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']);
@@ -152,7 +152,11 @@ 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 === 'band' || type === 'point' || type === 'ordinal' || type === 'categorical';
155
+ const isOrdinal = type === 'band' ||
156
+ type === 'point' ||
157
+ type === 'ordinal' ||
158
+ type === 'categorical' ||
159
+ type === 'threshold';
156
160
  if (isOrdinal && sortOrdinalDomain) {
157
161
  valueArr.sort(ascending);
158
162
  }
@@ -25,6 +25,10 @@
25
25
  wordSpacing?: ConstantAccessor<CSS.Property.WordSpacing, Datum>;
26
26
  textTransform?: ConstantAccessor<CSS.Property.TextTransform, Datum>;
27
27
  textDecoration?: ConstantAccessor<CSS.Property.TextDecoration, Datum>;
28
+ /**
29
+ * the horizontal text anchor; start, end, or middle
30
+ */
31
+ textAnchor?: ConstantAccessor<CSS.Property.TextAnchor, Datum>;
28
32
  /**
29
33
  * if you want to apply class names to individual text elements
30
34
  */
@@ -84,6 +84,10 @@ declare class __sveltets_Render<Datum extends DataRecord> {
84
84
  wordSpacing?: ConstantAccessor<CSS.Property.WordSpacing<0 | (string & {})>, Datum>;
85
85
  textTransform?: ConstantAccessor<CSS.Property.TextTransform, Datum>;
86
86
  textDecoration?: ConstantAccessor<CSS.Property.TextDecoration<0 | (string & {})>, Datum>;
87
+ /**
88
+ * the horizontal text anchor; start, end, or middle
89
+ */
90
+ textAnchor?: ConstantAccessor<CSS.Property.TextAnchor, Datum>;
87
91
  /**
88
92
  * if you want to apply class names to individual text elements
89
93
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.4.5-pr-208.6",
3
+ "version": "0.4.5-pr-208.8",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",
@@ -106,7 +106,7 @@
106
106
  "typedoc": "^0.28.13",
107
107
  "typedoc-plugin-markdown": "^4.9.0",
108
108
  "typescript": "^5.9.3",
109
- "vite": "^6.3.5",
109
+ "vite": "^6.3.6",
110
110
  "vitest": "^3.2.4",
111
111
  "vitest-matchmedia-mock": "^2.0.3",
112
112
  "yoctocolors": "^2.1.2"