diff --git a/src/plots/cartesian/dragbox.js b/src/plots/cartesian/dragbox.js index c0ca83a10c9..22a253f287e 100644 --- a/src/plots/cartesian/dragbox.js +++ b/src/plots/cartesian/dragbox.js @@ -712,7 +712,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { // This is specifically directed at scatter traces, applying an inverse // scale to individual points to counteract the scale of the trace // as a whole: - .selectAll('.points').selectAll('.point') + .select('.scatterlayer').selectAll('.points').selectAll('.point') .call(Drawing.setPointGroupScale, 1 / xScaleFactor, 1 / yScaleFactor); } } diff --git a/test/jasmine/tests/click_test.js b/test/jasmine/tests/click_test.js index fc2425e1b0e..88a32102dcd 100644 --- a/test/jasmine/tests/click_test.js +++ b/test/jasmine/tests/click_test.js @@ -3,6 +3,7 @@ var Lib = require('@src/lib'); var Drawing = require('@src/components/drawing'); var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY; +var d3 = require('d3'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); @@ -809,3 +810,48 @@ describe('Test click interactions:', function() { }); }); }); + +describe('dragbox', function() { + + afterEach(destroyGraphDiv); + + it('should scale subplot and inverse scale scatter points', function(done) { + var mock = Lib.extendDeep({}, require('@mocks/bar_line.json')); + + function assertScale(node, x, y) { + var scale = Drawing.getScale(node); + expect(scale.x).toBeCloseTo(x, 1); + expect(scale.y).toBeCloseTo(y, 1); + } + + Plotly.plot(createGraphDiv(), mock).then(function() { + var node = d3.select('rect.nedrag').node(); + var pos = getRectCenter(node); + + assertScale(d3.select('.plot').node(), 1, 1); + + d3.selectAll('.point').each(function() { + assertScale(this, 1, 1); + }); + + mouseEvent('mousemove', pos[0], pos[1]); + mouseEvent('mousedown', pos[0], pos[1]); + mouseEvent('mousemove', pos[0] + 50, pos[1]); + + setTimeout(function() { + assertScale(d3.select('.plot').node(), 1.14, 1); + + d3.select('.scatterlayer').selectAll('.point').each(function() { + assertScale(this, 0.87, 1); + }); + d3.select('.barlayer').selectAll('.point').each(function() { + assertScale(this, 1, 1); + }); + + mouseEvent('mouseup', pos[0] + 50, pos[1]); + done(); + }, DBLCLICKDELAY / 4); + }); + }); + +});