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
Show file tree
Hide file tree
Changes from 2 commits
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
21 changes: 21 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

x = x || 1;
y = y || 1;

// The same scale transform for every point:
var scale = ' scale(' + x + ',' + y + ')';

// A regex to strip any existing scale:
var re = /sc.*/;

selection.each(function() {
// Get the transform:
var t = this.getAttribute('transform').replace(re, '');

// Append the scale transform
this.setAttribute('transform', t + scale);
});

return scale;
};

lib.isIE = function() {
return typeof window.navigator.msSaveBlob !== 'undefined';
};
Expand Down
5 changes: 4 additions & 1 deletion src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

.call(Lib.setPointScale, 1 / xScaleFactor, 1 / yScaleFactor);

}
}

Expand Down