vendor/assets/javascripts/d3.v2.js in d3_rails-2.8.1 vs vendor/assets/javascripts/d3.v2.js in d3_rails-2.9.1

- 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.8.1"}; // semver +d3 = {version: "2.9.1"}; // semver function d3_class(ctor, properties) { try { for (var key in properties) { Object.defineProperty(ctor.prototype, key, { value: properties[key], @@ -98,16 +98,24 @@ } }); var d3_map_prefix = "\0", // prevent collision with built-ins d3_map_prefixCode = d3_map_prefix.charCodeAt(0); +function d3_identity(d) { + return d; +} function d3_this() { return this; } -d3.functor = function(v) { +function d3_true() { + return true; +} +function d3_functor(v) { return typeof v === "function" ? v : function() { return v; }; -}; +} + +d3.functor = d3_functor; // Copies a variable number of methods from source to target. d3.rebind = function(target, source) { var i = 1, n = arguments.length, method; while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]); return target; @@ -482,11 +490,14 @@ if (arguments.length < 3) callback = mime, mime = null; else if (mime && req.overrideMimeType) req.overrideMimeType(mime); req.open("GET", url, true); if (mime) req.setRequestHeader("Accept", mime); req.onreadystatechange = function() { - if (req.readyState === 4) callback(req.status < 300 ? req : null); + if (req.readyState === 4) { + var s = req.status; + callback(s >= 200 && s < 300 || s === 304 ? req : null); + } }; req.send(null); }; d3.text = function(url, mime, callback) { function ready(req) { @@ -1118,11 +1129,11 @@ for (k in i) c[k] = i[k](t); return c; }; } -var d3_interpolate_number = /[-+]?(?:\d*\.?\d+)(?:[eE][-+]?\d+)?/g; +var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g; function d3_interpolateByName(n) { return n == "transform" ? d3.interpolateTransform : d3.interpolate; @@ -2148,12 +2159,12 @@ function start(elapsed) { if (lock.active > id) return stop(); lock.active = id; tweens.forEach(function(key, value) { - if (tween = value.call(node, d, i)) { - tweened.push(tween); + if (value = value.call(node, d, i)) { + tweened.push(value); } }); event.start.call(node, d, i); if (!tick(elapsed)) d3.timer(tick, 0, time); @@ -3183,29 +3194,29 @@ + "Z"); } arc.innerRadius = function(v) { if (!arguments.length) return innerRadius; - innerRadius = d3.functor(v); + innerRadius = d3_functor(v); return arc; }; arc.outerRadius = function(v) { if (!arguments.length) return outerRadius; - outerRadius = d3.functor(v); + outerRadius = d3_functor(v); return arc; }; arc.startAngle = function(v) { if (!arguments.length) return startAngle; - startAngle = d3.functor(v); + startAngle = d3_functor(v); return arc; }; arc.endAngle = function(v) { if (!arguments.length) return endAngle; - endAngle = d3.functor(v); + endAngle = d3_functor(v); return arc; }; arc.centroid = function() { var r = (innerRadius.apply(this, arguments) @@ -3237,76 +3248,80 @@ return d.endAngle; } function d3_svg_line(projection) { var x = d3_svg_lineX, y = d3_svg_lineY, + defined = d3_true, interpolate = d3_svg_lineInterpolatorDefault, - interpolator = d3_svg_lineInterpolators.get(interpolate), + interpolator = d3_svg_lineLinear, tension = .7; - function line(d) { - return d.length < 1 ? null : "M" + interpolator(projection(d3_svg_linePoints(this, d, x, y)), tension); + function line(data) { + var segments = [], + points = [], + i = -1, + n = data.length, + d, + fx = d3_functor(x), + fy = d3_functor(y); + + function segment() { + segments.push("M", interpolator(projection(points), tension)); + } + + while (++i < n) { + if (defined.call(this, d = data[i], i)) { + points.push([+fx.call(this, d, i), +fy.call(this, d, i)]); + } else if (points.length) { + segment(); + points = []; + } + } + + if (points.length) segment(); + + return segments.length ? segments.join("") : null; } - line.x = function(v) { + line.x = function(_) { if (!arguments.length) return x; - x = v; + x = _; return line; }; - line.y = function(v) { + line.y = function(_) { if (!arguments.length) return y; - y = v; + y = _; return line; }; - line.interpolate = function(v) { + line.defined = function(_) { + if (!arguments.length) return defined; + defined = _; + return line; + }; + + line.interpolate = function(_) { if (!arguments.length) return interpolate; - if (!d3_svg_lineInterpolators.has(v += "")) v = d3_svg_lineInterpolatorDefault; - interpolator = d3_svg_lineInterpolators.get(interpolate = v); + if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault; + interpolator = d3_svg_lineInterpolators.get(interpolate = _); return line; }; - line.tension = function(v) { + line.tension = function(_) { if (!arguments.length) return tension; - tension = v; + tension = _; return line; }; return line; } d3.svg.line = function() { - return d3_svg_line(Object); + return d3_svg_line(d3_identity); }; -// Converts the specified array of data into an array of points -// (x-y tuples), by evaluating the specified `x` and `y` functions on each -// data point. The `this` context of the evaluated functions is the specified -// "self" object; each function is passed the current datum and index. -function d3_svg_linePoints(self, d, x, y) { - var points = [], - i = -1, - n = d.length, - fx = typeof x === "function", - fy = typeof y === "function", - value; - if (fx && fy) { - while (++i < n) points.push([ - x.call(self, value = d[i], i), - y.call(self, value, i) - ]); - } else if (fx) { - while (++i < n) points.push([x.call(self, d[i], i), y]); - } else if (fy) { - while (++i < n) points.push([x, y.call(self, d[i], i)]); - } else { - while (++i < n) points.push([x, y]); - } - return points; -} - // The default `x` property, which references d[0]. function d3_svg_lineX(d) { return d[0]; } @@ -3638,23 +3653,21 @@ // Compute the normalized tangent vector from the slopes. Note that if x is // not monotonic, it's possible that the slope will be infinite, so we protect // against NaN by setting the coordinate to zero. i = -1; while (++i <= j) { - s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) - / (6 * (1 + m[i] * m[i])); + s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i])); tangents.push([s || 0, m[i] * s || 0]); } return tangents; } function d3_svg_lineMonotone(points) { return points.length < 3 ? d3_svg_lineLinear(points) - : points[0] + - d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points)); + : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points)); } d3.svg.line.radial = function() { var line = d3_svg_line(d3_svg_lineRadial); line.radius = line.x, delete line.x; line.angle = line.y, delete line.y; @@ -3679,95 +3692,119 @@ function d3_svg_area(projection) { var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, - interpolate, - i0, - i1, + defined = d3_true, + interpolate = d3_svg_lineInterpolatorDefault, + i0 = d3_svg_lineLinear, + i1 = d3_svg_lineLinear, + L = "L", tension = .7; - function area(d) { - if (d.length < 1) return null; - var points0 = d3_svg_linePoints(this, d, x0, y0), - points1 = d3_svg_linePoints(this, d, x0 === x1 ? d3_svg_areaX(points0) : x1, y0 === y1 ? d3_svg_areaY(points0) : y1); - return "M" + i0(projection(points1), tension) - + "L" + i1(projection(points0.reverse()), tension) - + "Z"; + function area(data) { + var segments = [], + points0 = [], + points1 = [], + i = -1, + n = data.length, + d, + fx0 = d3_functor(x0), + fy0 = d3_functor(y0), + fx1 = x0 === x1 ? function() { return x; } : d3_functor(x1), + fy1 = y0 === y1 ? function() { return y; } : d3_functor(y1), + x, + y; + + function segment() { + segments.push("M", i0(projection(points1), tension), + L, i1(projection(points0.reverse()), tension), + "Z"); + } + + while (++i < n) { + if (defined.call(this, d = data[i], i)) { + points0.push([x = +fx0.call(this, d, i), y = +fy0.call(this, d, i)]); + points1.push([+fx1.call(this, d, i), +fy1.call(this, d, i)]); + } else if (points0.length) { + segment(); + points0 = []; + points1 = []; + } + } + + if (points0.length) segment(); + + return segments.length ? segments.join("") : null; } - area.x = function(x) { + area.x = function(_) { if (!arguments.length) return x1; - x0 = x1 = x; + x0 = x1 = _; return area; }; - area.x0 = function(x) { + area.x0 = function(_) { if (!arguments.length) return x0; - x0 = x; + x0 = _; return area; }; - area.x1 = function(x) { + area.x1 = function(_) { if (!arguments.length) return x1; - x1 = x; + x1 = _; return area; }; - area.y = function(y) { + area.y = function(_) { if (!arguments.length) return y1; - y0 = y1 = y; + y0 = y1 = _; return area; }; - area.y0 = function(y) { + area.y0 = function(_) { if (!arguments.length) return y0; - y0 = y; + y0 = _; return area; }; - area.y1 = function(y) { + area.y1 = function(_) { if (!arguments.length) return y1; - y1 = y; + y1 = _; return area; }; - area.interpolate = function(x) { + area.defined = function(_) { + if (!arguments.length) return defined; + defined = _; + return area; + }; + + area.interpolate = function(_) { if (!arguments.length) return interpolate; - if (!d3_svg_lineInterpolators.has(x += "")) x = d3_svg_lineInterpolatorDefault; - i0 = d3_svg_lineInterpolators.get(interpolate = x); + if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault; + i0 = d3_svg_lineInterpolators.get(interpolate = _); i1 = i0.reverse || i0; + L = /-closed$/.test(_) ? "M" : "L"; return area; }; - area.tension = function(x) { + area.tension = function(_) { if (!arguments.length) return tension; - tension = x; + tension = _; return area; }; - return area.interpolate("linear"); + return area; } d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter; d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore; d3.svg.area = function() { return d3_svg_area(Object); }; - -function d3_svg_areaX(points) { - return function(d, i) { - return points[i][0]; - }; -} - -function d3_svg_areaY(points) { - return function(d, i) { - return points[i][1]; - }; -} d3.svg.area.radial = function() { var area = d3_svg_area(d3_svg_lineRadial); area.radius = area.x, delete area.x; area.innerRadius = area.x0, delete area.x0; area.outerRadius = area.x1, delete area.x1; @@ -3823,35 +3860,35 @@ return "Q 0,0 " + p1; } chord.radius = function(v) { if (!arguments.length) return radius; - radius = d3.functor(v); + radius = d3_functor(v); return chord; }; chord.source = function(v) { if (!arguments.length) return source; - source = d3.functor(v); + source = d3_functor(v); return chord; }; chord.target = function(v) { if (!arguments.length) return target; - target = d3.functor(v); + target = d3_functor(v); return chord; }; chord.startAngle = function(v) { if (!arguments.length) return startAngle; - startAngle = d3.functor(v); + startAngle = d3_functor(v); return chord; }; chord.endAngle = function(v) { if (!arguments.length) return endAngle; - endAngle = d3.functor(v); + endAngle = d3_functor(v); return chord; }; return chord; }; @@ -3889,17 +3926,17 @@ return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3]; } diagonal.source = function(x) { if (!arguments.length) return source; - source = d3.functor(x); + source = d3_functor(x); return diagonal; }; diagonal.target = function(x) { if (!arguments.length) return target; - target = d3.functor(x); + target = d3_functor(x); return diagonal; }; diagonal.projection = function(x) { if (!arguments.length) return projection; @@ -3947,18 +3984,18 @@ (size.call(this, d, i)); } symbol.type = function(x) { if (!arguments.length) return type; - type = d3.functor(x); + type = d3_functor(x); return symbol; }; // size of symbol in square pixels symbol.size = function(x) { if (!arguments.length) return size; - size = d3.functor(x); + size = d3_functor(x); return symbol; }; return symbol; }; @@ -4631,10 +4668,11 @@ offset = [offset.x - origin_[0], offset.y - origin_[1]]; } else { offset = [0, 0]; } + d3_eventCancel(); event_({type: "dragstart"}); function point() { var p = target.parentNode, t = d3.event.changedTouches; @@ -4785,11 +4823,11 @@ } function mouseup() { if (moved) d3_eventCancel(); w.on("mousemove.zoom", null).on("mouseup.zoom", null); - if (moved && d3.event.target === eventTarget) w.on("click.zoom", click); + if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true); } function click() { d3_eventCancel(); w.on("click.zoom", null); @@ -5009,16 +5047,16 @@ startAngle: a0, endAngle: a1, value: v }; } - groups.push({ + groups[di] = { index: di, startAngle: x0, endAngle: x, value: (x - x0) / k - }); + }; x += padding; } // Generate chords for each (non-empty) subgroup-subgroup link. i = -1; while (++i < n) { @@ -5227,20 +5265,20 @@ return force; }; force.linkDistance = function(x) { if (!arguments.length) return linkDistance; - linkDistance = d3.functor(x); + linkDistance = d3_functor(x); return force; }; // For backwards-compatibility. force.distance = force.linkDistance; force.linkStrength = function(x) { if (!arguments.length) return linkStrength; - linkStrength = d3.functor(x); + linkStrength = d3_functor(x); return force; }; force.friction = function(x) { if (!arguments.length) return friction; @@ -5364,11 +5402,11 @@ }; // use `node.call(force.drag)` to make nodes draggable force.drag = function() { if (!drag) drag = d3.behavior.drag() - .origin(Object) + .origin(d3_identity) .on("dragstart", dragstart) .on("drag", d3_layout_forceDrag) .on("dragend", d3_layout_forceDragEnd); this.on("mouseover.force", d3_layout_forceDragOver) @@ -5587,11 +5625,11 @@ }; var d3_layout_pieSortByValue = {}; // data is two-dimensional array of x,y; we populate y0 d3.layout.stack = function() { - var values = Object, + var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY; @@ -5852,16 +5890,18 @@ bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]); bin.y = 0; } // Fill the bins, ignoring values outside the range. - i = -1; while(++i < n) { - x = values[i]; - if ((x >= range[0]) && (x <= range[1])) { - bin = bins[d3.bisect(thresholds, x, 1, m) - 1]; - bin.y += k; - bin.push(data[i]); + if (m > 0) { + i = -1; while(++i < n) { + x = values[i]; + if ((x >= range[0]) && (x <= range[1])) { + bin = bins[d3.bisect(thresholds, x, 1, m) - 1]; + bin.y += k; + bin.push(data[i]); + } } } return bins; } @@ -5880,11 +5920,11 @@ // function that returns the range given the array of values and the current // index `i`. The default range is the extent (minimum and maximum) of the // values. histogram.range = function(x) { if (!arguments.length) return ranger; - ranger = d3.functor(x); + ranger = d3_functor(x); return histogram; }; // Specifies how to bin values in the histogram. The argument `x` may be // specified as a number, in which case the range of values will be split @@ -5897,11 +5937,11 @@ // Sturges' formula. histogram.bins = function(x) { if (!arguments.length) return binner; binner = typeof x === "number" ? function(range) { return d3_layout_histogramBinFixed(range, x); } - : d3.functor(x); + : d3_functor(x); return histogram; }; // Specifies whether the histogram's `y` value is a count (frequency) or a // probability (density). The default value is true. @@ -7583,11 +7623,11 @@ d3.geo.circle = function() { var origin = [0, 0], degrees = 90 - 1e-2, radians = degrees * d3_geo_radians, - arc = d3.geo.greatArc().target(Object); + arc = d3.geo.greatArc().target(d3_identity); function circle() { // TODO render a circle as a Polygon } @@ -7601,11 +7641,11 @@ }; var clipType = d3_geo_type({ FeatureCollection: function(o) { - var features = o.features.map(clipType).filter(Object); + var features = o.features.map(clipType).filter(d3_identity); return features && (o = Object.create(o), o.features = features, o); }, Feature: function(o) { var geometry = clipType(o.geometry); @@ -7643,11 +7683,11 @@ var coordinates = o.coordinates.map(function(d) { return d.map(clip); }).filter(function(d) { return d[0].length; }); return coordinates.length && (o = Object.create(o), o.coordinates = coordinates, o); }, GeometryCollection: function(o) { - var geometries = o.geometries.map(clipType).filter(Object); + var geometries = o.geometries.map(clipType).filter(d3_identity); return geometries.length && (o = Object.create(o), o.geometries = geometries, o); } }); @@ -8807,10 +8847,10 @@ var n = d3_time_weekdayRe.exec(string.substring(i, i + 10)); return n ? i += n[0].length : -1; } var d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i, - d3_time_weekdayRe = /^(?:Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)/i; + d3_time_weekdayRe = /^(?:Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)/i, d3_time_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; function d3_time_parseMonthAbbrev(date, string, i) { var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase()); return n == null ? -1 : (date.m = n, i);