Skip to content

Add ability to rename grouped traces #1919

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 19 commits into from
Aug 15, 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
15 changes: 1 addition & 14 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ function drawTexts(g, gd) {

var transforms, direction;
var fullInput = legendItem.trace._fullInput || {};
var needsRedraw = false;
var update = {};

// N.B. this block isn't super clean,
Expand All @@ -419,7 +418,6 @@ function drawTexts(g, gd) {

if(BLANK_STRING_REGEX.test(origText)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, there is a use case for a blank name - maybe less so for groupby than for regular traces, but sometimes you want the title for one trace to stand in for a few traces below it. You could argue then that this should just be testing for an actual empty string '' but a space ' ' should be allowed as the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I could just check === '' instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

carr.remove(legendItem.trace._group);
needsRedraw = true;
} else {
carr.set(legendItem.trace._group, text);
}
Expand All @@ -429,18 +427,7 @@ function drawTexts(g, gd) {
update.name = text;
}

var p = Plotly.restyle(gd, update, traceIndex);

// If a groupby label is deleted, it seems like we need another redraw in order
// to restore the label. Otherwise it simply sets this property and the blank
// string is retained.
if(needsRedraw) {
p = p.then(function() {
return Plotly.redraw(gd);
});
}

return p;
return Plotly.restyle(gd, update, traceIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

fun 👍

});
}
else text.call(textLayout);
Expand Down