Skip to content

Commit a83ff05

Browse files
committed
Merge branch '3.3.3'
2 parents fc5a586 + e67138a commit a83ff05

12 files changed

Lines changed: 133 additions & 85 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.3.2",
3+
"version": "3.3.3",
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.3.2",
13+
"version": "3.3.3",
1414
"main": "index-browserify.js",
1515
"scripts": [
1616
"d3.js",

d3.js

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
d3 = function() {
22
var d3 = {
3-
version: "3.3.2"
3+
version: "3.3.3"
44
};
55
if (!Date.now) Date.now = function() {
66
return +new Date();
@@ -1088,13 +1088,9 @@ d3 = function() {
10881088
d3_mouse_bug44083 = !(ctm.f || ctm.e);
10891089
svg.remove();
10901090
}
1091-
if (d3_mouse_bug44083) {
1092-
point.x = e.pageX;
1093-
point.y = e.pageY;
1094-
} else {
1095-
point.x = e.clientX;
1096-
point.y = e.clientY;
1097-
}
1091+
if (e.changedTouches) e = e.changedTouches[0];
1092+
if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
1093+
point.y = e.clientY;
10981094
point = point.matrixTransform(container.getScreenCTM().inverse());
10991095
return [ point.x, point.y ];
11001096
}
@@ -1205,7 +1201,7 @@ d3 = function() {
12051201
x: 0,
12061202
y: 0,
12071203
k: 1
1208-
}, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchmove = "touchmove.zoom", touchend = "touchend.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
1204+
}, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
12091205
function zoom(g) {
12101206
g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
12111207
}
@@ -1355,21 +1351,24 @@ d3 = function() {
13551351
}
13561352
}
13571353
function touchstarted() {
1358-
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();
1354+
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();
13591355
d3_selection_interrupt.call(target);
13601356
started();
13611357
zoomstarted(event_);
13621358
function relocate() {
13631359
var touches = d3.touches(target);
13641360
scale0 = view.k;
1365-
locations0 = {};
13661361
touches.forEach(function(t) {
1367-
locations0[t.identifier] = location(t);
1362+
if (t.identifier in locations0) locations0[t.identifier] = location(t);
13681363
});
13691364
return touches;
13701365
}
13711366
function started() {
1372-
var now = Date.now(), touches = relocate();
1367+
var changed = d3.event.changedTouches;
1368+
for (var i = 0, n = changed.length; i < n; ++i) {
1369+
locations0[changed[i].identifier] = null;
1370+
}
1371+
var touches = relocate(), now = Date.now();
13731372
if (touches.length === 1) {
13741373
if (now - touchtime < 500) {
13751374
var p = touches[0], l = locations0[p.identifier];
@@ -1385,13 +1384,16 @@ d3 = function() {
13851384
}
13861385
}
13871386
function moved() {
1388-
var touches = d3.touches(target), p0 = touches[0], l0 = locations0[p0.identifier];
1389-
if (p1 = touches[1]) {
1390-
var p1, l1 = locations0[p1.identifier], scale1 = d3.event.scale;
1391-
if (scale1 == null) {
1392-
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
1393-
scale1 = distance0 && Math.sqrt(distance1 / distance0);
1387+
var touches = d3.touches(target), p0, l0, p1, l1;
1388+
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1389+
p1 = touches[i];
1390+
if (l1 = locations0[p1.identifier]) {
1391+
if (l0) break;
1392+
p0 = p1, l0 = l1;
13941393
}
1394+
}
1395+
if (l1) {
1396+
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
13951397
p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
13961398
l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
13971399
scaleTo(scale1 * scale0);
@@ -1402,13 +1404,18 @@ d3 = function() {
14021404
}
14031405
function ended() {
14041406
if (d3.event.touches.length) {
1405-
relocate();
1406-
} else {
1407-
w.on(touchmove, null).on(touchend, null);
1408-
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
1409-
dragRestore();
1410-
zoomended(event_);
1407+
var changed = d3.event.changedTouches;
1408+
for (var i = 0, n = changed.length; i < n; ++i) {
1409+
delete locations0[changed[i].identifier];
1410+
}
1411+
for (var identifier in locations0) {
1412+
return void relocate();
1413+
}
14111414
}
1415+
w.on(touchmove, null).on(touchend, null);
1416+
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
1417+
dragRestore();
1418+
zoomended(event_);
14121419
}
14131420
}
14141421
function mousewheeled() {
@@ -8118,7 +8125,7 @@ d3 = function() {
81188125
g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
81198126
}
81208127
function brushstart() {
8121-
var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(), center, origin = mouse(), offset;
8128+
var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(), center, origin = d3.mouse(target), offset;
81228129
var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
81238130
if (d3.event.changedTouches) {
81248131
w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
@@ -8141,10 +8148,6 @@ d3 = function() {
81418148
type: "brushstart"
81428149
});
81438150
brushmove();
8144-
function mouse() {
8145-
var touches = d3.event.changedTouches;
8146-
return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
8147-
}
81488151
function keydown() {
81498152
if (d3.event.keyCode == 32) {
81508153
if (!dragging) {
@@ -8165,7 +8168,7 @@ d3 = function() {
81658168
}
81668169
}
81678170
function brushmove() {
8168-
var point = mouse(), moved = false;
8171+
var point = d3.mouse(target), moved = false;
81698172
if (offset) {
81708173
point[0] += offset[0];
81718174
point[1] += offset[1];
@@ -8513,17 +8516,18 @@ d3 = function() {
85138516
H: 0,
85148517
M: 0,
85158518
S: 0,
8516-
L: 0
8519+
L: 0,
8520+
Z: null
85178521
}, i = d3_time_parse(d, template, string, 0);
85188522
if (i != string.length) return null;
85198523
if ("p" in d) d.H = d.H % 12 + d.p * 12;
8520-
var date = new d3_date();
8524+
var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
85218525
if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
85228526
date.setFullYear(d.y, 0, 1);
85238527
date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
85248528
} else date.setFullYear(d.y, d.m, d.d);
8525-
date.setHours(d.H, d.M, d.S, d.L);
8526-
return date;
8529+
date.setHours(d.H + Math.floor(d.Z / 100), d.M + d.Z % 100, d.S, d.L);
8530+
return localZ ? date._ : date;
85278531
};
85288532
format.toString = function() {
85298533
return template;
@@ -8652,6 +8656,7 @@ d3 = function() {
86528656
X: d3_time_parseLocaleTime,
86538657
y: d3_time_parseYear,
86548658
Y: d3_time_parseFullYear,
8659+
Z: d3_time_parseZone,
86558660
"%": d3_time_parseLiteralPercent
86568661
};
86578662
function d3_time_parseWeekdayAbbrev(date, string, i) {
@@ -8708,6 +8713,10 @@ d3 = function() {
87088713
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
87098714
return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
87108715
}
8716+
function d3_time_parseZone(date, string, i) {
8717+
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = +string,
8718+
i + 5) : -1;
8719+
}
87118720
function d3_time_expandYear(d) {
87128721
return d + (d > 68 ? 1900 : 2e3);
87138722
}

d3.min.js

Lines changed: 5 additions & 5 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.3.2",
3+
"version": "3.3.3",
44
"description": "A small, free JavaScript library for manipulating documents based on data.",
55
"keywords": [
66
"dom",

src/behavior/zoom.js

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ d3.behavior.zoom = function() {
1919
mouseup = "mouseup.zoom",
2020
mousewheelTimer,
2121
touchstart = "touchstart.zoom",
22-
touchmove = "touchmove.zoom",
23-
touchend = "touchend.zoom",
2422
touchtime, // time of last touchstart (to detect double-tap)
2523
event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"),
2624
x0,
@@ -186,9 +184,12 @@ d3.behavior.zoom = function() {
186184
function touchstarted() {
187185
var target = this,
188186
event_ = event.of(target, arguments),
189-
locations0, // touchstart locations
187+
locations0 = {}, // touchstart locations
190188
distance0 = 0, // distance² between initial touches
191189
scale0, // scale when we started touching
190+
eventId = d3.event.changedTouches[0].identifier,
191+
touchmove = "touchmove.zoom-" + eventId,
192+
touchend = "touchend.zoom-" + eventId,
192193
w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended),
193194
t = d3.select(target).on(mousedown, null).on(touchstart, started), // prevent duplicate events
194195
dragRestore = d3_event_dragSuppress();
@@ -197,18 +198,26 @@ d3.behavior.zoom = function() {
197198
started();
198199
zoomstarted(event_);
199200

201+
// Updates locations of any touches in locations0.
200202
function relocate() {
201203
var touches = d3.touches(target);
202204
scale0 = view.k;
203-
locations0 = {};
204-
touches.forEach(function(t) { locations0[t.identifier] = location(t); });
205+
touches.forEach(function(t) {
206+
if (t.identifier in locations0) locations0[t.identifier] = location(t);
207+
});
205208
return touches;
206209
}
207210

208211
// Temporarily override touchstart while gesture is active.
209212
function started() {
210-
var now = Date.now(),
211-
touches = relocate();
213+
// Only track touches started on the target element.
214+
var changed = d3.event.changedTouches;
215+
for (var i = 0, n = changed.length; i < n; ++i) {
216+
locations0[changed[i].identifier] = null;
217+
}
218+
219+
var touches = relocate(),
220+
now = Date.now();
212221

213222
if (touches.length === 1) {
214223
if (now - touchtime < 500) { // dbltap
@@ -228,16 +237,19 @@ d3.behavior.zoom = function() {
228237

229238
function moved() {
230239
var touches = d3.touches(target),
231-
p0 = touches[0],
232-
l0 = locations0[p0.identifier];
233-
234-
if (p1 = touches[1]) {
235-
var p1, l1 = locations0[p1.identifier],
236-
scale1 = d3.event.scale;
237-
if (scale1 == null) {
238-
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
239-
scale1 = distance0 && Math.sqrt(distance1 / distance0);
240+
p0, l0,
241+
p1, l1;
242+
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
243+
p1 = touches[i];
244+
if (l1 = locations0[p1.identifier]) {
245+
if (l0) break;
246+
p0 = p1, l0 = l1;
240247
}
248+
}
249+
250+
if (l1) {
251+
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1,
252+
scale1 = distance0 && Math.sqrt(distance1 / distance0);
241253
p0 = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
242254
l0 = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
243255
scaleTo(scale1 * scale0);
@@ -249,14 +261,24 @@ d3.behavior.zoom = function() {
249261
}
250262

251263
function ended() {
264+
// If there are any globally-active touches remaining, remove the ended
265+
// touches from locations0.
252266
if (d3.event.touches.length) {
253-
relocate(); // locations may have detached due to rotation
254-
} else {
255-
w.on(touchmove, null).on(touchend, null);
256-
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
257-
dragRestore();
258-
zoomended(event_);
267+
var changed = d3.event.changedTouches;
268+
for (var i = 0, n = changed.length; i < n; ++i) {
269+
delete locations0[changed[i].identifier];
270+
}
271+
// If locations0 is not empty, then relocate and continue listening for
272+
// touchmove and touchend.
273+
for (var identifier in locations0) {
274+
return void relocate(); // locations may have detached due to rotation
275+
}
259276
}
277+
// Otherwise, remove touchmove and touchend listeners.
278+
w.on(touchmove, null).on(touchend, null);
279+
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
280+
dragRestore();
281+
zoomended(event_);
260282
}
261283
}
262284

src/event/mouse.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ function d3_mousePoint(container, e) {
2424
d3_mouse_bug44083 = !(ctm.f || ctm.e);
2525
svg.remove();
2626
}
27-
if (d3_mouse_bug44083) {
28-
point.x = e.pageX;
29-
point.y = e.pageY;
30-
} else {
31-
point.x = e.clientX;
32-
point.y = e.clientY;
33-
}
27+
if (e.changedTouches) e = e.changedTouches[0];
28+
if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY;
29+
else point.x = e.clientX, point.y = e.clientY;
3430
point = point.matrixTransform(container.getScreenCTM().inverse());
3531
return [point.x, point.y];
3632
}

src/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
d3 = (function(){
2-
var d3 = {version: "3.3.2"}; // semver
2+
var d3 = {version: "3.3.3"}; // semver

src/svg/brush.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ d3.svg.brush = function() {
154154
dragging = eventTarget.classed("extent"),
155155
dragRestore = d3_event_dragSuppress(),
156156
center,
157-
origin = mouse(),
157+
origin = d3.mouse(target),
158158
offset;
159159

160160
var w = d3.select(d3_window)
@@ -198,11 +198,6 @@ d3.svg.brush = function() {
198198
event_({type: "brushstart"});
199199
brushmove();
200200

201-
function mouse() {
202-
var touches = d3.event.changedTouches;
203-
return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
204-
}
205-
206201
function keydown() {
207202
if (d3.event.keyCode == 32) {
208203
if (!dragging) {
@@ -225,7 +220,7 @@ d3.svg.brush = function() {
225220
}
226221

227222
function brushmove() {
228-
var point = mouse(),
223+
var point = d3.mouse(target),
229224
moved = false;
230225

231226
// Preserve the offset for thick resizers.

0 commit comments

Comments
 (0)