@@ -3100,6 +3100,52 @@ JSROOT.define(['d3', 'painter', 'base3d', 'hist'], (d3, jsrp, THREE) => {
31003100 return histo ;
31013101 }
31023102
3103+ /** @summary Function handles tooltips in the mesh
3104+ * @private */
3105+ TGraph2DPainter . prototype . graph2DTooltip = function ( intersect ) {
3106+ if ( ! Number . isInteger ( intersect . index ) ) {
3107+ console . error ( 'intersect.index not provided, check three.js version' , THREE . REVISION , 'expected r121' ) ;
3108+ return null ;
3109+ }
3110+
3111+ let indx = Math . floor ( intersect . index / this . nvertex ) ;
3112+ if ( ( indx < 0 ) || ( indx >= this . index . length ) ) return null ;
3113+ let sqr = v => v * v ;
3114+
3115+ indx = this . index [ indx ] ;
3116+
3117+ let p = this . painter ,
3118+ grx = p . grx ( this . graph . fX [ indx ] ) ,
3119+ gry = p . gry ( this . graph . fY [ indx ] ) ,
3120+ grz = p . grz ( this . graph . fZ [ indx ] ) ;
3121+
3122+ if ( this . check_next && indx + 1 < this . graph . fX . length ) {
3123+ let d = intersect . point ,
3124+ grx1 = p . grx ( this . graph . fX [ indx + 1 ] ) ,
3125+ gry1 = p . gry ( this . graph . fY [ indx + 1 ] ) ,
3126+ grz1 = p . grz ( this . graph . fZ [ indx + 1 ] ) ;
3127+ if ( sqr ( d . x - grx1 ) + sqr ( d . y - gry1 ) + sqr ( d . z - grz1 ) < sqr ( d . x - grx ) + sqr ( d . y - gry ) + sqr ( d . z - grz ) ) {
3128+ grx = grx1 ; gry = gry1 ; grz = grz1 ; indx ++ ;
3129+ }
3130+ }
3131+
3132+ return {
3133+ x1 : grx - this . scale0 ,
3134+ x2 : grx + this . scale0 ,
3135+ y1 : gry - this . scale0 ,
3136+ y2 : gry + this . scale0 ,
3137+ z1 : grz - this . scale0 ,
3138+ z2 : grz + this . scale0 ,
3139+ color : this . tip_color ,
3140+ lines : [ this . tip_name ,
3141+ "pnt: " + indx ,
3142+ "x: " + p . axisAsText ( "x" , this . graph . fX [ indx ] ) ,
3143+ "y: " + p . axisAsText ( "y" , this . graph . fY [ indx ] ) ,
3144+ "z: " + p . axisAsText ( "z" , this . graph . fZ [ indx ] )
3145+ ]
3146+ } ;
3147+ }
3148+
31033149 /** @summary Actual drawing of TGraph2D object
31043150 * @private */
31053151 TGraph2DPainter . prototype . redraw = function ( ) {
@@ -3123,51 +3169,6 @@ JSROOT.define(['d3', 'painter', 'base3d', 'hist'], (d3, jsrp, THREE) => {
31233169 return cnt ;
31243170 }
31253171
3126- function sqr ( v ) { return v * v ; }
3127-
3128- function graph2DTooltip ( intersect ) {
3129- if ( ! Number . isInteger ( intersect . index ) ) {
3130- console . error ( 'intersect.index not provided, check three.js version' , THREE . REVISION , 'expected r121' ) ;
3131- return null ;
3132- }
3133-
3134- let indx = Math . floor ( intersect . index / this . nvertex ) ;
3135- if ( ( indx < 0 ) || ( indx >= this . index . length ) ) return null ;
3136-
3137- indx = this . index [ indx ] ;
3138-
3139- let p = this . painter ,
3140- grx = p . grx ( this . graph . fX [ indx ] ) ,
3141- gry = p . gry ( this . graph . fY [ indx ] ) ,
3142- grz = p . grz ( this . graph . fZ [ indx ] ) ;
3143-
3144- if ( this . check_next && indx + 1 < this . graph . fX . length ) {
3145- let d = intersect . point ,
3146- grx1 = p . grx ( this . graph . fX [ indx + 1 ] ) ,
3147- gry1 = p . gry ( this . graph . fY [ indx + 1 ] ) ,
3148- grz1 = p . grz ( this . graph . fZ [ indx + 1 ] ) ;
3149- if ( sqr ( d . x - grx1 ) + sqr ( d . y - gry1 ) + sqr ( d . z - grz1 ) < sqr ( d . x - grx ) + sqr ( d . y - gry ) + sqr ( d . z - grz ) ) {
3150- grx = grx1 ; gry = gry1 ; grz = grz1 ; indx ++ ;
3151- }
3152- }
3153-
3154- return {
3155- x1 : grx - this . scale0 ,
3156- x2 : grx + this . scale0 ,
3157- y1 : gry - this . scale0 ,
3158- y2 : gry + this . scale0 ,
3159- z1 : grz - this . scale0 ,
3160- z2 : grz + this . scale0 ,
3161- color : this . tip_color ,
3162- lines : [ this . tip_name ,
3163- "pnt: " + indx ,
3164- "x: " + p . axisAsText ( "x" , this . graph . fX [ indx ] ) ,
3165- "y: " + p . axisAsText ( "y" , this . graph . fY [ indx ] ) ,
3166- "z: " + p . axisAsText ( "z" , this . graph . fZ [ indx ] )
3167- ]
3168- } ;
3169- }
3170-
31713172 // try to define scale-down factor
31723173 if ( ( JSROOT . settings . OptimizeDraw > 0 ) && ! fp . webgl ) {
31733174 let numselected = countSelected ( fp . scale_zmin , fp . scale_zmax ) ,
@@ -3285,7 +3286,7 @@ JSROOT.define(['d3', 'painter', 'base3d', 'hist'], (d3, jsrp, THREE) => {
32853286 linemesh . nvertex = 2 ;
32863287 linemesh . check_next = true ;
32873288
3288- linemesh . tooltip = graph2DTooltip ;
3289+ linemesh . tooltip = this . graph2DTooltip ;
32893290 }
32903291
32913292 if ( err ) {
@@ -3302,7 +3303,7 @@ JSROOT.define(['d3', 'painter', 'base3d', 'hist'], (d3, jsrp, THREE) => {
33023303 errmesh . tip_color = ( graph . fMarkerColor === 3 ) ? 0xFF0000 : 0x00FF00 ;
33033304 errmesh . nvertex = 6 ;
33043305
3305- errmesh . tooltip = graph2DTooltip ;
3306+ errmesh . tooltip = this . graph2DTooltip ;
33063307 }
33073308
33083309 if ( pnts ) {
@@ -3321,7 +3322,7 @@ JSROOT.define(['d3', 'painter', 'base3d', 'hist'], (d3, jsrp, THREE) => {
33213322 mesh . index = index ;
33223323
33233324 mesh . tip_name = this . getObjectHint ( ) ;
3324- mesh . tooltip = graph2DTooltip ;
3325+ mesh . tooltip = this . graph2DTooltip ;
33253326
33263327 fp . toplevel . add ( mesh ) ;
33273328 }
0 commit comments