Commit b0686e2a authored by Mike Bostock's avatar Mike Bostock

Merge branch '2.10.0'

parents 108d65da ee03eb6c
......@@ -4,6 +4,7 @@ NODE_PATH ?= ./node_modules
JS_COMPILER = $(NODE_PATH)/uglify-js/bin/uglifyjs
JS_BEAUTIFIER = $(NODE_PATH)/uglify-js/bin/uglifyjs -b -i 2 -nm -ns
JS_TESTER = $(NODE_PATH)/vows/bin/vows
LOCALE ?= en_US
all: \
d3.v2.js \
......@@ -19,7 +20,7 @@ all: \
d3.svg.js \
d3.behavior.js \
d3.layout.js \
d3.csv.js \
d3.dsv.js \
d3.geo.js \
d3.geom.js \
d3.time.js \
......@@ -80,6 +81,9 @@ d3.core.js: \
src/core/uninterpolate.js \
src/core/rgb.js \
src/core/hsl.js \
src/core/hcl.js \
src/core/lab.js \
src/core/xyz.js \
src/core/selection.js \
src/core/selection-select.js \
src/core/selection-selectAll.js \
......@@ -118,6 +122,7 @@ d3.core.js: \
src/core/transition-duration.js \
src/core/transition-each.js \
src/core/transition-transition.js \
src/core/tween.js \
src/core/timer.js \
src/core/mouse.js \
src/core/touches.js \
......@@ -136,6 +141,7 @@ d3.scale.js: \
src/scale/category.js \
src/scale/quantile.js \
src/scale/quantize.js \
src/scale/threshold.js \
src/scale/identity.js
d3.svg.js: \
......@@ -188,13 +194,14 @@ d3.geo.js: \
src/geo/greatArc.js \
src/geo/greatCircle.js
d3.csv.js: \
src/csv/csv.js \
src/csv/parse.js \
src/csv/format.js
d3.dsv.js: \
src/dsv/dsv.js \
src/dsv/csv.js \
src/dsv/tsv.js
d3.time.js: \
src/time/time.js \
src/time/format-$(LOCALE).js \
src/time/format.js \
src/time/format-utc.js \
src/time/format-iso.js \
......
......@@ -11,7 +11,7 @@
};
}
d3 = {
version: "2.9.7"
version: "2.10.0"
};
function d3_class(ctor, properties) {
try {
......@@ -183,9 +183,10 @@
return [ a, c ];
};
d3.random = {
normal: function(mean, deviation) {
if (arguments.length < 2) deviation = 1;
if (arguments.length < 1) mean = 0;
normal: function(µ, σ) {
var n = arguments.length;
if (n < 2) σ = 1;
if (n < 1) µ = 0;
return function() {
var x, y, r;
do {
......@@ -193,7 +194,22 @@
y = Math.random() * 2 - 1;
r = x * x + y * y;
} while (!r || r > 1);
return mean + deviation * x * Math.sqrt(-2 * Math.log(r) / r);
return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
};
},
logNormal: function(µ, σ) {
var n = arguments.length;
if (n < 2) σ = 1;
if (n < 1) µ = 0;
var random = d3.random.normal();
return function() {
return Math.exp(µ + σ * random());
};
},
irwinHall: function(m) {
return function() {
for (var s = 0, j = 0; j < m; j++) s += Math.random();
return s / m;
};
}
};
......@@ -373,7 +389,7 @@
return d == null;
}
function d3_collapse(s) {
return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ");
return s.trim().replace(/\s+/g, " ");
}
d3.range = function(start, stop, step) {
if (arguments.length < 3) {
......@@ -541,7 +557,7 @@
type = d3_format_types.get(type) || d3_format_typeDefault;
return function(value) {
if (integer && value % 1) return "";
var negative = value < 0 && (value = -value) ? "" : sign;
var negative = value < 0 && (value = -value) ? "-" : sign;
if (scale < 0) {
var prefix = d3.formatPrefix(value, precision);
value = prefix.scale(value);
......@@ -860,7 +876,6 @@
};
};
d3.interpolateTransform = function(a, b) {
if (n = d3_interpolateTransformSimilar(a, b)) return n;
var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
if (ta[0] != tb[0] || ta[1] != tb[1]) {
s.push("translate(", null, ",", null, ")");
......@@ -912,65 +927,6 @@
return s.join("");
};
};
var d3_interpolateTransformTypes = [ "", "", "translate", "scale", "rotate", "skewX", "skewY" ];
var d3_interpolateTransformSimilar = function(a, b) {
var ga = document.createElementNS(d3.ns.prefix.svg, "g"), gb = document.createElementNS(d3.ns.prefix.svg, "g");
return (d3_interpolateTransformSimilar = function(a, b) {
ga.setAttribute("transform", a);
gb.setAttribute("transform", b);
a = ga.transform.baseVal;
b = gb.transform.baseVal;
var sa = [], sb = [], i = -1, n = a.numberOfItems, m = b.numberOfItems, ta, tb, type;
if (m !== n) {
if (!m) b = d3_interpolateTransformIdentity(a); else if (!n) a = d3_interpolateTransformIdentity(b), n = m; else return;
} else if (!m) return;
while (++i < n) {
ta = a.getItem(i);
tb = b.getItem(i);
type = ta.type;
if (type !== tb.type || !type) return;
switch (type) {
case 1:
{
sa.push(new d3_transform(ta.matrix));
sb.push(new d3_transform(tb.matrix));
continue;
}
case 2:
{
ra = ta.matrix.e + "," + ta.matrix.f;
rb = tb.matrix.e + "," + tb.matrix.f;
break;
}
case 3:
{
ra = ta.matrix.a + "," + ta.matrix.d;
rb = tb.matrix.a + "," + tb.matrix.d;
break;
}
default:
{
ra = ta.angle;
rb = tb.angle;
}
}
sa.push(type = d3_interpolateTransformTypes[type], "(", ra, ")");
sb.push(type, "(", rb, ")");
}
return d3.interpolateString(sa.join(""), sb.join(""));
})(a, b);
};
function d3_interpolateTransformIdentity(a) {
return {
getItem: function(i) {
return {
type: a.getItem(i).type,
angle: 0,
matrix: d3_transformIdentity
};
}
};
}
d3.interpolateRgb = function(a, b) {
a = d3.rgb(a);
b = d3.rgb(b);
......@@ -985,7 +941,24 @@
var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
return function(t) {
return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t).toString();
return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
};
};
d3.interpolateLab = function(a, b) {
a = d3.lab(a);
b = d3.lab(b);
var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
return function(t) {
return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
};
};
d3.interpolateHcl = function(a, b) {
a = d3.hcl(a);
b = d3.hcl(b);
var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
return function(t) {
return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
};
};
d3.interpolateArray = function(a, b) {
......@@ -1018,8 +991,8 @@
};
};
var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
function d3_interpolateByName(n) {
return n == "transform" ? d3.interpolateTransform : d3.interpolate;
function d3_interpolateByName(name) {
return name == "transform" ? d3.interpolateTransform : d3.interpolate;
}
d3.interpolators = [ d3.interpolateObject, function(a, b) {
return b instanceof Array && d3.interpolateArray(a, b);
......@@ -1122,6 +1095,16 @@
}
return d3_hsl(h, s, l);
}
function d3_rgb_lab(r, g, b) {
r = d3_rgb_xyz(r);
g = d3_rgb_xyz(g);
b = d3_rgb_xyz(b);
var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
}
function d3_rgb_xyz(r) {
return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
}
function d3_rgb_parseNumber(c) {
var f = parseFloat(c);
return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
......@@ -1323,6 +1306,76 @@
}
return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
}
d3.hcl = function(h, c, l) {
return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
};
function d3_hcl(h, c, l) {
return new d3_Hcl(h, c, l);
}
function d3_Hcl(h, c, l) {
this.h = h;
this.c = c;
this.l = l;
}
d3_Hcl.prototype.brighter = function(k) {
return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
};
d3_Hcl.prototype.darker = function(k) {
return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
};
d3_Hcl.prototype.rgb = function() {
return d3_hcl_lab(this.h, this.c, this.l).rgb();
};
d3_Hcl.prototype.toString = function() {
return this.rgb() + "";
};
function d3_hcl_lab(h, c, l) {
return d3_lab(l, Math.cos(h *= Math.PI / 180) * c, Math.sin(h) * c);
}
d3.lab = function(l, a, b) {
return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
};
function d3_lab(l, a, b) {
return new d3_Lab(l, a, b);
}
function d3_Lab(l, a, b) {
this.l = l;
this.a = a;
this.b = b;
}
var d3_lab_K = 18;
var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
d3_Lab.prototype.brighter = function(k) {
return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
};
d3_Lab.prototype.darker = function(k) {
return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
};
d3_Lab.prototype.rgb = function() {
return d3_lab_rgb(this.l, this.a, this.b);
};
d3_Lab.prototype.toString = function() {
return this.rgb() + "";
};
function d3_lab_rgb(l, a, b) {
var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
x = d3_lab_xyz(x) * d3_lab_X;
y = d3_lab_xyz(y) * d3_lab_Y;
z = d3_lab_xyz(z) * d3_lab_Z;
return d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
}
function d3_lab_hcl(l, a, b) {
return d3_hcl(Math.atan2(b, a) / Math.PI * 180, Math.sqrt(a * a + b * b), l);
}
function d3_lab_xyz(x) {
return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
}
function d3_xyz_lab(x) {
return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
}
function d3_xyz_rgb(r) {
return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
}
function d3_selection(groups) {
d3_arraySubclass(groups, d3_selectionPrototype);
return groups;
......@@ -1389,11 +1442,19 @@
};
}
d3_selectionPrototype.attr = function(name, value) {
name = d3.ns.qualify(name);
if (arguments.length < 2) {
var node = this.node();
return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
if (typeof name === "string") {
var node = this.node();
name = d3.ns.qualify(name);
return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
}
for (value in name) this.each(d3_selection_attr(value, name[value]));
return this;
}
return this.each(d3_selection_attr(name, value));
};
function d3_selection_attr(name, value) {
name = d3.ns.qualify(name);
function attrNull() {
this.removeAttribute(name);
}
......@@ -1414,52 +1475,73 @@
var x = value.apply(this, arguments);
if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
}
return this.each(value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant);
};
return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
}
d3_selectionPrototype.classed = function(name, value) {
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);
if (arguments.length < 2) {
if (typeof name === "string") {
var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
if (value = node.classList) {
while (++i < n) if (!value.contains(name[i])) return false;
} else {
value = node.className;
if (value.baseVal != null) value = value.baseVal;
while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
}
return true;
}
for (value in name) this.each(d3_selection_classed(value, name[value]));
return this;
} else {
while (++i < n) if (!d3_selection_classed.call(this, names[i])) return false;
return true;
}
return this.each(d3_selection_classed(name, value));
};
function d3_selection_classedRe(name) {
return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
}
function d3_selection_classed(name, value) {
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");
if (arguments.length < 2) {
var node = this.node();
if (c = node.classList) return c.contains(name);
var c = node.className;
re.lastIndex = 0;
return re.test(c.baseVal != null ? c.baseVal : c);
}
function classedAdd() {
if (c = this.classList) return c.add(name);
var c = this.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
re.lastIndex = 0;
if (!re.test(cv)) {
cv = d3_collapse(cv + " " + name);
if (cb) c.baseVal = cv; else this.className = cv;
}
}
function classedRemove() {
if (c = this.classList) return c.remove(name);
var c = this.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
if (cv) {
cv = d3_collapse(cv.replace(re, " "));
if (cb) c.baseVal = cv; else this.className = cv;
}
name = name.trim().split(/\s+/).map(d3_selection_classedName);
var n = name.length;
function classedConstant() {
var i = -1;
while (++i < n) name[i](this, value);
}
function classedFunction() {
(value.apply(this, arguments) ? classedAdd : classedRemove).call(this);
}
return this.each(typeof value === "function" ? classedFunction : value ? classedAdd : classedRemove);
var i = -1, x = value.apply(this, arguments);
while (++i < n) name[i](this, x);
}
return typeof value === "function" ? classedFunction : classedConstant;
}
function d3_selection_classedName(name) {
var re = d3_selection_classedRe(name);
return function(node, value) {
if (c = node.classList) return value ? c.add(name) : c.remove(name);
var c = node.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
if (value) {
re.lastIndex = 0;
if (!re.test(cv)) {
cv = d3_collapse(cv + " " + name);
if (cb) c.baseVal = cv; else node.className = cv;
}
} else if (cv) {
cv = d3_collapse(cv.replace(re, " "));
if (cb) c.baseVal = cv; else node.className = cv;
}
};
}
d3_selectionPrototype.style = function(name, value, priority) {
if (arguments.length < 3) priority = "";
if (arguments.length < 2) return window.getComputedStyle(this.node(), null).getPropertyValue(name);
var n = arguments.length;
if (n < 3) {
if (typeof name !== "string") {
if (n < 2) value = "";
for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
return this;
}
if (n < 2) return window.getComputedStyle(this.node(), null).getPropertyValue(name);
priority = "";
}
return this.each(d3_selection_style(name, value, priority));
};
function d3_selection_style(name, value, priority) {
function styleNull() {
this.style.removeProperty(name);
}
......@@ -1470,10 +1552,17 @@
var x = value.apply(this, arguments);
if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
}
return this.each(value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant);
};
return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
}
d3_selectionPrototype.property = function(name, value) {
if (arguments.length < 2) return this.node()[name];
if (arguments.length < 2) {
if (typeof name === "string") return this.node()[name];
for (value in name) this.each(d3_selection_property(value, name[value]));
return this;
}
return this.each(d3_selection_property(name, value));
};
function d3_selection_property(name, value) {
function propertyNull() {
delete this[name];
}
......@@ -1484,8 +1573,8 @@
var x = value.apply(this, arguments);
if (x == null) delete this[name]; else this[name] = x;
}
return this.each(value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant);
};
return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
}
d3_selectionPrototype.text = function(value) {
return arguments.length < 1 ? this.node().textContent : this.each(typeof value === "function" ? function() {
var v = value.apply(this, arguments);
......@@ -1669,21 +1758,34 @@
};
}
d3_selectionPrototype.on = function(type, listener, capture) {
if (arguments.length < 3) capture = false;
var n = arguments.length;
if (n < 3) {
if (typeof type !== "string") {
if (n < 2) listener = false;
for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
return this;
}
if (n < 2) return (n = this.node()["__on" + type]) && n._;
capture = false;
}
return this.each(d3_selection_on(type, listener, capture));
};
function d3_selection_on(type, listener, capture) {
var name = "__on" + type, i = type.indexOf(".");
if (i > 0) type = type.substring(0, i);
if (arguments.length < 2) return (i = this.node()[name]) && i._;
return this.each(function() {
var node = this, args = arguments, o = node[name];
if (o) {
node.removeEventListener(type, o, o.$);
delete node[name];
}
if (listener) {
node.addEventListener(type, node[name] = l, l.$ = capture);
l._ = listener;
}
function l(e) {
function onRemove() {
var wrapper = this[name];
if (wrapper) {
this.removeEventListener(type, wrapper, wrapper.$);
delete this[name];
}
}
function onAdd() {
var node = this, args = arguments;
onRemove.call(this);
this.addEventListener(type, this[name] = wrapper, wrapper.$ = capture);
wrapper._ = listener;
function wrapper(e) {
var o = d3.event;
d3.event = e;
args[0] = node.__data__;
......@@ -1693,8 +1795,9 @@
d3.event = o;
}
}
});
};
}
return listener ? onAdd : onRemove;
}
d3_selectionPrototype.each = function(callback) {
return d3_selection_each(this, function(node, i, j) {
callback.call(node, node.__data__, i, j);
......@@ -1836,21 +1939,6 @@
}, 0, time);
return groups;
}
var d3_transitionRemove = {};
function d3_transitionNull(d, i, a) {
return a != "" && d3_transitionRemove;
}
function d3_transitionTween(name, b) {
var interpolate = d3_interpolateByName(name);
function transitionFunction(d, i, a) {
var v = b.call(this, d, i);
return v == null ? a != "" && d3_transitionRemove : a != v && interpolate(a, v);
}
function transitionString(d, i, a) {
return a != b && interpolate(a, b);
}
return typeof b === "function" ? transitionFunction : b == null ? d3_transitionNull : (b += "", transitionString);
}
var d3_transitionPrototype = [], d3_transitionNextId = 0, d3_transitionId = 0, d3_transitionDefaultDelay = 0, d3_transitionDefaultDuration = 250, d3_transitionDefaultEase = d3.ease("cubic-in-out"), d3_transitionDelay = d3_transitionDefaultDelay, d3_transitionDuration = d3_transitionDefaultDuration, d3_transitionEase = d3_transitionDefaultEase;
d3_transitionPrototype.call = d3_selectionPrototype.call;
d3.transition = function(selection) {
......@@ -1911,33 +1999,45 @@
return d3_transition(subgroups, this.id, this.time).ease(this.ease());
};
d3_transitionPrototype.attr = function(name, value) {
return this.attrTween(name, d3_transitionTween(name, value));
if (arguments.length < 2) {
for (value in name) this.attrTween(value, d3_tweenByName(name[value], value));
return this;
}
return this.attrTween(name, d3_tweenByName(value, name));
};
d3_transitionPrototype.attrTween = function(nameNS, tween) {
var name = d3.ns.qualify(nameNS);
function attrTween(d, i) {
var f = tween.call(this, d, i, this.getAttribute(name));
return f === d3_transitionRemove ? (this.removeAttribute(name), null) : f && function(t) {
return f === d3_tweenRemove ? (this.removeAttribute(name), null) : f && function(t) {
this.setAttribute(name, f(t));
};
}
function attrTweenNS(d, i) {
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
return f === d3_transitionRemove ? (this.removeAttributeNS(name.space, name.local), null) : f && function(t) {
return f === d3_tweenRemove ? (this.removeAttributeNS(name.space, name.local), null) : f && function(t) {
this.setAttributeNS(name.space, name.local, f(t));
};
}
return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
};
d3_transitionPrototype.style = function(name, value, priority) {
if (arguments.length < 3) priority = "";
return this.styleTween(name, d3_transitionTween(name, value), priority);
var n = arguments.length;
if (n < 3) {
if (typeof name !== "string") {
if (n < 2) value = "";
for (priority in name) this.styleTween(priority, d3_tweenByName(name[priority], priority), value);
return this;
}
priority = "";
}
return this.styleTween(name, d3_tweenByName(value, name), priority);
};
d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
return f === d3_transitionRemove ? (this.style.removeProperty(name), null) : f && function(t) {
return f === d3_tweenRemove ? (this.style.removeProperty(name), null) : f && function(t) {
this.style.setProperty(name, f(t), priority);
};