Begin d3 v4 update

This commit is contained in:
Tom MacWright
2016-08-12 10:29:00 -04:00
parent 36a90b4f86
commit cdb533fa84
137 changed files with 842 additions and 6691 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
import { rebind } from '../util/rebind';
import * as d3 from 'd3';
import { Browse } from '../modes/index';
import { Draw } from './draw';
@@ -35,5 +37,5 @@ export function AddWay(context) {
return addWay;
};
return d3.rebind(addWay, event, 'on');
return rebind(addWay, event, 'on');
}
+1
View File
@@ -1,3 +1,4 @@
import * as d3 from 'd3';
import _ from 'lodash';
export function Breathe(){
var duration = 800,
+3 -1
View File
@@ -1,7 +1,9 @@
import { d3keybinding } from '../../js/lib/d3.keybinding.js';
import * as d3 from 'd3';
import _ from 'lodash';
import { cmd } from '../ui/index';
export function Copy(context) {
var keybinding = d3.keybinding('copy');
var keybinding = d3keybinding('copy');
function groupEntities(ids, graph) {
var entities = ids.map(function (id) { return graph.entity(id); });
+8 -5
View File
@@ -1,3 +1,5 @@
import { rebind } from '../util/rebind';
import * as d3 from 'd3';
import { prefixCSSProperty, prefixDOMProperty } from '../util/index';
/*
`iD.behavior.drag` is like `d3.behavior.drag`, with the following differences:
@@ -31,11 +33,12 @@ export function drag() {
return function(e1) {
var e0 = e1.sourceEvent = d3.event;
e1.target = drag;
d3.event = e1;
// TODO
// d3.event = e1;
try {
event[e1.type].apply(thiz, argumentz);
} finally {
d3.event = e0;
// d3.event = e0;
}
};
};
@@ -59,7 +62,7 @@ export function drag() {
function mousedown() {
target = this;
event_ = event.of(target, arguments);
event_ = event.call("of", target, arguments);
var eventTarget = d3.event.target,
touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null,
offset,
@@ -188,7 +191,7 @@ export function drag() {
drag.target = function() {
if (!arguments.length) return target;
target = arguments[0];
event_ = event.of(target, Array.prototype.slice.call(arguments, 1));
event_ = event.call("of", target, Array.prototype.slice.call(arguments, 1));
return drag;
};
@@ -198,5 +201,5 @@ export function drag() {
return drag;
};
return d3.rebind(drag, event, 'on');
return rebind(drag, event, 'on');
}
+15 -11
View File
@@ -1,3 +1,7 @@
import { rebind } from '../util/rebind';
import { getDimensions } from '../util/dimensions';
import { d3keybinding } from '../../js/lib/d3.keybinding.js';
import * as d3 from 'd3';
import { chooseEdge, euclideanDistance } from '../geo/index';
import { Edit } from './edit';
import { Hover } from './hover';
@@ -6,7 +10,7 @@ import { Tail } from './tail';
export function Draw(context) {
var event = d3.dispatch('move', 'click', 'clickWay',
'clickNode', 'undo', 'cancel', 'finish'),
keybinding = d3.keybinding('draw'),
keybinding = d3keybinding('draw'),
hover = Hover(context)
.altDisables(true)
.on('hover', context.ui().sidebar.hover),
@@ -72,7 +76,7 @@ export function Draw(context) {
function mousemove() {
lastMouse = d3.event;
event.move(datum());
event.call("move", datum());
}
function mouseenter() {
@@ -86,7 +90,7 @@ export function Draw(context) {
function click() {
var d = datum();
if (d.type === 'way') {
var dims = context.map().dimensions(),
var dims = getDimensions(context.map()),
mouse = context.mouse(),
pad = 5,
trySnap = mouse[0] > pad && mouse[0] < dims[0] - pad &&
@@ -95,16 +99,16 @@ export function Draw(context) {
if (trySnap) {
var choice = chooseEdge(context.childNodes(d), context.mouse(), context.projection),
edge = [d.nodes[choice.index - 1], d.nodes[choice.index]];
event.clickWay(choice.loc, edge);
event.call("clickWay", choice.loc, edge);
} else {
event.click(context.map().mouseCoordinates());
event.call("click", context.map().mouseCoordinates());
}
} else if (d.type === 'node') {
event.clickNode(d);
event.call("clickNode", d);
} else {
event.click(context.map().mouseCoordinates());
event.call("click", context.map().mouseCoordinates());
}
}
@@ -134,17 +138,17 @@ export function Draw(context) {
function backspace() {
d3.event.preventDefault();
event.undo();
event.call("undo");
}
function del() {
d3.event.preventDefault();
event.cancel();
event.call("cancel");
}
function ret() {
d3.event.preventDefault();
event.finish();
event.call("finish");
}
function draw(selection) {
@@ -204,7 +208,7 @@ export function Draw(context) {
return draw;
};
return d3.rebind(draw, event, 'on');
return rebind(draw, event, 'on');
}
Draw.usedTails = {};
+5 -3
View File
@@ -1,11 +1,13 @@
import * as d3 from 'd3';
import { t } from '../util/locale';
import { getDimensions } from '../util/dimensions';
import _ from 'lodash';
import { AddEntity, AddMidpoint, AddVertex, MoveNode } from '../actions/index';
import { Browse, Select } from '../modes/index';
import { Node, Way } from '../core/index';
import { chooseEdge, edgeEqual } from '../geo/index';
import { Draw } from './draw';
import { entitySelector } from '../util/index';
import { entitySelector, functor } from '../util/index';
export function DrawWay(context, wayId, index, mode, baseGraph) {
var way = context.entity(wayId),
@@ -41,7 +43,7 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
loc = datum.loc;
} else if (datum.type === 'way' && datum.id !== segment.id) {
var dims = context.map().dimensions(),
var dims = getDimensions(context.map()),
mouse = context.mouse(),
pad = 5,
trySnap = mouse[0] > pad && mouse[0] < dims[0] - pad &&
@@ -199,7 +201,7 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
// Cancel the draw operation and return to browse, deleting everything drawn.
drawWay.cancel = function() {
context.perform(
d3.functor(baseGraph),
functor(baseGraph),
t('operations.cancel_draw.annotation'));
window.setTimeout(function() {
+1
View File
@@ -1,3 +1,4 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { qsString, stringQs } from '../util/index';
export function Hash(context) {
+10 -7
View File
@@ -1,3 +1,6 @@
import { rebind } from '../util/rebind';
import { d3keybinding } from '../../js/lib/d3.keybinding.js';
import * as d3 from 'd3';
import { Entity } from '../core/index';
/*
The hover behavior adds the `.hover` class on mouseover to all elements to which
@@ -15,8 +18,8 @@ export function Hover() {
target;
function keydown() {
if (altDisables && d3.event.keyCode === d3.keybinding.modifierCodes.alt) {
dispatch.hover(null);
if (altDisables && d3.event.keyCode === d3keybinding.modifierCodes.alt) {
dispatch.call("hover", this, null);
selection.selectAll('.hover')
.classed('hover-suppressed', true)
.classed('hover', false);
@@ -24,8 +27,8 @@ export function Hover() {
}
function keyup() {
if (altDisables && d3.event.keyCode === d3.keybinding.modifierCodes.alt) {
dispatch.hover(target ? target.id : null);
if (altDisables && d3.event.keyCode === d3keybinding.modifierCodes.alt) {
dispatch.call("hover", this, target ? target.id : null);
selection.selectAll('.hover-suppressed')
.classed('hover-suppressed', false)
.classed('hover', true);
@@ -59,9 +62,9 @@ export function Hover() {
selection.selectAll(selector)
.classed(suppressed ? 'hover-suppressed' : 'hover', true);
dispatch.hover(target.id);
dispatch.call("hover", this, target.id);
} else {
dispatch.hover(null);
dispatch.call("hover", this, null);
}
}
@@ -124,5 +127,5 @@ export function Hover() {
return hover;
};
return d3.rebind(hover, dispatch, 'on');
return rebind(hover, dispatch, 'on');
}
+1
View File
@@ -1,3 +1,4 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { Extent, pointInPolygon } from '../geo/index';
import { Select } from '../modes/index';
+3 -1
View File
@@ -1,3 +1,5 @@
import { d3keybinding } from '../../js/lib/d3.keybinding.js';
import * as d3 from 'd3';
import _ from 'lodash';
import { ChangeTags, CopyEntities, Move as MoveAction} from '../actions/index';
import { Extent, pointInPolygon } from '../geo/index';
@@ -5,7 +7,7 @@ import { Move as MoveMode } from '../modes/index';
import { cmd } from '../ui/index';
export function Paste(context) {
var keybinding = d3.keybinding('paste');
var keybinding = d3keybinding('paste');
function omitTag(v, k) {
return (
+1
View File
@@ -1,3 +1,4 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { Browse, Select as SelectMode } from '../modes/index';
import { Entity } from '../core/index';
+6 -4
View File
@@ -1,4 +1,6 @@
import * as d3 from 'd3';
import { setTransform } from '../util/index';
import { getDimensions } from '../util/dimensions';
export function Tail() {
var text,
container,
@@ -10,11 +12,11 @@ export function Tail() {
if (!text) return;
d3.select(window)
.on('resize.tail', function() { selectionSize = selection.dimensions(); });
.on('resize.tail', function() { selectionSize = getDimensions(selection); });
function show() {
container.style('display', 'block');
tooltipSize = container.dimensions();
tooltipSize = getDimensions(container);
}
function mousemove() {
@@ -53,8 +55,8 @@ export function Tail() {
container
.on('mousemove.tail', mousemove);
tooltipSize = container.dimensions();
selectionSize = selection.dimensions();
tooltipSize = getDimensions(container);
selectionSize = getDimensions(selection);
}
tail.off = function(selection) {