svelte-plots-basic 3.4.0 → 4.1.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,16 +2,16 @@
2
2
  @component Adds a series of lines connecting points with provided coordinates (polyline).
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
  - `lineColor` - lines color, default: `Colors.PRIMARY`.
9
- - `lineWidth` - width (thickness) of the lines in pixels, defailt: `1`.
9
+ - `lineWidth` - width (thickness) of the lines in pixels, default: `1`.
10
10
  - `lineType` - type of lines (`1` - solid, `2` - dashed, `3` - dotted, `4` - dashdot).
11
11
  - `title` - title of the line series group.
12
12
 
13
13
  Example:
14
- ```jsx
14
+ ```svelte
15
15
  <script>
16
16
  import { Axes, Lines } from 'svelte-plots-basic/3d';
17
17
 
@@ -29,7 +29,7 @@
29
29
  import { cbind } from 'mdatools/arrays';
30
30
  import { getContext } from 'svelte';
31
31
  import { Colors, LINE_STYLES } from '../constants';
32
- import { checkCoords, transform3D } from '../methods';
32
+ import { checkCoords, transform3D, normalizeLineType } from '../methods';
33
33
 
34
34
  let {
35
35
  xValues,
@@ -55,6 +55,7 @@
55
55
  const ux = $derived(checkCoords(xValues, 'Lines (3D)'));
56
56
  const uy = $derived(ux ? checkCoords(yValues, 'Lines (3D)', ux.length) : null);
57
57
  const uz = $derived(uy ? checkCoords(zValues, 'Lines (3D)', ux.length) : null);
58
+ const validLineType = $derived(normalizeLineType(lineType, 'Lines (3D)'));
58
59
 
59
60
  // combine world coordinates to matrices
60
61
  const uW = $derived(ux && uy && uz ? cbind(ux, uy, uz) : null);
@@ -65,7 +66,7 @@
65
66
  const p = $derived(s ? coords2points(s) : null);
66
67
 
67
68
  // reactive variables for coordinates of data points in pixels
68
- const lineStyleStr = $derived(`fill:transparent;stroke:${lineColor};stroke-width: ${lineWidth}px; stroke-dasharray:${LINE_STYLES[axes.scale()][lineType-1]}`);
69
+ const lineStyleStr = $derived(`fill:transparent;stroke:${lineColor};stroke-width: ${lineWidth}px; stroke-dasharray:${LINE_STYLES[axes.scale()][validLineType - 1]}`);
69
70
  </script>
70
71
 
71
72
  {#if p}
@@ -73,4 +74,3 @@
73
74
  <polyline class="line" points={p}/>
74
75
  </g>
75
76
  {/if}
76
-
@@ -1,20 +1,20 @@
1
1
  <!--
2
- @component Adds a mesh plot as a set of grid points and line segments connected them.
2
+ @component Adds a mesh plot as a set of grid points and line segments connecting them.
3
3
 
4
4
  Main properties:
5
- - `xValues` - array of vector with x-coordinates of the mesh points.
6
- - `zValues` - array of vector with z-coordinates of the mesh points.
5
+ - `xValues` - array or vector with x-coordinates of the mesh points.
6
+ - `zValues` - array or vector with z-coordinates of the mesh points.
7
7
  - `yValues` - matrix (!) with y-coordinates of the points defining its height.
8
- - `colmap` - array with colors to use for different height.
9
- - `lineWidth` - width (thickness) of the lines in pixels, defailt: `1`.
8
+ - `colmap` - array with colors to use for different heights.
9
+ - `lineWidth` - width (thickness) of the lines in pixels, default: `1`.
10
10
  - `lineType` - type of lines (`1` - solid, `2` - dashed, `3` - dotted, `4` - dashdot).
11
- - `title` - title of the line series group.
11
+ - `title` - title of the mesh series group.
12
12
 
13
13
  Example:
14
- ```jsx
14
+ ```svelte
15
15
  <script>
16
- import { Axes, Mesh } from 'svelte-plots-basic/3d';
17
- import { gecolmap } from 'svelte-plots-basic/utils';
16
+ import { Axes, Mesh, getcolmap } from 'svelte-plots-basic/3d';
17
+ import { Matrix, Vector } from 'mdatools/arrays';
18
18
 
19
19
  const xMesh = Vector.seq(-8, 8, 1);
20
20
  const zMesh = Vector.seq(-8, 8, 1);
@@ -24,6 +24,7 @@
24
24
  <Axes limX={[-10, 10]} limY={[-10, 10]} limZ={[-10, 10]}>
25
25
  <Mesh xValues={xMesh} yValues={yMesh} zValues={zMesh} colmap={getcolmap(16)}/>
26
26
  </Axes>
27
+ ```
27
28
  -->
28
29
  <script>
29
30
 
@@ -31,7 +32,7 @@
31
32
  import { range } from 'mdatools/stat';
32
33
  import { getContext } from 'svelte';
33
34
  import { Colors, LINE_STYLES } from '../constants';
34
- import { checkCoords, transform3D } from '../methods';
35
+ import { checkCoords, transform3D, normalizeLineType } from '../methods';
35
36
 
36
37
  let {
37
38
  title = '',
@@ -46,6 +47,7 @@
46
47
  // check user defined coordinates
47
48
  const ux = $derived(checkCoords(xValues, 'Mesh (3D)'));
48
49
  const uz = $derived(ux ? checkCoords(zValues, 'Mesh (3D)') : null);
50
+ const validLineType = $derived(normalizeLineType(lineType, 'Mesh (3D)'));
49
51
  const Uy = $derived.by(() => {
50
52
  if (!ux || !uz) return null;
51
53
  if (!ismatrix(yValues)) {
@@ -184,16 +186,16 @@
184
186
  const s2s = $derived(mesh ? transform3D(mesh.M2s, axes.tM()) : null);
185
187
  const s2e = $derived(mesh ? transform3D(mesh.M2e, axes.tM()) : null);
186
188
 
187
- const lineStyleStr = $derived(`stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scale()][lineType-1]};`);
189
+ const lineStyleStr = $derived(`stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scale()][validLineType - 1]};`);
188
190
  </script>
189
191
 
190
- <g class="series series_mesh" style={lineStyleStr} data-title={title}>
191
192
  {#if s1s && s1e && s2s && s2e }
193
+ <g class="series series_mesh" style={lineStyleStr} data-title={title}>
192
194
  {#each s1s.x as v, i}
193
195
  <line x1={s1s.x[i]} x2={s1e.x[i]} y1={s1s.y[i]} y2={s1e.y[i]} style={`stroke:${colors[mesh.color1.v[i]]};`} />
194
196
  {/each}
195
197
  {#each s2s.x as v, i}
196
198
  <line x1={s2s.x[i]} x2={s2e.x[i]} y1={s2s.y[i]} y2={s2e.y[i]} style={`stroke:${colors[mesh.color2.v[i]]};`} />
197
199
  {/each}
198
- {/if}
199
200
  </g>
201
+ {/if}
@@ -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,12 +11,11 @@
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
  ```
@@ -36,7 +35,7 @@
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});
@@ -46,4 +45,3 @@
46
45
  axes.setXAxis({show: false});
47
46
  });
48
47
  </script>
49
-
@@ -3,20 +3,19 @@
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
  ```
@@ -36,7 +35,7 @@
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});
@@ -46,4 +45,3 @@
46
45
  axes.setYAxis({show: false});
47
46
  });
48
47
  </script>
49
-
@@ -3,20 +3,19 @@
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
  ```
@@ -36,7 +35,7 @@
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});
@@ -46,4 +45,3 @@
46
45
  axes.setZAxis({show: false});
47
46
  });
48
47
  </script>
49
-