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.
- package/README.md +54 -69
- package/package.json +28 -33
- package/src/2d/Area.svelte +61 -0
- package/src/2d/Axes.svelte +500 -0
- package/src/2d/Axis.svelte +50 -0
- package/src/2d/AxisLines.svelte +54 -0
- package/src/2d/AxisTickLabels.svelte +82 -0
- package/src/2d/Bars.svelte +65 -0
- package/src/2d/Box.svelte +50 -0
- package/src/2d/ColorLegend.svelte +36 -0
- package/src/2d/Legend.svelte +148 -0
- package/src/2d/Lines.svelte +49 -0
- package/src/2d/Multilines.svelte +67 -0
- package/src/2d/Points.svelte +79 -0
- package/src/2d/Rectangles.svelte +74 -0
- package/src/2d/Segments.svelte +65 -0
- package/src/2d/TextLabels.svelte +107 -0
- package/src/2d/TextLegend.svelte +53 -0
- package/src/2d/XAxis.svelte +99 -0
- package/src/2d/YAxis.svelte +99 -0
- package/src/{index.js → 2d/index.js} +10 -6
- package/src/3d/Axes.svelte +445 -0
- package/src/3d/Axis.svelte +64 -0
- package/src/3d/AxisLines.svelte +50 -0
- package/src/3d/AxisTickLabels.svelte +54 -0
- package/src/3d/Lines.svelte +49 -0
- package/src/3d/Mesh.svelte +188 -0
- package/src/3d/Points.svelte +61 -0
- package/src/3d/Segments.svelte +69 -0
- package/src/3d/TextLabels.svelte +79 -0
- package/src/3d/XAxis.svelte +123 -0
- package/src/3d/YAxis.svelte +123 -0
- package/src/3d/ZAxis.svelte +123 -0
- package/src/3d/index.js +13 -0
- package/src/Colors.js +36 -1
- package/src/Utils.js +205 -0
- package/dist/index.js +0 -4209
- package/dist/index.mjs +0 -4187
- package/src/AreaSeries.svelte +0 -53
- package/src/Axes.svelte +0 -538
- package/src/BarSeries.svelte +0 -78
- package/src/Box.svelte +0 -35
- package/src/LineSeries.svelte +0 -50
- package/src/Rectangles.svelte +0 -64
- package/src/ScatterSeries.svelte +0 -85
- package/src/Segments.svelte +0 -48
- package/src/TextLabels.svelte +0 -78
- package/src/TextLegend.svelte +0 -38
- package/src/XAxis.svelte +0 -69
- package/src/YAxis.svelte +0 -72
|
@@ -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,99 @@
|
|
|
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 } 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
|
+
|
|
54
|
+
// compute coordinates for ticks, grid and axis line
|
|
55
|
+
$: if ($isOk) {
|
|
56
|
+
|
|
57
|
+
// compute x-coordinates of the ticks or take the ones manually specified by user
|
|
58
|
+
const ticksX = getAxisTicks(ticks, $xLim, axes.TICK_NUM[$scale], true);
|
|
59
|
+
const tickNum = ticksX.length;
|
|
60
|
+
|
|
61
|
+
// compute tick y-coordinates (up and bottom)
|
|
62
|
+
const dY = axes.invTransform([axes.TICK_SIZE[$scale]], $tY.objects)[0];
|
|
63
|
+
const ticksY1 = Vector.fill($yLim[0], tickNum);
|
|
64
|
+
const ticksY2 = ticksY1.add(dY);
|
|
65
|
+
|
|
66
|
+
// compute coordinates for the ends of grid
|
|
67
|
+
const gridYEnd = Vector.fill($yLim[1], tickNum);
|
|
68
|
+
|
|
69
|
+
// tick labels
|
|
70
|
+
tickLabels = (ticks === undefined || tickLabels === undefined) ? ticksX.v : tickLabels;
|
|
71
|
+
if (tickLabels.length !== ticksX.length) {
|
|
72
|
+
throw('XAxis: "tickLabels" must be a array of the same size as ticks.')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// combine all coordinates together
|
|
76
|
+
grid = [
|
|
77
|
+
[ticksX, ticksY1],
|
|
78
|
+
[ticksX, gridYEnd]
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
axisLine = [
|
|
82
|
+
[vector([$xLim[0]]), vector([$yLim[0]])],
|
|
83
|
+
[vector([$xLim[1]]), vector([$yLim[0]])]
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
tickCoords = [
|
|
87
|
+
[ticksX, ticksY2],
|
|
88
|
+
[ticksX, ticksY1]
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
{#if $isOk && axisLine.length > 0}
|
|
94
|
+
<Axis
|
|
95
|
+
className="mdaplot__xaxis" pos={1}
|
|
96
|
+
{lineColor} {gridColor} {textColor}
|
|
97
|
+
{showGrid} {grid} {axisLine} {tickCoords} {tickLabels} {las}
|
|
98
|
+
/>
|
|
99
|
+
{/if}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 } 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
|
+
|
|
54
|
+
// compute tick x-coordinates
|
|
55
|
+
$: if ($isOk) {
|
|
56
|
+
|
|
57
|
+
// compute x-coordinates of the ticks or take the ones manually specified by user
|
|
58
|
+
const ticksY = getAxisTicks(ticks, $yLim, axes.TICK_NUM[$scale], true);
|
|
59
|
+
const tickNum = ticksY.length;
|
|
60
|
+
|
|
61
|
+
// compute tick y-coordinates (up and bottom)
|
|
62
|
+
const dX = axes.invTransform([axes.TICK_SIZE[$scale]], $tX.objects)[0];
|
|
63
|
+
const ticksX1 = Vector.fill($xLim[0], tickNum)
|
|
64
|
+
const ticksX2 = ticksX1.add(dX)
|
|
65
|
+
|
|
66
|
+
// coordinates for the ends of grid
|
|
67
|
+
const gridXEnd = Vector.fill($xLim[1], tickNum);
|
|
68
|
+
|
|
69
|
+
// tick labels
|
|
70
|
+
tickLabels = (ticks === undefined || tickLabels === undefined) ? ticksY.v : tickLabels;
|
|
71
|
+
if (tickLabels.length !== ticksY.length) {
|
|
72
|
+
throw('YAxis: "tickLabels" must be a array of the same size as ticks.')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// combine all coordinates together
|
|
76
|
+
grid = [
|
|
77
|
+
[ticksX1, ticksY],
|
|
78
|
+
[gridXEnd, ticksY]
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
axisLine = [
|
|
82
|
+
[vector([$xLim[0]]), vector([$yLim[0]])],
|
|
83
|
+
[vector([$xLim[0]]), vector([$yLim[1]])]
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
tickCoords = [
|
|
87
|
+
[ticksX1, ticksY],
|
|
88
|
+
[ticksX2, ticksY]
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
{#if $isOk && axisLine.length > 0}
|
|
94
|
+
<Axis
|
|
95
|
+
className="mdaplot__yaxis" pos={4}
|
|
96
|
+
{lineColor} {gridColor} {textColor}
|
|
97
|
+
{showGrid} {grid} {axisLine} {tickCoords} {tickLabels} {las}
|
|
98
|
+
/>
|
|
99
|
+
{/if}
|
|
@@ -6,11 +6,15 @@ export { default as Box } from './Box.svelte';
|
|
|
6
6
|
export { default as Rectangles } from './Rectangles.svelte';
|
|
7
7
|
export { default as Segments } from './Segments.svelte';
|
|
8
8
|
export { default as TextLabels } from './TextLabels.svelte';
|
|
9
|
-
export { default as TextLegend } from './TextLegend.svelte';
|
|
10
9
|
|
|
11
|
-
export { default as
|
|
12
|
-
export { default as
|
|
13
|
-
export { default as
|
|
14
|
-
export { default as
|
|
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
|
+
|
|
16
|
+
export { default as ColorLegend } from './ColorLegend.svelte';
|
|
17
|
+
export { default as Legend } from './Legend.svelte';
|
|
18
|
+
export { default as TextLegend } from './TextLegend.svelte';
|
|
15
19
|
|
|
16
|
-
export { Colors } from '
|
|
20
|
+
export { getcolmap, Colors } from '../Colors.js';
|