svelte-plots-basic 2.3.3 → 2.3.4
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/ColormapLegend.svelte +15 -5
package/package.json
CHANGED
|
@@ -14,13 +14,16 @@
|
|
|
14
14
|
/* Input parameters */
|
|
15
15
|
/*****************************************/
|
|
16
16
|
|
|
17
|
-
export let breaks; // vector with breaks for color intervals
|
|
17
|
+
export let breaks; // vector with breaks for color intervals or vector with their indices
|
|
18
18
|
export let colmap; // array with colors for each interval
|
|
19
19
|
export let decNum = 1; // number of decimals to show the interval boundaries with
|
|
20
|
-
export let labels = null; // optional vector with labels for interval boundaries
|
|
20
|
+
export let labels = null; // optional vector with labels for interval boundaries or elements
|
|
21
21
|
export let labelColor = '#909090'; // color of labels
|
|
22
22
|
export let fontSize = 0.85; // font size for labels in em
|
|
23
23
|
|
|
24
|
+
// if number of breaks is the same as number of elements in color map
|
|
25
|
+
// the corresponding labels will be placed in the middle inder each color element in the legend
|
|
26
|
+
// if this number is by one larger, the labels will be placed on the boundaries
|
|
24
27
|
|
|
25
28
|
/*****************************************/
|
|
26
29
|
/* Component code */
|
|
@@ -40,7 +43,10 @@
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
// check colormap values
|
|
43
|
-
$: if (!colmap || colmap.length
|
|
46
|
+
$: if (!colmap || !(colmap.length === breaks.length - 1 || colmap.length === breaks.length )) {
|
|
47
|
+
console.log(colmap)
|
|
48
|
+
console.log(breaks)
|
|
49
|
+
console.log(labels)
|
|
44
50
|
throw new Error('ColormapLegend: number of color values in colormap does not match number of intervals defined by breaks.');
|
|
45
51
|
}
|
|
46
52
|
|
|
@@ -61,9 +67,10 @@
|
|
|
61
67
|
|
|
62
68
|
// number of elements
|
|
63
69
|
$: n = colmap.length;
|
|
70
|
+
$: isCentered = lLabels && lLabels.length === n;
|
|
64
71
|
|
|
65
72
|
// compute screen coordinates of the elements
|
|
66
|
-
let rx, ry, rw, rh = undefined;
|
|
73
|
+
let dxl, rx, ry, rw, rh = undefined;
|
|
67
74
|
$: {
|
|
68
75
|
if ($isOk) {
|
|
69
76
|
// compute size of the whole block in plot coordinates
|
|
@@ -82,6 +89,7 @@
|
|
|
82
89
|
rx = axes.transform(Vector.seq(0, n).apply(v => left + v * elWidth), $tX.coords);
|
|
83
90
|
rw = axes.transform([elWidth], $tX.objects);
|
|
84
91
|
rh = EL_HEIGHTS_PX[$scale];
|
|
92
|
+
dxl = isCentered ? rw[0] / 2 : 0
|
|
85
93
|
}
|
|
86
94
|
};
|
|
87
95
|
</script>
|
|
@@ -90,9 +98,11 @@
|
|
|
90
98
|
<g class="series colormap_legend" style="stroke:0;stroke-width:0px;">
|
|
91
99
|
{#each colmap as col, i}
|
|
92
100
|
<rect x={rx[i]} y={ry} width={rw} height={rh} fill="{col}"/>
|
|
93
|
-
<text x={rx[i]} y={ry} dx={
|
|
101
|
+
<text x={rx[i]} y={ry} dx={dxl} dy={rh * 1.25} dominant-baseline="hanging" fill={labelColor} font-size="{fontSize}em" text-anchor="middle">{@html lLabels[i]}</text>
|
|
94
102
|
{/each}
|
|
103
|
+
{#if !isCentered}
|
|
95
104
|
<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
|
+
{/if}
|
|
96
106
|
</g>
|
|
97
107
|
{/if}
|
|
98
108
|
|