Skip to content

Commit 23ee2c0

Browse files
committed
Merge branch '3.2.8'
2 parents c247e16 + 4c6b28d commit 23ee2c0

16 files changed

Lines changed: 141 additions & 93 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "3.2.7",
3+
"version": "3.2.8",
44
"main": "d3.js",
55
"scripts": [
66
"d3.js"

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"animation",
1111
"canvas"
1212
],
13-
"version": "3.2.7",
13+
"version": "3.2.8",
1414
"main": "index-browserify.js",
1515
"scripts": [
1616
"d3.js",

d3.js

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
d3 = function() {
22
var d3 = {
3-
version: "3.2.7"
3+
version: "3.2.8"
44
};
55
if (!Date.now) Date.now = function() {
66
return +new Date();
@@ -131,8 +131,8 @@ d3 = function() {
131131
return array;
132132
};
133133
d3.permute = function(array, indexes) {
134-
var permutes = [], i = -1, n = indexes.length;
135-
while (++i < n) permutes[i] = array[indexes[i]];
134+
var i = indexes.length, permutes = new Array(i);
135+
while (i--) permutes[i] = array[indexes[i]];
136136
return permutes;
137137
};
138138
d3.zip = function() {
@@ -204,7 +204,9 @@ d3 = function() {
204204
}
205205
d3.map = function(object) {
206206
var map = new d3_Map();
207-
for (var key in object) map.set(key, object[key]);
207+
if (object instanceof d3_Map) object.forEach(function(key, value) {
208+
map.set(key, value);
209+
}); else for (var key in object) map.set(key, object[key]);
208210
return map;
209211
};
210212
function d3_Map() {}
@@ -320,7 +322,7 @@ d3 = function() {
320322
};
321323
d3.set = function(array) {
322324
var set = new d3_Set();
323-
if (array) for (var i = 0; i < array.length; i++) set.add(array[i]);
325+
if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
324326
return set;
325327
};
326328
function d3_Set() {}
@@ -374,8 +376,8 @@ d3 = function() {
374376
var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
375377
var d3_array = d3_arraySlice;
376378
function d3_arrayCopy(pseudoarray) {
377-
var i = -1, n = pseudoarray.length, array = [];
378-
while (++i < n) array.push(pseudoarray[i]);
379+
var i = pseudoarray.length, array = new Array(i);
380+
while (i--) array[i] = pseudoarray[i];
379381
return array;
380382
}
381383
function d3_arraySlice(pseudoarray) {
@@ -855,7 +857,7 @@ d3 = function() {
855857
function d3_selection_sortComparator(comparator) {
856858
if (!arguments.length) comparator = d3.ascending;
857859
return function(a, b) {
858-
return !a - !b || comparator(a.__data__, b.__data__);
860+
return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
859861
};
860862
}
861863
d3_selectionPrototype.each = function(callback) {
@@ -1152,9 +1154,9 @@ d3 = function() {
11521154
return d3.rebind(drag, event, "on");
11531155
};
11541156
d3.behavior.zoom = function() {
1155-
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;
1157+
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;
11561158
function zoom() {
1157-
this.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on("touchstart.zoom", touchstarted);
1159+
this.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
11581160
}
11591161
zoom.translate = function(x) {
11601162
if (!arguments.length) return translate;
@@ -1232,27 +1234,37 @@ d3 = function() {
12321234
}
12331235
}
12341236
function touchstarted() {
1235-
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();
1236-
touches.forEach(function(t) {
1237-
locations[t.identifier] = location(t);
1238-
});
1239-
if (touches.length === 1) {
1240-
if (now - touchtime < 500) {
1241-
var p = touches[0], l = location(touches[0]);
1242-
scaleTo(scale * 2);
1243-
translateTo(p, l);
1244-
d3_eventPreventDefault();
1245-
dispatch(event_);
1237+
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();
1238+
started();
1239+
function relocate() {
1240+
var touches = d3.touches(target);
1241+
scale0 = scale;
1242+
locations0 = {};
1243+
touches.forEach(function(t) {
1244+
locations0[t.identifier] = location(t);
1245+
});
1246+
return touches;
1247+
}
1248+
function started() {
1249+
var now = Date.now(), touches = relocate();
1250+
if (touches.length === 1) {
1251+
if (now - touchtime < 500) {
1252+
var p = touches[0], l = locations0[p.identifier];
1253+
scaleTo(scale * 2);
1254+
translateTo(p, l);
1255+
d3_eventPreventDefault();
1256+
dispatch(event_);
1257+
}
1258+
touchtime = now;
1259+
} else if (touches.length > 1) {
1260+
var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1261+
distance0 = dx * dx + dy * dy;
12461262
}
1247-
touchtime = now;
1248-
} else if (touches.length > 1) {
1249-
var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1250-
distance0 = dx * dx + dy * dy;
12511263
}
12521264
function moved() {
1253-
var touches = d3.touches(target), p0 = touches[0], l0 = locations[p0.identifier];
1265+
var touches = d3.touches(target), p0 = touches[0], l0 = locations0[p0.identifier];
12541266
if (p1 = touches[1]) {
1255-
var p1, l1 = locations[p1.identifier], scale1 = d3.event.scale;
1267+
var p1, l1 = locations0[p1.identifier], scale1 = d3.event.scale;
12561268
if (scale1 == null) {
12571269
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
12581270
scale1 = distance0 && Math.sqrt(distance1 / distance0);
@@ -1266,9 +1278,13 @@ d3 = function() {
12661278
dispatch(event_);
12671279
}
12681280
function ended() {
1269-
w.on(touchmove, null).on(touchend, null);
1270-
t.on(mousedown, mousedowned);
1271-
dragRestore();
1281+
if (d3.event.touches.length) {
1282+
relocate();
1283+
} else {
1284+
w.on(touchmove, null).on(touchend, null);
1285+
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
1286+
dragRestore();
1287+
}
12721288
}
12731289
}
12741290
function mousewheeled() {
@@ -6843,9 +6859,8 @@ d3 = function() {
68436859
return scale;
68446860
};
68456861
scale.ticks = function() {
6846-
var extent = d3_scaleExtent(domain), ticks = [];
6847-
if (extent.every(isFinite)) {
6848-
var u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
6862+
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;
6863+
if (isFinite(j - i)) {
68496864
if (positive) {
68506865
for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
68516866
ticks.push(pow(i));

d3.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "3.2.7",
3+
"version": "3.2.8",
44
"description": "A small, free JavaScript library for manipulating documents based on data.",
55
"keywords": [
66
"dom",

src/arrays/map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import "../core/class";
22

33
d3.map = function(object) {
44
var map = new d3_Map;
5-
for (var key in object) map.set(key, object[key]);
5+
if (object instanceof d3_Map) object.forEach(function(key, value) { map.set(key, value); });
6+
else for (var key in object) map.set(key, object[key]);
67
return map;
78
};
89

src/arrays/permute.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
d3.permute = function(array, indexes) {
2-
var permutes = [],
3-
i = -1,
4-
n = indexes.length;
5-
while (++i < n) permutes[i] = array[indexes[i]];
2+
var i = indexes.length, permutes = new Array(i);
3+
while (i--) permutes[i] = array[indexes[i]];
64
return permutes;
75
};

src/arrays/set.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import "../core/class";
22
import "map";
33

44
d3.set = function(array) {
5-
var set = new d3_Set();
6-
if (array) for (var i = 0; i < array.length; i++) set.add(array[i]);
5+
var set = new d3_Set;
6+
if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
77
return set;
88
};
99

src/behavior/zoom.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ d3.behavior.zoom = function() {
1515
mousedown = "mousedown.zoom",
1616
mousemove = "mousemove.zoom",
1717
mouseup = "mouseup.zoom",
18+
touchstart = "touchstart.zoom",
19+
touchmove = "touchmove.zoom",
20+
touchend = "touchend.zoom",
21+
touchtime, // time of last touchstart (to detect double-tap)
1822
event = d3_eventDispatch(zoom, "zoom"),
1923
x0,
2024
x1,
2125
y0,
22-
y1,
23-
touchtime; // time of last touchstart (to detect double-tap)
26+
y1;
2427

2528
function zoom() {
2629
this.on(mousedown, mousedowned)
2730
.on(d3_behavior_zoomWheel + ".zoom", mousewheeled)
2831
.on(mousemove, mousewheelreset)
2932
.on("dblclick.zoom", dblclicked)
30-
.on("touchstart.zoom", touchstarted);
33+
.on(touchstart, touchstarted);
3134
}
3235

3336
zoom.translate = function(x) {
@@ -117,45 +120,55 @@ d3.behavior.zoom = function() {
117120
}
118121
}
119122

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

135-
touches.forEach(function(t) { locations[t.identifier] = location(t); });
134+
started();
136135

137-
if (touches.length === 1) {
138-
if (now - touchtime < 500) { // dbltap
139-
var p = touches[0], l = location(touches[0]);
140-
scaleTo(scale * 2);
141-
translateTo(p, l);
142-
d3_eventPreventDefault();
143-
dispatch(event_);
136+
function relocate() {
137+
var touches = d3.touches(target);
138+
scale0 = scale;
139+
locations0 = {};
140+
touches.forEach(function(t) { locations0[t.identifier] = location(t); });
141+
return touches;
142+
}
143+
144+
// Temporarily override touchstart while gesture is active.
145+
function started() {
146+
var now = Date.now(),
147+
touches = relocate();
148+
149+
if (touches.length === 1) {
150+
if (now - touchtime < 500) { // dbltap
151+
var p = touches[0], l = locations0[p.identifier];
152+
scaleTo(scale * 2);
153+
translateTo(p, l);
154+
d3_eventPreventDefault();
155+
dispatch(event_);
156+
}
157+
touchtime = now;
158+
} else if (touches.length > 1) {
159+
var p = touches[0], q = touches[1],
160+
dx = p[0] - q[0], dy = p[1] - q[1];
161+
distance0 = dx * dx + dy * dy;
144162
}
145-
touchtime = now;
146-
} else if (touches.length > 1) {
147-
var p = touches[0], q = touches[1],
148-
dx = p[0] - q[0], dy = p[1] - q[1];
149-
distance0 = dx * dx + dy * dy;
150163
}
151164

152165
function moved() {
153166
var touches = d3.touches(target),
154167
p0 = touches[0],
155-
l0 = locations[p0.identifier];
168+
l0 = locations0[p0.identifier];
156169

157170
if (p1 = touches[1]) {
158-
var p1, l1 = locations[p1.identifier],
171+
var p1, l1 = locations0[p1.identifier],
159172
scale1 = d3.event.scale;
160173
if (scale1 == null) {
161174
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
@@ -172,9 +185,13 @@ d3.behavior.zoom = function() {
172185
}
173186

174187
function ended() {
175-
w.on(touchmove, null).on(touchend, null);
176-
t.on(mousedown, mousedowned);
177-
dragRestore();
188+
if (d3.event.touches.length) {
189+
relocate(); // locations may have detached due to rotation
190+
} else {
191+
w.on(touchmove, null).on(touchend, null);
192+
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
193+
dragRestore();
194+
}
178195
}
179196
}
180197

src/core/array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import "document";
33
var d3_array = d3_arraySlice; // conversion for NodeLists
44

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

0 commit comments

Comments
 (0)