svelte-plots-basic 3.3.0 → 4.0.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.
@@ -2,18 +2,18 @@
2
2
  @component Adds a series of points (markers).
3
3
 
4
4
  Main properties:
5
- - `xValues` - array of vector with x-coordinates of the points.
6
- - `yValues` - array of vector with y-coordinates of the points.
7
- - `zValues` - array of vector with z-coordinates of the points.
5
+ - `xValues` - array or vector with x-coordinates of the points.
6
+ - `yValues` - array or vector with y-coordinates of the points.
7
+ - `zValues` - array or vector with z-coordinates of the points.
8
8
  - `marker` - marker number (from 1 to 8), default: `1`.
9
9
  - `faceColor` - face (fill) color of the markers, default: `'transparent'`.
10
- - `borderColor` - color markers' borders, default: `Colors.PRIMARY`.
10
+ - `borderColor` - color of the markers' borders, default: `Colors.PRIMARY`.
11
11
  - `borderWidth` - width (thickness) of the markers' borders in pixels, default: `1`.
12
12
  - `markerSize` - size of the markers in em, default: `1`.
13
- - `title` - title of the line series group.
13
+ - `title` - title of the point series group, default: `''`.
14
14
 
15
15
  Example:
16
- ```jsx
16
+ ```svelte
17
17
  <script>
18
18
  import { Axes, Points } from 'svelte-plots-basic/3d';
19
19
 
@@ -46,8 +46,8 @@
46
46
 
47
47
  // reactive variables for coordinates of data points in pixels (and line style)
48
48
  const markerSymbol = $derived.by(() => {
49
- if (typeof(marker) !== "number" || marker < 1 || marker > MARKER_SYMBOLS.length) {
50
- console.error(`Points (3D): parameter 'marker' must be a number from 1 to ${MARKER_SYMBOLS.length}."`);
49
+ if (!Number.isInteger(marker) || marker < 1 || marker > MARKER_SYMBOLS.length) {
50
+ console.error(`Points (3D): parameter "marker" must be a whole number from 1 to ${MARKER_SYMBOLS.length}.`);
51
51
  return null;
52
52
  }
53
53
 
@@ -66,7 +66,6 @@
66
66
 
67
67
  <style>
68
68
  :global(.series-scatter > text) {
69
- font-size: 1em;
70
69
  cursor: default;
71
70
  }
72
71
 
@@ -11,24 +11,22 @@
11
11
  - `lineColor` - color of segment lines, default: `Colors.PRIMARY`.
12
12
  - `lineType` - type of segment lines (`1` - solid, `2` - dashed, `3` - dotted, `4` - dashdot).
13
13
  - `lineWidth` - width (thickness) of segment lines in pixels, default: `1`.
14
- - `className` - CSS class name of the SVG group, default: `'series-seg'`.
15
14
  - `title` - title of the segment series group.
16
- - `onclick` - function (callback) to be called when user clicks on any segment.
17
15
 
18
16
  Example:
19
- ```jsx
17
+ ```svelte
20
18
  <script>
21
19
  import { Axes, Segments } from 'svelte-plots-basic/3d';
22
20
 
23
- const xStart = [1, 2, 3, 4];
24
- const xEnd = [1, 2, 3, 4];
21
+ const xStart = [1, 2, 3, 4, 5];
22
+ const xEnd = [1, 2, 3, 4, 5];
25
23
  const yStart = [-2, -1, 0, -1, -2];
26
24
  const yEnd = [2, 1, 0, 1, 2];
27
- const zStart = [1, 2, 3, 4];
28
- const zEnd = [1, 2, 3, 4];
25
+ const zStart = [1, 2, 3, 4, 5];
26
+ const zEnd = [1, 2, 3, 4, 5];
29
27
  </script>
30
28
 
31
- <Axes limX={[0, 5]} limY={[-3, 3]} >
29
+ <Axes limX={[0, 6]} limY={[-3, 3]} limZ={[0, 6]}>
32
30
  <Segments {xStart} {yStart} {zStart} {xEnd} {yEnd} {zEnd} lineColor="red" lineType={3} />
33
31
  </Axes>
34
32
  ```
@@ -37,7 +35,7 @@
37
35
  import { cbind } from 'mdatools/arrays';
38
36
  import { getContext } from 'svelte';
39
37
  import { Colors, LINE_STYLES } from '../constants';
40
- import { checkCoords, transform3D } from '../methods';
38
+ import { checkCoords, transform3D, normalizeLineType } from '../methods';
41
39
 
42
40
 
43
41
  let {
@@ -62,6 +60,7 @@
62
60
  const ux2 = $derived(uz1 ? checkCoords(xEnd, 'Segments (3D)', ux1.length) : null);
63
61
  const uy2 = $derived(ux2 ? checkCoords(yEnd, 'Segments (3D)', ux1.length) : null);
64
62
  const uz2 = $derived(uy2 ? checkCoords(zEnd, 'Segments (3D)', ux1.length) : null);
63
+ const validLineType = $derived(normalizeLineType(lineType, 'Segments (3D)'));
65
64
 
66
65
  // combine world coordinates to matrices
67
66
  const uW1 = $derived(ux1 && uy1 && uz1 ? cbind(ux1, uy1, uz1) : null);
@@ -72,14 +71,13 @@
72
71
  const s1 = $derived(uW1 ? transform3D(uW1, axes.tM()) : null);
73
72
  const s2 = $derived(uW2 ? transform3D(uW2, axes.tM()) : null);
74
73
 
75
- const lineStyleStr = $derived(`stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scale()][lineType-1]}`);
74
+ const lineStyleStr = $derived(`stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scale()][validLineType - 1]}`);
76
75
  </script>
77
76
 
78
- <g class="series series-segments" data-title={title} style={lineStyleStr}>
79
77
  {#if s1 && s2}
78
+ <g class="series series-segments" data-title={title} style={lineStyleStr}>
80
79
  {#each s1.x as v, i}
81
80
  <line x1={s1.x[i]} x2={s2.x[i]} y1={s1.y[i]} y2={s2.y[i]} />
82
81
  {/each}
83
- {/if}
84
82
  </g>
85
-
83
+ {/if}
@@ -2,18 +2,22 @@
2
2
  @component Adds a series of text labels at given coordinates.
3
3
 
4
4
  Main properties:
5
- - `xValues` - array of vector with x-coordinates of the points.
6
- - `yValues` - array of vector with y-coordinates of the points.
7
- - `zValues` - array of vector with z-coordinates of the points.
8
- - `labels` - array with labels.
9
- - `faceColor` - face (fill) color of the markers, default: `'transparent'`.
10
- - `borderColor` - color markers' borders, default: `Colors.PRIMARY`.
11
- - `borderWidth` - width (thickness) of the markers' borders in pixels, default: `1`.
12
- - `textSize` - size of the markers in em, default: `1`.
13
- - `title` - title of the line series group.
5
+ - `xValues` - array or vector with x-coordinates of the labels.
6
+ - `yValues` - array or vector with y-coordinates of the labels.
7
+ - `zValues` - array or vector with z-coordinates of the labels.
8
+ - `labels` - single string used at every coordinate or array with one string per coordinate.
9
+ - `faceColor` - text fill color, default: `Colors.PRIMARY_TEXT`.
10
+ - `borderColor` - text outline color, default: `'transparent'`.
11
+ - `borderWidth` - text outline width in pixels, default: `0`.
12
+ - `textSize` - text size in em, default: `1`.
13
+ - `fontWeight` - CSS font weight, default: `'normal'`.
14
+ - `className` - CSS class name for the labels group, default: `'series-textlabel'`.
15
+ - `title` - title of the labels group, default: `''`.
16
+
17
+ Values in `labels` are rendered as raw SVG/HTML markup. Only pass trusted content.
14
18
 
15
19
  Example:
16
- ```jsx
20
+ ```svelte
17
21
  <script>
18
22
  import { Axes, TextLabels } from 'svelte-plots-basic/3d';
19
23
 
@@ -56,10 +60,19 @@
56
60
 
57
61
  const l = $derived.by(() => {
58
62
  if (!ux) return null;
59
- if(Array.isArray(labels) && labels.length !== ux.length ) {
60
- console.error('TextLabels: labels provided as an array should have the same number of elements as number of coordinates.');
63
+
64
+ if (typeof labels === 'string') return labels;
65
+
66
+ if (!Array.isArray(labels)) {
67
+ console.error('TextLabels (3D): parameter "labels" must be a string or an array.');
61
68
  return null;
62
69
  }
70
+
71
+ if (labels.length !== ux.length) {
72
+ console.error('TextLabels (3D): labels provided as an array must have the same number of elements as coordinates.');
73
+ return null;
74
+ }
75
+
63
76
  return labels;
64
77
  });
65
78
 
@@ -75,7 +88,7 @@
75
88
  {#if s}
76
89
  <g class="series {className}" title={title} style={textStyleStr} >
77
90
 
78
- {#if typeof labels === 'string'}
91
+ {#if typeof l === 'string'}
79
92
  {#each s.x as v, i}
80
93
  <text data-id={i} x={s.x[i]} y={s.y[i]} dx={0} dy={0}>{@html l}</text>
81
94
  {/each}
@@ -91,4 +104,4 @@
91
104
  text, text > :global(tspan) {
92
105
  dominant-baseline: middle;
93
106
  }
94
- </style>
107
+ </style>
@@ -11,18 +11,17 @@
11
11
  - `textColor` - color of axis text labels, default: `Colors.DARKGRAY`.
12
12
 
13
13
  Example:
14
- ```jsx
14
+ ```svelte
15
15
  <script>
16
16
  import {Axes, XAxis} from 'svelte-plots-basic/3d';
17
17
  </script>
18
18
  <Axes>
19
- // all other plotting components are here
20
19
  <XAxis label="X" showGrid={true} />
21
20
  </Axes>
22
21
  ```
23
22
  -->
24
23
  <script>
25
- import { getContext } from 'svelte';
24
+ import { getContext, onDestroy } from 'svelte';
26
25
  import { Colors } from '../constants';
27
26
 
28
27
  let {
@@ -36,11 +35,13 @@
36
35
  } = $props();
37
36
 
38
37
 
39
- // get axes context and adjust x margins
38
+ // get axes context and synchronize x-axis settings
40
39
  const axes = getContext('axes');
41
40
  $effect(() => {
42
41
  axes.setXAxis({show: true, ticks, tickLabels, showGrid, label, lineColor, gridColor, textColor});
43
42
  });
44
- </script>
45
-
46
43
 
44
+ onDestroy(() => {
45
+ axes.setXAxis({show: false});
46
+ });
47
+ </script>
@@ -3,26 +3,25 @@
3
3
 
4
4
  Main properties:
5
5
  - `label` - text label for the axis (optional).
6
- - `showGrid` - logical, show or not vertical grid lines, default: `false`.
7
- - `ticks` - array or vector with tick positions (by default will be generated automatically based on `limX`).
6
+ - `showGrid` - logical, show or hide grid lines, default: `false`.
7
+ - `ticks` - array or vector with tick positions (by default will be generated automatically based on `limY`).
8
8
  - `tickLabels` - array with tick labels to show at each tick (by default will be generated automatically).
9
9
  - `lineColor` - color of axis line, default: `Colors.DARKGRAY`.
10
10
  - `gridColor` - color of axis grid line, default: `Colors.MIDDLEGRAY`.
11
11
  - `textColor` - color of axis text labels, default: `Colors.DARKGRAY`.
12
12
 
13
13
  Example:
14
- ```jsx
14
+ ```svelte
15
15
  <script>
16
16
  import {Axes, YAxis} from 'svelte-plots-basic/3d';
17
17
  </script>
18
18
  <Axes>
19
- // all other plotting components are here
20
19
  <YAxis label="Y" showGrid={true} />
21
20
  </Axes>
22
21
  ```
23
22
  -->
24
23
  <script>
25
- import { getContext } from 'svelte';
24
+ import { getContext, onDestroy } from 'svelte';
26
25
  import { Colors } from '../constants';
27
26
 
28
27
  let {
@@ -36,11 +35,13 @@
36
35
  } = $props();
37
36
 
38
37
 
39
- // get axes context and adjust x margins
38
+ // get axes context and synchronize y-axis settings
40
39
  const axes = getContext('axes');
41
40
  $effect(() => {
42
41
  axes.setYAxis({show: true, ticks, tickLabels, showGrid, label, lineColor, gridColor, textColor});
43
42
  });
44
- </script>
45
-
46
43
 
44
+ onDestroy(() => {
45
+ axes.setYAxis({show: false});
46
+ });
47
+ </script>
@@ -3,26 +3,25 @@
3
3
 
4
4
  Main properties:
5
5
  - `label` - text label for the axis (optional).
6
- - `showGrid` - logical, show or not vertical grid lines, default: `false`.
7
- - `ticks` - array or vector with tick positions (by default will be generated automatically based on `limX`).
6
+ - `showGrid` - logical, show or hide grid lines, default: `false`.
7
+ - `ticks` - array or vector with tick positions (by default will be generated automatically based on `limZ`).
8
8
  - `tickLabels` - array with tick labels to show at each tick (by default will be generated automatically).
9
9
  - `lineColor` - color of axis line, default: `Colors.DARKGRAY`.
10
10
  - `gridColor` - color of axis grid line, default: `Colors.MIDDLEGRAY`.
11
11
  - `textColor` - color of axis text labels, default: `Colors.DARKGRAY`.
12
12
 
13
13
  Example:
14
- ```jsx
14
+ ```svelte
15
15
  <script>
16
16
  import {Axes, ZAxis} from 'svelte-plots-basic/3d';
17
17
  </script>
18
18
  <Axes>
19
- // all other plotting components are here
20
19
  <ZAxis label="Z" showGrid={true} />
21
20
  </Axes>
22
21
  ```
23
22
  -->
24
23
  <script>
25
- import { getContext } from 'svelte';
24
+ import { getContext, onDestroy } from 'svelte';
26
25
  import { Colors } from '../constants';
27
26
 
28
27
  let {
@@ -36,11 +35,13 @@
36
35
  } = $props();
37
36
 
38
37
 
39
- // get axes context and adjust x margins
38
+ // get axes context and synchronize z-axis settings
40
39
  const axes = getContext('axes');
41
40
  $effect(() => {
42
41
  axes.setZAxis({show: true, ticks, tickLabels, showGrid, label, lineColor, gridColor, textColor});
43
42
  });
44
- </script>
45
-
46
43
 
44
+ onDestroy(() => {
45
+ axes.setZAxis({show: false});
46
+ });
47
+ </script>