@@ -30,8 +30,8 @@ module.exports = function draw(gd, opts) {
30
30
} else {
31
31
var legends = gd . _fullLayout . _legends ;
32
32
for ( var i = 0 ; i < legends . length ; i ++ ) {
33
- var id = legends [ i ] ;
34
- var legendObj = gd . _fullLayout [ 'legend' + ( id > 1 ? id : '' ) ] ;
33
+ var legendId = legends [ i ] ;
34
+ var legendObj = gd . _fullLayout [ legendId ] ;
35
35
drawOne ( gd , legendObj ) ;
36
36
}
37
37
}
@@ -41,7 +41,7 @@ function drawOne(gd, opts) {
41
41
var legendObj = opts || { } ;
42
42
43
43
var fullLayout = gd . _fullLayout ;
44
- var id = getId ( legendObj ) ;
44
+ var legendId = getId ( legendObj ) ;
45
45
46
46
var clipId , layer ;
47
47
@@ -51,7 +51,7 @@ function drawOne(gd, opts) {
51
51
clipId = 'hover' ;
52
52
} else {
53
53
layer = fullLayout . _infolayer ;
54
- clipId = 'legend' + id ;
54
+ clipId = legendId ;
55
55
}
56
56
if ( ! layer ) return ;
57
57
clipId += fullLayout . _uid ;
@@ -70,12 +70,12 @@ function drawOne(gd, opts) {
70
70
var hiddenSlices = fullLayout . hiddenlabels || [ ] ;
71
71
72
72
if ( ! inHover && ( ! fullLayout . showlegend || ! legendData . length ) ) {
73
- layer . selectAll ( '.legend ' + id ) . remove ( ) ;
73
+ layer . selectAll ( '.' + legendId ) . remove ( ) ;
74
74
fullLayout . _topdefs . select ( '#' + clipId ) . remove ( ) ;
75
- return Plots . autoMargin ( gd , 'legend' + id ) ;
75
+ return Plots . autoMargin ( gd , legendId ) ;
76
76
}
77
77
78
- var legend = Lib . ensureSingle ( layer , 'g' , 'legend' + id , function ( s ) {
78
+ var legend = Lib . ensureSingle ( layer , 'g' , legendId , function ( s ) {
79
79
if ( ! inHover ) s . attr ( 'pointer-events' , 'all' ) ;
80
80
} ) ;
81
81
@@ -96,14 +96,14 @@ function drawOne(gd, opts) {
96
96
legendObj . _titleWidth = 0 ;
97
97
legendObj . _titleHeight = 0 ;
98
98
if ( title . text ) {
99
- var titleEl = Lib . ensureSingle ( scrollBox , 'text' , 'legend' + id + 'titletext' ) ;
99
+ var titleEl = Lib . ensureSingle ( scrollBox , 'text' , legendId + 'titletext' ) ;
100
100
titleEl . attr ( 'text-anchor' , 'start' )
101
101
. call ( Drawing . font , title . font )
102
102
. text ( title . text ) ;
103
103
104
104
textLayout ( titleEl , scrollBox , gd , legendObj , MAIN_TITLE ) ; // handle mathjax or multi-line text and compute title height
105
105
} else {
106
- scrollBox . selectAll ( '.legend ' + id + 'titletext' ) . remove ( ) ;
106
+ scrollBox . selectAll ( '.' + legendId + 'titletext' ) . remove ( ) ;
107
107
}
108
108
109
109
var scrollBar = Lib . ensureSingle ( legend , 'rect' , 'scrollbar' , function ( s ) {
@@ -129,7 +129,7 @@ function drawOne(gd, opts) {
129
129
} )
130
130
. each ( function ( ) { d3 . select ( this ) . call ( drawTexts , gd , legendObj ) ; } )
131
131
. call ( style , gd , legendObj )
132
- . each ( function ( ) { if ( ! inHover ) d3 . select ( this ) . call ( setupTraceToggle , gd , id ) ; } ) ;
132
+ . each ( function ( ) { if ( ! inHover ) d3 . select ( this ) . call ( setupTraceToggle , gd , legendId ) ; } ) ;
133
133
134
134
Lib . syncOrAsync ( [
135
135
Plots . previousPromises ,
@@ -139,7 +139,7 @@ function drawOne(gd, opts) {
139
139
var bw = legendObj . borderwidth ;
140
140
141
141
if ( ! inHover ) {
142
- var expMargin = expandMargin ( gd , id ) ;
142
+ var expMargin = expandMargin ( gd , legendId ) ;
143
143
144
144
// IF expandMargin return a Promise (which is truthy),
145
145
// we're under a doAutoMargin redraw, so we don't have to
@@ -157,10 +157,10 @@ function drawOne(gd, opts) {
157
157
ly = Lib . constrain ( ly , 0 , fullLayout . height - legendObj . _effHeight ) ;
158
158
159
159
if ( lx !== lx0 ) {
160
- Lib . log ( 'Constrain legend ' + id + '.x to make legend fit inside graph' ) ;
160
+ Lib . log ( 'Constrain ' + legendId + '.x to make legend fit inside graph' ) ;
161
161
}
162
162
if ( ly !== ly0 ) {
163
- Lib . log ( 'Constrain legend ' + id + '.y to make legend fit inside graph' ) ;
163
+ Lib . log ( 'Constrain ' + legendId + '.y to make legend fit inside graph' ) ;
164
164
}
165
165
}
166
166
@@ -306,7 +306,7 @@ function drawOne(gd, opts) {
306
306
}
307
307
308
308
function scrollHandler ( scrollBoxY , scrollBarHeight , scrollRatio ) {
309
- legendObj . _scrollY = gd . _fullLayout [ 'legend' + id ] . _scrollY = scrollBoxY ;
309
+ legendObj . _scrollY = gd . _fullLayout [ legendId ] . _scrollY = scrollBoxY ;
310
310
Drawing . setTranslate ( scrollBox , 0 , - scrollBoxY ) ;
311
311
312
312
Drawing . setRect (
@@ -343,8 +343,8 @@ function drawOne(gd, opts) {
343
343
doneFn : function ( ) {
344
344
if ( xf !== undefined && yf !== undefined ) {
345
345
var obj = { } ;
346
- obj [ 'legend' + id + '.x' ] = xf ;
347
- obj [ 'legend' + id + '.y' ] = yf ;
346
+ obj [ legendId + '.x' ] = xf ;
347
+ obj [ legendId + '.y' ] = yf ;
348
348
Registry . call ( '_guiRelayout' , gd , obj ) ;
349
349
}
350
350
} ,
@@ -417,7 +417,7 @@ function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
417
417
}
418
418
419
419
function drawTexts ( g , gd , legendObj ) {
420
- var id = getId ( legendObj ) ;
420
+ var legendId = getId ( legendObj ) ;
421
421
var legendItem = g . data ( ) [ 0 ] [ 0 ] ;
422
422
var trace = legendItem . trace ;
423
423
var isPieLike = Registry . traceIs ( trace , 'pie-like' ) ;
@@ -440,7 +440,7 @@ function drawTexts(g, gd, legendObj) {
440
440
}
441
441
}
442
442
443
- var textEl = Lib . ensureSingle ( g , 'text' , 'legend' + id + 'text' ) ;
443
+ var textEl = Lib . ensureSingle ( g , 'text' , legendId + 'text' ) ;
444
444
445
445
textEl . attr ( 'text-anchor' , 'start' )
446
446
. call ( Drawing . font , font )
@@ -494,12 +494,12 @@ function ensureLength(str, maxLength) {
494
494
return str ;
495
495
}
496
496
497
- function setupTraceToggle ( g , gd , id ) {
497
+ function setupTraceToggle ( g , gd , legendId ) {
498
498
var doubleClickDelay = gd . _context . doubleClickDelay ;
499
499
var newMouseDownTime ;
500
500
var numClicks = 1 ;
501
501
502
- var traceToggle = Lib . ensureSingle ( g , 'rect' , 'legend' + id + 'toggle' , function ( s ) {
502
+ var traceToggle = Lib . ensureSingle ( g , 'rect' , legendId + 'toggle' , function ( s ) {
503
503
if ( ! gd . _context . staticPlot ) {
504
504
s . style ( 'cursor' , 'pointer' ) . attr ( 'pointer-events' , 'all' ) ;
505
505
}
@@ -521,7 +521,7 @@ function setupTraceToggle(g, gd, id) {
521
521
} ) ;
522
522
traceToggle . on ( 'mouseup' , function ( ) {
523
523
if ( gd . _dragged || gd . _editing ) return ;
524
- var legend = gd . _fullLayout [ 'legend' + id ] ;
524
+ var legend = gd . _fullLayout [ legendId ] ;
525
525
526
526
if ( ( new Date ( ) ) . getTime ( ) - gd . _legendMouseDownTime > doubleClickDelay ) {
527
527
numClicks = Math . max ( numClicks - 1 , 1 ) ;
@@ -548,9 +548,9 @@ function computeTextDimensions(g, gd, legendObj, aTitle) {
548
548
var mathjaxGroup = g . select ( 'g[class*=math-group]' ) ;
549
549
var mathjaxNode = mathjaxGroup . node ( ) ;
550
550
551
- var id = getId ( legendObj ) ;
551
+ var legendId = getId ( legendObj ) ;
552
552
if ( ! legendObj ) {
553
- legendObj = gd . _fullLayout [ 'legend' + id ] ;
553
+ legendObj = gd . _fullLayout [ legendId ] ;
554
554
}
555
555
var bw = legendObj . borderwidth ;
556
556
var font ;
@@ -576,7 +576,7 @@ function computeTextDimensions(g, gd, legendObj, aTitle) {
576
576
Drawing . setTranslate ( mathjaxGroup , 0 , height * 0.25 ) ;
577
577
}
578
578
} else {
579
- var cls = '.legend ' + id + (
579
+ var cls = '.' + legendId + (
580
580
aTitle === MAIN_TITLE ? 'title' : ''
581
581
) + 'text' ;
582
582
@@ -642,7 +642,7 @@ function getTitleSize(legendObj) {
642
642
}
643
643
644
644
/*
645
- * Computes in fullLayout['legend' + id ]:
645
+ * Computes in fullLayout[legendId ]:
646
646
*
647
647
* - _height: legend height including items past scrollbox height
648
648
* - _maxHeight: maximum legend height before scrollbox is required
@@ -653,9 +653,9 @@ function getTitleSize(legendObj) {
653
653
*/
654
654
function computeLegendDimensions ( gd , groups , traces , legendObj ) {
655
655
var fullLayout = gd . _fullLayout ;
656
- var id = getId ( legendObj ) ;
656
+ var legendId = getId ( legendObj ) ;
657
657
if ( ! legendObj ) {
658
- legendObj = fullLayout [ 'legend' + id ] ;
658
+ legendObj = fullLayout [ legendId ] ;
659
659
}
660
660
var gs = fullLayout . _size ;
661
661
@@ -844,7 +844,7 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
844
844
var edits = gd . _context . edits ;
845
845
var isEditable = edits . legendText || edits . legendPosition ;
846
846
traces . each ( function ( d ) {
847
- var traceToggle = d3 . select ( this ) . select ( '.legend ' + id + 'toggle' ) ;
847
+ var traceToggle = d3 . select ( this ) . select ( '.' + legendId + 'toggle' ) ;
848
848
var h = d [ 0 ] . height ;
849
849
var legendgroup = d [ 0 ] . trace . legendgroup ;
850
850
var traceWidth = getTraceWidth ( d , legendObj , textGap ) ;
@@ -859,13 +859,13 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
859
859
} ) ;
860
860
}
861
861
862
- function expandMargin ( gd , id ) {
862
+ function expandMargin ( gd , legendId ) {
863
863
var fullLayout = gd . _fullLayout ;
864
- var legendObj = fullLayout [ 'legend' + id ] ;
864
+ var legendObj = fullLayout [ legendId ] ;
865
865
var xanchor = getXanchor ( legendObj ) ;
866
866
var yanchor = getYanchor ( legendObj ) ;
867
867
868
- return Plots . autoMargin ( gd , 'legend' + id , {
868
+ return Plots . autoMargin ( gd , legendId , {
869
869
x : legendObj . x ,
870
870
y : legendObj . y ,
871
871
l : legendObj . _width * ( FROM_TL [ xanchor ] ) ,
@@ -888,6 +888,5 @@ function getYanchor(legendObj) {
888
888
}
889
889
890
890
function getId ( legendObj ) {
891
- var id = legendObj . _id ;
892
- return id > 1 ? id : '' ;
891
+ return legendObj . _id || 'legend' ;
893
892
}
0 commit comments