Commit fa55eead authored by Mike Bostock's avatar Mike Bostock
Browse files

Merge branch '3.4.4'

parents adeaf201 994235b3
{ {
"name": "d3", "name": "d3",
"version": "3.4.3", "version": "3.4.4",
"main": "d3.js", "main": "d3.js",
"scripts": [ "scripts": [
"d3.js" "d3.js"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"animation", "animation",
"canvas" "canvas"
], ],
"version": "3.4.3", "version": "3.4.4",
"main": "d3.js", "main": "d3.js",
"scripts": [ "scripts": [
"d3.js" "d3.js"
......
!function() { !function() {
var d3 = { var d3 = {
version: "3.4.3" version: "3.4.4"
}; };
if (!Date.now) Date.now = function() { if (!Date.now) Date.now = function() {
return +new Date(); return +new Date();
...@@ -32,9 +32,10 @@ ...@@ -32,9 +32,10 @@
d3_style_setProperty.call(this, name, value + "", priority); d3_style_setProperty.call(this, name, value + "", priority);
}; };
} }
d3.ascending = function(a, b) { d3.ascending = d3_ascending;
function d3_ascending(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}; }
d3.descending = function(a, b) { d3.descending = function(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN; return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
}; };
...@@ -105,16 +106,16 @@ ...@@ -105,16 +106,16 @@
d3.median = function(array, f) { d3.median = function(array, f) {
if (arguments.length > 1) array = array.map(f); if (arguments.length > 1) array = array.map(f);
array = array.filter(d3_number); array = array.filter(d3_number);
return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined; return array.length ? d3.quantile(array.sort(d3_ascending), .5) : undefined;
}; };
d3.bisector = function(f) { function d3_bisector(compare) {
return { return {
left: function(a, x, lo, hi) { left: function(a, x, lo, hi) {
if (arguments.length < 3) lo = 0; if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length; if (arguments.length < 4) hi = a.length;
while (lo < hi) { while (lo < hi) {
var mid = lo + hi >>> 1; var mid = lo + hi >>> 1;
if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid; if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
} }
return lo; return lo;
}, },
...@@ -123,17 +124,20 @@ ...@@ -123,17 +124,20 @@
if (arguments.length < 4) hi = a.length; if (arguments.length < 4) hi = a.length;
while (lo < hi) { while (lo < hi) {
var mid = lo + hi >>> 1; var mid = lo + hi >>> 1;
if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1; if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
} }
return lo; return lo;
} }
}; };
}
var d3_bisect = d3_bisector(d3_ascending);
d3.bisectLeft = d3_bisect.left;
d3.bisect = d3.bisectRight = d3_bisect.right;
d3.bisector = function(f) {
return d3_bisector(f.length === 1 ? function(d, x) {
return d3_ascending(f(d), x);
} : f);
}; };
var d3_bisector = d3.bisector(function(d) {
return d;
});
d3.bisectLeft = d3_bisector.left;
d3.bisect = d3.bisectRight = d3_bisector.right;
d3.shuffle = function(array) { d3.shuffle = function(array) {
var m = array.length, t, i; var m = array.length, t, i;
while (m) { while (m) {
...@@ -495,9 +499,7 @@ ...@@ -495,9 +499,7 @@
d3_select = function(s, n) { d3_select = function(s, n) {
return Sizzle(s, n)[0] || null; return Sizzle(s, n)[0] || null;
}; };
d3_selectAll = function(s, n) { d3_selectAll = Sizzle;
return Sizzle.uniqueSort(Sizzle(s, n));
};
d3_selectMatches = Sizzle.matchesSelector; d3_selectMatches = Sizzle.matchesSelector;
} }
d3.selection = function() { d3.selection = function() {
...@@ -872,7 +874,7 @@ ...@@ -872,7 +874,7 @@
return this.order(); return this.order();
}; };
function d3_selection_sortComparator(comparator) { function d3_selection_sortComparator(comparator) {
if (!arguments.length) comparator = d3.ascending; if (!arguments.length) comparator = d3_ascending;
return function(a, b) { return function(a, b) {
return a && b ? comparator(a.__data__, b.__data__) : !a - !b; return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
}; };
...@@ -1087,27 +1089,12 @@ ...@@ -1087,27 +1089,12 @@
d3.mouse = function(container) { d3.mouse = function(container) {
return d3_mousePoint(container, d3_eventSource()); return d3_mousePoint(container, d3_eventSource());
}; };
var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
function d3_mousePoint(container, e) { function d3_mousePoint(container, e) {
if (e.changedTouches) e = e.changedTouches[0]; if (e.changedTouches) e = e.changedTouches[0];
var svg = container.ownerSVGElement || container; var svg = container.ownerSVGElement || container;
if (svg.createSVGPoint) { if (svg.createSVGPoint) {
var point = svg.createSVGPoint(); var point = svg.createSVGPoint();
if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) { point.x = e.clientX, point.y = e.clientY;
svg = d3.select("body").append("svg").style({
position: "absolute",
top: 0,
left: 0,
margin: 0,
padding: 0,
border: "none"
}, "important");
var ctm = svg[0][0].getScreenCTM();
d3_mouse_bug44083 = !(ctm.f || ctm.e);
svg.remove();
}
if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
point.y = e.clientY;
point = point.matrixTransform(container.getScreenCTM().inverse()); point = point.matrixTransform(container.getScreenCTM().inverse());
return [ point.x, point.y ]; return [ point.x, point.y ];
} }
...@@ -1123,46 +1110,42 @@ ...@@ -1123,46 +1110,42 @@
}) : []; }) : [];
}; };
d3.behavior.drag = function() { d3.behavior.drag = function() {
var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, "mousemove", "mouseup"), touchstart = dragstart(touchid, touchposition, "touchmove", "touchend"); var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend");
function drag() { function drag() {
this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart); this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
} }
function touchid() { function dragstart(id, position, subject, move, end) {
return d3.event.changedTouches[0].identifier;
}
function touchposition(parent, id) {
return d3.touches(parent).filter(function(p) {
return p.identifier === id;
})[0];
}
function dragstart(id, position, move, end) {
return function() { return function() {
var target = this, parent = target.parentNode, event_ = event.of(target, arguments), eventTarget = d3.event.target, eventId = id(), drag = eventId == null ? "drag" : "drag-" + eventId, origin_ = position(parent, eventId), dragged = 0, offset, w = d3.select(d3_window).on(move + "." + drag, moved).on(end + "." + drag, ended), dragRestore = d3_event_dragSuppress(); var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject()).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(), position0 = position(parent, dragId);
if (origin) { if (origin) {
offset = origin.apply(target, arguments); dragOffset = origin.apply(that, arguments);
offset = [ offset.x - origin_[0], offset.y - origin_[1] ]; dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
} else { } else {
offset = [ 0, 0 ]; dragOffset = [ 0, 0 ];
} }
event_({ dispatch({
type: "dragstart" type: "dragstart"
}); });
function moved() { function moved() {
var p = position(parent, eventId), dx = p[0] - origin_[0], dy = p[1] - origin_[1]; var position1 = position(parent, dragId), dx, dy;
if (!position1) return;
dx = position1[0] - position0[0];
dy = position1[1] - position0[1];
dragged |= dx | dy; dragged |= dx | dy;
origin_ = p; position0 = position1;
event_({ dispatch({
type: "drag", type: "drag",
x: p[0] + offset[0], x: position1[0] + dragOffset[0],
y: p[1] + offset[1], y: position1[1] + dragOffset[1],
dx: dx, dx: dx,
dy: dy dy: dy
}); });
} }
function ended() { function ended() {
w.on(move + "." + drag, null).on(end + "." + drag, null); if (!position(parent, dragId)) return;
dragRestore(dragged && d3.event.target === eventTarget); dragSubject.on(move + dragName, null).on(end + dragName, null);
event_({ dragRestore(dragged && d3.event.target === target);
dispatch({
type: "dragend" type: "dragend"
}); });
} }
...@@ -1175,6 +1158,15 @@ ...@@ -1175,6 +1158,15 @@
}; };
return d3.rebind(drag, event, "on"); return d3.rebind(drag, event, "on");
}; };
function d3_behavior_dragTouchId() {
return d3.event.changedTouches[0].identifier;
}
function d3_behavior_dragTouchSubject() {
return d3.event.target;
}
function d3_behavior_dragMouseSubject() {
return d3_window;
}
var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π; var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
function d3_sgn(x) { function d3_sgn(x) {
return x > 0 ? 1 : x < 0 ? -1 : 0; return x > 0 ? 1 : x < 0 ? -1 : 0;
...@@ -1226,7 +1218,7 @@ ...@@ -1226,7 +1218,7 @@
} }
zoom.event = function(g) { zoom.event = function(g) {
g.each(function() { g.each(function() {
var event_ = event.of(this, arguments), view1 = view; var dispatch = event.of(this, arguments), view1 = view;
if (d3_transitionInheritId) { if (d3_transitionInheritId) {
d3.select(this).transition().each("start.zoom", function() { d3.select(this).transition().each("start.zoom", function() {
view = this.__chart__ || { view = this.__chart__ || {
...@@ -1234,7 +1226,7 @@ ...@@ -1234,7 +1226,7 @@
y: 0, y: 0,
k: 1 k: 1
}; };
zoomstarted(event_); zoomstarted(dispatch);
}).tween("zoom:zoom", function() { }).tween("zoom:zoom", function() {
var dx = size[0], dy = size[1], cx = dx / 2, cy = dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]); var dx = size[0], dy = size[1], cx = dx / 2, cy = dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
return function(t) { return function(t) {
...@@ -1244,16 +1236,16 @@ ...@@ -1244,16 +1236,16 @@
y: cy - l[1] * k, y: cy - l[1] * k,
k: k k: k
}; };
zoomed(event_); zoomed(dispatch);
}; };
}).each("end.zoom", function() { }).each("end.zoom", function() {
zoomended(event_); zoomended(dispatch);
}); });
} else { } else {
this.__chart__ = view; this.__chart__ = view;
zoomstarted(event_); zoomstarted(dispatch);
zoomed(event_); zoomed(dispatch);
zoomended(event_); zoomended(dispatch);
} }
}); });
}; };
...@@ -1336,46 +1328,46 @@ ...@@ -1336,46 +1328,46 @@
return (y - view.y) / view.k; return (y - view.y) / view.k;
}).map(y0.invert)); }).map(y0.invert));
} }
function zoomstarted(event) { function zoomstarted(dispatch) {
event({ dispatch({
type: "zoomstart" type: "zoomstart"
}); });
} }
function zoomed(event) { function zoomed(dispatch) {
rescale(); rescale();
event({ dispatch({
type: "zoom", type: "zoom",
scale: view.k, scale: view.k,
translate: [ view.x, view.y ] translate: [ view.x, view.y ]
}); });
} }
function zoomended(event) { function zoomended(dispatch) {
event({ dispatch({
type: "zoomend" type: "zoomend"
}); });
} }
function mousedowned() { function mousedowned() {
var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, dragged = 0, w = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), l = location(d3.mouse(target)), dragRestore = d3_event_dragSuppress(); var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(target); d3_selection_interrupt.call(that);
zoomstarted(event_); zoomstarted(dispatch);
function moved() { function moved() {
dragged = 1; dragged = 1;
translateTo(d3.mouse(target), l); translateTo(d3.mouse(that), location0);
zoomed(event_); zoomed(dispatch);
} }
function ended() { function ended() {
w.on(mousemove, d3_window === target ? mousewheelreset : null).on(mouseup, null); subject.on(mousemove, d3_window === that ? mousewheelreset : null).on(mouseup, null);
dragRestore(dragged && d3.event.target === eventTarget); dragRestore(dragged && d3.event.target === target);
zoomended(event_); zoomended(dispatch);
} }
} }
function touchstarted() { function touchstarted() {
var target = this, event_ = event.of(target, arguments), locations0 = {}, distance0 = 0, scale0, eventId = d3.event.changedTouches[0].identifier, touchmove = "touchmove.zoom-" + eventId, touchend = "touchend.zoom-" + eventId, w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended), t = d3.select(target).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress(); var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, target = d3.select(d3.event.target).on(touchmove, moved).on(touchend, ended), subject = d3.select(that).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(target); d3_selection_interrupt.call(that);
started(); started();
zoomstarted(event_); zoomstarted(dispatch);
function relocate() { function relocate() {
var touches = d3.touches(target); var touches = d3.touches(that);
scale0 = view.k; scale0 = view.k;
touches.forEach(function(t) { touches.forEach(function(t) {
if (t.identifier in locations0) locations0[t.identifier] = location(t); if (t.identifier in locations0) locations0[t.identifier] = location(t);
...@@ -1394,7 +1386,7 @@ ...@@ -1394,7 +1386,7 @@
scaleTo(view.k * 2); scaleTo(view.k * 2);
translateTo(p, l); translateTo(p, l);
d3_eventPreventDefault(); d3_eventPreventDefault();
zoomed(event_); zoomed(dispatch);
} }
touchtime = now; touchtime = now;
} else if (touches.length > 1) { } else if (touches.length > 1) {
...@@ -1403,7 +1395,7 @@ ...@@ -1403,7 +1395,7 @@
} }
} }
function moved() { function moved() {
var touches = d3.touches(target), p0, l0, p1, l1; var touches = d3.touches(that), p0, l0, p1, l1;
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) { for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
p1 = touches[i]; p1 = touches[i];
if (l1 = locations0[p1.identifier]) { if (l1 = locations0[p1.identifier]) {
...@@ -1419,7 +1411,7 @@ ...@@ -1419,7 +1411,7 @@
} }
touchtime = null; touchtime = null;
translateTo(p0, l0); translateTo(p0, l0);
zoomed(event_); zoomed(dispatch);
} }
function ended() { function ended() {
if (d3.event.touches.length) { if (d3.event.touches.length) {
...@@ -1431,37 +1423,37 @@ ...@@ -1431,37 +1423,37 @@
return void relocate(); return void relocate();
} }
} }
w.on(touchmove, null).on(touchend, null); target.on(zoomName, null);
t.on(mousedown, mousedowned).on(touchstart, touchstarted); subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
dragRestore(); dragRestore();
zoomended(event_); zoomended(dispatch);
} }
} }
function mousewheeled() { function mousewheeled() {
var event_ = event.of(this, arguments); var dispatch = event.of(this, arguments);
if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this), if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
zoomstarted(event_); zoomstarted(dispatch);
mousewheelTimer = setTimeout(function() { mousewheelTimer = setTimeout(function() {
mousewheelTimer = null; mousewheelTimer = null;
zoomended(event_); zoomended(dispatch);
}, 50); }, 50);
d3_eventPreventDefault(); d3_eventPreventDefault();
var point = center || d3.mouse(this); var point = center || d3.mouse(this);
if (!translate0) translate0 = location(point); if (!translate0) translate0 = location(point);
scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k); scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
translateTo(point, translate0); translateTo(point, translate0);
zoomed(event_); zoomed(dispatch);
} }
function mousewheelreset() { function mousewheelreset() {
translate0 = null; translate0 = null;
} }
function dblclicked() { function dblclicked() {
var event_ = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2; var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2;
zoomstarted(event_); zoomstarted(dispatch);
scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1)); scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
translateTo(p, l); translateTo(p, l);
zoomed(event_); zoomed(dispatch);
zoomended(event_); zoomended(dispatch);
} }
return d3.rebind(zoom, event, "on"); return d3.rebind(zoom, event, "on");
}; };
...@@ -1628,7 +1620,7 @@ ...@@ -1628,7 +1620,7 @@
return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16); return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
} }
function d3_rgb_parse(format, rgb, hsl) { function d3_rgb_parse(format, rgb, hsl) {
var r = 0, g = 0, b = 0, m1, m2, name; var r = 0, g = 0, b = 0, m1, m2, color;
m1 = /([a-z]+)\((.*)\)/i.exec(format); m1 = /([a-z]+)\((.*)\)/i.exec(format);
if (m1) { if (m1) {
m2 = m1[2].split(","); m2 = m1[2].split(",");
...@@ -1644,23 +1636,20 @@ ...@@ -1644,23 +1636,20 @@
} }
} }
} }
if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b); if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
if (format != null && format.charAt(0) === "#") { if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.substring(1), 16))) {
if (format.length === 4) { if (format.length === 4) {
r = format.charAt(1); r = (color & 3840) >> 4;
r += r; r = r >> 4 | r;
g = format.charAt(2); g = color & 240;
g += g; g = g >> 4 | g;
b = format.charAt(3); b = color & 15;
b += b; b = b << 4 | b;
} else if (format.length === 7) { } else if (format.length === 7) {
r = format.substring(1, 3); r = (color & 16711680) >> 16;
g = format.substring(3, 5); g = (color & 65280) >> 8;
b = format.substring(5, 7); b = color & 255;
} }
r = parseInt(r, 16);