vendor/assets/javascripts/d3.v2.js in d3-rails-0.0.4 vs vendor/assets/javascripts/d3.v2.js in d3-rails-0.0.5

- old
+ new

@@ -8,11 +8,11 @@ d3_style_setProperty = d3_style_prototype.setProperty; d3_style_prototype.setProperty = function(name, value, priority) { d3_style_setProperty.call(this, name, value + "", priority); }; } -d3 = {version: "2.9.2"}; // semver +d3 = {version: "2.9.5"}; // semver function d3_class(ctor, properties) { try { for (var key in properties) { Object.defineProperty(ctor.prototype, key, { value: properties[key], @@ -447,11 +447,11 @@ function d3_splitter(d) { return d == null; } function d3_collapse(s) { - return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " "); + return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " "); } d3.range = function(start, stop, step) { if (arguments.length < 3) { step = 1; if (arguments.length < 2) { @@ -492,11 +492,11 @@ req.open("GET", url, true); if (mime) req.setRequestHeader("Accept", mime); req.onreadystatechange = function() { if (req.readyState === 4) { var s = req.status; - callback(s >= 200 && s < 300 || s === 304 ? req : null); + callback(!s && req.response || s >= 200 && s < 300 || s === 304 ? req : null); } }; req.send(null); }; d3.text = function(url, mime, callback) { @@ -1033,10 +1033,11 @@ } else { s.push(""); } if (ra != rb) { + if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path q.push({i: s.push(s.pop() + "rotate(", null, ")") - 2, x: d3.interpolateNumber(ra, rb)}); } else if (rb) { s.push(s.pop() + "rotate(" + rb + ")"); } @@ -1513,11 +1514,11 @@ d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) { return d3_selectMatcher.call(n, s); }; // Prefer Sizzle, if available. if (typeof Sizzle === "function") { - d3_select = function(s, n) { return Sizzle(s, n)[0]; }; + d3_select = function(s, n) { return Sizzle(s, n)[0] || null; }; d3_selectAll = function(s, n) { return Sizzle.uniqueSort(Sizzle(s, n)); }; d3_selectMatches = Sizzle.matchesSelector; } var d3_selectionPrototype = []; @@ -1624,11 +1625,11 @@ ? (name.local ? attrNullNS : attrNull) : (typeof value === "function" ? (name.local ? attrFunctionNS : attrFunction) : (name.local ? attrConstantNS : attrConstant))); }; d3_selectionPrototype.classed = function(name, value) { - var names = name.split(d3_selection_classedWhitespace), + var names = d3_collapse(name).split(" "), n = names.length, i = -1; if (arguments.length > 1) { while (++i < n) d3_selection_classed.call(this, names[i], value); return this; @@ -1636,12 +1637,10 @@ while (++i < n) if (!d3_selection_classed.call(this, names[i])) return false; return true; } }; -var d3_selection_classedWhitespace = /\s+/g; - function d3_selection_classed(name, value) { var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g"); // If no value is specified, return the first value. if (arguments.length < 2) { @@ -2009,18 +2008,23 @@ } } }); }; d3_selectionPrototype.each = function(callback) { - for (var j = -1, m = this.length; ++j < m;) { - for (var group = this[j], i = -1, n = group.length; ++i < n;) { - var node = group[i]; - if (node) callback.call(node, node.__data__, i, j); + return d3_selection_each(this, function(node, i, j) { + callback.call(node, node.__data__, i, j); + }); +}; + +function d3_selection_each(groups, callback) { + for (var j = 0, m = groups.length; j < m; j++) { + for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) { + if (node = group[i]) callback(node, i, j); } } - return this; -}; + return groups; +} // // Note: assigning to the arguments array simultaneously changes the value of // the corresponding argument! // // TODO The `this` argument probably shouldn't be the first argument to the @@ -2143,16 +2147,16 @@ event.on(type, listener); return groups; }; d3.timer(function(elapsed) { - groups.each(function(d, i, j) { + return d3_selection_each(groups, function(node, i, j) { var tweened = [], - node = this, - delay = groups[j][i].delay, - duration = groups[j][i].duration, - lock = node.__transition__ || (node.__transition__ = {active: 0, count: 0}); + delay = node.delay, + duration = node.duration, + lock = (node = node.node).__transition__ || (node.__transition__ = {active: 0, count: 0}), + d = node.__data__; ++lock.count; delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time); @@ -2194,11 +2198,10 @@ function stop() { if (!--lock.count) delete node.__transition__; return 1; } }); - return 1; }, 0, time); return groups; } @@ -2339,39 +2342,32 @@ var p; if (!this.__transition__ && (p = this.parentNode)) p.removeChild(this); }); }; d3_transitionPrototype.delay = function(value) { - var groups = this; - return groups.each(typeof value === "function" - ? function(d, i, j) { groups[j][i].delay = value.apply(this, arguments) | 0; } - : (value = value | 0, function(d, i, j) { groups[j][i].delay = value; })); + return d3_selection_each(this, typeof value === "function" + ? function(node, i, j) { node.delay = value.call(node = node.node, node.__data__, i, j) | 0; } + : (value = value | 0, function(node) { node.delay = value; })); }; d3_transitionPrototype.duration = function(value) { - var groups = this; - return groups.each(typeof value === "function" - ? function(d, i, j) { groups[j][i].duration = Math.max(1, value.apply(this, arguments) | 0); } - : (value = Math.max(1, value | 0), function(d, i, j) { groups[j][i].duration = value; })); + return d3_selection_each(this, typeof value === "function" + ? function(node, i, j) { node.duration = Math.max(1, value.call(node = node.node, node.__data__, i, j) | 0); } + : (value = Math.max(1, value | 0), function(node) { node.duration = value; })); }; function d3_transition_each(callback) { var id = d3_transitionId, ease = d3_transitionEase, delay = d3_transitionDelay, duration = d3_transitionDuration; d3_transitionId = this.id; d3_transitionEase = this.ease(); - for (var j = 0, m = this.length; j < m; j++) { - for (var group = this[j], i = 0, n = group.length; i < n; i++) { - var node = group[i]; - if (node) { - d3_transitionDelay = this[j][i].delay; - d3_transitionDuration = this[j][i].duration; - callback.call(node = node.node, node.__data__, i, j); - } - } - } + d3_selection_each(this, function(node, i, j) { + d3_transitionDelay = node.delay; + d3_transitionDuration = node.duration; + callback.call(node = node.node, node.__data__, i, j); + }); d3_transitionId = id; d3_transitionEase = ease; d3_transitionDelay = delay; d3_transitionDuration = duration; @@ -2811,15 +2807,15 @@ }; scale.tickFormat = function(n, format) { if (arguments.length < 2) format = d3_scale_logFormat; if (arguments.length < 1) return format; - var k = n / scale.ticks().length, + var k = Math.max(.1, n / scale.ticks().length), f = log === d3_scale_logn ? (e = -1e-12, Math.floor) : (e = 1e-12, Math.ceil), e; return function(d) { - return d / pow(f(log(d) + e)) < k ? format(d) : ""; + return d / pow(f(log(d) + e)) <= k ? format(d) : ""; }; }; scale.copy = function() { return d3_scale_log(linear.copy(), log); @@ -3545,23 +3541,25 @@ } return path.join(""); } function d3_svg_lineBundle(points, tension) { - var n = points.length - 1, - x0 = points[0][0], - y0 = points[0][1], - dx = points[n][0] - x0, - dy = points[n][1] - y0, - i = -1, - p, - t; - while (++i <= n) { - p = points[i]; - t = i / n; - p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx); - p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy); + var n = points.length - 1; + if (n) { + var x0 = points[0][0], + y0 = points[0][1], + dx = points[n][0] - x0, + dy = points[n][1] - y0, + i = -1, + p, + t; + while (++i <= n) { + p = points[i]; + t = i / n; + p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx); + p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy); + } } return d3_svg_lineBasis(points); } // Returns the dot product of the given four-element vectors. @@ -9033,10 +9031,11 @@ function d3_time_formatIsoNative(date) { return date.toISOString(); } d3_time_formatIsoNative.parse = function(string) { - return new Date(string); + var date = new Date(string); + return isNaN(date) ? null : date; }; d3_time_formatIsoNative.toString = d3_time_formatIso.toString; function d3_time_interval(local, step, number) {