Skip to content
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

Pass customdata through to scatter calcdata #1379

Merged
merged 7 commits into from Feb 15, 2017

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Feb 14, 2017

This PR adds a customdata attribute to scatter traces that is passed through and assigned to the data property of the corresponding calcdata entry.

To do: verify the manner in which this is (or is not?) actually passed all the way through to the dom element.

ping @alexcjohnson @etpinard

@alexcjohnson
Copy link
Contributor

alexcjohnson commented Feb 14, 2017

Looks reasonable to me. Do you also want to:

  • add a class like plotly-customdata to the elements that actually have d.data (I think scatter/style.js is the right place (do we need to call out text or just path.point?) so the API doesn't need to know anything about our selectors to find the right elements to look for d.data on.
  • explicitly test passing through an object, not just a string, as that's probably what we'll need in practice.

@rreusser
Copy link
Contributor Author

I've added a plotly-customdata class that's set if data is anything except undefined or null. I could probably avoid the loop if customdata wasn't even provided. It didn't feel like a nice fit in the scatter tests, but I didn't really want to unit-test an intermediate API for this since it certainly doesn't need to be implemented in the style pass.

@alexcjohnson
Copy link
Contributor

Nice. Yes, I think it'd be worthwhile to avoid the loop in the (overwhelmingly common) case of no customdata.

var expected = [false, false, true, true, true, true, false];

points.each(function(cd, i) {
expect(d3.select(this).classed('plotly-customdata')).toBe(expected[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Beautiful test. I agree, end-to-end is the right way to test this particular beast.

pt.call(Drawing.pointStyle, d.trace || d[0].trace);

pt.each(function(cd) {
d3.select(this).classed('plotly-customdata', cd.data !== null && cd.data !== undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a little style point: pt makes it sounds like it refers to a single point, but it's all points so I'd change it to pts. And elsewhere cd refers to a whole calcdata array so this tripped me up for a sec - maybe change it to pointData or something.

@rreusser
Copy link
Contributor Author

rreusser commented Feb 15, 2017

Caveat I just can't ignore: animation. Going to add that to the test to ensure these are properly updated. Since transitions don't work through the style pass, an animation update won't update these. Fixing. This might be reason enough to move this to the plot step instead.

@rreusser
Copy link
Contributor Author

rreusser commented Feb 15, 2017

Okay, I've updated the PR (in a test-driven fail-first manner that actually tests what it claims to 👍). It unsets customdata via an animation that doesn't replot in order to verify that it's actually set/unset/updated correctly. This required moving it to plot.js which is pretty straightforward and doesn't really affect anything, to the best of my knowledge. I'm currently content with this.

@alexcjohnson
Copy link
Contributor

Very nice. 💃

@rreusser rreusser merged commit 4c4503f into master Feb 15, 2017
@rreusser rreusser deleted the add-extra-data-to-scatter-points branch February 15, 2017 18:50
@etpinard etpinard added this to the 1.24.0 milestone Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants