svelte-plots-basic 3.1.5 → 3.2.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.
- package/README.md +7 -1
- package/package.json +1 -1
- package/src/2d/Heatmap.svelte +20 -2
- package/src/2d/XAxis.svelte +4 -3
- package/src/2d/YAxis.svelte +4 -3
- package/src/methods.js +3 -2
package/README.md
CHANGED
|
@@ -15,8 +15,14 @@ These websites and web-applications use `svelte-plots-basic` library:
|
|
|
15
15
|
|
|
16
16
|
## News
|
|
17
17
|
|
|
18
|
-
### 3.
|
|
18
|
+
### 3.2.0
|
|
19
19
|
|
|
20
|
+
* Added mouse click handler option for `Heatmap.svelte` component (returns row and column index of the element).
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### 3.1.1-3.1.6
|
|
24
|
+
|
|
25
|
+
* Fixed bug which sometimes caused an error when manual text tick labels provided.
|
|
20
26
|
* Added `markerSize` specification to legend items.
|
|
21
27
|
* Small improvements and bug fixes.
|
|
22
28
|
|
package/package.json
CHANGED
package/src/2d/Heatmap.svelte
CHANGED
|
@@ -38,9 +38,11 @@
|
|
|
38
38
|
values, // Matrix with values to show heatmap for
|
|
39
39
|
breaks, // vector with breaks to distribute the values in
|
|
40
40
|
colmap = null, // array with colors for each interval
|
|
41
|
+
onclick = null, // callback for onclick (returns row and column indices of element)
|
|
41
42
|
} = $props();
|
|
42
43
|
|
|
43
44
|
|
|
45
|
+
|
|
44
46
|
// check that values are provided as a matrix
|
|
45
47
|
let v = $derived(ismatrix(values) && values.nrows > 0 && values.ncols > 0 ? values : null);
|
|
46
48
|
|
|
@@ -110,19 +112,35 @@
|
|
|
110
112
|
let rw = $derived(transformObjects([1], axes.tX()));
|
|
111
113
|
let rh = $derived(transformObjects([1], axes.tY()));
|
|
112
114
|
|
|
115
|
+
|
|
116
|
+
// mouse click handler
|
|
117
|
+
function handleClick(e) {
|
|
118
|
+
if (!onclick || typeof onclick !== 'function') return;
|
|
119
|
+
const el = e.target;
|
|
120
|
+
if (el.tagName !== 'rect') return;
|
|
121
|
+
const r = el.getBoundingClientRect();
|
|
122
|
+
const x = r.x + r.width / 2;
|
|
123
|
+
const y = r.y - r.height / 2;
|
|
124
|
+
onclick(Math.round(y / r.height) - 1, Math.round(x / r.width) - 1)
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
113
129
|
// check status
|
|
114
130
|
let isOk = $derived(rx && ry && rx.length === ry.length);
|
|
115
131
|
</script>
|
|
116
132
|
|
|
133
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
117
134
|
{#if isOk}
|
|
118
|
-
|
|
135
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
136
|
+
<g class="heatmap" style="stroke:0;stroke-width:0px;" onclick={handleClick}>
|
|
119
137
|
<!-- loop over colors/intervals -->
|
|
120
138
|
{#each lc as col, i}
|
|
121
139
|
<g title="heatmap-group" style="fill:{col};">
|
|
122
140
|
{#if rx[i].length > 0}
|
|
123
141
|
<!-- loop over elements which fall into the interval -->
|
|
124
142
|
{#each rx[i] as v, j}
|
|
125
|
-
<rect x={rx[i][j]} y={ry[i][j]} width={rw} height={rh}
|
|
143
|
+
<rect x={rx[i][j]} y={ry[i][j]} width={rw} height={rh}/>
|
|
126
144
|
{/each}
|
|
127
145
|
{/if}
|
|
128
146
|
</g>
|
package/src/2d/XAxis.svelte
CHANGED
|
@@ -47,16 +47,17 @@
|
|
|
47
47
|
// if ticks are provided check if they are valid and preprocess them
|
|
48
48
|
let ticksProcessed, error = '';
|
|
49
49
|
if (ticks) {
|
|
50
|
-
[ticksProcessed, error] = validateTicks(ticks, axes.limX())
|
|
50
|
+
[ticksProcessed, error] = validateTicks(ticks, axes.limX());
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// if tick labels are provided check if they are valid and preprocess them
|
|
54
|
+
let tickLabelsProcessed;
|
|
54
55
|
if (!error && tickLabels) {
|
|
55
|
-
[
|
|
56
|
+
[tickLabelsProcessed, error] = validateTickLabels(tickLabels, ticksProcessed);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
// activate axis
|
|
59
60
|
axes.setXAxis({show, error: error, label: axisLabel, ticks: ticksProcessed,
|
|
60
|
-
labelHeight, showGrid, las, whole, tickLabels});
|
|
61
|
+
labelHeight, showGrid, las, whole, tickLabels: tickLabelsProcessed});
|
|
61
62
|
});
|
|
62
63
|
</script>
|
package/src/2d/YAxis.svelte
CHANGED
|
@@ -50,16 +50,17 @@
|
|
|
50
50
|
// if ticks are provided check if they are valid and preprocess them
|
|
51
51
|
let ticksProcessed, error = '';
|
|
52
52
|
if (ticks) {
|
|
53
|
-
[ticksProcessed, error] = validateTicks(ticks, axes.limY())
|
|
53
|
+
[ticksProcessed, error] = validateTicks(ticks, axes.limY());
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// if tick labels are provided check if they are valid and preprocess them
|
|
57
|
+
let tickLabelsProcessed;
|
|
57
58
|
if (!error && tickLabels) {
|
|
58
|
-
[
|
|
59
|
+
[tickLabelsProcessed, error] = validateTickLabels(tickLabels, ticksProcessed);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// activate axis
|
|
62
63
|
axes.setYAxis({show, error: error, label: axisLabel, ticks: ticksProcessed,
|
|
63
|
-
labelHeight, showGrid, las, whole, tickLabels, pos: 4});
|
|
64
|
+
labelHeight, showGrid, las, whole, tickLabels: tickLabelsProcessed, pos: 4});
|
|
64
65
|
});
|
|
65
66
|
</script>
|
package/src/methods.js
CHANGED
|
@@ -885,8 +885,9 @@ export function getcolmap(n, alpha) {
|
|
|
885
885
|
*/
|
|
886
886
|
export function getXAxisParams(limX, limY, scales, tY, axis) {
|
|
887
887
|
|
|
888
|
-
|
|
889
|
-
let
|
|
888
|
+
|
|
889
|
+
let ticks = axis.error ? null : axis.ticks ;
|
|
890
|
+
let tickLabels = axis.error ? null : axis.tickLabels;
|
|
890
891
|
let tickFactor = 0;
|
|
891
892
|
|
|
892
893
|
// compute x-coordinates of the ticks or take the ones manually specified by user
|