app/assets/javascripts/d3.v4.js in d3-rails-4.7.4 vs app/assets/javascripts/d3.v4.js in d3-rails-4.8.0
- old
+ new
@@ -1,13 +1,13 @@
-// https://d3js.org Version 4.7.4. Copyright 2017 Mike Bostock.
+// https://d3js.org Version 4.8.0. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, (function (exports) { 'use strict';
-var version = "4.7.4";
+var version = "4.8.0";
var ascending = function(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
};
@@ -56,86 +56,111 @@
function pair(a, b) {
return [a, b];
}
-var cross = function(a, b, f) {
- var na = a.length, nb = b.length, c = new Array(na * nb), ia, ib, ic, va;
- if (f == null) f = pair;
- for (ia = ic = 0; ia < na; ++ia) for (va = a[ia], ib = 0; ib < nb; ++ib, ++ic) c[ic] = f(va, b[ib]);
- return c;
+var cross = function(values0, values1, reduce) {
+ var n0 = values0.length,
+ n1 = values1.length,
+ values = new Array(n0 * n1),
+ i0,
+ i1,
+ i,
+ value0;
+
+ if (reduce == null) reduce = pair;
+
+ for (i0 = i = 0; i0 < n0; ++i0) {
+ for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
+ values[i] = reduce(value0, values1[i1]);
+ }
+ }
+
+ return values;
};
var descending = function(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
};
var number = function(x) {
return x === null ? NaN : +x;
};
-var variance = function(array, f) {
- var n = array.length,
+var variance = function(values, valueof) {
+ var n = values.length,
m = 0,
- a,
- d,
- s = 0,
i = -1,
- j = 0;
+ mean = 0,
+ value,
+ delta,
+ sum = 0;
- if (f == null) {
+ if (valueof == null) {
while (++i < n) {
- if (!isNaN(a = number(array[i]))) {
- d = a - m;
- m += d / ++j;
- s += d * (a - m);
+ if (!isNaN(value = number(values[i]))) {
+ delta = value - mean;
+ mean += delta / ++m;
+ sum += delta * (value - mean);
}
}
}
else {
while (++i < n) {
- if (!isNaN(a = number(f(array[i], i, array)))) {
- d = a - m;
- m += d / ++j;
- s += d * (a - m);
+ if (!isNaN(value = number(valueof(values[i], i, values)))) {
+ delta = value - mean;
+ mean += delta / ++m;
+ sum += delta * (value - mean);
}
}
}
- if (j > 1) return s / (j - 1);
+ if (m > 1) return sum / (m - 1);
};
var deviation = function(array, f) {
var v = variance(array, f);
return v ? Math.sqrt(v) : v;
};
-var extent = function(array, f) {
- var i = -1,
- n = array.length,
- a,
- b,
- c;
+var extent = function(values, valueof) {
+ var n = values.length,
+ i = -1,
+ value,
+ min,
+ max;
- if (f == null) {
- while (++i < n) if ((b = array[i]) != null && b >= b) { a = c = b; break; }
- while (++i < n) if ((b = array[i]) != null) {
- if (a > b) a = b;
- if (c < b) c = b;
+ if (valueof == null) {
+ while (++i < n) { // Find the first comparable value.
+ if ((value = values[i]) != null && value >= value) {
+ min = max = value;
+ while (++i < n) { // Compare the remaining values.
+ if ((value = values[i]) != null) {
+ if (min > value) min = value;
+ if (max < value) max = value;
+ }
+ }
+ }
}
}
else {
- while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = c = b; break; }
- while (++i < n) if ((b = f(array[i], i, array)) != null) {
- if (a > b) a = b;
- if (c < b) c = b;
+ while (++i < n) { // Find the first comparable value.
+ if ((value = valueof(values[i], i, values)) != null && value >= value) {
+ min = max = value;
+ while (++i < n) { // Compare the remaining values.
+ if ((value = valueof(values[i], i, values)) != null) {
+ if (min > value) min = value;
+ if (max < value) max = value;
+ }
+ }
+ }
}
}
- return [a, c];
+ return [min, max];
};
var array = Array.prototype;
var slice = array.slice;
@@ -168,18 +193,46 @@
var e10 = Math.sqrt(50);
var e5 = Math.sqrt(10);
var e2 = Math.sqrt(2);
var ticks = function(start, stop, count) {
- var step = tickStep(start, stop, count);
- return sequence(
- Math.ceil(start / step) * step,
- Math.floor(stop / step) * step + step / 2, // inclusive
- step
- );
+ var reverse = stop < start,
+ i = -1,
+ n,
+ ticks,
+ step;
+
+ if (reverse) n = start, start = stop, stop = n;
+
+ if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
+
+ if (step > 0) {
+ start = Math.ceil(start / step);
+ stop = Math.floor(stop / step);
+ ticks = new Array(n = Math.ceil(stop - start + 1));
+ while (++i < n) ticks[i] = (start + i) * step;
+ } else {
+ start = Math.floor(start * step);
+ stop = Math.ceil(stop * step);
+ ticks = new Array(n = Math.ceil(start - stop + 1));
+ while (++i < n) ticks[i] = (start - i) / step;
+ }
+
+ if (reverse) ticks.reverse();
+
+ return ticks;
};
+function tickIncrement(start, stop, count) {
+ var step = (stop - start) / Math.max(0, count),
+ power = Math.floor(Math.log(step) / Math.LN10),
+ error = step / Math.pow(10, power);
+ return power >= 0
+ ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
+ : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
+}
+
function tickStep(start, stop, count) {
var step0 = Math.abs(stop - start) / Math.max(0, count),
step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
error = step0 / step1;
if (error >= e10) step1 *= 10;
@@ -211,16 +264,19 @@
x0 = xz[0],
x1 = xz[1],
tz = threshold(values, x0, x1);
// Convert number of thresholds into uniform thresholds.
- if (!Array.isArray(tz)) tz = ticks(x0, x1, tz);
+ if (!Array.isArray(tz)) {
+ tz = tickStep(x0, x1, tz);
+ tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
+ }
// Remove any thresholds outside the domain.
var m = tz.length;
while (tz[0] <= x0) tz.shift(), --m;
- while (tz[m - 1] >= x1) tz.pop(), --m;
+ while (tz[m - 1] > x1) tz.pop(), --m;
var bins = new Array(m + 1),
bin;
// Initialize bins.
@@ -254,21 +310,21 @@
};
return histogram;
};
-var threshold = function(array, p, f) {
- if (f == null) f = number;
- if (!(n = array.length)) return;
- if ((p = +p) <= 0 || n < 2) return +f(array[0], 0, array);
- if (p >= 1) return +f(array[n - 1], n - 1, array);
+var threshold = function(values, p, valueof) {
+ if (valueof == null) valueof = number;
+ if (!(n = values.length)) return;
+ if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
+ if (p >= 1) return +valueof(values[n - 1], n - 1, values);
var n,
- h = (n - 1) * p,
- i = Math.floor(h),
- a = +f(array[i], i, array),
- b = +f(array[i + 1], i + 1, array);
- return a + (b - a) * (h - i);
+ i = (n - 1) * p,
+ i0 = Math.floor(i),
+ value0 = +valueof(values[i0], i0, values),
+ value1 = +valueof(values[i0 + 1], i0 + 1, values);
+ return value0 + (value1 - value0) * (i - i0);
};
var freedmanDiaconis = function(values, min, max) {
values = map.call(values, number).sort(ascending);
return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
@@ -276,59 +332,89 @@
var scott = function(values, min, max) {
return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
};
-var max = function(array, f) {
- var i = -1,
- n = array.length,
- a,
- b;
+var max = function(values, valueof) {
+ var n = values.length,
+ i = -1,
+ value,
+ max;
- if (f == null) {
- while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
- while (++i < n) if ((b = array[i]) != null && b > a) a = b;
+ if (valueof == null) {
+ while (++i < n) { // Find the first comparable value.
+ if ((value = values[i]) != null && value >= value) {
+ max = value;
+ while (++i < n) { // Compare the remaining values.
+ if ((value = values[i]) != null && value > max) {
+ max = value;
+ }
+ }
+ }
+ }
}
else {
- while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
- while (++i < n) if ((b = f(array[i], i, array)) != null && b > a) a = b;
+ while (++i < n) { // Find the first comparable value.
+ if ((value = valueof(values[i], i, values)) != null && value >= value) {
+ max = value;
+ while (++i < n) { // Compare the remaining values.
+ if ((value = valueof(values[i], i, values)) != null && value > max) {
+ max = value;
+ }
+ }
+ }
+ }
}
- return a;
+ return max;
};
-var mean = function(array, f) {
- var s = 0,
- n = array.length,
- a,
+var mean = function(values, valueof) {
+ var n = values.length,
+ m = n,
i = -1,
- j = n;
+ value,
+ sum = 0;
- if (f == null) {
- while (++i < n) if (!isNaN(a = number(array[i]))) s += a; else --j;
+ if (valueof == null) {
+ while (++i < n) {
+ if (!isNaN(value = number(values[i]))) sum += value;
+ else --m;
+ }
}
else {
- while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) s += a; else --j;
+ while (++i < n) {
+ if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
+ else --m;
+ }
}
- if (j) return s / j;
+ if (m) return sum / m;
};
-var median = function(array, f) {
- var numbers = [],
- n = array.length,
- a,
- i = -1;
+var median = function(values, valueof) {
+ var n = values.length,
+ i = -1,
+ value,
+ numbers = [];
- if (f == null) {
- while (++i < n) if (!isNaN(a = number(array[i]))) numbers.push(a);
+ if (valueof == null) {
+ while (++i < n) {
+ if (!isNaN(value = number(values[i]))) {
+ numbers.push(value);
+ }
+ }
}
else {
- while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) numbers.push(a);
+ while (++i < n) {
+ if (!isNaN(value = number(valueof(values[i], i, values)))) {
+ numbers.push(value);
+ }
+ }
}
return threshold(numbers.sort(ascending), 0.5);
};
@@ -352,46 +438,66 @@
}
return merged;
};
-var min = function(array, f) {
- var i = -1,
- n = array.length,
- a,
- b;
+var min = function(values, valueof) {
+ var n = values.length,
+ i = -1,
+ value,
+ min;
- if (f == null) {
- while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
- while (++i < n) if ((b = array[i]) != null && a > b) a = b;
+ if (valueof == null) {
+ while (++i < n) { // Find the first comparable value.
+ if ((value = values[i]) != null && value >= value) {
+ min = value;
+ while (++i < n) { // Compare the remaining values.
+ if ((value = values[i]) != null && min > value) {
+ min = value;
+ }
+ }
+ }
+ }
}
else {
- while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
- while (++i < n) if ((b = f(array[i], i, array)) != null && a > b) a = b;
+ while (++i < n) { // Find the first comparable value.
+ if ((value = valueof(values[i], i, values)) != null && value >= value) {
+ min = value;
+ while (++i < n) { // Compare the remaining values.
+ if ((value = valueof(values[i], i, values)) != null && min > value) {
+ min = value;
+ }
+ }
+ }
+ }
}
- return a;
+ return min;
};
var permute = function(array, indexes) {
var i = indexes.length, permutes = new Array(i);
while (i--) permutes[i] = array[indexes[i]];
return permutes;
};
-var scan = function(array, compare) {
- if (!(n = array.length)) return;
- var i = 0,
- n,
+var scan = function(values, compare) {
+ if (!(n = values.length)) return;
+ var n,
+ i = 0,
j = 0,
xi,
- xj = array[j];
+ xj = values[j];
- if (!compare) compare = ascending;
+ if (compare == null) compare = ascending;
- while (++i < n) if (compare(xi = array[i], xj) < 0 || compare(xj, xj) !== 0) xj = xi, j = i;
+ while (++i < n) {
+ if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
+ xj = xi, j = i;
+ }
+ }
if (compare(xj, xj) === 0) return j;
};
var shuffle = function(array, i0, i1) {
@@ -407,25 +513,29 @@
}
return array;
};
-var sum = function(array, f) {
- var s = 0,
- n = array.length,
- a,
- i = -1;
+var sum = function(values, valueof) {
+ var n = values.length,
+ i = -1,
+ value,
+ sum = 0;
- if (f == null) {
- while (++i < n) if (a = +array[i]) s += a; // Note: zero and null are equivalent.
+ if (valueof == null) {
+ while (++i < n) {
+ if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
+ }
}
else {
- while (++i < n) if (a = +f(array[i], i, array)) s += a;
+ while (++i < n) {
+ if (value = +valueof(values[i], i, values)) sum += value;
+ }
}
- return s;
+ return sum;
};
var transpose = function(matrix) {
if (!(n = matrix.length)) return [];
for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
@@ -6403,11 +6513,12 @@
var formatLocale = function(locale) {
var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
currency = locale.currency,
decimal = locale.decimal,
- numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3;
+ numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
+ percent = locale.percent || "%";
function newFormat(specifier) {
specifier = formatSpecifier(specifier);
var fill = specifier.fill,
@@ -6421,11 +6532,11 @@
type = specifier.type;
// Compute the prefix and suffix.
// For SI-prefix, the suffix is lazily computed.
var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
- suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? "%" : "";
+ suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
// What format function should we use?
// Is this an integer type?
// Can this type generate exponential notation?
var formatType = formatTypes[type],
@@ -16201,9 +16312,10 @@
exports.range = sequence;
exports.scan = scan;
exports.shuffle = shuffle;
exports.sum = sum;
exports.ticks = ticks;
+exports.tickIncrement = tickIncrement;
exports.tickStep = tickStep;
exports.transpose = transpose;
exports.variance = variance;
exports.zip = zip;
exports.axisTop = axisTop;