Skip to content

Commit

Permalink
Merge branch '3.2.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 1, 2013
2 parents c247e16 + 4c6b28d commit 23ee2c0
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 93 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.2.7",
"version": "3.2.8",
"main": "d3.js",
"scripts": [
"d3.js"
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"animation",
"canvas"
],
"version": "3.2.7",
"version": "3.2.8",
"main": "index-browserify.js",
"scripts": [
"d3.js",
Expand Down
81 changes: 48 additions & 33 deletions d3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3 = function() {
var d3 = {
version: "3.2.7"
version: "3.2.8"
};
if (!Date.now) Date.now = function() {
return +new Date();
Expand Down Expand Up @@ -131,8 +131,8 @@ d3 = function() {
return array;
};
d3.permute = function(array, indexes) {
var permutes = [], i = -1, n = indexes.length;
while (++i < n) permutes[i] = array[indexes[i]];
var i = indexes.length, permutes = new Array(i);
while (i--) permutes[i] = array[indexes[i]];
return permutes;
};
d3.zip = function() {
Expand Down Expand Up @@ -204,7 +204,9 @@ d3 = function() {
}
d3.map = function(object) {
var map = new d3_Map();
for (var key in object) map.set(key, object[key]);
if (object instanceof d3_Map) object.forEach(function(key, value) {
map.set(key, value);
}); else for (var key in object) map.set(key, object[key]);
return map;
};
function d3_Map() {}
Expand Down Expand Up @@ -320,7 +322,7 @@ d3 = function() {
};
d3.set = function(array) {
var set = new d3_Set();
if (array) for (var i = 0; i < array.length; i++) set.add(array[i]);
if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
return set;
};
function d3_Set() {}
Expand Down Expand Up @@ -374,8 +376,8 @@ d3 = function() {
var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
var d3_array = d3_arraySlice;
function d3_arrayCopy(pseudoarray) {
var i = -1, n = pseudoarray.length, array = [];
while (++i < n) array.push(pseudoarray[i]);
var i = pseudoarray.length, array = new Array(i);
while (i--) array[i] = pseudoarray[i];
return array;
}
function d3_arraySlice(pseudoarray) {
Expand Down Expand Up @@ -855,7 +857,7 @@ d3 = function() {
function d3_selection_sortComparator(comparator) {
if (!arguments.length) comparator = d3.ascending;
return function(a, b) {
return !a - !b || comparator(a.__data__, b.__data__);
return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
};
}
d3_selectionPrototype.each = function(callback) {
Expand Down Expand Up @@ -1152,9 +1154,9 @@ d3 = function() {
return d3.rebind(drag, event, "on");
};
d3.behavior.zoom = function() {
var translate = [ 0, 0 ], translate0, scale = 1, scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
var translate = [ 0, 0 ], translate0, scale = 1, scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", touchstart = "touchstart.zoom", touchmove = "touchmove.zoom", touchend = "touchend.zoom", touchtime, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1;
function zoom() {
this.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on("touchstart.zoom", touchstarted);
this.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
}
zoom.translate = function(x) {
if (!arguments.length) return translate;
Expand Down Expand Up @@ -1232,27 +1234,37 @@ d3 = function() {
}
}
function touchstarted() {
var target = this, event_ = event.of(target, arguments), touches = d3.touches(target), locations = {}, distance0 = 0, scale0 = scale, now = Date.now(), name = "zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove." + name, touchend = "touchend." + name, w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended), t = d3.select(target).on(mousedown, null), dragRestore = d3_event_dragSuppress();
touches.forEach(function(t) {
locations[t.identifier] = location(t);
});
if (touches.length === 1) {
if (now - touchtime < 500) {
var p = touches[0], l = location(touches[0]);
scaleTo(scale * 2);
translateTo(p, l);
d3_eventPreventDefault();
dispatch(event_);
var target = this, event_ = event.of(target, arguments), locations0, distance0 = 0, scale0, 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();
started();
function relocate() {
var touches = d3.touches(target);
scale0 = scale;
locations0 = {};
touches.forEach(function(t) {
locations0[t.identifier] = location(t);
});
return touches;
}
function started() {
var now = Date.now(), touches = relocate();
if (touches.length === 1) {
if (now - touchtime < 500) {
var p = touches[0], l = locations0[p.identifier];
scaleTo(scale * 2);
translateTo(p, l);
d3_eventPreventDefault();
dispatch(event_);
}
touchtime = now;
} else if (touches.length > 1) {
var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
distance0 = dx * dx + dy * dy;
}
touchtime = now;
} else if (touches.length > 1) {
var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
distance0 = dx * dx + dy * dy;
}
function moved() {
var touches = d3.touches(target), p0 = touches[0], l0 = locations[p0.identifier];
var touches = d3.touches(target), p0 = touches[0], l0 = locations0[p0.identifier];
if (p1 = touches[1]) {
var p1, l1 = locations[p1.identifier], scale1 = d3.event.scale;
var p1, l1 = locations0[p1.identifier], scale1 = d3.event.scale;
if (scale1 == null) {
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
scale1 = distance0 && Math.sqrt(distance1 / distance0);
Expand All @@ -1266,9 +1278,13 @@ d3 = function() {
dispatch(event_);
}
function ended() {
w.on(touchmove, null).on(touchend, null);
t.on(mousedown, mousedowned);
dragRestore();
if (d3.event.touches.length) {
relocate();
} else {
w.on(touchmove, null).on(touchend, null);
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
dragRestore();
}
}
}
function mousewheeled() {
Expand Down Expand Up @@ -6843,9 +6859,8 @@ d3 = function() {
return scale;
};
scale.ticks = function() {
var extent = d3_scaleExtent(domain), ticks = [];
if (extent.every(isFinite)) {
var u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
if (isFinite(j - i)) {
if (positive) {
for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
ticks.push(pow(i));
Expand Down
8 changes: 4 additions & 4 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.2.7",
"version": "3.2.8",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand Down
3 changes: 2 additions & 1 deletion src/arrays/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import "../core/class";

d3.map = function(object) {
var map = new d3_Map;
for (var key in object) map.set(key, object[key]);
if (object instanceof d3_Map) object.forEach(function(key, value) { map.set(key, value); });
else for (var key in object) map.set(key, object[key]);
return map;
};

Expand Down
6 changes: 2 additions & 4 deletions src/arrays/permute.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
d3.permute = function(array, indexes) {
var permutes = [],
i = -1,
n = indexes.length;
while (++i < n) permutes[i] = array[indexes[i]];
var i = indexes.length, permutes = new Array(i);
while (i--) permutes[i] = array[indexes[i]];
return permutes;
};
4 changes: 2 additions & 2 deletions src/arrays/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import "../core/class";
import "map";

d3.set = function(array) {
var set = new d3_Set();
if (array) for (var i = 0; i < array.length; i++) set.add(array[i]);
var set = new d3_Set;
if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
return set;
};

Expand Down
75 changes: 46 additions & 29 deletions src/behavior/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ d3.behavior.zoom = function() {
mousedown = "mousedown.zoom",
mousemove = "mousemove.zoom",
mouseup = "mouseup.zoom",
touchstart = "touchstart.zoom",
touchmove = "touchmove.zoom",
touchend = "touchend.zoom",
touchtime, // time of last touchstart (to detect double-tap)
event = d3_eventDispatch(zoom, "zoom"),
x0,
x1,
y0,
y1,
touchtime; // time of last touchstart (to detect double-tap)
y1;

function zoom() {
this.on(mousedown, mousedowned)
.on(d3_behavior_zoomWheel + ".zoom", mousewheeled)
.on(mousemove, mousewheelreset)
.on("dblclick.zoom", dblclicked)
.on("touchstart.zoom", touchstarted);
.on(touchstart, touchstarted);
}

zoom.translate = function(x) {
Expand Down Expand Up @@ -117,45 +120,55 @@ d3.behavior.zoom = function() {
}
}

// These closures persist for as long as at least one touch is active.
function touchstarted() {
var target = this,
event_ = event.of(target, arguments),
touches = d3.touches(target),
locations = {},
locations0, // touchstart locations
distance0 = 0, // distance² between initial touches
scale0 = scale, // scale when we started touching
now = Date.now(),
name = "zoom-" + d3.event.changedTouches[0].identifier,
touchmove = "touchmove." + name,
touchend = "touchend." + name,
scale0, // scale when we started touching
w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended),
t = d3.select(target).on(mousedown, null), // prevent duplicate events
t = d3.select(target).on(mousedown, null).on(touchstart, started), // prevent duplicate events
dragRestore = d3_event_dragSuppress();

touches.forEach(function(t) { locations[t.identifier] = location(t); });
started();

if (touches.length === 1) {
if (now - touchtime < 500) { // dbltap
var p = touches[0], l = location(touches[0]);
scaleTo(scale * 2);
translateTo(p, l);
d3_eventPreventDefault();
dispatch(event_);
function relocate() {
var touches = d3.touches(target);
scale0 = scale;
locations0 = {};
touches.forEach(function(t) { locations0[t.identifier] = location(t); });
return touches;
}

// Temporarily override touchstart while gesture is active.
function started() {
var now = Date.now(),
touches = relocate();

if (touches.length === 1) {
if (now - touchtime < 500) { // dbltap
var p = touches[0], l = locations0[p.identifier];
scaleTo(scale * 2);
translateTo(p, l);
d3_eventPreventDefault();
dispatch(event_);
}
touchtime = now;
} else if (touches.length > 1) {
var p = touches[0], q = touches[1],
dx = p[0] - q[0], dy = p[1] - q[1];
distance0 = dx * dx + dy * dy;
}
touchtime = now;
} else if (touches.length > 1) {
var p = touches[0], q = touches[1],
dx = p[0] - q[0], dy = p[1] - q[1];
distance0 = dx * dx + dy * dy;
}

function moved() {
var touches = d3.touches(target),
p0 = touches[0],
l0 = locations[p0.identifier];
l0 = locations0[p0.identifier];

if (p1 = touches[1]) {
var p1, l1 = locations[p1.identifier],
var p1, l1 = locations0[p1.identifier],
scale1 = d3.event.scale;
if (scale1 == null) {
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
Expand All @@ -172,9 +185,13 @@ d3.behavior.zoom = function() {
}

function ended() {
w.on(touchmove, null).on(touchend, null);
t.on(mousedown, mousedowned);
dragRestore();
if (d3.event.touches.length) {
relocate(); // locations may have detached due to rotation
} else {
w.on(touchmove, null).on(touchend, null);
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
dragRestore();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import "document";
var d3_array = d3_arraySlice; // conversion for NodeLists

function d3_arrayCopy(pseudoarray) {
var i = -1, n = pseudoarray.length, array = [];
while (++i < n) array.push(pseudoarray[i]);
var i = pseudoarray.length, array = new Array(i);
while (i--) array[i] = pseudoarray[i];
return array;
}

Expand Down
14 changes: 7 additions & 7 deletions src/scale/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ function d3_scale_log(linear, base, positive, domain) {

scale.ticks = function() {
var extent = d3_scaleExtent(domain),
ticks = [];
if (extent.every(isFinite)) {
var u = extent[0],
v = extent[1],
i = Math.floor(log(u)),
j = Math.ceil(log(v)),
n = base % 1 ? 2 : base;
ticks = [],
u = extent[0],
v = extent[1],
i = Math.floor(log(u)),
j = Math.ceil(log(v)),
n = base % 1 ? 2 : base;
if (isFinite(j - i)) {
if (positive) {
for (; i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
ticks.push(pow(i));
Expand Down
2 changes: 1 addition & 1 deletion src/selection/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ d3_selectionPrototype.sort = function(comparator) {
function d3_selection_sortComparator(comparator) {
if (!arguments.length) comparator = d3.ascending;
return function(a, b) {
return (!a - !b) || comparator(a.__data__, b.__data__);
return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
};
}
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
d3 = (function(){
var d3 = {version: "3.2.7"}; // semver
var d3 = {version: "3.2.8"}; // semver
8 changes: 8 additions & 0 deletions test/arrays/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ suite.addBatch({
var m = map(Object.create(null, {foo: {value: 42, enumerable: false}}));
assert.isFalse(m.has("foo"));
assert.isUndefined(m.get("foo"));
},
"map(map) copies the given map": function(map) {
var a = map({foo: 42}),
b = map(a);
assert.isTrue(b.has("foo"));
assert.equal(b.get("foo"), 42);
a.set("bar", true);
assert.isFalse(b.has("bar"));
}
},
"forEach": {
Expand Down

0 comments on commit 23ee2c0

Please sign in to comment.