svelte-plots-basic 2.5.6 → 2.5.7
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/package.json +1 -1
- package/src/2d/Axis.svelte +2 -9
- package/src/2d/ColormapLegend.svelte +19 -8
- package/src/Utils.js +14 -1
package/package.json
CHANGED
package/src/2d/Axis.svelte
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
*****************************************************/
|
|
8
8
|
|
|
9
9
|
import { Colors } from '../Colors.js';
|
|
10
|
+
import { getTickFactorLabel } from '../Utils.js';
|
|
11
|
+
|
|
10
12
|
import AxisLines from './AxisLines.svelte';
|
|
11
13
|
import AxisTickLabels from './AxisTickLabels.svelte';
|
|
12
14
|
|
|
13
|
-
|
|
14
15
|
/*****************************************/
|
|
15
16
|
/* Input parameters */
|
|
16
17
|
/*****************************************/
|
|
@@ -32,14 +33,6 @@
|
|
|
32
33
|
export let textColor = Colors.DARKGRAY; // color of tick labels
|
|
33
34
|
|
|
34
35
|
// generate text for tick factor label
|
|
35
|
-
function getTickFactorLabel(tf) {
|
|
36
|
-
if (tf === 0) return '';
|
|
37
|
-
if (tf < 0) {
|
|
38
|
-
return `×10<tspan dy="-0.5em">${(tf).toString()}</tspan>`;
|
|
39
|
-
} else {
|
|
40
|
-
return `×10<tspan dy="-0.5em">${(tf).toString()}</tspan>`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
36
|
</script>
|
|
44
37
|
|
|
45
38
|
<g class="mdaplot__axis {className}">
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
**********************************************************/
|
|
7
7
|
|
|
8
8
|
import { getContext } from 'svelte';
|
|
9
|
-
import { checkCoords } from '../Utils';
|
|
9
|
+
import { checkCoords, getTickLabels, getTickFactorLabel } from '../Utils';
|
|
10
10
|
import { Vector, isvector } from 'mdatools/arrays';
|
|
11
11
|
|
|
12
12
|
|
|
@@ -44,17 +44,21 @@
|
|
|
44
44
|
|
|
45
45
|
// check colormap values
|
|
46
46
|
$: if (!colmap || !(colmap.length === breaks.length - 1 || colmap.length === breaks.length )) {
|
|
47
|
-
console.log(colmap)
|
|
48
|
-
console.log(breaks)
|
|
49
|
-
console.log(labels)
|
|
50
47
|
throw new Error('ColormapLegend: number of color values in colormap does not match number of intervals defined by breaks.');
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
// define local variables for breaks and prepare breaks labels
|
|
54
51
|
$: lBreaks = isvector(breaks) ? breaks.v : breaks;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
|
|
53
|
+
let breakFactor, breakLabels;
|
|
54
|
+
$: if (lBreaks) {
|
|
55
|
+
[breakFactor, breakLabels] = getTickLabels(lBreaks);
|
|
56
|
+
} else {
|
|
57
|
+
breakFactor = null;
|
|
58
|
+
breakLabels = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
$: lLabels = labels && labels.length === lBreaks.length ? labels : breakLabels;
|
|
58
62
|
|
|
59
63
|
// get axes context and reactive variables needed to compute coordinates
|
|
60
64
|
const axes = getContext('axes');
|
|
@@ -80,7 +84,7 @@
|
|
|
80
84
|
const height = axesHeight * HEIGHT_RATIO;
|
|
81
85
|
|
|
82
86
|
// compute elements size and position
|
|
83
|
-
const elWidth = width / n;
|
|
87
|
+
const elWidth = width / (n + (breakFactor !== 0));
|
|
84
88
|
const left = $xLim[0] + axesWidth * (1 - WIDTH_RATIO) * 0.5 ;
|
|
85
89
|
const elTop = $yLim[1] - height * TOP_MARGIN;
|
|
86
90
|
|
|
@@ -103,7 +107,14 @@
|
|
|
103
107
|
{#if !isCentered}
|
|
104
108
|
<text x={rx[n]} y={ry} dx={0} dy={rh * 1.25} dominant-baseline="hanging" fill={labelColor} font-size="{fontSize}em" text-anchor="middle">{@html lLabels[n]}</text>
|
|
105
109
|
{/if}
|
|
110
|
+
|
|
111
|
+
{#if breakFactor !== 0}
|
|
112
|
+
<text x={rx[n] + rw[0] * 0.85} y={ry[0] + rh * 2.2} dx={0} dy={0} dominant-baseline="hanging" fill={labelColor} font-size="{fontSize}em" text-anchor="middle">{@html getTickFactorLabel(breakFactor)}</text>
|
|
113
|
+
{/if}
|
|
114
|
+
|
|
106
115
|
</g>
|
|
116
|
+
|
|
117
|
+
|
|
107
118
|
{/if}
|
|
108
119
|
|
|
109
120
|
|
package/src/Utils.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { cbind, vector, isvector, Vector } from 'mdatools/arrays';
|
|
2
2
|
import { min, max, diff } from 'mdatools/stat';
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates label for a tick factor.
|
|
7
|
+
*
|
|
8
|
+
* @param {Number} tf - tick factor value (negative or positive)
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function getTickFactorLabel(tf) {
|
|
12
|
+
if (tf === 0) return '';
|
|
13
|
+
return `<tspan>×10</tspan><tspan baseline-shift="super">${(tf).toString()}</tspan>`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
4
17
|
/**
|
|
5
18
|
* Trim number leaving only significant decimals.
|
|
6
19
|
* @param {number} num
|
|
7
20
|
* @returns trimmed number
|
|
8
21
|
*/
|
|
9
|
-
function trimNum(num) {
|
|
22
|
+
export function trimNum(num) {
|
|
10
23
|
|
|
11
24
|
// check if number is whole — return as is
|
|
12
25
|
if (num === Math.round(num)) return num;
|