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.
- package/README.md +530 -445
- package/package.json +5 -2
- package/src/2d/Area.svelte +56 -48
- package/src/2d/Axes.svelte +409 -390
- package/src/2d/AxisLines.svelte +37 -36
- package/src/2d/AxisTickLabels.svelte +41 -49
- package/src/2d/Bars.svelte +102 -47
- package/src/2d/Box.svelte +21 -41
- package/src/2d/ColormapLegend.svelte +47 -111
- package/src/2d/Heatmap.svelte +107 -85
- package/src/2d/Legend.svelte +115 -126
- package/src/2d/Lines.svelte +54 -40
- package/src/2d/Multilines.svelte +73 -46
- package/src/2d/Points.svelte +76 -58
- package/src/2d/Rectangles.svelte +67 -58
- package/src/2d/Segments.svelte +59 -46
- package/src/2d/TextLabels.svelte +102 -72
- package/src/2d/TextLegend.svelte +17 -39
- package/src/2d/XAxis.svelte +49 -99
- package/src/2d/YAxis.svelte +47 -94
- package/src/2d/index.js +2 -1
- package/src/3d/Axes.svelte +306 -348
- package/src/3d/AxisLines.svelte +19 -37
- package/src/3d/AxisTickLabels.svelte +15 -32
- package/src/3d/Lines.svelte +59 -32
- package/src/3d/Mesh.svelte +106 -128
- package/src/3d/Points.svelte +56 -36
- package/src/3d/Segments.svelte +68 -52
- package/src/3d/TextLabels.svelte +63 -49
- package/src/3d/XAxis.svelte +36 -113
- package/src/3d/YAxis.svelte +36 -113
- package/src/3d/ZAxis.svelte +37 -114
- package/src/3d/index.js +2 -1
- package/src/constants.js +103 -0
- package/src/methods.js +1484 -0
- package/src/2d/Axis.svelte +0 -60
- package/src/3d/Axis.svelte +0 -64
- package/src/Colors.js +0 -51
- package/src/Utils.js +0 -639
package/src/3d/AxisLines.svelte
CHANGED
|
@@ -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 '../
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/*****************************************/
|
|
13
|
-
/* Input parameters */
|
|
14
|
-
/*****************************************/
|
|
6
|
+
import { Colors, LINE_STYLES } from '../constants';
|
|
7
|
+
import { transform3D } from '../methods';
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
29
|
-
const
|
|
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
|
-
|
|
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
|
|
44
|
-
<g class="
|
|
45
|
-
{#each
|
|
46
|
-
<line
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
20
|
+
const textStyleStr = $derived(`dominant-baseline:middle;fill:${textColor};font-size:0.85em; text-anchor:middle;`);
|
|
38
21
|
</script>
|
|
39
22
|
|
|
40
|
-
{#if
|
|
41
|
-
<g class="
|
|
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}
|
package/src/3d/Lines.svelte
CHANGED
|
@@ -1,48 +1,75 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
const
|
|
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
|
|
38
|
-
|
|
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
|
-
|
|
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
|
|
45
|
-
<g class="series
|
|
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}
|
package/src/3d/Mesh.svelte
CHANGED
|
@@ -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
|
|
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 '../
|
|
12
|
-
import { checkCoords } from '../
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
59
|
+
// compute coordinates of mesh elements
|
|
60
|
+
const mesh = $derived.by(() => {
|
|
49
61
|
|
|
50
|
-
if (!
|
|
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 =
|
|
56
|
-
const nz =
|
|
65
|
+
const nx = Uy.nrows;
|
|
66
|
+
const nz = Uy.ncols;
|
|
57
67
|
|
|
58
|
-
const nr = range(
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
83
|
+
const color1 = Vector.zeros((nx - 1) * nz);
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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(((
|
|
102
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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(((
|
|
119
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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
|
|
177
|
-
{#each
|
|
178
|
-
|
|
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
|
|
181
|
-
|
|
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>
|
package/src/3d/Points.svelte
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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="
|
|
61
|
+
className="series-scatter"
|
|
43
62
|
labels={markerSymbol}
|
|
44
63
|
textSize={markerSize}
|
|
45
64
|
/>
|
|
65
|
+
{/if}
|
|
46
66
|
|
|
47
67
|
<style>
|
|
48
|
-
:global(.
|
|
68
|
+
:global(.series-scatter > text) {
|
|
49
69
|
font-size: 1em;
|
|
50
70
|
cursor: default;
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
:global(.
|
|
73
|
+
:global(.series-scatter > text:hover) {
|
|
54
74
|
opacity: 90%;
|
|
55
75
|
}
|
|
56
76
|
|
|
57
|
-
:global(.
|
|
77
|
+
:global(.series-scatter > *:hover + .labels-hover) {
|
|
58
78
|
visibility: visible;
|
|
59
79
|
opacity: 1;
|
|
60
80
|
}
|