@@ -30,24 +30,31 @@ function setupUI() {
3030
3131/** Setup canvas to properly handle high DPI and redraw current plot. */
3232function setupCanvas ( ) {
33- const dpr = window . devicePixelRatio || 1 ;
33+ const dpr = window . devicePixelRatio || 1.0 ;
3434 const aspectRatio = canvas . width / canvas . height ;
35- const size = Math . min ( canvas . width , canvas . parentNode . offsetWidth ) ;
35+ const size = canvas . parentNode . offsetWidth * 0.8 ;
3636 canvas . style . width = size + "px" ;
3737 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 ;
4140 updatePlot ( ) ;
4241}
4342
4443/** Update displayed coordinates. */
4544function onMouseMove ( event ) {
4645 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 ;
5158 }
5259}
5360
0 commit comments