@@ -22,7 +22,10 @@ var handleClick = require('./handle_click');
22
22
23
23
var constants = require ( './constants' ) ;
24
24
var interactConstants = require ( '../../constants/interactions' ) ;
25
- var LINE_SPACING = require ( '../../constants/alignment' ) . LINE_SPACING ;
25
+ var alignmentConstants = require ( '../../constants/alignment' ) ;
26
+ var LINE_SPACING = alignmentConstants . LINE_SPACING ;
27
+ var FROM_TL = alignmentConstants . FROM_TL ;
28
+ var FROM_BR = alignmentConstants . FROM_BR ;
26
29
27
30
var getLegendData = require ( './get_legend_data' ) ;
28
31
var style = require ( './style' ) ;
@@ -141,7 +144,7 @@ module.exports = function draw(gd) {
141
144
142
145
computeLegendDimensions ( gd , groups , traces ) ;
143
146
144
- if ( opts . height > lyMax ) {
147
+ if ( opts . _height > lyMax ) {
145
148
// If the legend doesn't fit in the plot area,
146
149
// do not expand the vertical margins.
147
150
expandHorizontalMargin ( gd ) ;
@@ -157,21 +160,21 @@ module.exports = function draw(gd) {
157
160
ly = gs . t + gs . h * ( 1 - opts . y ) ;
158
161
159
162
if ( anchorUtils . isRightAnchor ( opts ) ) {
160
- lx -= opts . width ;
163
+ lx -= opts . _width ;
161
164
}
162
165
else if ( anchorUtils . isCenterAnchor ( opts ) ) {
163
- lx -= opts . width / 2 ;
166
+ lx -= opts . _width / 2 ;
164
167
}
165
168
166
169
if ( anchorUtils . isBottomAnchor ( opts ) ) {
167
- ly -= opts . height ;
170
+ ly -= opts . _height ;
168
171
}
169
172
else if ( anchorUtils . isMiddleAnchor ( opts ) ) {
170
- ly -= opts . height / 2 ;
173
+ ly -= opts . _height / 2 ;
171
174
}
172
175
173
176
// Make sure the legend left and right sides are visible
174
- var legendWidth = opts . width ,
177
+ var legendWidth = opts . _width ,
175
178
legendWidthMax = gs . w ;
176
179
177
180
if ( legendWidth > legendWidthMax ) {
@@ -181,13 +184,13 @@ module.exports = function draw(gd) {
181
184
else {
182
185
if ( lx + legendWidth > lxMax ) lx = lxMax - legendWidth ;
183
186
if ( lx < lxMin ) lx = lxMin ;
184
- legendWidth = Math . min ( lxMax - lx , opts . width ) ;
187
+ legendWidth = Math . min ( lxMax - lx , opts . _width ) ;
185
188
}
186
189
187
190
// Make sure the legend top and bottom are visible
188
191
// (legends with a scroll bar are not allowed to stretch beyond the extended
189
192
// margins)
190
- var legendHeight = opts . height ,
193
+ var legendHeight = opts . _height ,
191
194
legendHeightMax = gs . h ;
192
195
193
196
if ( legendHeight > legendHeightMax ) {
@@ -197,7 +200,7 @@ module.exports = function draw(gd) {
197
200
else {
198
201
if ( ly + legendHeight > lyMax ) ly = lyMax - legendHeight ;
199
202
if ( ly < lyMin ) ly = lyMin ;
200
- legendHeight = Math . min ( lyMax - ly , opts . height ) ;
203
+ legendHeight = Math . min ( lyMax - ly , opts . _height ) ;
201
204
}
202
205
203
206
// Set size and position of all the elements that make up a legend:
@@ -207,11 +210,11 @@ module.exports = function draw(gd) {
207
210
var scrollBarYMax = legendHeight -
208
211
constants . scrollBarHeight -
209
212
2 * constants . scrollBarMargin ,
210
- scrollBoxYMax = opts . height - legendHeight ,
213
+ scrollBoxYMax = opts . _height - legendHeight ,
211
214
scrollBarY ,
212
215
scrollBoxY ;
213
216
214
- if ( opts . height <= legendHeight || gd . _context . staticPlot ) {
217
+ if ( opts . _height <= legendHeight || gd . _context . staticPlot ) {
215
218
// if scrollbar should not be shown.
216
219
bg . attr ( {
217
220
width : legendWidth - opts . borderwidth ,
@@ -533,8 +536,8 @@ function computeLegendDimensions(gd, groups, traces) {
533
536
534
537
var extraWidth = 0 ;
535
538
536
- opts . width = 0 ;
537
- opts . height = 0 ;
539
+ opts . _width = 0 ;
540
+ opts . _height = 0 ;
538
541
539
542
if ( helpers . isVertical ( opts ) ) {
540
543
if ( isGrouped ) {
@@ -550,23 +553,23 @@ function computeLegendDimensions(gd, groups, traces) {
550
553
551
554
Drawing . setTranslate ( this ,
552
555
borderwidth ,
553
- ( 5 + borderwidth + opts . height + textHeight / 2 ) ) ;
556
+ ( 5 + borderwidth + opts . _height + textHeight / 2 ) ) ;
554
557
555
- opts . height += textHeight ;
556
- opts . width = Math . max ( opts . width , textWidth ) ;
558
+ opts . _height += textHeight ;
559
+ opts . _width = Math . max ( opts . _width , textWidth ) ;
557
560
} ) ;
558
561
559
- opts . width += 45 + borderwidth * 2 ;
560
- opts . height += 10 + borderwidth * 2 ;
562
+ opts . _width += 45 + borderwidth * 2 ;
563
+ opts . _height += 10 + borderwidth * 2 ;
561
564
562
565
if ( isGrouped ) {
563
- opts . height += ( opts . _lgroupsLength - 1 ) * opts . tracegroupgap ;
566
+ opts . _height += ( opts . _lgroupsLength - 1 ) * opts . tracegroupgap ;
564
567
}
565
568
566
569
extraWidth = 40 ;
567
570
}
568
571
else if ( isGrouped ) {
569
- var groupXOffsets = [ opts . width ] ,
572
+ var groupXOffsets = [ opts . _width ] ,
570
573
groupData = groups . data ( ) ;
571
574
572
575
for ( var i = 0 , n = groupData . length ; i < n ; i ++ ) {
@@ -576,9 +579,9 @@ function computeLegendDimensions(gd, groups, traces) {
576
579
577
580
var groupWidth = 40 + Math . max . apply ( null , textWidths ) ;
578
581
579
- opts . width += opts . tracegroupgap + groupWidth ;
582
+ opts . _width += opts . tracegroupgap + groupWidth ;
580
583
581
- groupXOffsets . push ( opts . width ) ;
584
+ groupXOffsets . push ( opts . _width ) ;
582
585
}
583
586
584
587
groups . each ( function ( d , i ) {
@@ -601,11 +604,11 @@ function computeLegendDimensions(gd, groups, traces) {
601
604
groupHeight += textHeight ;
602
605
} ) ;
603
606
604
- opts . height = Math . max ( opts . height , groupHeight ) ;
607
+ opts . _height = Math . max ( opts . _height , groupHeight ) ;
605
608
} ) ;
606
609
607
- opts . height += 10 + borderwidth * 2 ;
608
- opts . width += borderwidth * 2 ;
610
+ opts . _height += 10 + borderwidth * 2 ;
611
+ opts . _width += borderwidth * 2 ;
609
612
}
610
613
else {
611
614
var rowHeight = 0 ,
@@ -631,7 +634,7 @@ function computeLegendDimensions(gd, groups, traces) {
631
634
if ( ( borderwidth + offsetX + traceGap + traceWidth ) > ( fullLayout . width - ( fullLayout . margin . r + fullLayout . margin . l ) ) ) {
632
635
offsetX = 0 ;
633
636
rowHeight = rowHeight + maxTraceHeight ;
634
- opts . height = opts . height + maxTraceHeight ;
637
+ opts . _height = opts . _height + maxTraceHeight ;
635
638
// reset for next row
636
639
maxTraceHeight = 0 ;
637
640
}
@@ -640,22 +643,22 @@ function computeLegendDimensions(gd, groups, traces) {
640
643
( borderwidth + offsetX ) ,
641
644
( 5 + borderwidth + legendItem . height / 2 ) + rowHeight ) ;
642
645
643
- opts . width += traceGap + traceWidth ;
644
- opts . height = Math . max ( opts . height , legendItem . height ) ;
646
+ opts . _width += traceGap + traceWidth ;
647
+ opts . _height = Math . max ( opts . _height , legendItem . height ) ;
645
648
646
649
// keep track of tallest trace in group
647
650
offsetX += traceGap + traceWidth ;
648
651
maxTraceHeight = Math . max ( legendItem . height , maxTraceHeight ) ;
649
652
} ) ;
650
653
651
- opts . width += borderwidth * 2 ;
652
- opts . height += 10 + borderwidth * 2 ;
654
+ opts . _width += borderwidth * 2 ;
655
+ opts . _height += 10 + borderwidth * 2 ;
653
656
654
657
}
655
658
656
659
// make sure we're only getting full pixels
657
- opts . width = Math . ceil ( opts . width ) ;
658
- opts . height = Math . ceil ( opts . height ) ;
660
+ opts . _width = Math . ceil ( opts . _width ) ;
661
+ opts . _height = Math . ceil ( opts . _height ) ;
659
662
660
663
traces . each ( function ( d ) {
661
664
var legendItem = d [ 0 ] ,
@@ -664,7 +667,7 @@ function computeLegendDimensions(gd, groups, traces) {
664
667
bg . call ( Drawing . setRect ,
665
668
0 ,
666
669
- legendItem . height / 2 ,
667
- ( gd . _context . edits . legendText ? 0 : opts . width ) + extraWidth ,
670
+ ( gd . _context . edits . legendText ? 0 : opts . _width ) + extraWidth ,
668
671
legendItem . height
669
672
) ;
670
673
} ) ;
@@ -694,10 +697,10 @@ function expandMargin(gd) {
694
697
Plots . autoMargin ( gd , 'legend' , {
695
698
x : opts . x ,
696
699
y : opts . y ,
697
- l : opts . width * ( { right : 1 , center : 0.5 } [ xanchor ] || 0 ) ,
698
- r : opts . width * ( { left : 1 , center : 0.5 } [ xanchor ] || 0 ) ,
699
- b : opts . height * ( { top : 1 , middle : 0.5 } [ yanchor ] || 0 ) ,
700
- t : opts . height * ( { bottom : 1 , middle : 0.5 } [ yanchor ] || 0 )
700
+ l : opts . _width * ( FROM_TL [ xanchor ] ) ,
701
+ r : opts . _width * ( FROM_BR [ xanchor ] ) ,
702
+ b : opts . _height * ( FROM_BR [ yanchor ] ) ,
703
+ t : opts . _height * ( FROM_TL [ yanchor ] )
701
704
} ) ;
702
705
}
703
706
@@ -717,8 +720,8 @@ function expandHorizontalMargin(gd) {
717
720
Plots . autoMargin ( gd , 'legend' , {
718
721
x : opts . x ,
719
722
y : 0.5 ,
720
- l : opts . width * ( { right : 1 , center : 0.5 } [ xanchor ] || 0 ) ,
721
- r : opts . width * ( { left : 1 , center : 0.5 } [ xanchor ] || 0 ) ,
723
+ l : opts . _width * ( FROM_TL [ xanchor ] ) ,
724
+ r : opts . _width * ( FROM_BR [ xanchor ] ) ,
722
725
b : 0 ,
723
726
t : 0
724
727
} ) ;
0 commit comments