@@ -30,24 +30,31 @@ function setupUI() {
30
30
31
31
/** Setup canvas to properly handle high DPI and redraw current plot. */
32
32
function setupCanvas ( ) {
33
- const dpr = window . devicePixelRatio || 1 ;
33
+ const dpr = window . devicePixelRatio || 1.0 ;
34
34
const aspectRatio = canvas . width / canvas . height ;
35
- const size = Math . min ( canvas . width , canvas . parentNode . offsetWidth ) ;
35
+ const size = canvas . parentNode . offsetWidth * 0.8 ;
36
36
canvas . style . width = size + "px" ;
37
37
canvas . style . height = size / aspectRatio + "px" ;
38
- canvas . width = size * dpr ;
39
- canvas . height = size / aspectRatio * dpr ;
40
- canvas . getContext ( "2d" ) . scale ( dpr , dpr ) ;
38
+ canvas . width = size ;
39
+ canvas . height = size / aspectRatio ;
41
40
updatePlot ( ) ;
42
41
}
43
42
44
43
/** Update displayed coordinates. */
45
44
function onMouseMove ( event ) {
46
45
if ( chart ) {
47
- const point = chart . coord ( event . offsetX , event . offsetY ) ;
48
- coord . innerText = ( point )
49
- ? `(${ point . x . toFixed ( 3 ) } , ${ point . y . toFixed ( 3 ) } )`
50
- : "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 ;
51
58
}
52
59
}
53
60
0 commit comments