svelteplot 0.4.8-pr-222.2 → 0.4.8-pr-227.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.
@@ -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']);
@@ -88,31 +88,19 @@
88
88
  </script>
89
89
 
90
90
  <div
91
- class={['tooltip', { hide: !datum }]}
91
+ class={['svelteplot-tooltip', { hide: !datum }]}
92
92
  style:left="{tooltipX ? facetOffsetX + projectX('x', plot.scales, tooltipX) : 0}px"
93
93
  style:top="{tooltipY ? facetOffsetY + projectY('y', plot.scales, tooltipY) : 0}px">
94
- <div class="tooltip-body">
95
- {@render children({ datum })}
96
- </div>
94
+ {@render children({ datum })}
97
95
  </div>
98
96
 
99
97
  <style>
100
- div.tooltip {
101
- background: white;
102
- background: var(--svelteplot-tooltip-bg);
103
- border: 1px solid #ccc;
104
- border-color: var(--svelteplot-tooltip-border);
105
- font-size: 12px;
106
- padding: 1ex 1em;
107
- border-radius: 3px;
108
- line-height: 1.2;
109
- box-shadow:
110
- rgba(50, 50, 93, 0.25) 0px 2px 5px -1px,
111
- rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
98
+ div.svelteplot-tooltip {
112
99
  position: absolute;
113
100
  pointer-events: none;
114
- }
115
- .tooltip.hide {
116
- display: none;
101
+
102
+ &.hide {
103
+ display: none;
104
+ }
117
105
  }
118
106
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.4.8-pr-222.2",
3
+ "version": "0.4.8-pr-227.0",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",