Skip to content

Commit c0dfc8a

Browse files
committed
Legend: move placing of groups and traces together
* Moved the placing of legend groups to `computeLegendDimensions` so that they are handled along with the placing of legend traces. * This change is a preliminary step to implement horizontal legends. * Checked all jasmine and image tests still pass.
1 parent f68344b commit c0dfc8a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/components/legend/draw.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ module.exports = function draw(gd) {
101101

102102
groups.exit().remove();
103103

104-
if(helpers.isGrouped(opts)) {
105-
groups.attr('transform', function(d, i) {
106-
return 'translate(0,' + i * opts.tracegroupgap + ')';
107-
});
108-
}
109-
110104
var traces = groups.selectAll('g.traces')
111105
.data(Lib.identity);
112106

@@ -128,15 +122,15 @@ module.exports = function draw(gd) {
128122
});
129123

130124
if(gd.firstRender) {
131-
computeLegendDimensions(gd, traces);
125+
computeLegendDimensions(gd, groups, traces);
132126
expandMargin(gd);
133127
}
134128

135129
// Position and size the legend
136130
var lyMin = 0,
137131
lyMax = fullLayout.height;
138132

139-
computeLegendDimensions(gd, traces);
133+
computeLegendDimensions(gd, groups, traces);
140134

141135
if(opts.height > lyMax) {
142136
// If the legend doesn't fit in the plot area,
@@ -453,11 +447,17 @@ function computeTextDimensions(gd, container, legendItem) {
453447
legendItem.width = width;
454448
}
455449

456-
function computeLegendDimensions(gd, traces) {
450+
function computeLegendDimensions(gd, groups, traces) {
457451
var fullLayout = gd._fullLayout,
458452
opts = fullLayout.legend,
459453
borderwidth = opts.borderwidth;
460454

455+
if(helpers.isGrouped(opts)) {
456+
groups.attr('transform', function(d, i) {
457+
return 'translate(0,' + i * opts.tracegroupgap + ')';
458+
});
459+
}
460+
461461
opts.width = 0;
462462
opts.height = 0;
463463

0 commit comments

Comments
 (0)