Skip to content

Commit

Permalink
Smaller nudge regions in drag_node and move
Browse files Browse the repository at this point in the history
(closes #3956)
  • Loading branch information
bhousel committed Apr 21, 2017
1 parent 3e917f3 commit d441cd9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
33 changes: 20 additions & 13 deletions modules/modes/drag_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ export function modeDragNode(context) {
}

function edge(point, size) {
var pad = [30, 100, 30, 100],
var pad = [80, 20, 50, 20], // top, right, bottom, left
x = 0,
y = 0;

if (point[0] > size[0] - pad[0])
if (point[0] > size[0] - pad[1])
x = -10;
if (point[0] < pad[2])
if (point[0] < pad[3])
x = 10;
if (point[1] > size[1] - pad[1])
if (point[1] > size[1] - pad[2])
y = -10;
if (point[1] < pad[3])
if (point[1] < pad[0])
y = 10;

if (x || y) {
Expand All @@ -76,8 +76,10 @@ export function modeDragNode(context) {


function stopNudge() {
if (nudgeInterval) window.clearInterval(nudgeInterval);
nudgeInterval = null;
if (nudgeInterval) {
window.clearInterval(nudgeInterval);
nudgeInterval = null;
}
}


Expand Down Expand Up @@ -159,10 +161,12 @@ export function modeDragNode(context) {
loc = context.projection.invert(currMouse),
d = datum();

if (d.type === 'node' && d.id !== entity.id) {
loc = d.loc;
} else if (d.type === 'way' && !d3.select(d3.event.sourceEvent.target).classed('fill')) {
loc = geoChooseEdge(context.childNodes(d), context.mouse(), context.projection).loc;
if (!nudgeInterval) {
if (d.type === 'node' && d.id !== entity.id) {
loc = d.loc;
} else if (d.type === 'way' && !d3.select(d3.event.sourceEvent.target).classed('fill')) {
loc = geoChooseEdge(context.childNodes(d), context.mouse(), context.projection).loc;
}
}

context.replace(
Expand All @@ -181,8 +185,11 @@ export function modeDragNode(context) {

doMove(entity);
var nudge = edge(d3.event.point, context.map().dimensions());
if (nudge) startNudge(entity, nudge);
else stopNudge();
if (nudge) {
startNudge(entity, nudge);
} else {
stopNudge();
}
}


Expand Down
30 changes: 19 additions & 11 deletions modules/modes/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,24 @@ export function modeMove(context, entityIDs, baseGraph) {


function edge(point, size) {
var pad = [30, 100, 30, 100],
var pad = [80, 20, 50, 20], // top, right, bottom, left
x = 0,
y = 0;

if (point[0] > size[0] - pad[0])
if (point[0] > size[0] - pad[1])
x = -10;
if (point[0] < pad[2])
if (point[0] < pad[3])
x = 10;
if (point[1] > size[1] - pad[1])
if (point[1] > size[1] - pad[2])
y = -10;
if (point[1] < pad[3])
if (point[1] < pad[0])
y = 10;

if (x || y) return [x, y];
else return null;
if (x || y) {
return [x, y];
} else {
return null;
}
}


Expand Down Expand Up @@ -100,16 +103,21 @@ export function modeMove(context, entityIDs, baseGraph) {


function stopNudge() {
if (nudgeInterval) window.clearInterval(nudgeInterval);
nudgeInterval = null;
if (nudgeInterval) {
window.clearInterval(nudgeInterval);
nudgeInterval = null;
}
}


function move() {
doMove();
var nudge = edge(context.mouse(), context.map().dimensions());
if (nudge) startNudge(nudge);
else stopNudge();
if (nudge) {
startNudge(nudge);
} else {
stopNudge();
}
}


Expand Down

0 comments on commit d441cd9

Please sign in to comment.