Skip to content

Horizontal legend traces wrap to new lines #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 2, 2016
28 changes: 25 additions & 3 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,18 +568,40 @@ function computeLegendDimensions(gd, groups, traces) {
else {
opts.width = 0;
opts.height = 0;
var rowHeight = 0,
maxTraceHeight = 0,
maxTraceWidth = 0,
offsetX = 0;

//calculate largest width for traces and use for width of all legend items
traces.each(function(d) {
maxTraceWidth = Math.max(40 + d[0].width, maxTraceWidth);
});

traces.each(function(d) {

var legendItem = d[0],
traceWidth = 40 + legendItem.width,
traceWidth = maxTraceWidth,
traceGap = opts.tracegroupgap || 5;

if((borderwidth + offsetX + traceGap + traceWidth) > (fullLayout.width - (fullLayout.margin.r + fullLayout.margin.l))) {
offsetX = 0;
rowHeight = rowHeight + maxTraceHeight;
opts.height = opts.height + maxTraceHeight;
//reset for next row
maxTraceHeight = 0;
}

Lib.setTranslate(this,
(borderwidth + opts.width),
(5 + borderwidth + legendItem.height / 2));
(borderwidth + offsetX),
(5 + borderwidth + legendItem.height / 2) + rowHeight);

opts.width += traceGap + traceWidth;
opts.height = Math.max(opts.height, legendItem.height);

//keep track of tallest trace in group
offsetX += traceGap + traceWidth;
maxTraceHeight = Math.max(legendItem.height, maxTraceHeight);
});

opts.width += borderwidth * 2;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading