svelte-plots-basic 1.1.3 → 2.0.1

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.
Files changed (50) hide show
  1. package/README.md +54 -69
  2. package/package.json +28 -33
  3. package/src/2d/Area.svelte +61 -0
  4. package/src/2d/Axes.svelte +500 -0
  5. package/src/2d/Axis.svelte +50 -0
  6. package/src/2d/AxisLines.svelte +54 -0
  7. package/src/2d/AxisTickLabels.svelte +82 -0
  8. package/src/2d/Bars.svelte +65 -0
  9. package/src/2d/Box.svelte +50 -0
  10. package/src/2d/ColorLegend.svelte +36 -0
  11. package/src/2d/Legend.svelte +148 -0
  12. package/src/2d/Lines.svelte +49 -0
  13. package/src/2d/Multilines.svelte +67 -0
  14. package/src/2d/Points.svelte +79 -0
  15. package/src/2d/Rectangles.svelte +74 -0
  16. package/src/2d/Segments.svelte +65 -0
  17. package/src/2d/TextLabels.svelte +107 -0
  18. package/src/2d/TextLegend.svelte +53 -0
  19. package/src/2d/XAxis.svelte +99 -0
  20. package/src/2d/YAxis.svelte +99 -0
  21. package/src/{index.js → 2d/index.js} +10 -6
  22. package/src/3d/Axes.svelte +445 -0
  23. package/src/3d/Axis.svelte +64 -0
  24. package/src/3d/AxisLines.svelte +50 -0
  25. package/src/3d/AxisTickLabels.svelte +54 -0
  26. package/src/3d/Lines.svelte +49 -0
  27. package/src/3d/Mesh.svelte +188 -0
  28. package/src/3d/Points.svelte +61 -0
  29. package/src/3d/Segments.svelte +69 -0
  30. package/src/3d/TextLabels.svelte +79 -0
  31. package/src/3d/XAxis.svelte +123 -0
  32. package/src/3d/YAxis.svelte +123 -0
  33. package/src/3d/ZAxis.svelte +123 -0
  34. package/src/3d/index.js +13 -0
  35. package/src/Colors.js +36 -1
  36. package/src/Utils.js +205 -0
  37. package/dist/index.js +0 -4209
  38. package/dist/index.mjs +0 -4187
  39. package/src/AreaSeries.svelte +0 -53
  40. package/src/Axes.svelte +0 -538
  41. package/src/BarSeries.svelte +0 -78
  42. package/src/Box.svelte +0 -35
  43. package/src/LineSeries.svelte +0 -50
  44. package/src/Rectangles.svelte +0 -64
  45. package/src/ScatterSeries.svelte +0 -85
  46. package/src/Segments.svelte +0 -48
  47. package/src/TextLabels.svelte +0 -78
  48. package/src/TextLegend.svelte +0 -38
  49. package/src/XAxis.svelte +0 -69
  50. package/src/YAxis.svelte +0 -72
@@ -0,0 +1,188 @@
1
+ <script>
2
+ /****************************************************
3
+ * Segments for 3D plot *
4
+ * -------------------- *
5
+ * shows a series of line segments on the plot *
6
+ *****************************************************/
7
+
8
+ import { Vector, cbind, ismatrix, isvector } from 'mdatools/arrays';
9
+ import { range } from 'mdatools/stat';
10
+ 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
+ $: {
38
+ if (!ismatrix(yValues)) {
39
+ throw Error('Mesh: parameter "yValues" must be a matrix with height values of mesh points.');
40
+ }
41
+
42
+ if (Array.isArray(xValues)) {
43
+ xValues = vector(xValues);
44
+ }
45
+
46
+ if (Array.isArray(zValues)) {
47
+ zValues = vector(zValues);
48
+ }
49
+
50
+ if (!isvector(zValues) || !isvector(xValues)) {
51
+ throw Error('Mesh: parameters "xValues" and "zValues" must be vectors or arrays with values.');
52
+ }
53
+
54
+ const nbins = colmap.length;
55
+ const nx = yValues.nrows;
56
+ const nz = yValues.ncols;
57
+
58
+ const nr = range(yValues.v);
59
+ const dnr = (nr[1] - nr[0]) / 100;
60
+ const left = nr[0] - dnr;
61
+ const right = nr[1] + dnr;
62
+ const span = right - left;
63
+ console.log(nr)
64
+ console.log([left, right, span])
65
+
66
+ // compute coordinates for mesh segments lines
67
+ xMesh1Start = Vector.zeros((nx - 1) * nz);
68
+ zMesh1Start = Vector.zeros((nx - 1) * nz);
69
+ yMesh1Start = Vector.zeros((nx - 1) * nz);
70
+
71
+ xMesh2Start = Vector.zeros((nx - 1) * nz);
72
+ zMesh2Start = Vector.zeros((nx - 1) * nz);
73
+ yMesh2Start = Vector.zeros((nx - 1) * nz);
74
+
75
+ meshColor1 = Vector.zeros((nx - 1) * nz);
76
+
77
+ xMesh1End = Vector.zeros((nx - 1) * nz);
78
+ zMesh1End = Vector.zeros((nx - 1) * nz);
79
+ yMesh1End = Vector.zeros((nx - 1) * nz);
80
+
81
+ xMesh2End = Vector.zeros((nx - 1) * nz);
82
+ zMesh2End = Vector.zeros((nx - 1) * nz);
83
+ yMesh2End = Vector.zeros((nx - 1) * nz);
84
+
85
+ meshColor2 = Vector.zeros((nx - 1) * nz);
86
+
87
+ let n1 = 0, n2 = 0;
88
+ for (let z = 0; z < nz; z++) {
89
+ for (let x = 0; x < nx; x++) {
90
+
91
+ if (x < nx - 1) {
92
+
93
+ // x-direction - start
94
+ xMesh1Start.v[n1] = xValues.v[x];
95
+ zMesh1Start.v[n1] = zValues.v[z];
96
+ yMesh1Start.v[n1] = yValues.v[z * nz + x];
97
+
98
+ // x-direction - end
99
+ xMesh1End.v[n1] = xValues.v[x + 1];
100
+ zMesh1End.v[n1] = zValues.v[z];
101
+ yMesh1End.v[n1] = yValues.v[z * nz + x + 1];
102
+
103
+ const colInd = Math.round(((yValues.v[z * nz + x] + yValues.v[z * nz + x + 1]) / 2 - left) / span * (nbins - 1));
104
+ meshColor1.v[n1] = colInd;
105
+ n1 = n1 + 1;
106
+ }
107
+
108
+ if (z < nz - 1) {
109
+
110
+ // z-direction - start
111
+ xMesh2Start.v[n2] = xValues.v[x];
112
+ zMesh2Start.v[n2] = zValues.v[z];
113
+ yMesh2Start.v[n2] = yValues.v[z * nz + x];
114
+
115
+ // z-direction - end
116
+ xMesh2End.v[n2] = xValues.v[x];
117
+ zMesh2End.v[n2] = zValues.v[z + 1];
118
+ yMesh2End.v[n2] = yValues.v[(z + 1) * nz + x];
119
+
120
+ const colInd = Math.round(((yValues.v[z * nz + x] + yValues.v[(z + 1) * nz + x]) / 2 - left) / span * (nbins - 1));
121
+ meshColor2.v[n2] = colInd;
122
+ n2 = n2 + 1;
123
+ }
124
+ }
125
+ }
126
+
127
+ xMesh1Start = xMesh1Start.copy()
128
+ xMesh1End = xMesh1End.copy()
129
+ yMesh1Start = yMesh1Start.copy()
130
+ yMesh1End = yMesh1End.copy()
131
+ zMesh1Start = zMesh1Start.copy()
132
+ zMesh1End = zMesh1End.copy()
133
+ };
134
+
135
+ let x11, y11, x12, y12;
136
+ let x21, y21, x22, y22;
137
+
138
+ $: {
139
+ if ($isOk) {
140
+ [x11, y11] = axes.transform(
141
+ cbind(
142
+ checkCoords(xMesh1Start, 'Segments'),
143
+ checkCoords(yMesh1Start, 'Segments'),
144
+ checkCoords(zMesh1Start, 'Segments')
145
+ ), $tM
146
+ );
147
+
148
+ [x12, y12] = axes.transform(
149
+ cbind(
150
+ checkCoords(xMesh1End, 'Segments'),
151
+ checkCoords(yMesh1End, 'Segments'),
152
+ checkCoords(zMesh1End, 'Segments')
153
+ ), $tM
154
+ );
155
+
156
+ [x21, y21] = axes.transform(
157
+ cbind(
158
+ checkCoords(xMesh2Start, 'Segments'),
159
+ checkCoords(yMesh2Start, 'Segments'),
160
+ checkCoords(zMesh2Start, 'Segments')
161
+ ), $tM
162
+ );
163
+
164
+ [x22, y22] = axes.transform(
165
+ cbind(
166
+ checkCoords(xMesh2End, 'Segments'),
167
+ checkCoords(yMesh2End, 'Segments'),
168
+ checkCoords(zMesh2End, 'Segments')
169
+ ), $tM
170
+ );
171
+ }
172
+ };
173
+
174
+ $: console.log(meshColor1)
175
+ $: lineStyleStr = `stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType-1]};`;
176
+ </script>
177
+
178
+ <g class="series series_mesh" style={lineStyleStr} data-title={title}>
179
+ {#if $isOk }
180
+ {#each x11 as v, i}
181
+ <line vector-effect="non-scaling-stroke" x1={x11[i]} x2={x12[i]} y1={y11[i]} y2={y12[i]} style={`stroke:${colmap[meshColor1.v[i]]};`} />
182
+ {/each}
183
+ {#each x21 as v, i}
184
+ <line vector-effect="non-scaling-stroke" x1={x21[i]} x2={x22[i]} y1={y21[i]} y2={y22[i]} style={`stroke:${colmap[meshColor2.v[i]]};`} />
185
+ {/each}
186
+ {/if}
187
+ </g>
188
+
@@ -0,0 +1,61 @@
1
+ <script>
2
+ /****************************************************
3
+ * ScatterSeries component *
4
+ * -------------------- *
5
+ * shows a series of points on the plot *
6
+ * *
7
+ *****************************************************/
8
+
9
+ import { Colors } from '../Colors';
10
+ import TextLabels from './TextLabels.svelte';
11
+
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(`ScatterSeries: parameter 'marker' must be a number from 1 to ${markers.length}."`);
34
+ }
35
+
36
+ // reactive variables for coordinates of data points in pixels (and line style)
37
+ $: markerSymbol = markers[marker - 1];
38
+ </script>
39
+
40
+ <TextLabels
41
+ {xValues} {yValues} {zValues} {faceColor} {borderColor} {borderWidth} {title}
42
+ className="series_scatter"
43
+ labels={markerSymbol}
44
+ textSize={markerSize}
45
+ />
46
+
47
+ <style>
48
+ :global(.series_scatter > text) {
49
+ font-size: 1em;
50
+ cursor: default;
51
+ }
52
+
53
+ :global(.series_scatter > text:hover) {
54
+ opacity: 90%;
55
+ }
56
+
57
+ :global(.series_scatter > *:hover + .labels_hover) {
58
+ visibility: visible;
59
+ opacity: 1;
60
+ }
61
+ </style>
@@ -0,0 +1,69 @@
1
+ <script>
2
+ /****************************************************
3
+ * Segments for 3D plot *
4
+ * -------------------- *
5
+ * shows a series of line segments on the plot *
6
+ *****************************************************/
7
+
8
+ import { cbind } from 'mdatools/arrays';
9
+ import { getContext } from 'svelte';
10
+ import { Colors } from '../Colors';
11
+ import { checkCoords } from '../Utils';
12
+
13
+
14
+ /*****************************************/
15
+ /* Input parameters */
16
+ /*****************************************/
17
+
18
+ export let title = '';
19
+ export let xStart;
20
+ export let xEnd;
21
+ export let yStart;
22
+ export let yEnd;
23
+ export let zStart;
24
+ export let zEnd;
25
+
26
+ export let lineColor = Colors.PRIMARY;
27
+ export let lineType = 1;
28
+ export let lineWidth = 1;
29
+
30
+ // get axes context and reactive variables needed to compute coordinates
31
+ const axes = getContext('axes');
32
+ const scale = axes.scale;
33
+ const tM = axes.tM;
34
+ const isOk = axes.isOk;
35
+
36
+ let x1, y1, x2, y2 = undefined;
37
+ $: {
38
+ if ($isOk) {
39
+
40
+ [x1, y1] = axes.transform(
41
+ cbind(
42
+ checkCoords(xStart, 'Segments'),
43
+ checkCoords(yStart, 'Segments'),
44
+ checkCoords(zStart, 'Segments')
45
+ ), $tM
46
+ );
47
+
48
+ [x2, y2] = axes.transform(
49
+ cbind(
50
+ checkCoords(xEnd, 'Segments'),
51
+ checkCoords(yEnd, 'Segments'),
52
+ checkCoords(zEnd, 'Segments')
53
+ ), $tM
54
+ );
55
+
56
+ }
57
+ }
58
+
59
+ $: lineStyleStr = `stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType-1]}`;
60
+ </script>
61
+
62
+ <g class="series series_segment" data-title="{title}" style={lineStyleStr}>
63
+ {#if $isOk && x1 !== undefined && y1 !== undefined && x2 !== undefined && y2 !== undefined}
64
+ {#each x1 as v, i}
65
+ <line vector-effect="non-scaling-stroke" x1={x1[i]} x2={x2[i]} y1={y1[i]} y2={y2[i]} />
66
+ {/each}
67
+ {/if}
68
+ </g>
69
+
@@ -0,0 +1,79 @@
1
+ <script>
2
+ /****************************************************
3
+ * TextLabels for 3D plots *
4
+ * ----------------------- *
5
+ * shows a series of text labels on the plot *
6
+ *****************************************************/
7
+
8
+ import { cbind } from 'mdatools/arrays';
9
+ import { getContext } from 'svelte';
10
+ import { Colors } from '../Colors';
11
+ import { checkCoords } from '../Utils';
12
+
13
+
14
+ /*****************************************/
15
+ /* Input parameters */
16
+ /*****************************************/
17
+
18
+ export let title = '';
19
+ export let xValues;
20
+ export let yValues;
21
+ export let zValues;
22
+ export let labels;
23
+
24
+ export let faceColor = Colors.PRIMARY_TEXT;
25
+ export let borderColor = 'transparent';
26
+ export let borderWidth = 0;
27
+ export let textSize = 1;
28
+ export let className = 'series_textlabel';
29
+
30
+
31
+ // get axes context and reactive variables needed to compute coordinates
32
+ const axes = getContext('axes');
33
+ const tM = axes.tM;
34
+ const isOk = axes.isOk;
35
+
36
+ // compute screen coordinates
37
+ let x, y = undefined;
38
+ $: {
39
+ if ($isOk) {
40
+
41
+ [x, y] = axes.transform(
42
+ cbind(
43
+ checkCoords(xValues, 'TextValues'),
44
+ checkCoords(yValues, 'TextValues'),
45
+ checkCoords(zValues, 'TextValues')
46
+ ), $tM
47
+ );
48
+
49
+ if (Array.isArray(labels) && labels.length !== x.length ) {
50
+ throw('TextLabels: number of elements in "labels" does not match number of coordinates.')
51
+ }
52
+ }
53
+ }
54
+
55
+ // styles for the elements
56
+ $: textStyleStr = `dominant-baseline:middle;fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};
57
+ font-size:${textSize}em; text-anchor:middle;`;
58
+ </script>
59
+
60
+ {#if $isOk && x !== undefined && y !== undefined}
61
+ <g class="series {className}" title={title} style={textStyleStr} >
62
+
63
+ {#if typeof labels === 'string'}
64
+ {#each x as v, i}
65
+ <text data-id={i} x={x[i]} y={y[i]} dx={0} dy={0}>{@html labels}</text>
66
+ {/each}
67
+ {:else}
68
+ {#each x as v, i}
69
+ <text data-id={i} x={x[i]} y={y[i]} dx={0} dy={0}>{@html labels[i]}</text>
70
+ {/each}
71
+ {/if}
72
+ </g>
73
+ {/if}
74
+
75
+ <style>
76
+ text, text > :global(tspan) {
77
+ dominant-baseline: middle;
78
+ }
79
+ </style>
@@ -0,0 +1,123 @@
1
+ <script>
2
+ /****************************************************
3
+ * X-Axis for 3D plots *
4
+ * -------------------- *
5
+ * shows x-axis and its elements (ticks, grid, etc.) *
6
+ *****************************************************/
7
+
8
+ import { cbind, matrix, Vector } from 'mdatools/arrays';
9
+ import { getContext } from 'svelte';
10
+ import { Colors } from '../Colors';
11
+ import { getAxisTicks } from '../Utils.js';
12
+ import Axis from './Axis.svelte';
13
+
14
+
15
+ /*****************************************/
16
+ /* Input parameters */
17
+ /*****************************************/
18
+
19
+ export let slot = 'xaxis'; // slot the component must be placed in
20
+ export let ticks = undefined; // vector with numeric tick positions in plot units
21
+ export let tickLabels = ticks; // vector with labels for each tick
22
+ export let showGrid = false; // logical, show or not grid lines
23
+ export let title = ''; // axis title
24
+
25
+ export let lineColor = Colors.DARKGRAY;
26
+ export let gridColor = Colors.MIDDLEGRAY;
27
+ export let textColor = Colors.DARKGRAY;
28
+
29
+
30
+ /*****************************************/
31
+ /* Component code */
32
+ /*****************************************/
33
+
34
+ if (slot !== 'xaxis') {
35
+ throw('Component XAxis must have "slot=\'xaxis\'" attribute.');
36
+ }
37
+
38
+ // get axes context and adjust x margins
39
+ const axes = getContext('axes');
40
+
41
+ // get reactive variables needed to compute coordinates
42
+ const xLim = axes.xLim;
43
+ const yLim = axes.yLim;
44
+ const zLim = axes.zLim;
45
+ const scale = axes.scale;
46
+ const isOk = axes.isOk;
47
+
48
+ // prepare variables for coordinates
49
+ let titleCoords = [];
50
+ let grid1 = [];
51
+ let grid2 = [];
52
+ let axisLine = [];
53
+ let tickCoords = [];
54
+
55
+ // compute tick x-coordinates
56
+ $: if ($isOk) {
57
+ const dX = ($xLim[1] - $xLim[0]) / 100; // 1% of axis size
58
+ const ticksX = getAxisTicks(ticks, $xLim, axes.TICK_NUM[$scale], true);
59
+ const tickNum = ticksX.length;
60
+
61
+ // compute tick y-coordinates (middle, up and bottom)
62
+ const dY = ($yLim[1] - $yLim[0]) / 100; // 1% of axis size
63
+ const ticksY = Vector.fill($yLim[0], tickNum);
64
+ const ticksY1 = ticksY.subtract(dY * 1.5);
65
+ const ticksY2 = ticksY.add(dY * 1.5);
66
+ const ticksY3 = ticksY.subtract(dY * 5);
67
+
68
+ // tick z-coordinates (middle, up and bottom)
69
+ const dZ = ($zLim[1] - $zLim[0]) / 100; // 1% of axis size
70
+ const ticksZ = Vector.fill($zLim[0], tickNum);
71
+ const ticksZ1 = ticksZ.subtract(dZ * 1.5);
72
+ const ticksZ2 = ticksZ.add(dZ * 1.5);
73
+ const ticksZ3 = ticksZ.subtract(dZ * 2);
74
+
75
+ // coordinates for the ends of grid
76
+ const gridYEnd = Vector.fill($yLim[1], tickNum);
77
+ const gridZEnd = Vector.fill($zLim[1], tickNum);
78
+
79
+ // tick labels
80
+ tickLabels = (ticks === undefined || tickLabels === undefined) ? ticksX.v : tickLabels;
81
+ if (tickLabels.length !== ticksX.length) {
82
+ throw Error('XAxis: "tickLabels" must be a array of the same size as ticks.');
83
+ }
84
+
85
+ // combine all coordinates together
86
+ grid1 = [
87
+ cbind(ticksX, ticksY, ticksZ),
88
+ cbind(ticksX, gridYEnd, ticksZ)
89
+ ];
90
+
91
+ grid2 = [
92
+ cbind(ticksX, ticksY, ticksZ),
93
+ cbind(ticksX, ticksY2, gridZEnd)
94
+ ];
95
+
96
+ axisLine = [
97
+ matrix([$xLim[0], $yLim[0], $zLim[0]], 1, 3),
98
+ matrix([$xLim[1], $yLim[0], $zLim[0]], 1, 3)
99
+ ]
100
+
101
+ tickCoords = [
102
+ cbind(ticksX, ticksY, ticksZ), // middle point
103
+ cbind(ticksX, ticksY2, ticksZ), // middle point with positive shift along Y
104
+ cbind(ticksX, ticksY, ticksZ2), // middle point with positive shift along Z
105
+ cbind(ticksX, ticksY1, ticksZ1), // middle point with negative shift along Y and Z
106
+ cbind(ticksX, ticksY3, ticksZ3) // middle point with negative shift along Y and Z for ticks
107
+ ];
108
+
109
+ // here we do not need to make a matrix as the three values will be used as vectors
110
+ titleCoords = [
111
+ [$xLim[1] + 3 * dX], [$yLim[0] - 2 * dY], [$zLim[0] - 2 * dZ]
112
+ ];
113
+ }
114
+ </script>
115
+
116
+ {#if $isOk && axisLine.length > 0}
117
+ <Axis
118
+ className="mdaplot__xaxis"
119
+ {title} {lineColor} {gridColor} {textColor} {titleCoords}
120
+ {showGrid} {grid1} {grid2} {axisLine} {tickCoords} {tickLabels}
121
+ />
122
+ {/if}
123
+
@@ -0,0 +1,123 @@
1
+ <script>
2
+ /****************************************************
3
+ * Y-Axis for 3D plots *
4
+ * -------------------- *
5
+ * shows y-axis and its elements (ticks, grid, etc.) *
6
+ *****************************************************/
7
+
8
+ import { cbind, matrix, Vector } from 'mdatools/arrays';
9
+ import { getContext } from 'svelte';
10
+ import { Colors } from '../Colors';
11
+ import { getAxisTicks } from '../Utils.js';
12
+ import Axis from './Axis.svelte';
13
+
14
+
15
+ /*****************************************/
16
+ /* Input parameters */
17
+ /*****************************************/
18
+
19
+ export let slot = 'yaxis'; // slot the component must be placed in
20
+ export let ticks = undefined; // vector with numeric tick positions in plot units
21
+ export let tickLabels = ticks; // vector with labels for each tick
22
+ export let showGrid = false; // logical, show or not grid lines
23
+ export let title = ''; // axis title
24
+
25
+ export let lineColor = Colors.DARKGRAY;
26
+ export let gridColor = Colors.MIDDLEGRAY;
27
+ export let textColor = Colors.DARKGRAY;
28
+
29
+
30
+ /*****************************************/
31
+ /* Component code */
32
+ /*****************************************/
33
+
34
+ if (slot !== 'yaxis') {
35
+ throw('Component YAxis must have "slot=\'yaxis\'" attribute.');
36
+ }
37
+
38
+ // get axes context and adjust x margins
39
+ const axes = getContext('axes');
40
+
41
+ // get reactive variables needed to compute coordinates
42
+ const xLim = axes.xLim;
43
+ const yLim = axes.yLim;
44
+ const zLim = axes.zLim;
45
+ const scale = axes.scale;
46
+ const isOk = axes.isOk;
47
+
48
+ // prepare variables for coordinates
49
+ let titleCoords = [];
50
+ let grid1 = [];
51
+ let grid2 = [];
52
+ let axisLine = [];
53
+ let tickCoords = [];
54
+
55
+ // compute tick x-coordinates
56
+ $: if ($isOk) {
57
+ const dY = ($yLim[1] - $yLim[0]) / 100; // 1% of axis size
58
+ const ticksY = getAxisTicks(ticks, $yLim, axes.TICK_NUM[$scale], true);
59
+ const tickNum = ticksY.length;
60
+
61
+ // compute tick y-coordinates (middle, up and bottom)
62
+ const dX = ($xLim[1] - $xLim[0]) / 100; // 1% of axis size
63
+ const ticksX = Vector.fill($xLim[0], tickNum);
64
+ const ticksX1 = ticksX.subtract(dX * 1.5);
65
+ const ticksX2 = ticksX.add(dX * 1.5);
66
+ const ticksX3 = ticksX.subtract(dX * 3);
67
+
68
+ // tick z-coordinates (middle, up and bottom)
69
+ const dZ = ($zLim[1] - $zLim[0]) / 100; // 1% of axis size
70
+ const ticksZ = Vector.fill($zLim[0], tickNum);
71
+ const ticksZ1 = ticksZ.subtract(dZ * 1.5);
72
+ const ticksZ2 = ticksZ.add(dZ * 1.5);
73
+ const ticksZ3 = ticksZ.subtract(dZ * 2);
74
+
75
+ // coordinates for the ends of grid
76
+ const gridXEnd = Vector.fill($xLim[1], tickNum);
77
+ const gridZEnd = Vector.fill($zLim[1], tickNum);
78
+
79
+ // tick labels
80
+ tickLabels = (ticks === undefined || tickLabels === undefined) ? ticksY.v : tickLabels;
81
+ if (tickLabels.length !== ticksY.length) {
82
+ throw Error('YAxis: "tickLabels" must be a array of the same size as ticks.');
83
+ }
84
+
85
+ // combine all coordinates together
86
+ grid1 = [
87
+ cbind(ticksX, ticksY, ticksZ),
88
+ cbind(gridXEnd, ticksY, ticksZ)
89
+ ];
90
+
91
+ grid2 = [
92
+ cbind(ticksX, ticksY, ticksZ),
93
+ cbind(ticksX, ticksY, gridZEnd)
94
+ ];
95
+
96
+ axisLine = [
97
+ matrix([$xLim[0], $yLim[0], $zLim[0]], 1, 3),
98
+ matrix([$xLim[0], $yLim[1], $zLim[0]], 1, 3)
99
+ ]
100
+
101
+ tickCoords = [
102
+ cbind(ticksX, ticksY, ticksZ), // middle point
103
+ cbind(ticksX2, ticksY, ticksZ), // middle point with positive shift along X
104
+ cbind(ticksX, ticksY, ticksZ2), // middle point with positive shift along Z
105
+ cbind(ticksX1, ticksY, ticksZ1), // middle point with negative shift along X and Z
106
+ cbind(ticksX3, ticksY, ticksZ3) // middle point with negative shift along X and Z for ticks
107
+ ];
108
+
109
+ // here we do not need to make a matrix as the three values will be used as vectors
110
+ titleCoords = [
111
+ [$xLim[0] - 2 * dX], [$yLim[1] + 3 * dY], [$zLim[0] - 2 * dZ]
112
+ ];
113
+ }
114
+ </script>
115
+
116
+ {#if $isOk && axisLine.length > 0}
117
+ <Axis
118
+ className="mdaplot__yaxis"
119
+ {title} {lineColor} {gridColor} {textColor} {titleCoords}
120
+ {showGrid} {grid1} {grid2} {axisLine} {tickCoords} {tickLabels}
121
+ />
122
+ {/if}
123
+