svelte-plots-basic 1.1.4 → 2.1.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.
Files changed (51) hide show
  1. package/README.md +59 -67
  2. package/package.json +10 -4
  3. package/src/2d/Area.svelte +61 -0
  4. package/src/2d/Axes.svelte +500 -0
  5. package/src/2d/Axis.svelte +67 -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/ColormapLegend.svelte +100 -0
  12. package/src/2d/Heatmap.svelte +109 -0
  13. package/src/2d/Legend.svelte +148 -0
  14. package/src/2d/Lines.svelte +49 -0
  15. package/src/2d/Multilines.svelte +67 -0
  16. package/src/2d/Points.svelte +79 -0
  17. package/src/2d/Rectangles.svelte +74 -0
  18. package/src/2d/Segments.svelte +65 -0
  19. package/src/2d/TextLabels.svelte +107 -0
  20. package/src/2d/TextLegend.svelte +53 -0
  21. package/src/2d/XAxis.svelte +109 -0
  22. package/src/2d/YAxis.svelte +109 -0
  23. package/src/2d/index.js +21 -0
  24. package/src/3d/Axes.svelte +445 -0
  25. package/src/3d/Axis.svelte +64 -0
  26. package/src/3d/AxisLines.svelte +50 -0
  27. package/src/3d/AxisTickLabels.svelte +54 -0
  28. package/src/3d/Lines.svelte +49 -0
  29. package/src/3d/Mesh.svelte +185 -0
  30. package/src/3d/Points.svelte +61 -0
  31. package/src/3d/Segments.svelte +69 -0
  32. package/src/3d/TextLabels.svelte +79 -0
  33. package/src/3d/XAxis.svelte +123 -0
  34. package/src/3d/YAxis.svelte +123 -0
  35. package/src/3d/ZAxis.svelte +123 -0
  36. package/src/3d/index.js +13 -0
  37. package/src/Colors.js +36 -1
  38. package/src/Utils.js +243 -0
  39. package/src/AreaSeries.svelte +0 -53
  40. package/src/Axes.svelte +0 -550
  41. package/src/BarSeries.svelte +0 -68
  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 -69
  46. package/src/Segments.svelte +0 -52
  47. package/src/TextLabels.svelte +0 -88
  48. package/src/TextLegend.svelte +0 -38
  49. package/src/XAxis.svelte +0 -69
  50. package/src/YAxis.svelte +0 -72
  51. package/src/index.js +0 -16
@@ -0,0 +1,79 @@
1
+ <script>
2
+ /****************************************************
3
+ * Points *
4
+ * -------------------- *
5
+ * shows series of points/markers on a plot *
6
+ *****************************************************/
7
+
8
+ 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; // array of vector with x-coordinates of points
18
+ export let yValues; // array of vector with y-coordinates of points
19
+ export let marker = 1 // index for point symbol (from 1 to 8): "●", "◼", "▲", "▼", "⬥", "+", "*", "✕"
20
+ export let faceColor = 'transparent'; // face (fill) color of the points
21
+ export let borderColor = Colors.PRIMARY; // border color of the points
22
+ export let borderWidth = 1; // width (thickness) of the points
23
+ export let markerSize = 1; // size of the marker symbols
24
+ export let title = ''; // title of the point series - required for handling mouse click events
25
+
26
+
27
+ /*****************************************/
28
+ /* Component code */
29
+ /*****************************************/
30
+
31
+ // get axes context and adjust x margins
32
+ const axes = getContext('axes');
33
+ const tX = axes.tX;
34
+ const tY = axes.tY;
35
+ const isOk = axes.isOk;
36
+
37
+ let x, y, markerSymbol;
38
+
39
+ // reactive calculations triggered by changes in coordinates and plot parameters
40
+ $: if ($isOk) {
41
+
42
+ if (typeof(marker) !== "number" || marker < 1 || marker > axes.MARKER_SYMBOLS.length) {
43
+ throw Error(`Points: parameter "marker" must be a number from 1 to ${axes.MARKER_SYMBOLS.length}.`);
44
+ }
45
+
46
+ markerSymbol = axes.MARKER_SYMBOLS[marker - 1];
47
+
48
+
49
+ x = axes.transform(checkCoords(xValues, 'Points'), $tX.coords);
50
+ y = axes.transform(checkCoords(yValues, 'Points'), $tY.coords);
51
+
52
+ // sanity check for input parameters
53
+ if (x.length !== y.length) {
54
+ throw Error('Points: parameters "xValues" and "yValues" must be vectors of the same length.')
55
+ }
56
+ }
57
+
58
+
59
+ // styles for the elements
60
+ $: textStyleStr = `dominant-baseline:middle;fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};
61
+ font-size:${markerSize}em; text-anchor:middle;cursor:default;user-select:none;`;
62
+ </script>
63
+
64
+ {#if $isOk && x !== undefined && y !== undefined}
65
+ <g class="series series_points" title={title} style={textStyleStr} >
66
+ {#each x as v, i}
67
+ <text x={x[i]} y={y[i]}>{markerSymbol}</text>
68
+ {/each}
69
+ </g>
70
+ {/if}
71
+
72
+ <style>
73
+ text, text > :global(tspan) {
74
+ dominant-baseline: middle;
75
+ text-anchor: middle;
76
+ cursor: default;
77
+ user-select: none;
78
+ }
79
+ </style>
@@ -0,0 +1,74 @@
1
+ <script>
2
+ /****************************************************
3
+ * Rectangles *
4
+ * -------------------- *
5
+ * shows series of rectangles *
6
+ *****************************************************/
7
+
8
+ import { getContext } from 'svelte';
9
+ import { Vector } from 'mdatools/arrays';
10
+ import { Colors } from '../Colors';
11
+ import { checkCoords } from '../Utils';
12
+
13
+
14
+ /*****************************************/
15
+ /* Input parameters */
16
+ /*****************************************/
17
+
18
+ export let left; // array of vector with coordinates of left sides of the bars
19
+ export let top; // array of vector with coordinates of top sides of the bars
20
+ export let width; // single value (same for all) or vector/array with bar width
21
+ export let height; // single value (same for all) or vector/array with bar height
22
+ export let faceColor = Colors.PRIMARY; // color of bar faces (fill)
23
+ export let borderColor = faceColor; // color of bar borders
24
+ export let lineWidth = 1; // width (thickness) of bar border lines
25
+ export let className = 'series_rect'; // CSS class name of the SVG group
26
+ export let title = ''; // title of the rectangle series (reserved for future use)
27
+
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 tX = axes.tX;
36
+ const tY = axes.tY;
37
+ const isOk = axes.isOk;
38
+
39
+ let rx, ry, rw, rh = undefined;
40
+ $: {
41
+ if ($isOk) {
42
+ rx = axes.transform(checkCoords(left, 'Rectangles'), $tX.coords);
43
+ ry = axes.transform(checkCoords(top, 'Rectangles'), $tY.coords);
44
+
45
+ if (rx.length !== ry.length) {
46
+ throw Error('Rectangles: parameters "left" and "top" must be vectors of the same length.');
47
+ }
48
+
49
+ if (typeof width !== 'object') {
50
+ width = Vector.fill(width, left.length);
51
+ }
52
+
53
+ if (typeof height !== 'object') {
54
+ height = Vector.fill(height, left.length);
55
+ }
56
+
57
+ rw = axes.transform(width, $tX.objects);
58
+ rh = axes.transform(height, $tY.objects);
59
+ }
60
+ }
61
+
62
+ // styles for bars and labels
63
+ $: barsStyleStr = `fill:${faceColor};stroke:${borderColor};stroke-width:${lineWidth}px;`;
64
+ </script>
65
+
66
+ {#if $isOk}
67
+ <g class="series {className}" title={title} style={barsStyleStr}>
68
+ {#each left as v, i}
69
+ <rect x={rx[i]} y={ry[i]} width={rw[i]} height={rh[i]} />
70
+ {/each}
71
+ </g>
72
+ {/if}
73
+
74
+
@@ -0,0 +1,65 @@
1
+ <script>
2
+ /****************************************************
3
+ * Segments *
4
+ * -------------------- *
5
+ * shows series of line segments *
6
+ *****************************************************/
7
+
8
+ import { getContext } from 'svelte';
9
+ import { Colors } from '../Colors';
10
+ import { checkCoords } from '../Utils';
11
+
12
+ /*****************************************/
13
+ /* Input parameters */
14
+ /*****************************************/
15
+
16
+ export let xStart; // vector or array with x-coordinates of starting points
17
+ export let xEnd; // vector or array with x-coordinates of end points
18
+ export let yStart; // vector or array with y-coordinates of starting points
19
+ export let yEnd; // vector or array with y-coordinates of end points
20
+ export let lineColor = Colors.PRIMARY; // color of segment lines
21
+ export let lineType = 1; // type of segment lines (1 - solid, 2 - dashed, 3 - dotted, 4 - dashdot)
22
+ export let lineWidth = 1; // width (thickness) of segment lines
23
+ export let className = 'series_seg'; // CSS class name of the SVG group
24
+ export let title = ''; // title of the segment series (reserved for future use)
25
+
26
+
27
+ /*****************************************/
28
+ /* Component code */
29
+ /*****************************************/
30
+
31
+ // get axes context and reactive variables needed to compute coordinates
32
+ const axes = getContext('axes');
33
+ const scale = axes.scale;
34
+ const isOk = axes.isOk;
35
+ const tX = axes.tX;
36
+ const tY = axes.tY;
37
+
38
+ let x1, x2, y1, y2 = undefined;
39
+ $: {
40
+ if ($isOk) {
41
+
42
+ x1 = axes.transform(checkCoords(xStart, 'Segments'), $tX.coords);
43
+ y1 = axes.transform(checkCoords(yStart, 'Segments'), $tY.coords);
44
+ x2 = axes.transform(checkCoords(xEnd, 'Segments'), $tX.coords);
45
+ y2 = axes.transform(checkCoords(yEnd, 'Segments'), $tY.coords);
46
+
47
+ const n = x1.length;
48
+ if (x2.length !== n || y1.length !== n || y2.length !== n) {
49
+ throw Error('Segments: parameters "xStart", "yStart", "xEnd" and "yEnd" should have the same length.');
50
+ }
51
+ }
52
+ }
53
+
54
+ // reactive variables for coordinates of data points in pixels (and line style)
55
+ $: lineStyleStr = `stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType-1]}`;
56
+ </script>
57
+
58
+ {#if $isOk}
59
+ <g class="series {className}" title={title} style={lineStyleStr}>
60
+ {#each x1 as v, i}
61
+ <line x1={x1[i]} x2={x2[i]} y1={y1[i]} y2={y2[i]} />
62
+ {/each}
63
+ </g>
64
+ {/if}
65
+
@@ -0,0 +1,107 @@
1
+ <script>
2
+ /****************************************************
3
+ * TextLabels component *
4
+ * -------------------- *
5
+ * shows a series of text labels on the plot *
6
+ *****************************************************/
7
+
8
+ 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
+
40
+ const textAnchors = ['middle', 'middle', 'start', 'middle', 'end'];
41
+
42
+ let x, y = undefined;
43
+ let dx = 0, dy = 0;
44
+
45
+ // reactive calculations triggered by changes in coordinates and plot parameters
46
+ $: if ($isOk) {
47
+
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.');
50
+ }
51
+
52
+ x = axes.transform(checkCoords(xValues, 'TextLabels'), $tX.coords);
53
+ y = axes.transform(checkCoords(yValues, 'TextLabels'), $tY.coords);
54
+
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
+ }
59
+
60
+ if (Array.isArray(labels) && labels.length !== x.length ) {
61
+ throw Error('TextLabels: number of elements in "labels" does not match number of coordinates.');
62
+ }
63
+ }
64
+
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
+ }
71
+
72
+ // styles for the elements
73
+ $: textStyleStr = `dominant-baseline:middle;fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};
74
+ font-size:${textSize}em;`;
75
+ </script>
76
+
77
+ {#if $isOk && x !== undefined && y !== undefined}
78
+ <g class="series {className}" title={title} style={textStyleStr} >
79
+
80
+ {#if typeof labels === 'string'}
81
+ {#each x as v, i}
82
+ <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]}
83
+ transform={rotateAngle !== undefined ? `rotate(${rotateAngle}, ${x[i] + dx[pos]}, ${y[i] + dy[pos]})` : ''}
84
+ text-anchor={textAnchors[pos[i]]}>{@html labels}</text>
85
+ {/each}
86
+
87
+ {:else if (Array.isArray(pos) || ArrayBuffer.isView(pos))}
88
+ {#each x as v, i}
89
+ <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>
90
+ {/each}
91
+
92
+ {:else}
93
+ {#each x as v, i}
94
+ <text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]} text-anchor={textAnchors[pos]}>{@html labels[i]}</text>
95
+ {/each}
96
+ {/if}
97
+ </g>
98
+ {/if}
99
+
100
+ <style>
101
+ text, text > :global(tspan) {
102
+ dominant-baseline: middle;
103
+ text-anchor: middle;
104
+ cursor: default;
105
+ user-select: none;
106
+ }
107
+ </style>
@@ -0,0 +1,53 @@
1
+ <script>
2
+ /****************************************************
3
+ * TextLegend *
4
+ * -------------------- *
5
+ * shows list of several formatted text elements *
6
+ *****************************************************/
7
+
8
+ 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
+ /*****************************************/
30
+
31
+ 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
+ }
42
+
43
+ // styles for bars and labels
44
+ $: textStyleStr = `fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};font-size:${textSize}em;`;
45
+ </script>
46
+
47
+ {#if $isOk && x !== undefined && y !== undefined && elements.length > 0}
48
+ <text style={textStyleStr} x={x} y={y} dx={dx} dy={dy} dominant-baseline="middle" text-anchor="start">
49
+ {#each elements as el, i}
50
+ <tspan {x} {dx} dy={i === 0 ? 0 : dy}>{@html el}</tspan>
51
+ {/each}
52
+ </text>
53
+ {/if}
@@ -0,0 +1,109 @@
1
+ <script>
2
+ /****************************************************
3
+ * X-Axis *
4
+ * -------------------- *
5
+ * shows x-axis and its elements (ticks, grid, etc.) *
6
+ *****************************************************/
7
+
8
+ 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
+
25
+ export let lineColor = Colors.DARKGRAY; // color of axis and tick lines
26
+ export let gridColor = Colors.MIDDLEGRAY; // color og grid lines
27
+ export let textColor = Colors.DARKGRAY; // color of text tick labels
28
+
29
+
30
+ /*****************************************/
31
+ /* Component code */
32
+ /*****************************************/
33
+
34
+ // sanity checks of input parameters
35
+ if (slot !== 'xaxis') {
36
+ throw('Component XAxis must have "slot=\'xaxis\'" attribute.');
37
+ }
38
+
39
+ // get axes context and adjust x margins
40
+ const axes = getContext('axes');
41
+
42
+ // get reactive variables needed to compute coordinates
43
+ const xLim = axes.xLim;
44
+ const yLim = axes.yLim;
45
+ const scale = axes.scale;
46
+ const isOk = axes.isOk;
47
+ const tY = axes.tY;
48
+
49
+ // prepare variables for coordinates
50
+ let grid = [];
51
+ let axisLine = [];
52
+ let tickCoords = [];
53
+ let tfCoords = [];
54
+ let tickFactor = 0;
55
+
56
+ // compute coordinates for ticks, grid and axis line
57
+ $: if ($isOk) {
58
+
59
+ // compute x-coordinates of the ticks or take the ones manually specified by user
60
+ const ticksX = getAxisTicks(ticks, $xLim, axes.TICK_NUM[$scale], true);
61
+ const tickNum = ticksX.length;
62
+
63
+ // compute tick y-coordinates (up and bottom)
64
+ const dY = axes.invTransform([axes.TICK_SIZE[$scale]], $tY.objects)[0];
65
+ const ticksY1 = Vector.fill($yLim[0], tickNum);
66
+ const ticksY2 = ticksY1.add(dY);
67
+
68
+ // compute coordinates for the ends of grid
69
+ const gridYEnd = Vector.fill($yLim[1], tickNum);
70
+
71
+ // tick labels and tick factor
72
+ if (ticks === undefined || tickLabels === undefined) {
73
+ [tickFactor, tickLabels] = getTickLabels(ticksX.v);
74
+ }
75
+
76
+ if (tickLabels.length !== ticksX.length) {
77
+ throw('XAxis: "tickLabels" must be a array of the same size as ticks.')
78
+ }
79
+
80
+ // combine all coordinates together
81
+ grid = [
82
+ [ticksX, ticksY1],
83
+ [ticksX, gridYEnd]
84
+ ];
85
+
86
+ axisLine = [
87
+ [vector([$xLim[0]]), vector([$yLim[0]])],
88
+ [vector([$xLim[1]]), vector([$yLim[0]])]
89
+ ]
90
+
91
+ tickCoords = [
92
+ [ticksX, ticksY2],
93
+ [ticksX, ticksY1]
94
+ ];
95
+
96
+ tfCoords = [
97
+ [null, null],
98
+ [[$xLim[1]], [ticksY1.v[tickNum - 1]]],
99
+ ];
100
+ }
101
+ </script>
102
+
103
+ {#if $isOk && axisLine.length > 0}
104
+ <Axis
105
+ className="mdaplot__xaxis" pos={1}
106
+ {lineColor} {gridColor} {textColor}
107
+ {showGrid} {grid} {axisLine} {tickCoords} {tickLabels} {tfCoords} {tickFactor} {las}
108
+ />
109
+ {/if}
@@ -0,0 +1,109 @@
1
+ <script>
2
+ /****************************************************
3
+ * Y-Axis *
4
+ * -------------------- *
5
+ * shows y-axis and its elements (ticks, grid, etc.) *
6
+ *****************************************************/
7
+
8
+ 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 = '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
+
25
+ export let lineColor = Colors.DARKGRAY; // color of axis and tick lines
26
+ export let gridColor = Colors.MIDDLEGRAY; // color og grid lines
27
+ export let textColor = Colors.DARKGRAY; // color of text tick labels
28
+
29
+
30
+ /*****************************************/
31
+ /* Component code */
32
+ /*****************************************/
33
+
34
+ // sanity checks of input parameters
35
+ if (slot !== 'yaxis') {
36
+ throw('Component YAxis must have "slot=\'yaxis\'" attribute.');
37
+ }
38
+
39
+ // get axes context and adjust x margins
40
+ const axes = getContext('axes');
41
+
42
+ // get reactive variables needed to compute coordinates
43
+ const xLim = axes.xLim;
44
+ const yLim = axes.yLim;
45
+ const scale = axes.scale;
46
+ const isOk = axes.isOk;
47
+ const tX = axes.tX;
48
+
49
+ // prepare variables for coordinates
50
+ let grid = [];
51
+ let axisLine = [];
52
+ let tickCoords = [];
53
+ let tfCoords = [];
54
+ let tickFactor = 0;
55
+
56
+ // compute tick x-coordinates
57
+ $: if ($isOk) {
58
+
59
+ // compute x-coordinates of the ticks or take the ones manually specified by user
60
+ const ticksY = getAxisTicks(ticks, $yLim, axes.TICK_NUM[$scale], true);
61
+ const tickNum = ticksY.length;
62
+
63
+ // compute tick y-coordinates (up and bottom)
64
+ const dX = axes.invTransform([axes.TICK_SIZE[$scale]], $tX.objects)[0];
65
+ const ticksX1 = Vector.fill($xLim[0], tickNum)
66
+ const ticksX2 = ticksX1.add(dX)
67
+
68
+ // coordinates for the ends of grid
69
+ const gridXEnd = Vector.fill($xLim[1], tickNum);
70
+
71
+ // tick labels and tick factor
72
+ if (ticks === undefined || tickLabels === undefined) {
73
+ [tickFactor, tickLabels] = getTickLabels(ticksY.v)
74
+ }
75
+
76
+ if (tickLabels.length !== ticksY.length) {
77
+ throw('YAxis: "tickLabels" must be a array of the same size as ticks.')
78
+ }
79
+
80
+ // combine all coordinates together
81
+ grid = [
82
+ [ticksX1, ticksY],
83
+ [gridXEnd, ticksY]
84
+ ];
85
+
86
+ axisLine = [
87
+ [vector([$xLim[0]]), vector([$yLim[0]])],
88
+ [vector([$xLim[0]]), vector([$yLim[1]])]
89
+ ]
90
+
91
+ tickCoords = [
92
+ [ticksX1, ticksY],
93
+ [ticksX2, ticksY]
94
+ ];
95
+
96
+ tfCoords = [
97
+ [[], []],
98
+ [[ticksX1.v[tickNum - 1]], [$yLim[1]]],
99
+ ];
100
+ }
101
+ </script>
102
+
103
+ {#if $isOk && axisLine.length > 0}
104
+ <Axis
105
+ className="mdaplot__yaxis" pos={4}
106
+ {lineColor} {gridColor} {textColor}
107
+ {showGrid} {grid} {axisLine} {tickCoords} {tickLabels} {tfCoords} {tickFactor} {las}
108
+ />
109
+ {/if}
@@ -0,0 +1,21 @@
1
+ export { default as Axes } from './Axes.svelte';
2
+ export { default as XAxis } from './XAxis.svelte';
3
+ export { default as YAxis } from './YAxis.svelte';
4
+ export { default as Box } from './Box.svelte';
5
+
6
+ export { default as Rectangles } from './Rectangles.svelte';
7
+ export { default as Segments } from './Segments.svelte';
8
+ export { default as TextLabels } from './TextLabels.svelte';
9
+
10
+ export { default as Area } from './Area.svelte';
11
+ export { default as Bars } from './Bars.svelte';
12
+ export { default as Points } from './Points.svelte';
13
+ export { default as Lines } from './Lines.svelte';
14
+ export { default as Multilines } from './Multilines.svelte';
15
+ export { default as Heatmap } from './Heatmap.svelte';
16
+
17
+ export { default as Legend } from './Legend.svelte';
18
+ export { default as TextLegend } from './TextLegend.svelte';
19
+ export { default as ColormapLegend } from './ColormapLegend.svelte';
20
+
21
+ export { getcolmap, Colors } from '../Colors.js';