svelte-plots-basic 2.5.7 → 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,97 +1,127 @@
1
+ <!--
2
+ @component Adds a series with line segments.
3
+
4
+ Main properties:
5
+ - `xValues`- vector or array with x-coordinates for each label.
6
+ - `yValues`- vector or array with y-coordinates for each label.
7
+ - `labels`- single string or array with labels (strings).
8
+ - `pos`- position of labels related to coordinates (`0` - middle - default, `1` - bottom, `2` - left, `3` - top, `4` - right).
9
+ - `faceColor`- face color of label symbols, default: `Colors.PRIMARY_TEXT`.
10
+ - `lineColor`- border colors of label symbols, default: `'transparent'`.
11
+ - `lineWidth`- border width of label symbols in pixels, default: `0`.
12
+ - `textSize`- size of label symbols in em, default: `1`.
13
+ - `className`- CSS class name for the labels group, default: `'series-text'`.
14
+ - `rotateAngle`- angle to rotate labels, default: `0`.
15
+ - `onclick` - function (callback) to be called when user clicks on a label.
16
+
17
+ Example:
18
+
19
+ ```svelte
20
+ <script>
21
+ import { Axes, TextLabels } from 'svelte-plots-basic/2d';
22
+
23
+ const xValues = [1, 2, 3, 4];
24
+ const yValues = [1, 2, 3, 4];
25
+ const labels = ['🤣', '😀', '😀', '🤣'];
26
+ </script>
27
+
28
+ <Axes limX={[0, 5]} limY={[0, 5]} >
29
+ <TextLabels {xValues} {yValues} {labels} />
30
+ </Axes>
31
+ ```
32
+ -->
1
33
  <script>
2
- /****************************************************
3
- * TextLabels component *
4
- * -------------------- *
5
- * shows a series of text labels on the plot *
6
- *****************************************************/
7
-
8
34
  import { getContext } from 'svelte';
9
- import { Colors } from '../Colors';
10
- import { checkCoords } from '../Utils';
11
-
12
-
13
- /*****************************************/
14
- /* Input parameters */
15
- /*****************************************/
16
-
17
- export let xValues; // vector or array with x-coordinates for each label
18
- export let yValues; // vector or array with y-coordinates for each label
19
- export let labels; // array with labels (strings)
20
- export let pos = 0; // position of labels related to coordinates (middle, bottom, left, top, right)
21
- export let faceColor = Colors.PRIMARY_TEXT; // face color of label symbols
22
- export let borderColor = 'transparent'; // border colors of label symbols
23
- export let borderWidth = 0; // border width of label symbols
24
- export let textSize = 1; // size of label symbols
25
- export let className = 'series-text'; // CSS class name for the labels group
26
- export let title = 'series-text'; // title of the labels SVG group
27
- export let rotateAngle = 0; // angle to rotate labels
28
-
29
- /*****************************************/
30
- /* Component code */
31
- /*****************************************/
32
-
33
- // get axes context and reactive variables needed to compute coordinates
34
- const axes = getContext('axes');
35
- const scale = axes.scale;
36
- const tX = axes.tX;
37
- const tY = axes.tY;
38
- const isOk = axes.isOk;
39
-
35
+ import { Colors } from '../constants';
36
+ import { checkCoords, transformCoords, handleClick } from '../methods';
37
+ import { LABELS_MARGIN } from '../constants';
38
+
39
+ let {
40
+ xValues, // vector or array with x-coordinates for each label
41
+ yValues, // vector or array with y-coordinates for each label
42
+ labels, // array with labels (strings)
43
+ pos = 0, // position of labels related to coordinates (middle, bottom, left, top, right)
44
+ faceColor = Colors.PRIMARY_TEXT, // face color of label symbols
45
+ lineColor = 'transparent', // border colors of label symbols
46
+ lineWidth = 0, // border width of label symbols
47
+ textSize = 1, // size of label symbols
48
+ rotateAngle = 0, // angle to rotate labels
49
+ onclick, // function to be called if onclick event fires
50
+ } = $props();
51
+
52
+ // array with text anchors for correct positioning
40
53
  const textAnchors = ['middle', 'middle', 'start', 'middle', 'end'];
41
54
 
42
- let x, y = undefined;
43
- let dx = 0, dy = 0;
55
+ // sanity checks of coordinates provided by user
56
+ const xv = $derived(checkCoords(xValues, 'TextLabels'));
57
+ const yv = $derived(xv ? checkCoords(yValues, 'TextLabels', xv.length) : null);
44
58
 
45
- // reactive calculations triggered by changes in coordinates and plot parameters
46
- $: if ($isOk) {
59
+ // sanity check for labels
60
+ const l = $derived.by(() => {
61
+ if (!yv) return null;
47
62
 
48
- if (typeof labels === 'string' && typeof pos !== 'number' ) {
49
- throw Error('TextLabels: parameter "labels" is provided as single string, so "pos" must be a single number.');
63
+ if (Array.isArray(labels) && labels.length !== yv.length) {
64
+ console.error('TextLabels: number of elements in "labels" does not match number of coordinates');
65
+ return null;
50
66
  }
51
67
 
52
- x = axes.transform(checkCoords(xValues, 'TextLabels'), $tX.coords);
53
- y = axes.transform(checkCoords(yValues, 'TextLabels'), $tY.coords);
68
+ return labels;
69
+ });
54
70
 
55
- // sanity check for input parameters
56
- if (x.length !== y.length) {
57
- throw Error('TextLabels: parameters "xValues" and "yValues" must be vectors of the same length.');
58
- }
71
+ // sanity check for position values
72
+ const p = $derived.by(() => {
73
+ if (!l) return null;
59
74
 
60
- if (Array.isArray(labels) && labels.length !== x.length ) {
61
- throw Error('TextLabels: number of elements in "labels" does not match number of coordinates.');
75
+ if (typeof labels === 'string' && typeof pos !== 'number' ) {
76
+ console.error('TextLabels: parameter "labels" is provided as single string, so "pos" must be a single number.');
77
+ return null;
62
78
  }
63
- }
64
79
 
65
- // reactive calculations triggered by changes in scale
66
- $: {
67
- const m = axes.LABELS_MARGIN[$scale];
68
- dx = [0, 0, m, 0, -m, m];
69
- dy = [0, m, 0, -m, 0, m];
70
- }
80
+ return pos;
81
+ })
82
+
83
+ // get axes context and compute coordinates
84
+ const axes = getContext('axes');
85
+ const x = $derived(xv && p !== null ? transformCoords(xv, axes.tX()) : null);
86
+ const y = $derived(yv && x ? transformCoords(yv, axes.tY()) : null);
87
+
88
+ // define x and y shifts for positioning
89
+ const m = $derived(LABELS_MARGIN[axes.scales().plot]);
90
+ const dx = $derived([0, 0, m, 0, -m, m]);
91
+ const dy = $derived([0, m, 0, -m, 0, m]);
71
92
 
72
93
  // styles for the elements
73
- $: textStyleStr = `fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};font-size:${textSize}em;`;
94
+ const textStyleStr = $derived(`fill:${faceColor};stroke-width:${lineWidth}px;stroke:${lineColor};font-size:${textSize}em;`);
95
+
96
+ // local status
97
+ const isOk = $derived(x && y && p !== null && l && x.length === y.length);
74
98
  </script>
75
99
 
76
- {#if $isOk && x !== undefined && y !== undefined}
77
- <g class="series {className}" title={title} style={textStyleStr} >
100
+ {#if isOk}
101
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
102
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
103
+ <g class="series series-textlabels" style={textStyleStr} onclick={(e) => handleClick(e, 'text', onclick)} >
78
104
 
79
105
  {#if typeof labels === 'string'}
80
- {#each x as v, i}
81
- <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]}
82
- transform={rotateAngle !== undefined ? `rotate(${rotateAngle}, ${x[i] + dx[pos]}, ${y[i] + dy[pos]})` : ''}
83
- text-anchor={textAnchors[pos[i]]}>{@html labels}</text>
84
- {/each}
106
+
107
+ {#each x as v, i}
108
+ <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]}
109
+ transform={rotateAngle !== undefined ? `rotate(${rotateAngle}, ${x[i] + dx[pos]}, ${y[i] + dy[pos]})` : ''}
110
+ text-anchor={textAnchors[pos[i]]}>{@html labels}</text>
111
+ {/each}
85
112
 
86
113
  {:else if (Array.isArray(pos) || ArrayBuffer.isView(pos))}
87
- {#each x as v, i}
88
- <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos[i]]} dy={dy[pos[i]]} text-anchor={textAnchors[pos[i]]}>{@html labels[i]}</text>
89
- {/each}
114
+
115
+ {#each x as v, i}
116
+ <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos[i]]} dy={dy[pos[i]]} text-anchor={textAnchors[pos[i]]}>{@html labels[i]}</text>
117
+ {/each}
90
118
 
91
119
  {:else}
92
- {#each x as v, i}
93
- <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]} text-anchor={textAnchors[pos]}>{@html labels[i]}</text>
94
- {/each}
120
+
121
+ {#each x as v, i}
122
+ <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]} text-anchor={textAnchors[pos]}>{@html labels[i]}</text>
123
+ {/each}
124
+
95
125
  {/if}
96
126
  </g>
97
127
  {/if}
@@ -1,50 +1,28 @@
1
1
  <script>
2
- /****************************************************
3
- * TextLegend *
4
- * -------------------- *
5
- * shows list of several formatted text elements *
6
- *****************************************************/
7
-
8
2
  import { getContext } from 'svelte';
9
- import { Colors } from '../Colors';
10
-
11
-
12
- /*****************************************/
13
- /* Input parameters */
14
- /*****************************************/
15
-
16
- export let left; // vector/array with coordinates of lef side of each text box
17
- export let top; // vector/array with coordinates of top side of each text box
18
- export let dx = "0"; // horizontal margin between left size and text in 'em' units
19
- export let dy = "1.25em"; // vertical margin between elements in 'em' units
20
- export let elements; // array with text elements (svg tags are acceptable)
21
- export let faceColor = Colors.PRIMARY_TEXT; // face color of the text symbols
22
- export let borderColor = "transparent"; // border color of the text symbols
23
- export let borderWidth = 0; // border width of the text symbols
24
- export let textSize = 1; // size of the text symbols
25
-
26
-
27
- /*****************************************/
28
- /* Component code */
29
- /*****************************************/
3
+ import { Colors } from '../constants';
4
+
5
+ let {
6
+ left, // vector/array with coordinates of lef side of each text box
7
+ top, // vector/array with coordinates of top side of each text box
8
+ dx = "0", // horizontal margin between left size and text in 'em' units
9
+ dy = "1.25em", // vertical margin between elements in 'em' units
10
+ elements, // array with text elements (svg tags are acceptable)
11
+ faceColor = Colors.PRIMARY_TEXT, // face color of the text symbols
12
+ lineColor = "transparent", // border color of the text symbols
13
+ lineWidth = 0, // border width of the text symbols
14
+ textSize = 1, // size of the text symbols
15
+ } = $props()
30
16
 
31
17
  const axes = getContext('axes');
32
- const tX = axes.tX;
33
- const tY = axes.tY;
34
- const isOk = axes.isOk;
35
-
36
- // reactive variables for coordinates of data points in pixels
37
- let x, y = undefined;
38
- $: if ($isOk) {
39
- x = axes.transform([left], $tX.coords);
40
- y = axes.transform([top], $tY.coords);
41
- }
18
+ const x = $derived(left ? transformCoords([left], axes.tX()) : null);
19
+ const y = $derived(top ? transformCoords([top], axes.tY()) : null );
42
20
 
43
21
  // styles for bars and labels
44
- $: textStyleStr = `fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};font-size:${textSize}em;`;
22
+ const textStyleStr = $derived(`fill:${faceColor};stroke-width:${lineWidth}px;stroke:${lineColor};font-size:${textSize}em;`);
45
23
  </script>
46
24
 
47
- {#if $isOk && x !== undefined && y !== undefined && elements.length > 0}
25
+ {#if x && y && elements.length > 0}
48
26
  <text style={textStyleStr} x={x} y={y} dx={dx} dy={dy} dominant-baseline="middle" text-anchor="start">
49
27
  {#each elements as el, i}
50
28
  <tspan {x} {dx} dy={i === 0 ? 0 : dy}>{@html el}</tspan>
@@ -1,110 +1,61 @@
1
+ <!--
2
+ @component Adds x-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
+ - `las` - orientation of tick labels (`1` - horizontal - default, `2` - vertical).
10
+ - `whole` - logical, show numeric tick labels as whole numbers (without decimals) or not, default: `false`.
11
+
12
+ Example:
13
+ ```svelte
14
+ <script>
15
+ import {Axes, XAxis} from 'svelte-plots-basic/2d';
16
+ </script>
17
+ <Axes>
18
+ <XAxis label="x-axis label" showGrid={true} />
19
+ </Axes>
20
+ ```
21
+ -->
1
22
  <script>
2
- /****************************************************
3
- * X-Axis *
4
- * -------------------- *
5
- * shows x-axis and its elements (ticks, grid, etc.) *
6
- *****************************************************/
7
23
 
8
24
  import { getContext } from 'svelte';
9
- import { Vector, vector } from 'mdatools/arrays';
10
- import { Colors } from '../Colors.js';
11
- import { getAxisTicks, getTickLabels } 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 (must be "xaxis")
20
- export let ticks = undefined; // vector with numeric tick positions (by default is computed automatically)
21
- export let tickLabels = undefined; // vector with labels for each tick (by default tick values will be used)
22
- export let showGrid = false; // logical, show or not grid lines
23
- export let las = 1; // orientation of tick labels (1 - horizontal, 2 - vertical)
24
- export let whole = false; // should the ticks be a whole number or not
25
-
26
- export let lineColor = Colors.DARKGRAY; // color of axis and tick lines
27
- export let gridColor = Colors.MIDDLEGRAY; // color og grid lines
28
- export let textColor = Colors.DARKGRAY; // color of text tick labels
29
-
30
-
31
- /*****************************************/
32
- /* Component code */
33
- /*****************************************/
34
-
35
- // sanity checks of input parameters
36
- if (slot !== 'xaxis') {
37
- throw('Component XAxis must have "slot=\'xaxis\'" attribute.');
38
- }
39
-
40
- // get axes context and adjust x margins
25
+ import { text2svg, validateTicks, validateTickLabels } from '../methods';
26
+
27
+ let {
28
+ label, // text label
29
+ showGrid = false, // logical, show or not grid lines
30
+ ticks, // vector with numeric tick positions (by default is computed automatically)
31
+ tickLabels, // vector with labels for each tick (by default tick position values will be used)
32
+ las = 1, // orientation of tick labels (1 - horizontal, 2 - vertical)
33
+ whole = false // should the tick positions be a whole number or not.
34
+ } = $props();
35
+
36
+ // get axes context and send axis parameters to parent
41
37
  const axes = getContext('axes');
42
38
 
43
- // get reactive variables needed to compute coordinates
44
- const xLim = axes.xLim;
45
- const yLim = axes.yLim;
46
- const scale = axes.scale;
47
- const isOk = axes.isOk;
48
- const tY = axes.tY;
39
+ // reactive effects to validate and activate user input
40
+ $effect(() => {
49
41
 
50
- // prepare variables for coordinates
51
- let grid = [];
52
- let axisLine = [];
53
- let tickCoords = [];
54
- let tfCoords = [];
55
- let tickFactor = 0;
42
+ // process label text in case if there are sub or superscripts and adjust height of label correspondingly
43
+ const axisLabel = text2svg(label);
44
+ const labelHeight = axisLabel ? (axisLabel.length === label.length ? 1 : 1.4) : 0;
56
45
 
57
- // compute coordinates for ticks, grid and axis line
58
- $: if ($isOk) {
59
-
60
- // compute x-coordinates of the ticks or take the ones manually specified by user
61
- const ticksX = getAxisTicks(ticks, $xLim, axes.TICK_NUM[$scale], true, whole);
62
- const tickNum = ticksX.length;
63
-
64
- // compute tick y-coordinates (up and bottom)
65
- const dY = axes.invTransform([axes.TICK_SIZE[$scale]], $tY.objects)[0];
66
- const ticksY1 = Vector.fill($yLim[0], tickNum);
67
- const ticksY2 = ticksY1.add(dY);
68
-
69
- // compute coordinates for the ends of grid
70
- const gridYEnd = Vector.fill($yLim[1], tickNum);
71
-
72
- // tick labels and tick factor
73
- if (ticks === undefined || tickLabels === undefined) {
74
- [tickFactor, tickLabels] = getTickLabels(ticksX.v);
46
+ // if ticks are provided check if they are valid and preprocess them
47
+ let ticksProcessed, error = '';
48
+ if (ticks) {
49
+ [ticksProcessed, error] = validateTicks(ticks, axes.limX())
75
50
  }
76
51
 
77
- if (tickLabels.length !== ticksX.length) {
78
- throw('XAxis: "tickLabels" must be a array of the same size as ticks.')
52
+ // if tick labels are provided check if they are valid and preprocess them
53
+ if (!error && tickLabels) {
54
+ [tickLabels, error] = validateTickLabels(tickLabels, ticksProcessed);
79
55
  }
80
56
 
81
- // combine all coordinates together
82
- grid = [
83
- [ticksX, ticksY1],
84
- [ticksX, gridYEnd]
85
- ];
86
-
87
- axisLine = [
88
- [vector([$xLim[0]]), vector([$yLim[0]])],
89
- [vector([$xLim[1]]), vector([$yLim[0]])]
90
- ]
91
-
92
- tickCoords = [
93
- [ticksX, ticksY2],
94
- [ticksX, ticksY1]
95
- ];
96
-
97
- tfCoords = [
98
- [null, null],
99
- [[$xLim[1]], [ticksY1.v[tickNum - 1] - 1.5 * dY]],
100
- ];
101
- }
57
+ // activate axis
58
+ axes.setXAxis({show: true, error: error, label: axisLabel, ticks: ticksProcessed,
59
+ labelHeight, showGrid, las, whole, tickLabels});
60
+ });
102
61
  </script>
103
-
104
- {#if $isOk && axisLine.length > 0}
105
- <Axis
106
- className="mdaplot__xaxis" pos={1}
107
- {lineColor} {gridColor} {textColor} {showGrid} {grid} {axisLine}
108
- {tickCoords} {tickLabels} {tfCoords} {tickFactor} {las}
109
- />
110
- {/if}
@@ -1,110 +1,64 @@
1
+ <!--
2
+ @component Adds y-axis with ticks, label, etc.
3
+
4
+ Main properties:
5
+ - `label` - text label for the axis (optional).
6
+ - `showGrid` - logical, show or not horizontal 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
+ - `las` - orientation of tick labels (`1` - horizontal - default, `2` - vertical).
10
+ - `whole` - logical, show numeric tick labels as whole numbers (without decimals) or not, default: `false`.
11
+
12
+ Example:
13
+ ```svelte
14
+ <script>
15
+ import {Axes, YAxis} from 'svelte-plots-basic/2d';
16
+ </script>
17
+ <Axes>
18
+ <YAxis label="y-axis label" showGrid={true} />
19
+ </Axes>
20
+ ```
21
+ -->
1
22
  <script>
2
- /****************************************************
3
- * Y-Axis *
4
- * -------------------- *
5
- * shows y-axis and its elements (ticks, grid, etc.) *
6
- *****************************************************/
7
23
 
8
24
  import { getContext } from 'svelte';
9
- import { Vector, vector } from 'mdatools/arrays';
10
- import { Colors } from '../Colors.js';
11
- import { getAxisTicks, getTickLabels } from '../Utils.js';
12
- import Axis from './Axis.svelte';
25
+ import { text2svg, validateTicks, validateTickLabels } from '../methods';
13
26
 
14
27
 
15
- /*****************************************/
16
- /* Input parameters */
17
- /*****************************************/
28
+ let {
29
+ label, // text label
30
+ ticks, // vector with numeric tick positions (by default is computed automatically)
31
+ tickLabels, // vector with labels for each tick (by default tick values will be used)
32
+ showGrid = false, // logical, show or not grid lines
33
+ las = 1, // orientation of tick labels (1 - horizontal, 2 - vertical)
34
+ whole = false // should the ticks be a whole number or not
35
+ } = $props();
18
36
 
19
- export let slot = 'yaxis'; // slot the component must be placed in (must be "yaxis")
20
- export let ticks = undefined; // vector with numeric tick positions (by default is computed automatically)
21
- export let tickLabels = undefined; // vector with labels for each tick (by default tick values will be used)
22
- export let showGrid = false; // logical, show or not grid lines
23
- export let las = 1; // orientation of tick labels (1 - horizontal, 2 - vertical)
24
- export let whole = false; // should the ticks be a whole number or not
25
37
 
26
- export let lineColor = Colors.DARKGRAY; // color of axis and tick lines
27
- export let gridColor = Colors.MIDDLEGRAY; // color og grid lines
28
- export let textColor = Colors.DARKGRAY; // color of text tick labels
29
-
30
-
31
- /*****************************************/
32
- /* Component code */
33
- /*****************************************/
34
-
35
- // sanity checks of input parameters
36
- if (slot !== 'yaxis') {
37
- throw('Component YAxis must have "slot=\'yaxis\'" attribute.');
38
- }
39
-
40
- // get axes context and adjust x margins
38
+ // get axes context and send axis parameters to parent
41
39
  const axes = getContext('axes');
42
40
 
43
- // get reactive variables needed to compute coordinates
44
- const xLim = axes.xLim;
45
- const yLim = axes.yLim;
46
- const scale = axes.scale;
47
- const isOk = axes.isOk;
48
- const tX = axes.tX;
49
-
50
- // prepare variables for coordinates
51
- let grid = [];
52
- let axisLine = [];
53
- let tickCoords = [];
54
- let tfCoords = [];
55
- let tickFactor = 0;
56
-
57
- // compute tick x-coordinates
58
- $: if ($isOk) {
41
+ // reactive effects to validate and activate user input
42
+ $effect(() => {
59
43
 
60
- // compute x-coordinates of the ticks or take the ones manually specified by user
61
- const ticksY = getAxisTicks(ticks, $yLim, axes.TICK_NUM[$scale], true, whole);
62
- const tickNum = ticksY.length;
44
+ // process label text in case if there are sub or superscripts and adjust height of label correspondingly
45
+ const axisLabel = text2svg(label);
46
+ const labelHeight = axisLabel ? (axisLabel.length === label.length ? 1.0 : 1.4) : 0;
63
47
 
64
- // compute tick y-coordinates (up and bottom)
65
- const dX = axes.invTransform([axes.TICK_SIZE[$scale]], $tX.objects)[0];
66
- const ticksX1 = Vector.fill($xLim[0], tickNum)
67
- const ticksX2 = ticksX1.add(dX)
68
48
 
69
- // coordinates for the ends of grid
70
- const gridXEnd = Vector.fill($xLim[1], tickNum);
71
-
72
- // tick labels and tick factor
73
- if (ticks === undefined || tickLabels === undefined) {
74
- [tickFactor, tickLabels] = getTickLabels(ticksY.v)
49
+ // if ticks are provided check if they are valid and preprocess them
50
+ let ticksProcessed, error = '';
51
+ if (ticks) {
52
+ [ticksProcessed, error] = validateTicks(ticks, axes.limY())
75
53
  }
76
54
 
77
- if (tickLabels.length !== ticksY.length) {
78
- throw('YAxis: "tickLabels" must be a array of the same size as ticks.')
55
+ // if tick labels are provided check if they are valid and preprocess them
56
+ if (!error && tickLabels) {
57
+ [tickLabels, error] = validateTickLabels(tickLabels, ticksProcessed);
79
58
  }
80
59
 
81
- // combine all coordinates together
82
- grid = [
83
- [ticksX1, ticksY],
84
- [gridXEnd, ticksY]
85
- ];
86
-
87
- axisLine = [
88
- [vector([$xLim[0]]), vector([$yLim[0]])],
89
- [vector([$xLim[0]]), vector([$yLim[1]])]
90
- ]
91
-
92
- tickCoords = [
93
- [ticksX1, ticksY],
94
- [ticksX2, ticksY]
95
- ];
96
-
97
- tfCoords = [
98
- [[], []],
99
- [[ticksX2.v[tickNum - 1] + dX], [$yLim[1]]],
100
- ];
101
- }
60
+ // activate axis
61
+ axes.setYAxis({show: true, error: error, label: axisLabel, ticks: ticksProcessed,
62
+ labelHeight, showGrid, las, whole, tickLabels, pos: 4});
63
+ });
102
64
  </script>
103
-
104
- {#if $isOk && axisLine.length > 0}
105
- <Axis
106
- className="mdaplot__yaxis" pos={4}
107
- {lineColor} {gridColor} {textColor} {showGrid} {grid} {axisLine}
108
- {tickCoords} {tickLabels} {tfCoords} {tickFactor} {las}
109
- />
110
- {/if}
package/src/2d/index.js CHANGED
@@ -18,4 +18,5 @@ export { default as Legend } from './Legend.svelte';
18
18
  export { default as TextLegend } from './TextLegend.svelte';
19
19
  export { default as ColormapLegend } from './ColormapLegend.svelte';
20
20
 
21
- export { getcolmap, Colors } from '../Colors.js';
21
+ export { getcolmap } from '../methods.js';
22
+ export { Colors } from '../constants.js';