@@ -45,20 +45,7 @@ module.exports = function draw(gd) {
45
45
if ( ! fullLayout . showlegend || ! legendData . length ) {
46
46
fullLayout . _infolayer . selectAll ( '.legend' ) . remove ( ) ;
47
47
fullLayout . _topdefs . select ( '#' + clipId ) . remove ( ) ;
48
-
49
- Plots . autoMargin ( gd , 'legend' ) ;
50
- return ;
51
- }
52
-
53
- var maxLength = 0 ;
54
- for ( var i = 0 ; i < legendData . length ; i ++ ) {
55
- for ( var j = 0 ; j < legendData [ i ] . length ; j ++ ) {
56
- var item = legendData [ i ] [ j ] [ 0 ] ;
57
- var trace = item . trace ;
58
- var isPieLike = Registry . traceIs ( trace , 'pie-like' ) ;
59
- var name = isPieLike ? item . label : trace . name ;
60
- maxLength = Math . max ( maxLength , name && name . length || 0 ) ;
61
- }
48
+ return Plots . autoMargin ( gd , 'legend' ) ;
62
49
}
63
50
64
51
var legend = Lib . ensureSingle ( fullLayout . _infolayer , 'g' , 'legend' , function ( s ) {
@@ -72,7 +59,6 @@ module.exports = function draw(gd) {
72
59
var bg = Lib . ensureSingle ( legend , 'rect' , 'bg' , function ( s ) {
73
60
s . attr ( 'shape-rendering' , 'crispEdges' ) ;
74
61
} ) ;
75
-
76
62
bg . call ( Color . stroke , opts . bordercolor )
77
63
. call ( Color . fill , opts . bgcolor )
78
64
. style ( 'stroke-width' , opts . borderwidth + 'px' ) ;
@@ -89,17 +75,11 @@ module.exports = function draw(gd) {
89
75
. call ( Color . fill , '#808BA4' ) ;
90
76
} ) ;
91
77
92
- var groups = scrollBox . selectAll ( 'g.groups' )
93
- . data ( legendData ) ;
94
-
95
- groups . enter ( ) . append ( 'g' )
96
- . attr ( 'class' , 'groups' ) ;
97
-
78
+ var groups = scrollBox . selectAll ( 'g.groups' ) . data ( legendData ) ;
79
+ groups . enter ( ) . append ( 'g' ) . attr ( 'class' , 'groups' ) ;
98
80
groups . exit ( ) . remove ( ) ;
99
81
100
- var traces = groups . selectAll ( 'g.traces' )
101
- . data ( Lib . identity ) ;
102
-
82
+ var traces = groups . selectAll ( 'g.traces' ) . data ( Lib . identity ) ;
103
83
traces . enter ( ) . append ( 'g' ) . attr ( 'class' , 'traces' ) ;
104
84
traces . exit ( ) . remove ( ) ;
105
85
@@ -111,15 +91,9 @@ module.exports = function draw(gd) {
111
91
return trace . visible === 'legendonly' ? 0.5 : 1 ;
112
92
}
113
93
} )
114
- . each ( function ( ) {
115
- d3 . select ( this )
116
- . call ( drawTexts , gd , maxLength ) ;
117
- } )
94
+ . each ( function ( ) { d3 . select ( this ) . call ( drawTexts , gd ) ; } )
118
95
. call ( style , gd )
119
- . each ( function ( ) {
120
- d3 . select ( this )
121
- . call ( setupTraceToggle , gd ) ;
122
- } ) ;
96
+ . each ( function ( ) { d3 . select ( this ) . call ( setupTraceToggle , gd ) ; } ) ;
123
97
124
98
Lib . syncOrAsync ( [ Plots . previousPromises ,
125
99
function ( ) {
@@ -296,9 +270,7 @@ module.exports = function draw(gd) {
296
270
constants . scrollBarWidth ,
297
271
scrollBarHeight
298
272
) ;
299
- clipPath . select ( 'rect' ) . attr ( {
300
- y : opts . borderwidth + scrollBoxY
301
- } ) ;
273
+ clipPath . select ( 'rect' ) . attr ( 'y' , bw + scrollBoxY ) ;
302
274
}
303
275
304
276
if ( gd . _context . edits . legendPosition ) {
@@ -384,13 +356,15 @@ function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
384
356
}
385
357
}
386
358
387
- function drawTexts ( g , gd , maxLength ) {
359
+ function drawTexts ( g , gd ) {
388
360
var legendItem = g . data ( ) [ 0 ] [ 0 ] ;
389
361
var fullLayout = gd . _fullLayout ;
362
+ var opts = fullLayout . legend ;
390
363
var trace = legendItem . trace ;
391
364
var isPieLike = Registry . traceIs ( trace , 'pie-like' ) ;
392
365
var traceIndex = trace . index ;
393
366
var isEditable = gd . _context . edits . legendText && ! isPieLike ;
367
+ var maxNameLength = opts . _maxNameLength ;
394
368
395
369
var name = isPieLike ? legendItem . label : trace . name ;
396
370
if ( trace . _meta ) {
@@ -402,7 +376,7 @@ function drawTexts(g, gd, maxLength) {
402
376
textEl . attr ( 'text-anchor' , 'start' )
403
377
. classed ( 'user-select-none' , true )
404
378
. call ( Drawing . font , fullLayout . legend . font )
405
- . text ( isEditable ? ensureLength ( name , maxLength ) : name ) ;
379
+ . text ( isEditable ? ensureLength ( name , maxNameLength ) : name ) ;
406
380
407
381
svgTextUtils . positionText ( textEl , constants . textOffsetX , 0 ) ;
408
382
@@ -416,7 +390,7 @@ function drawTexts(g, gd, maxLength) {
416
390
textEl . call ( svgTextUtils . makeEditable , { gd : gd , text : name } )
417
391
. call ( textLayout )
418
392
. on ( 'edit' , function ( newName ) {
419
- this . text ( ensureLength ( newName , maxLength ) )
393
+ this . text ( ensureLength ( newName , maxNameLength ) )
420
394
. call ( textLayout ) ;
421
395
422
396
var fullInput = legendItem . trace . _fullInput || { } ;
0 commit comments