@@ -30,19 +30,20 @@ module.exports = function draw(gd, opts) {
30
30
// Check whether this is the main legend (ie. called without any opts)
31
31
if ( ! opts ) {
32
32
opts = fullLayout . legend || { } ;
33
- opts . _isLegend = true ;
34
33
layer = fullLayout . _infolayer ;
35
34
} else {
36
35
layer = opts . layer ;
37
36
clipId += '-hover' ;
38
37
}
39
38
39
+ var inHover = ! ! opts . _inHover ;
40
+
40
41
if ( ! layer ) return ;
41
42
42
43
if ( ! gd . _legendMouseDownTime ) gd . _legendMouseDownTime = 0 ;
43
44
44
45
var legendData ;
45
- if ( opts . _isLegend ) {
46
+ if ( ! inHover ) {
46
47
if ( ! gd . calcdata ) return ;
47
48
legendData = fullLayout . showlegend && getLegendData ( gd . calcdata , opts ) ;
48
49
} else {
@@ -52,14 +53,14 @@ module.exports = function draw(gd, opts) {
52
53
53
54
var hiddenSlices = fullLayout . hiddenlabels || [ ] ;
54
55
55
- if ( opts . _isLegend && ( ! fullLayout . showlegend || ! legendData . length ) ) {
56
+ if ( ! inHover && ( ! fullLayout . showlegend || ! legendData . length ) ) {
56
57
layer . selectAll ( '.legend' ) . remove ( ) ;
57
58
fullLayout . _topdefs . select ( '#' + clipId ) . remove ( ) ;
58
59
return Plots . autoMargin ( gd , 'legend' ) ;
59
60
}
60
61
61
62
var legend = Lib . ensureSingle ( layer , 'g' , 'legend' , function ( s ) {
62
- if ( opts . _isLegend ) s . attr ( 'pointer-events' , 'all' ) ;
63
+ if ( ! inHover ) s . attr ( 'pointer-events' , 'all' ) ;
63
64
} ) ;
64
65
65
66
var clipPath = Lib . ensureSingleById ( fullLayout . _topdefs , 'clipPath' , clipId , function ( s ) {
@@ -112,7 +113,7 @@ module.exports = function draw(gd, opts) {
112
113
} )
113
114
. each ( function ( ) { d3 . select ( this ) . call ( drawTexts , gd , opts ) ; } )
114
115
. call ( style , gd , opts )
115
- . each ( function ( ) { if ( opts . _isLegend ) d3 . select ( this ) . call ( setupTraceToggle , gd ) ; } ) ;
116
+ . each ( function ( ) { if ( ! inHover ) d3 . select ( this ) . call ( setupTraceToggle , gd ) ; } ) ;
116
117
117
118
Lib . syncOrAsync ( [
118
119
Plots . previousPromises ,
@@ -121,15 +122,15 @@ module.exports = function draw(gd, opts) {
121
122
// IF expandMargin return a Promise (which is truthy),
122
123
// we're under a doAutoMargin redraw, so we don't have to
123
124
// draw the remaining pieces below
124
- if ( opts . _isLegend && expandMargin ( gd ) ) return ;
125
+ if ( ! inHover && expandMargin ( gd ) ) return ;
125
126
126
127
var gs = fullLayout . _size ;
127
128
var bw = opts . borderwidth ;
128
129
129
130
var lx = gs . l + gs . w * opts . x - FROM_TL [ getXanchor ( opts ) ] * opts . _width ;
130
131
var ly = gs . t + gs . h * ( 1 - opts . y ) - FROM_TL [ getYanchor ( opts ) ] * opts . _effHeight ;
131
132
132
- if ( opts . _isLegend && fullLayout . margin . autoexpand ) {
133
+ if ( ! inHover && fullLayout . margin . autoexpand ) {
133
134
var lx0 = lx ;
134
135
var ly0 = ly ;
135
136
@@ -146,18 +147,18 @@ module.exports = function draw(gd, opts) {
146
147
147
148
// Set size and position of all the elements that make up a legend:
148
149
// legend, background and border, scroll box and scroll bar as well as title
149
- if ( opts . _isLegend ) Drawing . setTranslate ( legend , lx , ly ) ;
150
+ if ( ! inHover ) Drawing . setTranslate ( legend , lx , ly ) ;
150
151
151
152
// to be safe, remove previous listeners
152
153
scrollBar . on ( '.drag' , null ) ;
153
154
legend . on ( 'wheel' , null ) ;
154
155
155
- if ( ! opts . _isLegend || opts . _height <= opts . _maxHeight || gd . _context . staticPlot ) {
156
+ if ( inHover || opts . _height <= opts . _maxHeight || gd . _context . staticPlot ) {
156
157
// if scrollbar should not be shown.
157
158
var height = opts . _effHeight ;
158
159
159
160
// if unified hover, let it be its full size
160
- if ( ! opts . _isLegend ) height = opts . _height ;
161
+ if ( inHover ) height = opts . _height ;
161
162
162
163
bg . attr ( {
163
164
width : opts . _width - bw ,
@@ -386,7 +387,7 @@ function drawTexts(g, gd, opts) {
386
387
var trace = legendItem . trace ;
387
388
var isPieLike = Registry . traceIs ( trace , 'pie-like' ) ;
388
389
var traceIndex = trace . index ;
389
- var isEditable = opts . _isLegend && gd . _context . edits . legendText && ! isPieLike ;
390
+ var isEditable = ! opts . _inHover && gd . _context . edits . legendText && ! isPieLike ;
390
391
var maxNameLength = opts . _maxNameLength ;
391
392
392
393
var name ;
@@ -491,15 +492,15 @@ function setupTraceToggle(g, gd) {
491
492
}
492
493
493
494
function textLayout ( s , g , gd , opts ) {
494
- if ( ! opts . _isLegend ) s . attr ( 'data-notex' , true ) ; // do not process MathJax for unified hover
495
+ if ( opts . _inHover ) s . attr ( 'data-notex' , true ) ; // do not process MathJax for unified hover
495
496
svgTextUtils . convertToTspans ( s , gd , function ( ) {
496
497
computeTextDimensions ( g , gd , opts ) ;
497
498
} ) ;
498
499
}
499
500
500
501
function computeTextDimensions ( g , gd , opts ) {
501
502
var legendItem = g . data ( ) [ 0 ] [ 0 ] ;
502
- if ( opts . _isLegend && legendItem && ! legendItem . trace . showlegend ) {
503
+ if ( ! opts . _inHover && legendItem && ! legendItem . trace . showlegend ) {
503
504
g . remove ( ) ;
504
505
return ;
505
506
}
0 commit comments