app/assets/javascripts/d3.js in d3_rails-3.2.7 vs app/assets/javascripts/d3.js in d3_rails-3.2.8
- old
+ new
@@ -1,8 +1,8 @@
d3 = function() {
var d3 = {
- version: "3.2.7"
+ version: "3.2.8"
};
if (!Date.now) Date.now = function() {
return +new Date();
};
var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window;
@@ -129,12 +129,12 @@
t = array[m], array[m] = array[i], array[i] = t;
}
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() {
if (!(n = arguments.length)) return [];
for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
@@ -202,11 +202,13 @@
ctor.prototype = properties;
}
}
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() {}
d3_class(d3_Map, {
has: function(key) {
@@ -318,11 +320,11 @@
};
return nest;
};
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() {}
d3_class(d3_Set, {
has: function(value) {
@@ -372,12 +374,12 @@
}
}
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) {
return Array.prototype.slice.call(pseudoarray);
}
@@ -853,11 +855,11 @@
return this.order();
};
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) {
return d3_selection_each(this, function(node, i, j) {
callback.call(node, node.__data__, i, j);
@@ -1150,13 +1152,13 @@
return drag;
};
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;
translate = x.map(Number);
rescale();
@@ -1230,31 +1232,41 @@
w.on(mousemove, d3_window === target ? mousewheelreset : null).on(mouseup, null);
dragRestore(dragged && d3.event.target === eventTarget);
}
}
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);
}
p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
@@ -1264,13 +1276,17 @@
touchtime = null;
translateTo(p0, l0);
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() {
d3_eventPreventDefault();
if (!translate0) translate0 = location(d3.mouse(this));
@@ -6841,12 +6857,11 @@
linear.domain(niced);
domain = niced.map(pow);
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));
} else {
ticks.push(pow(i));
\ No newline at end of file