Skip to content

Commit a1c0b32

Browse files
committed
Fix the WASM example for the coordinate mapping
1 parent c2d7c8f commit a1c0b32

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

examples/wasm-demo/www/index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@ function setupCanvas() {
4343
/** Update displayed coordinates. */
4444
function onMouseMove(event) {
4545
if (chart) {
46-
const point = chart.coord(event.offsetX, event.offsetY);
47-
coord.innerText = (point)
48-
? `(${point.x.toFixed(3)}, ${point.y.toFixed(3)})`
49-
: "Mouse pointer is out of range";
46+
var text = "Mouse pointer is out of range";
47+
48+
if(event.target == canvas) {
49+
let actualRect = canvas.getBoundingClientRect();
50+
let logicX = event.offsetX * canvas.width / actualRect.width;
51+
let logicY = event.offsetY * canvas.height / actualRect.height;
52+
const point = chart.coord(logicX, logicY);
53+
text = (point)
54+
? `(${point.x.toFixed(3)}, ${point.y.toFixed(3)})`
55+
: text;
56+
}
57+
coord.innerText = text;
5058
}
5159
}
5260

0 commit comments

Comments
 (0)