svelte-plots-basic 2.5.8 → 3.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.
@@ -1,49 +1,31 @@
1
+ <!--
2
+ @component draws line segments for axis elements (ticks. etc), not for manual use.
3
+ -->
1
4
  <script>
2
- /****************************************************
3
- * Axis lines for 3D plot *
4
- * ---------------------- *
5
- * shows lines for axis (main, grid, etc) *
6
- *****************************************************/
7
-
8
5
  import { getContext } from 'svelte';
9
- import { Colors } from '../Colors';
10
-
11
-
12
- /*****************************************/
13
- /* Input parameters */
14
- /*****************************************/
6
+ import { Colors, LINE_STYLES } from '../constants';
7
+ import { transform3D } from '../methods';
15
8
 
16
- export let lineCoords = [];
17
- export let lineColor = Colors.DARKGRAY;
18
- export let lineType = 1;
19
- export let lineWidth = 1;
9
+ let {
10
+ lineCoords = [], // nested array for line segments coordinates (start and end points).
11
+ lineColor = Colors.DARKGRAY, // color of the lines.
12
+ lineType = 1, // line type (1, 2, 3, 4).
13
+ lineWidth = 1, // line width (thickness) in pixels.
14
+ } = $props();
20
15
 
21
-
22
- /*****************************************/
23
- /* Component code */
24
- /*****************************************/
25
-
26
- // get axes context and reactive variables needed to compute coordinates
16
+ // get axes context and and compute screen coordinates
27
17
  const axes = getContext('axes');
28
- const scale = axes.scale;
29
- const tM = axes.tM;
30
- const isOk = axes.isOk;
31
-
32
- // compute coordinates of start and end points for each line
33
- let x1, x2, y1, y2, lineStyleStr = undefined;
34
- $: if (lineCoords.length == 2) {
35
- [x1, y1] = axes.transform(lineCoords[0], $tM);
36
- [x2, y2] = axes.transform(lineCoords[1], $tM);
37
- }
18
+ const s1 = $derived(lineCoords.length == 2 ? transform3D(lineCoords[0], axes.tM()) : null);
19
+ const s2 = $derived(s1 ? transform3D(lineCoords[1], axes.tM()) : null);
38
20
 
39
21
  // line style
40
- $: lineStyleStr = `stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType-1]}`;
22
+ const lineStyleStr = $derived(`stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scale()][lineType-1]}`);
41
23
  </script>
42
24
 
43
- {#if $isOk && x1 !== undefined && y1 !== undefined && x2 !== undefined && y2 !== undefined}
44
- <g class="axis__grid">
45
- {#each x1 as v, i}
46
- <line vector-effect="non-scaling-stroke" x1={x1[i]} x2={x2[i]} y1={y1[i]} y2={y2[i]} style={lineStyleStr} />
25
+ {#if s1 && s2}
26
+ <g class="axis-lines" style={lineStyleStr}>
27
+ {#each s1.x as v, i}
28
+ <line x1={s1.x[i]} x2={s2.x[i]} y1={s1.y[i]} y2={s2.y[i]} />
47
29
  {/each}
48
30
  </g>
49
31
  {/if}
@@ -1,46 +1,29 @@
1
+ <!--
2
+ @component shows tick labels.
3
+ -->
1
4
  <script>
2
- /****************************************************
3
- * AxisTickLabels for 3D plots *
4
- * ---------------------------- *
5
- * shows a series of tick labels along an axis *
6
- *****************************************************/
7
5
 
8
6
  import { getContext } from 'svelte';
7
+ import { transform3D } from '../methods';
9
8
 
10
-
11
- /*****************************************/
12
- /* Input parameters */
13
- /*****************************************/
14
-
15
- export let tickCoords;
16
- export let textColor;
17
- export let tickLabels;
18
-
19
-
20
- /*****************************************/
21
- /* Component code */
22
- /*****************************************/
9
+ let {
10
+ tickCoords, // nested array with coordinates of axis ticks.
11
+ textColor, // color of tick labels text.
12
+ tickLabels, // array with the labels.
13
+ } = $props();
23
14
 
24
15
  // get axes context and reactive variables needed to compute coordinates
25
16
  const axes = getContext('axes');
26
- const isOk = axes.isOk;
27
- const tM = axes.tM;
28
-
29
- let x, y = undefined;
30
-
31
- // reactive calculations triggered by changes in coordinates and plot parameters
32
- $: if ($isOk) {
33
- [x, y] = axes.transform(tickCoords, $tM);
34
- }
17
+ const s = $derived(transform3D(tickCoords, axes.tM()));
35
18
 
36
19
  // styles for the elements
37
- $: textStyleStr = `dominant-baseline:middle;fill:${textColor};font-size:0.85em; text-anchor:middle;`;
20
+ const textStyleStr = $derived(`dominant-baseline:middle;fill:${textColor};font-size:0.85em; text-anchor:middle;`);
38
21
  </script>
39
22
 
40
- {#if x !== undefined && y !== undefined}
41
- <g class="tick_labels" style={textStyleStr} >
42
- {#each x as v, i}
43
- <text data-id={i} x={x[i]} y={y[i]} dx={0} dy={0}>{@html tickLabels[i]}</text>
23
+ {#if s}
24
+ <g class="tick-labels" style={textStyleStr} >
25
+ {#each s.x as v, i}
26
+ <text data-id={i} x={s.x[i]} y={s.y[i]} dx={0} dy={0}>{@html tickLabels[i]}</text>
44
27
  {/each}
45
28
  </g>
46
29
  {/if}
@@ -1,48 +1,75 @@
1
- <script>
2
- /****************************************************
3
- * LineSeries *
4
- * -------------------- *
5
- * shows series of lines/curves *
6
- *****************************************************/
1
+ <!--
2
+ @component Adds a series of lines connecting points with provided coordinates (polyline).
7
3
 
8
- import { getContext } from 'svelte';
9
- import { Colors } from '../Colors';
10
- import { val2p3d } from '../Utils';
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
+ - `lineColor` - lines color, default: `Colors.PRIMARY`.
9
+ - `lineWidth` - width (thickness) of the lines in pixels, defailt: `1`.
10
+ - `lineType` - type of lines (`1` - solid, `2` - dashed, `3` - dotted, `4` - dashdot).
11
+ - `title` - title of the line series group.
11
12
 
13
+ Example:
14
+ ```jsx
15
+ <script>
16
+ import { Axes, Lines } from 'svelte-plots-basic/3d';
12
17
 
13
- /*****************************************/
14
- /* Input parameters */
15
- /*****************************************/
18
+ const xValues = [-3, -2, -1, 0, 1, 2, 3];
19
+ const yValues = [ 9, 4, 1, 0, 1, 4, 9];
20
+ const zValues = [-3, -2, -1, 0, 1, 2, 3];
21
+ </script>
16
22
 
17
- export let xValues;
18
- export let yValues;
19
- export let zValues;
20
- export let title = '';
21
- export let lineWidth = 1;
22
- export let lineColor = Colors.PRIMARY;
23
- export let lineType = 1;
23
+ <Axes limX={[-4, 4]} limY={[-2, 10]} limZ={[-4, 4]}>
24
+ <Lines {xValues} {yValues} {zValues} />
25
+ </Axes>
26
+ ```
27
+ -->
28
+ <script>
29
+ import { cbind } from 'mdatools/arrays';
30
+ import { getContext } from 'svelte';
31
+ import { Colors, LINE_STYLES } from '../constants';
32
+ import { checkCoords, transform3D } from '../methods';
24
33
 
34
+ let {
35
+ xValues,
36
+ yValues,
37
+ zValues,
38
+ lineWidth = 1,
39
+ lineColor = Colors.PRIMARY,
40
+ lineType = 1,
41
+ title = '',
42
+ } = $props();
25
43
 
26
- /*****************************************/
27
- /* Component code */
28
- /*****************************************/
29
44
 
30
- // get axes context
31
- const axes = getContext('axes');
45
+ /* convert 2D coordinates to points string */
46
+ function coords2points(s) {
47
+ let p = '';
48
+ for (let i = 0; i < s.x.length; i++) {
49
+ p += s.x[i] + ',' + s.y[i] + ' ';
50
+ }
51
+ return p;
52
+ }
53
+
54
+ // check user defined coordinates
55
+ const ux = $derived(checkCoords(xValues, 'Lines (3D)'));
56
+ const uy = $derived(ux ? checkCoords(yValues, 'Lines (3D)', ux.length) : null);
57
+ const uz = $derived(uy ? checkCoords(zValues, 'Lines (3D)', ux.length) : null);
32
58
 
33
- const scale = axes.scale;
34
- const isOk = axes.isOk;
35
- const tM = axes.tM;
59
+ // combine world coordinates to matrices
60
+ const uW = $derived(ux && uy && uz ? cbind(ux, uy, uz) : null);
36
61
 
37
- // compute polynomial coordinates as string
38
- $: p = $isOk ? val2p3d(xValues, yValues, zValues, $tM, axes) : undefined;
62
+ // get axes context and compute screen coordinates
63
+ const axes = getContext('axes');
64
+ const s = $derived(uW ? transform3D(uW, axes.tM()) : null);
65
+ const p = $derived(s ? coords2points(s) : null);
39
66
 
40
67
  // reactive variables for coordinates of data points in pixels
41
- $: lineStyleStr = `fill:transparent;stroke:${lineColor};stroke-width: ${lineWidth}px; stroke-dasharray:${axes.LINE_STYLES[$scale][lineType-1]}`;
68
+ const lineStyleStr = $derived(`fill:transparent;stroke:${lineColor};stroke-width: ${lineWidth}px; stroke-dasharray:${LINE_STYLES[axes.scale()][lineType-1]}`);
42
69
  </script>
43
70
 
44
- {#if $isOk && p !== undefined}
45
- <g class="series series_line" style={lineStyleStr} title={title}>
71
+ {#if p}
72
+ <g class="series series-line" style={lineStyleStr} title={title}>
46
73
  <polyline class="line" points={p}/>
47
74
  </g>
48
75
  {/if}
@@ -1,86 +1,96 @@
1
+ <!--
2
+ @component Adds a mesh plot as a set of grid points and line segments connected them.
3
+
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.
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`.
10
+ - `lineType` - type of lines (`1` - solid, `2` - dashed, `3` - dotted, `4` - dashdot).
11
+ - `title` - title of the line series group.
12
+
13
+ Example:
14
+ ```jsx
15
+ <script>
16
+ import { Axes, Mesh } from 'svelte-plots-basic/3d';
17
+ import { gecolmap } from 'svelte-plots-basic/utils';
18
+
19
+ const xMesh = Vector.seq(-8, 8, 1);
20
+ const zMesh = Vector.seq(-8, 8, 1);
21
+ const yMesh = Matrix.outer(xMesh, zMesh, (x, y) => 6 - (x**2 + y**2) / 10);
22
+ </script>
23
+
24
+ <Axes limX={[-10, 10]} limY={[-10, 10]} limZ={[-10, 10]}>
25
+ <Mesh xValues={xMesh} yValues={yMesh} zValues={zMesh} colmap={getcolmap(16)}/>
26
+ </Axes>
27
+ -->
1
28
  <script>
2
- /****************************************************
3
- * Segments for 3D plot *
4
- * -------------------- *
5
- * shows a series of line segments on the plot *
6
- *****************************************************/
7
29
 
8
- import { Vector, cbind, ismatrix, isvector } from 'mdatools/arrays';
30
+ import { Vector, cbind, ismatrix } from 'mdatools/arrays';
9
31
  import { range } from 'mdatools/stat';
10
32
  import { getContext } from 'svelte';
11
- import { Colors } from '../Colors';
12
- import { checkCoords } from '../Utils';
13
-
14
-
15
- /*****************************************/
16
- /* Input parameters */
17
- /*****************************************/
18
-
19
- export let title = '';
20
- export let xValues;
21
- export let yValues;
22
- export let zValues;
23
-
24
- export let colmap = [Colors.PRIMARY, Colors.PRIMARY];
25
- export let lineType = 1;
26
- export let lineWidth = 1;
27
-
28
- // get axes context and reactive variables needed to compute coordinates
29
- const axes = getContext('axes');
30
- const scale = axes.scale;
31
- const tM = axes.tM;
32
- const isOk = axes.isOk;
33
-
34
- let xMesh1Start, xMesh1End, yMesh1Start, yMesh1End, zMesh1Start, zMesh1End, meshColor1;
35
- let xMesh2Start, xMesh2End, yMesh2Start, yMesh2End, zMesh2Start, zMesh2End, meshColor2;
36
-
37
- $: {
33
+ import { Colors, LINE_STYLES } from '../constants';
34
+ import { checkCoords, transform3D } from '../methods';
35
+
36
+ let {
37
+ title = '',
38
+ xValues,
39
+ yValues,
40
+ zValues,
41
+ colmap = [Colors.PRIMARY, Colors.PRIMARY],
42
+ lineType = 1,
43
+ lineWidth = 1,
44
+ } = $props();
45
+
46
+ // check user defined coordinates
47
+ const ux = $derived(checkCoords(xValues, 'Mesh (3D)'));
48
+ const uz = $derived(ux ? checkCoords(zValues, 'Mesh (3D)', ux.length) : null);
49
+ const Uy = $derived.by(() => {
50
+ if (!ux || !uz) return null;
38
51
  if (!ismatrix(yValues)) {
39
- throw Error('Mesh: parameter "yValues" must be a matrix with height values of mesh points.');
52
+ console.error('Mesh: parameter "yValues" must be a matrix with height values of mesh points.');
53
+ return null;
40
54
  }
55
+ return yValues;
56
+ });
41
57
 
42
- if (Array.isArray(xValues)) {
43
- xValues = vector(xValues);
44
- }
45
58
 
46
- if (Array.isArray(zValues)) {
47
- zValues = vector(zValues);
48
- }
59
+ // compute coordinates of mesh elements
60
+ const mesh = $derived.by(() => {
49
61
 
50
- if (!isvector(zValues) || !isvector(xValues)) {
51
- throw Error('Mesh: parameters "xValues" and "zValues" must be vectors or arrays with values.');
52
- }
62
+ if (!Uy) return null;
53
63
 
54
64
  const nbins = colmap.length;
55
- const nx = yValues.nrows;
56
- const nz = yValues.ncols;
65
+ const nx = Uy.nrows;
66
+ const nz = Uy.ncols;
57
67
 
58
- const nr = range(yValues.v);
68
+ const nr = range(Uy.v);
59
69
  const dnr = (nr[1] - nr[0]) / 100;
60
70
  const left = nr[0] - dnr;
61
71
  const right = nr[1] + dnr;
62
72
  const span = right - left;
63
73
 
64
74
  // compute coordinates for mesh segments lines
65
- xMesh1Start = Vector.zeros((nx - 1) * nz);
66
- zMesh1Start = Vector.zeros((nx - 1) * nz);
67
- yMesh1Start = Vector.zeros((nx - 1) * nz);
75
+ const x1s = Vector.zeros((nx - 1) * nz);
76
+ const z1s = Vector.zeros((nx - 1) * nz);
77
+ const y1s = Vector.zeros((nx - 1) * nz);
68
78
 
69
- xMesh2Start = Vector.zeros((nx - 1) * nz);
70
- zMesh2Start = Vector.zeros((nx - 1) * nz);
71
- yMesh2Start = Vector.zeros((nx - 1) * nz);
79
+ const x2s = Vector.zeros((nx - 1) * nz);
80
+ const z2s = Vector.zeros((nx - 1) * nz);
81
+ const y2s = Vector.zeros((nx - 1) * nz);
72
82
 
73
- meshColor1 = Vector.zeros((nx - 1) * nz);
83
+ const color1 = Vector.zeros((nx - 1) * nz);
74
84
 
75
- xMesh1End = Vector.zeros((nx - 1) * nz);
76
- zMesh1End = Vector.zeros((nx - 1) * nz);
77
- yMesh1End = Vector.zeros((nx - 1) * nz);
85
+ const x1e = Vector.zeros((nx - 1) * nz);
86
+ const z1e = Vector.zeros((nx - 1) * nz);
87
+ const y1e = Vector.zeros((nx - 1) * nz);
78
88
 
79
- xMesh2End = Vector.zeros((nx - 1) * nz);
80
- zMesh2End = Vector.zeros((nx - 1) * nz);
81
- yMesh2End = Vector.zeros((nx - 1) * nz);
89
+ const x2e = Vector.zeros((nx - 1) * nz);
90
+ const z2e = Vector.zeros((nx - 1) * nz);
91
+ const y2e = Vector.zeros((nx - 1) * nz);
82
92
 
83
- meshColor2 = Vector.zeros((nx - 1) * nz);
93
+ const color2 = Vector.zeros((nx - 1) * nz);
84
94
 
85
95
  let n1 = 0, n2 = 0;
86
96
  for (let z = 0; z < nz; z++) {
@@ -89,96 +99,64 @@
89
99
  if (x < nx - 1) {
90
100
 
91
101
  // x-direction - start
92
- xMesh1Start.v[n1] = xValues.v[x];
93
- zMesh1Start.v[n1] = zValues.v[z];
94
- yMesh1Start.v[n1] = yValues.v[z * nz + x];
102
+ x1s.v[n1] = ux.v[x];
103
+ z1s.v[n1] = uz.v[z];
104
+ y1s.v[n1] = Uy.v[z * nz + x];
95
105
 
96
106
  // x-direction - end
97
- xMesh1End.v[n1] = xValues.v[x + 1];
98
- zMesh1End.v[n1] = zValues.v[z];
99
- yMesh1End.v[n1] = yValues.v[z * nz + x + 1];
107
+ x1e.v[n1] = ux.v[x + 1];
108
+ z1e.v[n1] = uz.v[z];
109
+ y1e.v[n1] = Uy.v[z * nz + x + 1];
100
110
 
101
- const colInd = Math.round(((yValues.v[z * nz + x] + yValues.v[z * nz + x + 1]) / 2 - left) / span * (nbins - 1));
102
- meshColor1.v[n1] = colInd;
111
+ const colInd = Math.round(((Uy.v[z * nz + x] + Uy.v[z * nz + x + 1]) / 2 - left) / span * (nbins - 1));
112
+ color1.v[n1] = colInd;
103
113
  n1 = n1 + 1;
104
114
  }
105
115
 
106
116
  if (z < nz - 1) {
107
117
 
108
118
  // z-direction - start
109
- xMesh2Start.v[n2] = xValues.v[x];
110
- zMesh2Start.v[n2] = zValues.v[z];
111
- yMesh2Start.v[n2] = yValues.v[z * nz + x];
119
+ x2s.v[n2] = ux.v[x];
120
+ z2s.v[n2] = uz.v[z];
121
+ y2s.v[n2] = Uy.v[z * nz + x];
112
122
 
113
123
  // z-direction - end
114
- xMesh2End.v[n2] = xValues.v[x];
115
- zMesh2End.v[n2] = zValues.v[z + 1];
116
- yMesh2End.v[n2] = yValues.v[(z + 1) * nz + x];
124
+ x2e.v[n2] = ux.v[x];
125
+ z2e.v[n2] = uz.v[z + 1];
126
+ y2e.v[n2] = Uy.v[(z + 1) * nz + x];
117
127
 
118
- const colInd = Math.round(((yValues.v[z * nz + x] + yValues.v[(z + 1) * nz + x]) / 2 - left) / span * (nbins - 1));
119
- meshColor2.v[n2] = colInd;
128
+ const colInd = Math.round(((Uy.v[z * nz + x] + Uy.v[(z + 1) * nz + x]) / 2 - left) / span * (nbins - 1));
129
+ color2.v[n2] = colInd;
120
130
  n2 = n2 + 1;
121
131
  }
122
132
  }
123
133
  }
124
134
 
125
- xMesh1Start = xMesh1Start.copy()
126
- xMesh1End = xMesh1End.copy()
127
- yMesh1Start = yMesh1Start.copy()
128
- yMesh1End = yMesh1End.copy()
129
- zMesh1Start = zMesh1Start.copy()
130
- zMesh1End = zMesh1End.copy()
131
- };
132
-
133
- let x11, y11, x12, y12;
134
- let x21, y21, x22, y22;
135
-
136
- $: {
137
- if ($isOk) {
138
- [x11, y11] = axes.transform(
139
- cbind(
140
- checkCoords(xMesh1Start, 'Segments'),
141
- checkCoords(yMesh1Start, 'Segments'),
142
- checkCoords(zMesh1Start, 'Segments')
143
- ), $tM
144
- );
145
-
146
- [x12, y12] = axes.transform(
147
- cbind(
148
- checkCoords(xMesh1End, 'Segments'),
149
- checkCoords(yMesh1End, 'Segments'),
150
- checkCoords(zMesh1End, 'Segments')
151
- ), $tM
152
- );
153
-
154
- [x21, y21] = axes.transform(
155
- cbind(
156
- checkCoords(xMesh2Start, 'Segments'),
157
- checkCoords(yMesh2Start, 'Segments'),
158
- checkCoords(zMesh2Start, 'Segments')
159
- ), $tM
160
- );
161
-
162
- [x22, y22] = axes.transform(
163
- cbind(
164
- checkCoords(xMesh2End, 'Segments'),
165
- checkCoords(yMesh2End, 'Segments'),
166
- checkCoords(zMesh2End, 'Segments')
167
- ), $tM
168
- );
169
- }
170
- };
135
+ const M1s = cbind(x1s, y1s, z1s);
136
+ const M1e = cbind(x1e, y1e, z1e);
137
+ const M2s = cbind(x2s, y2s, z2s);
138
+ const M2e = cbind(x2e, y2e, z2e);
139
+
140
+ return {M1s, M1e, M2s, M2e, color1, color2};
141
+ });
142
+
143
+ // get axes context and compute screen coordinates
144
+ const axes = getContext('axes');
145
+ const s1s = $derived(mesh ? transform3D(mesh.M1s, axes.tM()) : null);
146
+ const s1e = $derived(mesh ? transform3D(mesh.M1e, axes.tM()) : null);
147
+ const s2s = $derived(mesh ? transform3D(mesh.M2s, axes.tM()) : null);
148
+ const s2e = $derived(mesh ? transform3D(mesh.M2e, axes.tM()) : null);
171
149
 
172
- $: lineStyleStr = `stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType-1]};`;
150
+ const lineStyleStr = $derived(`stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scale()][lineType-1]};`);
173
151
  </script>
174
152
 
175
153
  <g class="series series_mesh" style={lineStyleStr} data-title={title}>
176
- {#if $isOk }
177
- {#each x11 as v, i}
178
- <line vector-effect="non-scaling-stroke" x1={x11[i]} x2={x12[i]} y1={y11[i]} y2={y12[i]} style={`stroke:${colmap[meshColor1.v[i]]};`} />
154
+ {#if s1s && s1e && s2s && s2e }
155
+ {#each s1s.x as v, i}
156
+ <line x1={s1s.x[i]} x2={s1e.x[i]} y1={s1s.y[i]} y2={s1e.y[i]} style={`stroke:${colmap[mesh.color1.v[i]]};`} />
179
157
  {/each}
180
- {#each x21 as v, i}
181
- <line vector-effect="non-scaling-stroke" x1={x21[i]} x2={x22[i]} y1={y21[i]} y2={y22[i]} style={`stroke:${colmap[meshColor2.v[i]]};`} />
158
+ {#each s2s.x as v, i}
159
+ <line x1={s2s.x[i]} x2={s2e.x[i]} y1={s2s.y[i]} y2={s2e.y[i]} style={`stroke:${colmap[mesh.color2.v[i]]};`} />
182
160
  {/each}
183
161
  {/if}
184
162
  </g>
@@ -1,60 +1,80 @@
1
+ <!--
2
+ @component Adds a series of points (markers).
3
+
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
+ - `marker` - marker number (from 1 to 8), default: `1`.
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
+ - `markerSize` - size of the markers in em, default: `1`.
13
+ - `title` - title of the line series group.
14
+
15
+ Example:
16
+ ```jsx
17
+ <script>
18
+ import { Axes, Points } from 'svelte-plots-basic/3d';
19
+
20
+ const xValues = [-3, -2, -1, 0, 1, 2, 3];
21
+ const yValues = [ 9, 4, 1, 0, 1, 4, 9];
22
+ const zValues = [-3, -2, -1, 0, 1, 2, 3];
23
+ </script>
24
+
25
+ <Axes limX={[-4, 4]} limY={[-2, 10]} limZ={[-4, 4]}>
26
+ <Points {xValues} {yValues} {zValues} />
27
+ </Axes>
28
+ ```
29
+ -->
1
30
  <script>
2
- /****************************************************
3
- * ScatterSeries component *
4
- * -------------------- *
5
- * shows a series of points on the plot *
6
- * *
7
- *****************************************************/
8
-
9
- import { Colors } from '../Colors';
31
+
32
+ import { Colors, MARKER_SYMBOLS } from '../constants';
10
33
  import TextLabels from './TextLabels.svelte';
11
34
 
12
- /*****************************************/
13
- /* Input parameters */
14
- /*****************************************/
15
-
16
- // input parameters
17
- export let xValues;
18
- export let yValues;
19
- export let zValues = undefined
20
- export let marker = 1
21
- export let title = "";
22
- export let faceColor = "transparent";
23
- export let borderColor = Colors.PRIMARY;
24
- export let borderWidth = 1;
25
- export let markerSize = 1;
26
-
27
- /* constants for internal use */
28
- const markers = ["●", "◼", "▲", "▼", "⬥", "+", "*", "⨯"];
29
- let markerSymbol;
30
-
31
- /* sanity check of input parameters */
32
- if (typeof(marker) !== "number" || marker < 1 || marker > markers.length) {
33
- throw(`Points: parameter 'marker' must be a number from 1 to ${markers.length}."`);
34
- }
35
+ let {
36
+ xValues,
37
+ yValues,
38
+ zValues,
39
+ marker = 1,
40
+ title = '',
41
+ faceColor = "transparent",
42
+ borderColor = Colors.PRIMARY,
43
+ borderWidth = 1,
44
+ markerSize = 1,
45
+ } = $props();
35
46
 
36
47
  // reactive variables for coordinates of data points in pixels (and line style)
37
- $: markerSymbol = markers[marker - 1];
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}."`);
51
+ return null;
52
+ }
53
+
54
+ return MARKER_SYMBOLS[marker - 1];
55
+ });
38
56
  </script>
39
57
 
58
+ {#if markerSymbol}
40
59
  <TextLabels
41
60
  {xValues} {yValues} {zValues} {faceColor} {borderColor} {borderWidth} {title}
42
- className="series_scatter"
61
+ className="series-scatter"
43
62
  labels={markerSymbol}
44
63
  textSize={markerSize}
45
64
  />
65
+ {/if}
46
66
 
47
67
  <style>
48
- :global(.series_scatter > text) {
68
+ :global(.series-scatter > text) {
49
69
  font-size: 1em;
50
70
  cursor: default;
51
71
  }
52
72
 
53
- :global(.series_scatter > text:hover) {
73
+ :global(.series-scatter > text:hover) {
54
74
  opacity: 90%;
55
75
  }
56
76
 
57
- :global(.series_scatter > *:hover + .labels_hover) {
77
+ :global(.series-scatter > *:hover + .labels-hover) {
58
78
  visibility: visible;
59
79
  opacity: 1;
60
80
  }