Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ var Registry = require('../registry');
var PlotSchema = require('./plot_schema');
var Plots = require('../plots/plots');
var Polar = require('../plots/polar/legacy');
var initInteractions = require('../plots/cartesian/graph_interact');

var Axes = require('../plots/cartesian/axes');
var Drawing = require('../components/drawing');
var Color = require('../components/color');
var initInteractions = require('../plots/cartesian/graph_interact').initInteractions;
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
var svgTextUtils = require('../lib/svg_text_utils');

Expand Down
3 changes: 1 addition & 2 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var Color = require('../components/color');
var Drawing = require('../components/drawing');
var Titles = require('../components/titles');
var ModeBar = require('../components/modebar');

var Axes = require('../plots/cartesian/axes');
var initInteractions = require('../plots/cartesian/graph_interact');
var cartesianConstants = require('../plots/cartesian/constants');
var alignmentConstants = require('../constants/alignment');
var axisConstraints = require('../plots/cartesian/constraints');
Expand Down Expand Up @@ -465,7 +465,6 @@ exports.doModeBar = function(gd) {
var fullLayout = gd._fullLayout;

ModeBar.manage(gd);
initInteractions(gd);

for(var i = 0; i < fullLayout._basePlotModules.length; i++) {
var updateFx = fullLayout._basePlotModules[i].updateFx;
Expand Down
21 changes: 12 additions & 9 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
// within DBLCLICKDELAY so we can check for click or doubleclick events
// dragged stores whether a drag has occurred, so we don't have to
// redraw unnecessarily, ie if no move bigger than MINDRAG or MINZOOM px
var fullLayout = gd._fullLayout;
var zoomlayer = gd._fullLayout._zoomlayer;
var isMainDrag = (ns + ew === 'nsew');
var singleEnd = (ns + ew).length === 1;
Expand Down Expand Up @@ -111,6 +110,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {

recomputeAxisLists();

var cursor = getDragCursor(yActive + xActive, gd._fullLayout.dragmode, isMainDrag);
var dragger = makeRectDragger(plotinfo, ns + ew + 'drag', cursor, x, y, w, h);

var allFixedRanges = !yActive && !xActive;
Expand All @@ -131,6 +131,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
prepFn: function(e, startX, startY) {
var dragModeNow = gd._fullLayout.dragmode;

recomputeAxisLists();

if(!allFixedRanges) {
if(isMainDrag) {
// main dragger handles all drag modes, and changes
Expand Down Expand Up @@ -204,7 +206,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
.call(svgTextUtils.makeEditable, {
gd: gd,
immediate: true,
background: fullLayout.paper_bgcolor,
background: gd._fullLayout.paper_bgcolor,
text: String(initialText),
fill: ax.tickfont ? ax.tickfont.color : '#444',
horizontalAlign: hAlign,
Expand Down Expand Up @@ -354,7 +356,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
// deactivate mousewheel scrolling on embedded graphs
// devs can override this with layout._enablescrollzoom,
// but _ ensures this setting won't leave their page
if(!gd._context.scrollZoom && !fullLayout._enablescrollzoom) {
if(!gd._context.scrollZoom && !gd._fullLayout._enablescrollzoom) {
return;
}

Expand Down Expand Up @@ -456,8 +458,6 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
return;
}

recomputeAxisLists();

if(xActive === 'ew' || yActive === 'ns') {
if(xActive) dragAxList(xa, dx);
if(yActive) dragAxList(ya, dy);
Expand Down Expand Up @@ -584,9 +584,9 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
// annotations and shapes 'draw' method is slow,
// use the finer-grained 'drawOne' method instead

redrawObjs(fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
redrawObjs(fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
redrawObjs(gd._fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
redrawObjs(gd._fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
redrawObjs(gd._fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
}

function doubleClick() {
Expand Down Expand Up @@ -892,9 +892,12 @@ function dZoom(d) {
1 / (1 / Math.max(d, -0.3) + 3.222));
}

function getDragCursor(nsew, dragmode) {
function getDragCursor(nsew, dragmode, isMainDrag) {
if(!nsew) return 'pointer';
if(nsew === 'nsew') {
// in this case here, clear cursor and
// use the cursor style set on <g .draglayer>
if(isMainDrag) return '';
if(dragmode === 'pan') return 'move';
return 'crosshair';
}
Expand Down
26 changes: 18 additions & 8 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ var d3 = require('d3');

var Fx = require('../../components/fx');
var dragElement = require('../../components/dragelement');
var setCursor = require('../../lib/setcursor');

var constants = require('./constants');
var makeDragBox = require('./dragbox').makeDragBox;
var DRAGGERSIZE = require('./constants').DRAGGERSIZE;

module.exports = function initInteractions(gd) {
exports.initInteractions = function initInteractions(gd) {
var fullLayout = gd._fullLayout;

if(gd._context.staticPlot) {
Expand All @@ -43,12 +44,9 @@ module.exports = function initInteractions(gd) {

subplots.forEach(function(subplot) {
var plotinfo = fullLayout._plots[subplot];

var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;

var DRAGGERSIZE = constants.DRAGGERSIZE;

// main and corner draggers need not be repeated for
// overlaid subplots - these draggers drag them all
if(!plotinfo.mainplot) {
Expand Down Expand Up @@ -139,17 +137,29 @@ module.exports = function initInteractions(gd) {
var hoverLayer = fullLayout._hoverlayer.node();

hoverLayer.onmousemove = function(evt) {
evt.target = fullLayout._lasthover;
evt.target = gd._fullLayout._lasthover;
Fx.hover(gd, evt, fullLayout._hoversubplot);
};

hoverLayer.onclick = function(evt) {
evt.target = fullLayout._lasthover;
evt.target = gd._fullLayout._lasthover;
Fx.click(gd, evt);
};

// also delegate mousedowns... TODO: does this actually work?
hoverLayer.onmousedown = function(evt) {
fullLayout._lasthover.onmousedown(evt);
gd._fullLayout._lasthover.onmousedown(evt);
};

exports.updateFx(fullLayout);
};

// Minimal set of update needed on 'modebar' edits.
// We only need to update the <g .draglayer> cursor style.
//
// Note that changing the axis configuration and/or the fixedrange attribute
// should trigger a full initInteractions.
exports.updateFx = function(fullLayout) {
var cursor = fullLayout.dragmode === 'pan' ? 'move' : 'crosshair';
setCursor(fullLayout._draggers, cursor);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, great solution - much simpler than what I was thinking, and at least as fast 🐎

};
2 changes: 2 additions & 0 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,5 @@ exports.toSVG = function(gd) {

canvases.each(canvasToImage);
};

exports.updateFx = require('./graph_interact').updateFx;
7 changes: 3 additions & 4 deletions test/jasmine/tests/fx_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ describe('relayout', function() {
afterEach(destroyGraphDiv);

it('should update main drag with correct', function(done) {

function assertMainDrag(cursor, isActive) {
expect(d3.selectAll('rect.nsewdrag').size()).toEqual(1, 'number of nodes');
var mainDrag = d3.select('rect.nsewdrag'),
node = mainDrag.node();
var mainDrag = d3.select('rect.nsewdrag');
var node = mainDrag.node();

expect(mainDrag.classed('cursor-' + cursor)).toBe(true, 'cursor ' + cursor);
expect(window.getComputedStyle(node).cursor).toBe(cursor, 'cursor ' + cursor);
expect(node.style.pointerEvents).toEqual('all', 'pointer event');
expect(!!node.onmousedown).toBe(isActive, 'mousedown handler');
}
Expand Down