Skip to content

Unique colors for expanded traces #1830

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 8 commits into from
Jul 10, 2017
Merged

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Jun 28, 2017

This PR clears color defaults between supplyDefault passes so that expanded traces get unique colors.

@rreusser rreusser changed the title [Failing test] Unique colors for expanded traces Unique colors for expanded traces Jun 30, 2017
@rreusser
Copy link
Contributor Author

@etpinard @alexcjohnson I implemented this as discussed. It turned out to be pretty simple, but these things usually have unintended consequences, so glad to get feedback if I'm missing any caveats. I've added an image test and a supplyDefaults test, though maybe that's a bit redundant.


if(!trace || !trace._module) continue;

PlotSchema.crawl(trace._module.attributes, locateExpandedTraceAttrs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be worthwhile to cache colorAttrs in _module so we don't need to crawl the schema with every supplyDefaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Will do.

@rreusser
Copy link
Contributor Author

Current status: Lots of test failures due to subtle color changes. Debugging the source to determine whether desired or not.

@etpinard etpinard added this to the 1.29.0 milestone Jun 30, 2017
@@ -0,0 +1,30 @@
var Plots = require('@src/plots/plots');
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for a new file here.

Can you move this to either transform_groupby_test.js or the poorly-named transform_multi_test.js?

plots.clearExpandedTraceDefaultColors = function(expandedTraces) {
var colorAttrs, path, trace, i, j;

// A better check *might* be to explicitly check for a groupby transform
Copy link
Contributor

Choose a reason for hiding this comment

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

would be better for sure, but I'm ok with this for now, as this will never get called for transform-less traces.

Maybe we start thinking about adding transform module categories (similar to our trace module categories) to help us out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a hypothetical for now, since groupby is currently the only one that can yield more than one trace... but my rationale for suggesting this was that it's precisely this condition that breaks default colors. We'll see what happens if/when we add more such transforms, if this is insufficient then a category system is a great idea!

@etpinard
Copy link
Contributor

@rreusser looking good!

I didn't notice any red flags in those failed tests. 👌 for updating them.

@rreusser
Copy link
Contributor Author

rreusser commented Jul 3, 2017

@etpinard Your initial sense was correct. To get the sequence correct and to preserve existing behavior, I had to move this into the groupby code instead of calling it directly from supplyDataDefaults. That makes it a general-purpose function that still has to be called manually where needed (since the styling pass from within the transform is kinda custom), so I left it in plots.js. Waiting to confirm that it passes the original and new tests, otherwise I think I'm content.

@rreusser
Copy link
Contributor Author

rreusser commented Jul 7, 2017

I've removed a redundant image mock and transferred making sure the colors are correct over to the jasmine test. Looks like it's green, so I don't have anything further to add to this PR.

@alexcjohnson
Copy link
Collaborator

Looks great to me! One more question though: Are there other trace types that make sense with groupby that we should include useExpandedTraceDefaultColor in (and test)? The ones that look like they should be groupable to me are bar, box, choropleth, histogram (perhaps not 2d histogram? grouping makes sense but the presentation is tricky), and all the other scatter types.

@etpinard
Copy link
Contributor

etpinard commented Jul 7, 2017

Are there other trace types that make sense with groupby that we should include useExpandedTraceDefaultColor

In theory, all attributes that get coerced using defaultColor should be declared with useExpandedTraceDefaultColor: true.

I'll make sure they're handled properly in this PR.


By the way, as object keys can't be minified, would anyone be opposed to shortening useExpandedTraceDefaultColor to something smaller (e.g. colorDflt)?

Even better, I think we don't even have to add another attribute field: all valType: 'color' attribute in traces that don't have a dflt field set should --- in theory --- be useExpandedTraceDefaultColor: true.

@alexcjohnson
Copy link
Collaborator

Even better, I think we don't even have to add another attribute field: all valType: 'color' attribute in traces that don't have a dflt field set should --- in theory --- be useExpandedTraceDefaultColor: true.

Interesting - I think this is valid (in traces only, of course, not in layout, but we're only crawling trace modules anyway) so yeah, go for it!

@alexcjohnson
Copy link
Collaborator

attribute in traces that don't have a dflt field set

Does coerce complain if it sees either zero or two defaults? Either if the attribute has a dflt but we override it in the coerce call, or if neither the attribute nor the coerce call contains a default? Should it? That would make this distinction more robust.

And even if we decide this is a good idea, not sure if we want it to happen all the time or just patch it in during testing somehow.

@etpinard
Copy link
Contributor

etpinard commented Jul 7, 2017

Interesting - I think this is valid

Replacing

(attr.useExpandedTraceDefaultColor)

by

(attr.valType === 'color' && attr.dflt === undefined)

on this line, gives the following colorAttrs list:

 ['line.color', 'fillcolor', 'marker.colorbar.tickfont.color', 'marker.colorbar.titlefont.color', 'marker.line.color', 'marker.gradient.color', 'marker.color', 'textfont.color', 'error_y.color', 'error_x.color']

which includes a few attributes that should have had useExpandedTraceDefaultColor: true (e.g. error_y.color) and a few others like marker.colorbar.tickfont.color that inherit from layout.font.color.

Clearing attributes that inherit from layout.font.color doesn't have any side-effects (apart from a few extra items in that for-loop), so I think this solution is the way to go. It's definitely a lot more robust than manually having to list useExpandedTraceDefaultColor: true for all traces. I hope agree.

- now, Plots.clearExpandedTraceDefaultColors clears any trace
  attributes with valType: color and no set dflt.
@etpinard
Copy link
Contributor

etpinard commented Jul 7, 2017

so I think this solution is the way to go.

All done in 25c2951.

@alexcjohnson ready to 💃 ?

@alexcjohnson
Copy link
Collaborator

Very nice. 💃

@rreusser
Copy link
Contributor Author

Great solution re: not having to manually set, @etpinard. Thanks! 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants