File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,18 @@ function setupCanvas() {
43
43
/** Update displayed coordinates. */
44
44
function onMouseMove ( event ) {
45
45
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 ;
50
58
}
51
59
}
52
60
You can’t perform that action at this time.
0 commit comments