@@ -71,18 +71,21 @@ function render(scene) {
71
71
var pdata = project ( scene . glplot . cameraParams , selection . dataCoordinate ) ;
72
72
trace = lastPicked . data ;
73
73
var ptNumber = selection . index ;
74
- var hoverinfo = Fx . castHoverinfo ( trace , scene . fullLayout , ptNumber ) ;
75
- var hoverinfoParts = hoverinfo . split ( '+' ) ;
76
- var isHoverinfoAll = hoverinfo === 'all' ;
77
74
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' ;
81
84
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 ;
86
89
if ( hoverinfoParts . indexOf ( 'text' ) === - 1 ) selection . textLabel = undefined ;
87
90
if ( hoverinfoParts . indexOf ( 'name' ) === - 1 ) lastPicked . name = undefined ;
88
91
}
@@ -91,27 +94,38 @@ function render(scene) {
91
94
var vectorTx = [ ] ;
92
95
93
96
if ( trace . type === 'cone' || trace . type === 'streamtube' ) {
97
+ labels . uLabel = formatter ( 'xaxis' , selection . traceCoordinate [ 3 ] ) ;
94
98
if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'u' ) !== - 1 ) {
95
- vectorTx . push ( 'u: ' + formatter ( 'xaxis' , selection . traceCoordinate [ 3 ] ) ) ;
99
+ vectorTx . push ( 'u: ' + labels . uLabel ) ;
96
100
}
101
+
102
+ labels . vLabel = formatter ( 'yaxis' , selection . traceCoordinate [ 4 ] ) ;
97
103
if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'v' ) !== - 1 ) {
98
- vectorTx . push ( 'v: ' + formatter ( 'yaxis' , selection . traceCoordinate [ 4 ] ) ) ;
104
+ vectorTx . push ( 'v: ' + labels . vLabel ) ;
99
105
}
106
+
107
+ labels . wLabel = formatter ( 'zaxis' , selection . traceCoordinate [ 5 ] ) ;
100
108
if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'w' ) !== - 1 ) {
101
- vectorTx . push ( 'w: ' + formatter ( 'zaxis' , selection . traceCoordinate [ 5 ] ) ) ;
109
+ vectorTx . push ( 'w: ' + labels . wLabel ) ;
102
110
}
111
+
112
+ labels . normLabel = selection . traceCoordinate [ 6 ] . toPrecision ( 3 ) ;
103
113
if ( isHoverinfoAll || hoverinfoParts . indexOf ( 'norm' ) !== - 1 ) {
104
- vectorTx . push ( 'norm: ' + selection . traceCoordinate [ 6 ] . toPrecision ( 3 ) ) ;
114
+ vectorTx . push ( 'norm: ' + labels . normLabel ) ;
105
115
}
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
+ }
108
121
}
109
122
if ( selection . textLabel ) {
110
123
vectorTx . push ( selection . textLabel ) ;
111
124
}
112
125
tx = vectorTx . join ( '<br>' ) ;
113
126
} 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 ) ;
115
129
if ( selection . textLabel ) {
116
130
vectorTx . push ( selection . textLabel ) ;
117
131
}
@@ -120,27 +134,6 @@ function render(scene) {
120
134
tx = selection . textLabel ;
121
135
}
122
136
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
144
137
var pointData = {
145
138
x : selection . traceCoordinate [ 0 ] ,
146
139
y : selection . traceCoordinate [ 1 ] ,
@@ -151,18 +144,41 @@ function render(scene) {
151
144
pointNumber : ptNumber
152
145
} ;
153
146
147
+ Fx . appendArrayPointValue ( pointData , trace , ptNumber ) ;
148
+
154
149
if ( trace . _module . eventData ) {
155
150
pointData = trace . _module . eventData ( pointData , selection , trace , { } , ptNumber ) ;
156
151
}
157
152
158
- Fx . appendArrayPointValue ( pointData , trace , ptNumber ) ;
159
-
160
153
var eventData = { points : [ pointData ] } ;
161
154
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
+
162
179
if ( selection . buttons && selection . distance < 5 ) {
163
180
scene . graphDiv . emit ( 'plotly_click' , eventData ) ;
164
- }
165
- else {
181
+ } else {
166
182
scene . graphDiv . emit ( 'plotly_hover' , eventData ) ;
167
183
}
168
184
0 commit comments