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,123 +1,46 @@
1
+ <!--
2
+ @component Adds z-axis with ticks, label, etc.
3
+
4
+ Main properties:
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`).
8
+ - `tickLabels` - array with tick labels to show at each tick (by default will be generated automatically).
9
+ - `lineColor` - color of axis line, default: `Colors.DARKGRAY`.
10
+ - `gridColor` - color of axis grid line, default: `Colors.MIDDLEGRAY`.
11
+ - `textColor` - color of axis text labels, default: `Colors.DARKGRAY`.
12
+
13
+ Example:
14
+ ```jsx
15
+ <script>
16
+ import {Axes, ZAxis} from 'svelte-plots-basic/3d';
17
+ </script>
18
+ <Axes>
19
+ // all other plotting components are here
20
+ <ZAxis label="Z" showGrid={true} />
21
+ </Axes>
22
+ ```
23
+ -->
1
24
  <script>
2
- /****************************************************
3
- * Z-Axis for 3D plots *
4
- * -------------------- *
5
- * shows z-axis and its elements (ticks, grid, etc.) *
6
- *****************************************************/
7
-
8
- import { cbind, matrix, Vector } from 'mdatools/arrays';
9
25
  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 = 'zaxis'; // 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;
26
+ import { Colors } from '../constants';
28
27
 
28
+ let {
29
+ ticks, // vector with numeric tick positions in plot units
30
+ tickLabels = ticks, // vector with labels for each tick
31
+ showGrid = false, // logical, show or not grid lines
32
+ label = '', // axis title
33
+ lineColor = Colors.DARKGRAY,
34
+ gridColor = Colors.MIDDLEGRAY,
35
+ textColor = Colors.DARKGRAY,
36
+ } = $props();
29
37
 
30
- /*****************************************/
31
- /* Component code */
32
- /*****************************************/
33
38
 
34
- if (slot !== 'zaxis') {
35
- throw('Component ZAxis must have "slot=\'zaxis\'" attribute.');
36
- }
37
-
38
- // get axes context
39
+ // get axes context and adjust x margins
39
40
  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 dZ = ($zLim[1] - $zLim[0]) / 100; // 1% of axis size
58
- const ticksZ = getAxisTicks(ticks, $zLim, axes.TICK_NUM[$scale], true);
59
- const tickNum = ticksZ.length;
60
-
61
- // compute tick x-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 * 1);
67
-
68
- // tick y-coordinates
69
- const dY = ($yLim[1] - $yLim[0]) / 100; // 1% of axis size
70
- const ticksY = Vector.fill($yLim[0], tickNum);
71
- const ticksY1 = ticksY.subtract(dY * 1.5);
72
- const ticksY2 = ticksY.add(dY * 1.5);
73
- const ticksY3 = ticksY.subtract(dY * 5);
74
-
75
- // coordinates for the ends of grid
76
- const gridXEnd = Vector.fill($xLim[1], tickNum);
77
- const gridYEnd = Vector.fill($yLim[1], tickNum);
78
-
79
- // tick labels
80
- tickLabels = (ticks === undefined || tickLabels === undefined) ? ticksZ.v : tickLabels;
81
- if (tickLabels.length !== ticksZ.length) {
82
- throw Error('ZAxis: "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, gridYEnd, ticksZ)
94
- ];
95
-
96
- axisLine = [
97
- matrix([$xLim[0], $yLim[0], $zLim[0]], 1, 3),
98
- matrix([$xLim[0], $yLim[0], $zLim[1]], 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, ticksY2, ticksZ), // middle point with positive shift along Y
105
- cbind(ticksX1, ticksY1, ticksZ), // middle point with negative shift along X and Y
106
- cbind(ticksX3, ticksY3, ticksZ) // middle point with negative shift along X and Y 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[0] - 2 * dY], [$zLim[1] + 3 * dZ]
112
- ];
113
- }
41
+ $effect(() => {
42
+ axes.setZAxis({show: true, ticks, tickLabels, showGrid, label, lineColor, gridColor, textColor});
43
+ });
114
44
  </script>
115
45
 
116
- {#if $isOk && axisLine.length > 0}
117
- <Axis
118
- className="mdaplot__zaxis"
119
- {title} {lineColor} {gridColor} {textColor} {titleCoords}
120
- {showGrid} {grid1} {grid2} {axisLine} {tickCoords} {tickLabels}
121
- />
122
- {/if}
123
46
 
package/src/3d/index.js CHANGED
@@ -10,4 +10,5 @@ export { default as Lines } from './Lines.svelte';
10
10
  export { default as Mesh } from './Mesh.svelte';
11
11
  export { default as Points } from './Points.svelte';
12
12
 
13
- export { getcolmap, Colors } from '../Colors.js';
13
+ export { getcolmap } from '../methods.js';
14
+ export { Colors } from '../constants.js';
@@ -0,0 +1,103 @@
1
+ // how big are margins (number of pixels in unit margin value) between axis and plot area if axis are shown
2
+ export const AXES_MARGIN_FACTORS = {
3
+ 'small': 30,
4
+ 'medium': 40,
5
+ 'large': 50,
6
+ 'xlarge': 60
7
+ }
8
+
9
+ // number of x-ticks along each axis
10
+ export const XTICK_NUM = {
11
+ 'small': 5,
12
+ 'medium': 8,
13
+ 'large': 12,
14
+ 'xlarge': 15
15
+ };
16
+
17
+ // number of y-ticks along each axis
18
+ export const YTICK_NUM = {
19
+ 'small': 6,
20
+ 'medium': 10,
21
+ 'large': 14,
22
+ 'xlarge': 18
23
+ };
24
+
25
+ // size of ticks
26
+ export const TICK_SIZE = {
27
+ 'small': 4,
28
+ 'medium': 6,
29
+ 'large': 8,
30
+ 'xlarge': 10
31
+ };
32
+
33
+ // font size for plot element
34
+ export const LEGEND_FONT_SIZE = {
35
+ "small": 11,
36
+ "medium": 14,
37
+ "large": 16,
38
+ "xlarge": 18
39
+ };
40
+
41
+ // font size for legend items in pixels
42
+ export const PLOT_FONT_SIZE = {
43
+ "small": 12,
44
+ "medium": 15,
45
+ "large": 19,
46
+ "xlarge": 21
47
+ };
48
+
49
+ // margin between plot series elements and data labels
50
+ export const LABELS_MARGIN = {
51
+ 'small': 11,
52
+ 'medium': 15,
53
+ 'large': 17,
54
+ 'xlarge': 19
55
+ };
56
+
57
+ // line styles for different scales and types
58
+ export const LINE_STYLES = {
59
+ small: ['0', '3,3', '1,1', '3,1,1,1'],
60
+ medium: ['0', '5,5', '2,2', '5,2,2,2'],
61
+ large: ['0', '7,7', '3,3', '7,3,2,3'],
62
+ xlarge: ['0', '9,9', '4,4', '9,3,3,3'],
63
+ }
64
+
65
+ // marker symbols
66
+ export const MARKER_SYMBOLS = ["●", "◼", "▲", "▼", "⬥", "+", "✳", "✕"];
67
+
68
+ // colormap legend parameters
69
+ export const COLMAP_WIDTH_RATIO = 0.80; // legend will span 80% of plot width
70
+ export const COLMAP_TOP_MARGIN = 0.50; // legend top margin is 25% of its height
71
+
72
+ // height of the legend elements in pixels
73
+ export const COLMAP_EL_HEIGHTS_PX = {'small': 5, 'medium': 8, 'large': 12, 'xlarge': 15};
74
+
75
+ // number of bins to split matrix values into in heatmap
76
+ export const HEATMAP_NUM_SPLITS = 12;
77
+
78
+ export const Colors = {
79
+ "WHITE": "#fff",
80
+ "BLACK": "#000",
81
+ "GRAY": "#909090",
82
+ "MIDDLEGRAY": "#dadada",
83
+ "LIGHTGRAY": "#f0f0f0",
84
+ "DARKGRAY": "#606060",
85
+ "LEGEND": "#303030",
86
+
87
+ "PRIMARY": "#2679B2",
88
+ "PRIMARY_LIGHT": "#d2ebff",
89
+ "PRIMARY_TEXT": "#333",
90
+
91
+ "AXIS_LINE": "#303030",
92
+ "AXIS_TICK": "#606060",
93
+ "CLEGEND_LABELS": "#606060"
94
+ }
95
+
96
+
97
+ // number of ticks along each axis for 3D plots
98
+ export const TICK_NUM = {
99
+ "small": 5,
100
+ "medium": 8,
101
+ "large": 12,
102
+ "xlarge": 15
103
+ };