svelte-plots-basic 3.1.6 → 3.2.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 +5 -0
- package/package.json +1 -1
- package/src/2d/Heatmap.svelte +23 -2
package/README.md
CHANGED
|
@@ -15,6 +15,11 @@ These websites and web-applications use `svelte-plots-basic` library:
|
|
|
15
15
|
|
|
16
16
|
## News
|
|
17
17
|
|
|
18
|
+
### 3.2.0
|
|
19
|
+
|
|
20
|
+
* Added mouse click handler option for `Heatmap.svelte` component (returns row and column index of the element).
|
|
21
|
+
|
|
22
|
+
|
|
18
23
|
### 3.1.1-3.1.6
|
|
19
24
|
|
|
20
25
|
* Fixed bug which sometimes caused an error when manual text tick labels provided.
|
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,38 @@
|
|
|
110
112
|
let rw = $derived(transformObjects([1], axes.tX()));
|
|
111
113
|
let rh = $derived(transformObjects([1], axes.tY()));
|
|
112
114
|
|
|
115
|
+
// mouse click handler
|
|
116
|
+
function handleClick(e) {
|
|
117
|
+
if (!onclick || typeof onclick !== 'function') return;
|
|
118
|
+
|
|
119
|
+
const el = e.target;
|
|
120
|
+
if (el.tagName !== 'rect') return;
|
|
121
|
+
|
|
122
|
+
const pel = el.parentNode.parentNode;
|
|
123
|
+
const pr = pel.getBoundingClientRect();
|
|
124
|
+
const r = el.getBoundingClientRect();
|
|
125
|
+
const x = (r.x - pr.x) + r.width * 0.2;
|
|
126
|
+
const y = (r.y - pr.y) + r.height * 0.2;
|
|
127
|
+
onclick(Math.abs(Math.round(y / r.height)), Math.abs(Math.round(x / r.width)))
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
113
132
|
// check status
|
|
114
133
|
let isOk = $derived(rx && ry && rx.length === ry.length);
|
|
115
134
|
</script>
|
|
116
135
|
|
|
136
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
117
137
|
{#if isOk}
|
|
118
|
-
|
|
138
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
139
|
+
<g class="heatmap" style="stroke:0;stroke-width:0px;" onclick={handleClick}>
|
|
119
140
|
<!-- loop over colors/intervals -->
|
|
120
141
|
{#each lc as col, i}
|
|
121
142
|
<g title="heatmap-group" style="fill:{col};">
|
|
122
143
|
{#if rx[i].length > 0}
|
|
123
144
|
<!-- loop over elements which fall into the interval -->
|
|
124
145
|
{#each rx[i] as v, j}
|
|
125
|
-
<rect x={rx[i][j]} y={ry[i][j]} width={rw} height={rh}
|
|
146
|
+
<rect x={rx[i][j]} y={ry[i][j]} width={rw} height={rh}/>
|
|
126
147
|
{/each}
|
|
127
148
|
{/if}
|
|
128
149
|
</g>
|