Skip to content

Granular options for on-chart editing #1895

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 4 commits into from
Jul 19, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 25 additions & 57 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,15 @@ function computeTextDimensions(g, gd) {
}

function computeLegendDimensions(gd, groups, traces) {
var fullLayout = gd._fullLayout,
opts = fullLayout.legend,
borderwidth = opts.borderwidth,
isGrouped = helpers.isGrouped(opts);
var fullLayout = gd._fullLayout;
var opts = fullLayout.legend;
var borderwidth = opts.borderwidth;
var isGrouped = helpers.isGrouped(opts);

var extraWidth = 0;

opts.width = 0;
opts.height = 0;

if(helpers.isVertical(opts)) {
if(isGrouped) {
Expand All @@ -609,9 +614,6 @@ function computeLegendDimensions(gd, groups, traces) {
});
}

opts.width = 0;
opts.height = 0;

traces.each(function(d) {
var legendItem = d[0],
textHeight = legendItem.height,
Expand All @@ -632,26 +634,9 @@ function computeLegendDimensions(gd, groups, traces) {
opts.height += (opts._lgroupsLength - 1) * opts.tracegroupgap;
}

// make sure we're only getting full pixels
opts.width = Math.ceil(opts.width);
opts.height = Math.ceil(opts.height);

traces.each(function(d) {
var legendItem = d[0],
bg = d3.select(this).select('.legendtoggle');

bg.call(Drawing.setRect,
0,
-legendItem.height / 2,
(gd._context.editable ? 0 : opts.width) + 40,
legendItem.height
);
});
extraWidth = 40;
}
else if(isGrouped) {
opts.width = 0;
opts.height = 0;

var groupXOffsets = [opts.width],
groupData = groups.data();

Expand Down Expand Up @@ -692,26 +677,8 @@ function computeLegendDimensions(gd, groups, traces) {

opts.height += 10 + borderwidth * 2;
opts.width += borderwidth * 2;

// make sure we're only getting full pixels
opts.width = Math.ceil(opts.width);
opts.height = Math.ceil(opts.height);

traces.each(function(d) {
var legendItem = d[0],
bg = d3.select(this).select('.legendtoggle');

bg.call(Drawing.setRect,
0,
-legendItem.height / 2,
(gd._context.editable ? 0 : opts.width),
legendItem.height
);
});
}
else {
opts.width = 0;
opts.height = 0;
var rowHeight = 0,
maxTraceHeight = 0,
maxTraceWidth = 0,
Expand Down Expand Up @@ -750,22 +717,23 @@ function computeLegendDimensions(gd, groups, traces) {
opts.width += borderwidth * 2;
opts.height += 10 + borderwidth * 2;

// make sure we're only getting full pixels
opts.width = Math.ceil(opts.width);
opts.height = Math.ceil(opts.height);
}

traces.each(function(d) {
var legendItem = d[0],
bg = d3.select(this).select('.legendtoggle');
// make sure we're only getting full pixels
opts.width = Math.ceil(opts.width);
opts.height = Math.ceil(opts.height);

bg.call(Drawing.setRect,
0,
-legendItem.height / 2,
(gd._context.editable ? 0 : opts.width),
legendItem.height
);
});
}
traces.each(function(d) {
var legendItem = d[0],
bg = d3.select(this).select('.legendtoggle');

bg.call(Drawing.setRect,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely commit 🎉

0,
-legendItem.height / 2,
(gd._context.editable ? 0 : opts.width) + extraWidth,
legendItem.height
);
});
}

function expandMargin(gd) {
Expand Down