Skip to content

Fixup SVG Removal Panning #442

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 2 commits into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
74 changes: 34 additions & 40 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
pw = xa[0]._length,
ph = ya[0]._length,
MINDRAG = constants.MINDRAG,
MINZOOM = constants.MINZOOM,
i,
subplotXa,
subplotYa;

for(i = 1; i < subplots.length; i++) {
subplotXa = subplots[i].x();
subplotYa = subplots[i].y();
MINZOOM = constants.MINZOOM;

for(var i = 1; i < subplots.length; i++) {
var subplotXa = subplots[i].x(),
subplotYa = subplots[i].y();
if(xa.indexOf(subplotXa) === -1) xa.push(subplotXa);
if(ya.indexOf(subplotYa) === -1) ya.push(subplotYa);
}

function isDirectionActive(axList, activeVal) {
for(i = 0; i < axList.length; i++) {
for(var i = 0; i < axList.length; i++) {
if(!axList[i].fixedrange) return activeVal;
}
return '';
Expand Down Expand Up @@ -183,7 +180,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
.attr('d','M0,0Z');

clearSelect();
for(i = 0; i < allaxes.length; i++) forceNumbers(allaxes[i].range);
for(var i = 0; i < allaxes.length; i++) forceNumbers(allaxes[i].range);
}

function clearSelect() {
Expand Down Expand Up @@ -403,7 +400,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
}

// viewbox redraw at first
updateViewBoxes(scrollViewBox);
updateSubplots(scrollViewBox);
ticksAndAnnotations(ns,ew);

// then replot after a delay to make sure
Expand Down Expand Up @@ -437,7 +434,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
if(xActive === 'ew' || yActive === 'ns') {
if(xActive) dragAxList(xa, dx);
if(yActive) dragAxList(ya, dy);
updateViewBoxes([xActive ? -dx : 0, yActive ? -dy : 0, pw, ph]);
updateSubplots([xActive ? -dx : 0, yActive ? -dy : 0, pw, ph]);
ticksAndAnnotations(yActive, xActive);
return;
}
Expand Down Expand Up @@ -479,7 +476,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
else if(yActive === 's') dy = dz(ya, 0, -dy);
else if(!yActive) dy = 0;

updateViewBoxes([
updateSubplots([
(xActive === 'w') ? dx : 0,
(yActive === 'n') ? dy : 0,
pw - dx,
Expand Down Expand Up @@ -580,41 +577,38 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
axi.range=axi._r.slice();
}

updateViewBoxes([0,0,pw,ph]);
updateSubplots([0,0,pw,ph]);
Plotly.relayout(gd,attrs);
}

// updateViewBoxes - find all plot viewboxes that should be
// updateSubplots - find all plot viewboxes that should be
// affected by this drag, and update them. look for all plots
// sharing an affected axis (including the one being dragged)
function updateViewBoxes(viewBox) {
function updateSubplots(viewBox) {
var plotinfos = fullLayout._plots,
subplots = Object.keys(plotinfos),
i,
plotinfo2,
xa2,
ya2,
editX,
editY;

for(i = 0; i < subplots.length; i++) {
plotinfo2 = plotinfos[subplots[i]];
xa2 = plotinfo2.x();
ya2 = plotinfo2.y();
editX = ew && xa.indexOf(xa2)!==-1 && !xa2.fixedrange;
editY = ns && ya.indexOf(ya2)!==-1 && !ya2.fixedrange;
subplots = Object.keys(plotinfos);

for(var i = 0; i < subplots.length; i++) {
var subplot = plotinfos[subplots[i]],
xa2 = subplot.x(),
ya2 = subplot.y(),
editX = ew && xa.indexOf(xa2)!==-1 && !xa2.fixedrange,
editY = ns && ya.indexOf(ya2)!==-1 && !ya2.fixedrange;

if(editX || editY) {
var newVB = [0,0,xa2._length,ya2._length];
if(editX) {
newVB[0] = viewBox[0];
newVB[2] = viewBox[2];
}
if(editY) {
newVB[1] = viewBox[1];
newVB[3] = viewBox[3];
}
plotinfo2.plot.attr('viewBox',newVB.join(' '));
// plot requires offset position and
// clip moves with opposite sign
var clipDx = editX ? viewBox[0] : 0,
clipDy = editY ? viewBox[1] : 0,
plotDx = xa2._offset - clipDx,
plotDy = ya2._offset - clipDy;

var clipId = 'clip' + fullLayout._uid + subplots[i] + 'plot';

fullLayout._defs.selectAll('#' + clipId)
.attr('transform', 'translate(' + clipDx + ', ' + clipDy + ')');
subplot.plot
.attr('transform', 'translate(' + plotDx + ', ' + plotDy + ')');
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,20 @@ describe('Test click interactions:', function() {
done();
});
});


it('should move the plot when panning', function() {
var start = 100,
end = 300,
plot = gd._fullLayout._plots.xy.plot;

mouseEvent('mousemove', start, start);
mouseEvent('mousedown', start, start);
mouseEvent('mousemove', end, end);

expect(plot.attr('transform')).toBe('translate(250, 280)');
Copy link
Contributor

Choose a reason for hiding this comment

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

yes yes 🎉


mouseEvent('mouseup', end, end);
});
});
});