Skip to content

Non-scaling SVG scatter points #762

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 3 commits into from
Jul 21, 2016
Merged

Non-scaling SVG scatter points #762

merged 3 commits into from
Jul 21, 2016

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Jul 21, 2016

See issue: #760
See related line scaling PR: #761
See codepen example (visible on scrollZoom): http://codepen.io/rsreusser/pen/OXvmjR?editors=0010

This PR compensates for point scaling by applying an inverse scale transform. It's simple, but kind of an ugly hack since it requires stripping any existing scale from points before applying a new scale. That may make it prohibitive, but it was a bit easier than expected, so maybe it's not unreasonable. cc @mdtusz

@@ -484,6 +484,27 @@ lib.setScale = function(element, x, y) {
return transform;
};

lib.setPointScale = function(selection, x, y) {
Copy link
Contributor Author

@rreusser rreusser Jul 21, 2016

Choose a reason for hiding this comment

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

This is scatter-specific. It's here since related functions are right next to it, but it probably should not in lib/. I just don't think there's a world in which this can be meaningfully generalized.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with this being in lib/. Putting this in src/traces/scatter/set_point_scale.js would be ok too. Your call @rreusser

@@ -633,7 +633,10 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {

subplot.plot
.call(Lib.setTranslate, plotDx, plotDy)
.call(Lib.setScale, xScaleFactor, yScaleFactor);
.call(Lib.setScale, xScaleFactor, yScaleFactor)
.selectAll('.points').selectAll('.point')
Copy link
Contributor

Choose a reason for hiding this comment

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

a one-line comment here would be nice.

@etpinard
Copy link
Contributor

Nice solution. Looks like isolating the setPointScale call in dragbox.js worked out well.

@rreusser Would you mind adding a few unit tests for setPointScale ?

@rreusser
Copy link
Contributor Author

rreusser commented Jul 21, 2016

@etpinard Should setPointScale work with d3 elements, like setTranslate? As long as it's clearly implemented, tested, and commented, it seems unnecessary to implement at the moment unless needed.

(Specifically, there's a danger of it being a bit expensive when lots of zoom events are happening since it applies to all points, so it's not totally general and abstract)

@etpinard
Copy link
Contributor

Should setPointScale work with d3 elements, like setTranslate?

No. I don't see the need.

@rreusser
Copy link
Contributor Author

rreusser commented Jul 21, 2016

Added comment, changed the name to be more descriptive (setPointGroupScale since it operates on a selection—although that name doesn't seem quite right either since it's not an svg <group>), added tests, removed scale if = (1, 1), and confirmed that it still has the same visual effect.

@rreusser rreusser force-pushed the non-scaling-points branch from 5d0a2e1 to 96deefe Compare July 21, 2016 17:09
@rreusser rreusser force-pushed the non-scaling-points branch from 96deefe to f786b4f Compare July 21, 2016 17:10
@etpinard
Copy link
Contributor

Very nicely done. 💃 merge away.

@rreusser rreusser merged commit a3aebfe into master Jul 21, 2016
@rreusser rreusser deleted the non-scaling-points branch July 21, 2016 20:08
@etpinard etpinard added this to the v1.15.0 milestone Jul 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants