@@ -71,18 +71,21 @@ function render(scene) {
7171 var pdata = project ( scene . glplot . cameraParams , selection . dataCoordinate ) ;
7272 trace = lastPicked . data ;
7373 var ptNumber = selection . index ;
74- var hoverinfo = Fx . castHoverinfo ( trace , scene . fullLayout , ptNumber ) ;
75- var hoverinfoParts = hoverinfo . split ( '+' ) ;
76- var isHoverinfoAll = hoverinfo === 'all' ;
7774
78- var xVal = formatter ( 'xaxis' , selection . traceCoordinate [ 0 ] ) ;
79- var yVal = formatter ( 'yaxis' , selection . traceCoordinate [ 1 ] ) ;
80- var zVal = formatter ( 'zaxis' , selection . traceCoordinate [ 2 ] ) ;
75+ var labels = {
76+ xLabel : formatter ( 'xaxis' , selection . traceCoordinate [ 0 ] ) ,
77+ yLabel : formatter ( 'yaxis' , selection . traceCoordinate [ 1 ] ) ,
78+ zLabel : formatter ( 'zaxis' , selection . traceCoordinate [ 2 ] )
79+ } ;
80+
81+ var hoverinfo = Fx . castHoverinfo ( trace , scene . fullLayout , ptNumber ) ;
82+ var hoverinfoParts = ( hoverinfo || '' ) . split ( '+' ) ;
83+ var isHoverinfoAll = hoverinfo && hoverinfo === 'all' ;
8184
82- if ( ! isHoverinfoAll ) {
83- if ( hoverinfoParts . indexOf ( 'x' ) === - 1 ) xVal = undefined ;
84- if ( hoverinfoParts . indexOf ( 'y' ) === - 1 ) yVal = undefined ;
85- if ( hoverinfoParts . indexOf ( 'z' ) === - 1 ) zVal = undefined ;
85+ if ( ! trace . hovertemplate && ! isHoverinfoAll ) {
86+ if ( hoverinfoParts . indexOf ( 'x' ) === - 1 ) labels . xLabel = undefined ;
87+ if ( hoverinfoParts . indexOf ( 'y' ) === - 1 ) labels . yLabel = undefined ;
88+ if ( hoverinfoParts . indexOf ( 'z' ) === - 1 ) labels . zLabel = undefined ;
8689 if ( hoverinfoParts . indexOf ( 'text' ) === - 1 ) selection . textLabel = undefined ;
8790 if ( hoverinfoParts . indexOf ( 'name' ) === - 1 ) lastPicked . name = undefined ;
8891 }
@@ -91,27 +94,38 @@ function render(scene) {
9194 var vectorTx = [ ] ;
9295
9396 if ( trace . type === 'cone' || trace . type === 'streamtube' ) {
97+ labels . uLabel = formatter ( 'xaxis' , selection . traceCoordinate [ 3 ] ) ;
9498 if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'u' ) !== - 1 ) {
95- vectorTx . push ( 'u: ' + formatter ( 'xaxis' , selection . traceCoordinate [ 3 ] ) ) ;
99+ vectorTx . push ( 'u: ' + labels . uLabel ) ;
96100 }
101+
102+ labels . vLabel = formatter ( 'yaxis' , selection . traceCoordinate [ 4 ] ) ;
97103 if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'v' ) !== - 1 ) {
98- vectorTx . push ( 'v: ' + formatter ( 'yaxis' , selection . traceCoordinate [ 4 ] ) ) ;
104+ vectorTx . push ( 'v: ' + labels . vLabel ) ;
99105 }
106+
107+ labels . wLabel = formatter ( 'zaxis' , selection . traceCoordinate [ 5 ] ) ;
100108 if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'w' ) !== - 1 ) {
101- vectorTx . push ( 'w: ' + formatter ( 'zaxis' , selection . traceCoordinate [ 5 ] ) ) ;
109+ vectorTx . push ( 'w: ' + labels . wLabel ) ;
102110 }
111+
112+ labels . normLabel = selection . traceCoordinate [ 6 ] . toPrecision ( 3 ) ;
103113 if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'norm' ) !== - 1 ) {
104- vectorTx . push ( 'norm: ' + selection . traceCoordinate [ 6 ] . toPrecision ( 3 ) ) ;
114+ vectorTx . push ( 'norm: ' + labels . normLabel ) ;
105115 }
106- if ( trace . type === 'streamtube' && ( isHoverinfoAll || hoverinfoParts . indexOf ( 'divergence' ) !== - 1 ) ) {
107- vectorTx . push ( 'divergence: ' + selection . traceCoordinate [ 7 ] . toPrecision ( 3 ) ) ;
116+ if ( trace . type === 'streamtube' ) {
117+ labels . divergenceLabel = selection . traceCoordinate [ 7 ] . toPrecision ( 3 ) ;
118+ if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'divergence' ) !== - 1 ) {
119+ vectorTx . push ( 'divergence: ' + labels . divergenceLabel ) ;
120+ }
108121 }
109122 if ( selection . textLabel ) {
110123 vectorTx . push ( selection . textLabel ) ;
111124 }
112125 tx = vectorTx . join ( '<br>' ) ;
113126 } else if ( trace . type === 'isosurface' ) {
114- vectorTx . push ( 'value: ' + Axes . tickText ( scene . mockAxis , scene . mockAxis . d2l ( selection . traceCoordinate [ 3 ] ) , 'hover' ) . text ) ;
127+ labels . valueLabel = Axes . tickText ( scene . mockAxis , scene . mockAxis . d2l ( selection . traceCoordinate [ 3 ] ) , 'hover' ) . text ;
128+ vectorTx . push ( 'value: ' + labels . valueLabel ) ;
115129 if ( selection . textLabel ) {
116130 vectorTx . push ( selection . textLabel ) ;
117131 }
@@ -120,27 +134,6 @@ function render(scene) {
120134 tx = selection . textLabel ;
121135 }
122136
123- if ( scene . fullSceneLayout . hovermode ) {
124- Fx . loneHover ( {
125- x : ( 0.5 + 0.5 * pdata [ 0 ] / pdata [ 3 ] ) * width ,
126- y : ( 0.5 - 0.5 * pdata [ 1 ] / pdata [ 3 ] ) * height ,
127- xLabel : xVal ,
128- yLabel : yVal ,
129- zLabel : zVal ,
130- text : tx ,
131- name : lastPicked . name ,
132- color : Fx . castHoverOption ( trace , ptNumber , 'bgcolor' ) || lastPicked . color ,
133- borderColor : Fx . castHoverOption ( trace , ptNumber , 'bordercolor' ) ,
134- fontFamily : Fx . castHoverOption ( trace , ptNumber , 'font.family' ) ,
135- fontSize : Fx . castHoverOption ( trace , ptNumber , 'font.size' ) ,
136- fontColor : Fx . castHoverOption ( trace , ptNumber , 'font.color' )
137- } , {
138- container : svgContainer ,
139- gd : scene . graphDiv
140- } ) ;
141- }
142-
143- // TODO not sure if streamtube x/y/z should be emitted as x/y/z
144137 var pointData = {
145138 x : selection . traceCoordinate [ 0 ] ,
146139 y : selection . traceCoordinate [ 1 ] ,
@@ -151,18 +144,41 @@ function render(scene) {
151144 pointNumber : ptNumber
152145 } ;
153146
147+ Fx . appendArrayPointValue ( pointData , trace , ptNumber ) ;
148+
154149 if ( trace . _module . eventData ) {
155150 pointData = trace . _module . eventData ( pointData , selection , trace , { } , ptNumber ) ;
156151 }
157152
158- Fx . appendArrayPointValue ( pointData , trace , ptNumber ) ;
159-
160153 var eventData = { points : [ pointData ] } ;
161154
155+ if ( scene . fullSceneLayout . hovermode ) {
156+ Fx . loneHover ( {
157+ trace : trace ,
158+ x : ( 0.5 + 0.5 * pdata [ 0 ] / pdata [ 3 ] ) * width ,
159+ y : ( 0.5 - 0.5 * pdata [ 1 ] / pdata [ 3 ] ) * height ,
160+ xLabel : labels . xLabel ,
161+ yLabel : labels . yLabel ,
162+ zLabel : labels . zLabel ,
163+ text : tx ,
164+ name : lastPicked . name ,
165+ color : Fx . castHoverOption ( trace , ptNumber , 'bgcolor' ) || lastPicked . color ,
166+ borderColor : Fx . castHoverOption ( trace , ptNumber , 'bordercolor' ) ,
167+ fontFamily : Fx . castHoverOption ( trace , ptNumber , 'font.family' ) ,
168+ fontSize : Fx . castHoverOption ( trace , ptNumber , 'font.size' ) ,
169+ fontColor : Fx . castHoverOption ( trace , ptNumber , 'font.color' ) ,
170+ hovertemplate : Lib . castOption ( trace , ptNumber , 'hovertemplate' ) ,
171+ hovertemplateLabels : Lib . extendFlat ( { } , pointData , labels ) ,
172+ eventData : [ pointData ]
173+ } , {
174+ container : svgContainer ,
175+ gd : scene . graphDiv
176+ } ) ;
177+ }
178+
162179 if ( selection . buttons && selection . distance < 5 ) {
163180 scene . graphDiv . emit ( 'plotly_click' , eventData ) ;
164- }
165- else {
181+ } else {
166182 scene . graphDiv . emit ( 'plotly_hover' , eventData ) ;
167183 }
168184
0 commit comments