summaryrefslogtreecommitdiff
path: root/media/d3.js
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-10-14 10:03:06 -0500
committerDan McGee <dan@archlinux.org>2011-10-14 10:07:16 -0500
commitd9abb069ec5976414982a2c344d7e55413224a22 (patch)
treea4d93231016327d04c6dcb6293d2ee580bb5fb55 /media/d3.js
parent1cde4d45da91abae2525785c4d93e9ec648ec416 (diff)
Update d3 JS resources to latest version
This fixes an issue I discovered in attribute transition values in IE. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'media/d3.js')
-rw-r--r--media/d3.js270
1 files changed, 188 insertions, 82 deletions
diff --git a/media/d3.js b/media/d3.js
index 9b77bec1..23edb6b1 100644
--- a/media/d3.js
+++ b/media/d3.js
@@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
-d3 = {version: "2.3.0"}; // semver
+d3 = {version: "2.4.3"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists
function d3_arrayCopy(pseudoarray) {
@@ -59,6 +59,24 @@ d3.ascending = function(a, b) {
d3.descending = function(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
};
+d3.mean = function(array, f) {
+ var n = array.length,
+ a,
+ m = 0,
+ i = -1,
+ j = 0;
+ if (arguments.length === 1) {
+ while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
+ } else {
+ while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
+ }
+ return j ? m : undefined;
+};
+d3.median = function(array, f) {
+ if (arguments.length > 1) array = array.map(f);
+ array = array.filter(d3_number);
+ return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
+};
d3.min = function(array, f) {
var i = -1,
n = array.length,
@@ -87,6 +105,9 @@ d3.max = function(array, f) {
}
return a;
};
+function d3_number(x) {
+ return x != null && !isNaN(x);
+}
d3.sum = function(array, f) {
var s = 0,
n = array.length,
@@ -472,10 +493,11 @@ d3.format = function(specifier) {
comma = match[7],
precision = match[8],
type = match[9],
- percentage = false,
+ scale = 1,
+ suffix = "",
integer = false;
- if (precision) precision = precision.substring(1);
+ if (precision) precision = +precision.substring(1);
if (zfill) {
fill = "0"; // TODO align = "=";
@@ -484,22 +506,36 @@ d3.format = function(specifier) {
switch (type) {
case "n": comma = true; type = "g"; break;
- case "%": percentage = true; type = "f"; break;
- case "p": percentage = true; type = "r"; break;
- case "d": integer = true; precision = "0"; break;
+ case "%": scale = 100; suffix = "%"; type = "f"; break;
+ case "p": scale = 100; suffix = "%"; type = "r"; break;
+ case "d": integer = true; precision = 0; break;
+ case "s": scale = -1; type = "r"; break;
}
+ // If no precision is specified for r, fallback to general notation.
+ if (type == "r" && !precision) type = "g";
+
type = d3_format_types[type] || d3_format_typeDefault;
return function(value) {
- var number = percentage ? value * 100 : +value,
- negative = (number < 0) && (number = -number) ? "\u2212" : sign;
// Return the empty string for floats formatted as ints.
- if (integer && (number % 1)) return "";
+ if (integer && (value % 1)) return "";
- // Convert the input value to the desired precision.
- value = type(number, precision);
+ // Convert negative to positive, and record the sign prefix.
+ var negative = (value < 0) && (value = -value) ? "\u2212" : sign;
+
+ // Apply the scale, computing it from the value's exponent for si format.
+ if (scale < 0) {
+ var prefix = d3.formatPrefix(value, precision);
+ value *= prefix.scale;
+ suffix = prefix.symbol;
+ } else {
+ value *= scale;
+ }
+
+ // Convert to the desired precision.
+ value = type(value, precision);
// If the fill character is 0, the sign and group is applied after the fill.
if (zfill) {
@@ -516,9 +552,8 @@ d3.format = function(specifier) {
var length = value.length;
if (length < width) value = new Array(width - length + 1).join(fill) + value;
}
- if (percentage) value += "%";
- return value;
+ return value + suffix;
};
};
@@ -529,12 +564,13 @@ var d3_format_types = {
g: function(x, p) { return x.toPrecision(p); },
e: function(x, p) { return x.toExponential(p); },
f: function(x, p) { return x.toFixed(p); },
- r: function(x, p) {
- var n = x ? 1 + Math.floor(1e-15 + Math.log(x) / Math.LN10) : 1;
- return d3.round(x, p - n).toFixed(Math.max(0, Math.min(20, p - n)));
- }
+ r: function(x, p) { return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p))); }
};
+function d3_format_precision(x, p) {
+ return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
+}
+
function d3_format_typeDefault(x) {
return x + "";
}
@@ -547,6 +583,26 @@ function d3_format_group(value) {
while (i > 0) t.push(value.substring(i -= 3, i + 3));
return t.reverse().join(",") + f;
}
+var d3_formatPrefixes = ["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"].map(d3_formatPrefix);
+
+d3.formatPrefix = function(value, precision) {
+ var i = 0;
+ if (value) {
+ if (value < 0) value *= -1;
+ if (precision) value = d3.round(value, d3_format_precision(value, precision));
+ i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
+ i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
+ }
+ return d3_formatPrefixes[8 + i / 3];
+};
+
+function d3_formatPrefix(d, i) {
+ return {
+ scale: Math.pow(10, (8 - i) * 3),
+ symbol: d
+ };
+}
+
/*
* TERMS OF USE - EASING EQUATIONS
*
@@ -780,10 +836,10 @@ d3.interpolateRgb = function(a, b) {
bg = b.g - ag,
bb = b.b - ab;
return function(t) {
- return "rgb(" + Math.round(ar + br * t)
- + "," + Math.round(ag + bg * t)
- + "," + Math.round(ab + bb * t)
- + ")";
+ return "#"
+ + d3_rgb_hex(Math.round(ar + br * t))
+ + d3_rgb_hex(Math.round(ag + bg * t))
+ + d3_rgb_hex(Math.round(ab + bb * t));
};
};
@@ -867,7 +923,8 @@ function d3_uninterpolateClamp(a, b) {
}
d3.rgb = function(r, g, b) {
return arguments.length === 1
- ? d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb)
+ ? (r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b)
+ : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb))
: d3_rgb(~~r, ~~g, ~~b);
};
@@ -892,17 +949,17 @@ d3_Rgb.prototype.brighter = function(k) {
if (g && g < i) g = i;
if (b && b < i) b = i;
return d3_rgb(
- Math.min(255, Math.floor(r / k)),
- Math.min(255, Math.floor(g / k)),
- Math.min(255, Math.floor(b / k)));
+ Math.min(255, Math.floor(r / k)),
+ Math.min(255, Math.floor(g / k)),
+ Math.min(255, Math.floor(b / k)));
};
d3_Rgb.prototype.darker = function(k) {
k = Math.pow(0.7, arguments.length ? k : 1);
return d3_rgb(
- Math.max(0, Math.floor(k * this.r)),
- Math.max(0, Math.floor(k * this.g)),
- Math.max(0, Math.floor(k * this.b)));
+ Math.floor(k * this.r),
+ Math.floor(k * this.g),
+ Math.floor(k * this.b));
};
d3_Rgb.prototype.hsl = function() {
@@ -914,7 +971,9 @@ d3_Rgb.prototype.toString = function() {
};
function d3_rgb_hex(v) {
- return v < 0x10 ? "0" + v.toString(16) : v.toString(16);
+ return v < 0x10
+ ? "0" + Math.max(0, v).toString(16)
+ : Math.min(255, v).toString(16);
}
function d3_rgb_parse(format, rgb, hsl) {
@@ -1151,7 +1210,8 @@ for (var d3_rgb_name in d3_rgb_names) {
}
d3.hsl = function(h, s, l) {
return arguments.length === 1
- ? d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl)
+ ? (h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l)
+ : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl))
: d3_hsl(+h, +s, +l);
};
@@ -1180,7 +1240,7 @@ d3_Hsl.prototype.rgb = function() {
};
d3_Hsl.prototype.toString = function() {
- return "hsl(" + this.h + "," + this.s * 100 + "%," + this.l * 100 + "%)";
+ return this.rgb().toString();
};
function d3_hsl_rgb(h, s, l) {
@@ -1331,6 +1391,21 @@ d3_selectionPrototype.attr = function(name, value) {
: (name.local ? attrConstantNS : attrConstant)));
};
d3_selectionPrototype.classed = function(name, value) {
+ var names = name.split(d3_selection_classedWhitespace),
+ n = names.length,
+ i = -1;
+ if (arguments.length > 1) {
+ while (++i < n) d3_selection_classed.call(this, names[i], value);
+ return this;
+ } else {
+ 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.
@@ -1375,7 +1450,7 @@ d3_selectionPrototype.classed = function(name, value) {
? classedFunction : value
? classedAdd
: classedRemove);
-};
+}
d3_selectionPrototype.style = function(name, value, priority) {
if (arguments.length < 3) priority = "";
@@ -1856,10 +1931,28 @@ function d3_transition(groups, id) {
return groups;
}
+var d3_transitionRemove = {};
+
+function d3_transitionNull(d, i, a) {
+ return a != "" && d3_transitionRemove;
+}
+
function d3_transitionTween(b) {
- return typeof b === "function"
- ? function(d, i, a) { var v = b.call(this, d, i) + ""; return a != v && d3.interpolate(a, v); }
- : (b = b + "", function(d, i, a) { return a != b && d3.interpolate(a, b); });
+
+ function transitionFunction(d, i, a) {
+ var v = b.call(this, d, i);
+ return v == null
+ ? a != "" && d3_transitionRemove
+ : a != v && d3.interpolate(a, v);
+ }
+
+ function transitionString(d, i, a) {
+ return a != b && d3.interpolate(a, b);
+ }
+
+ return typeof b === "function" ? transitionFunction
+ : b == null ? d3_transitionNull
+ : (b += "", transitionString);
}
var d3_transitionPrototype = [],
@@ -1899,6 +1992,7 @@ d3_transitionPrototype.select = function(selector) {
d3_transitionPrototype.selectAll = function(selector) {
var subgroups = [],
subgroup,
+ subnodes,
node;
if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
@@ -1906,9 +2000,10 @@ d3_transitionPrototype.selectAll = function(selector) {
for (var j = -1, m = this.length; ++j < m;) {
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
- subgroups.push(subgroup = selector.call(node.node, node.node.__data__, i));
- for (var k = -1, o = subgroup.length; ++k < o;) {
- subgroup[k] = {node: subgroup[k], delay: node.delay, duration: node.duration};
+ subnodes = selector.call(node.node, node.node.__data__, i);
+ subgroups.push(subgroup = []);
+ for (var k = -1, o = subnodes.length; ++k < o;) {
+ subgroup.push({node: subnodes[k], delay: node.delay, duration: node.duration});
}
}
}
@@ -1920,24 +2015,24 @@ d3_transitionPrototype.attr = function(name, value) {
return this.attrTween(name, d3_transitionTween(value));
};
-d3_transitionPrototype.attrTween = function(name, tween) {
- name = d3.ns.qualify(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 && function(t) {
- this.setAttribute(name, f(t));
- };
+ return f === d3_transitionRemove
+ ? (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 && function(t) {
- this.setAttributeNS(name.space, name.local, f(t));
- };
+ return f === d3_transitionRemove
+ ? (this.removeAttributeNS(name.space, name.local), null)
+ : f && function(t) { this.setAttributeNS(name.space, name.local, f(t)); };
}
- return this.tween("attr." + name, name.local ? attrTweenNS : attrTween);
+ return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
};
d3_transitionPrototype.style = function(name, value, priority) {
if (arguments.length < 3) priority = "";
@@ -1948,9 +2043,9 @@ 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 && function(t) {
- this.style.setProperty(name, f(t), priority);
- };
+ return f === d3_transitionRemove
+ ? (this.style.removeProperty(name), null)
+ : f && function(t) { this.style.setProperty(name, f(t), priority); };
});
};
d3_transitionPrototype.text = function(value) {
@@ -2113,9 +2208,12 @@ function d3_scale_nice(domain, nice) {
dx = x0; x0 = x1; x1 = dx;
}
- nice = nice(x1 - x0);
- domain[i0] = nice.floor(x0);
- domain[i1] = nice.ceil(x1);
+ if (dx = x1 - x0) {
+ nice = nice(dx);
+ domain[i0] = nice.floor(x0);
+ domain[i1] = nice.ceil(x1);
+ }
+
return domain;
}
@@ -3147,16 +3245,17 @@ function d3_svg_area(projection) {
x1 = d3_svg_lineX,
y0 = 0,
y1 = d3_svg_lineY,
- interpolate = "linear",
- interpolator = d3_svg_lineInterpolators[interpolate],
+ interpolate,
+ i0,
+ i1,
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" + interpolator(projection(points1), tension)
- + "L" + interpolator(projection(points0.reverse()), tension)
+ return "M" + i0(projection(points1), tension)
+ + "L" + i1(projection(points0.reverse()), tension)
+ "Z";
}
@@ -3198,7 +3297,8 @@ function d3_svg_area(projection) {
area.interpolate = function(x) {
if (!arguments.length) return interpolate;
- interpolator = d3_svg_lineInterpolators[interpolate = x];
+ i0 = d3_svg_lineInterpolators[interpolate = x];
+ i1 = i0.reverse || i0;
return area;
};
@@ -3208,9 +3308,12 @@ function d3_svg_area(projection) {
return area;
};
- return area;
+ return area.interpolate("linear");
}
+d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
+d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
+
d3.svg.area = function() {
return d3_svg_area(Object);
};
@@ -3545,6 +3648,20 @@ d3.svg.axis = function() {
selection.each(function(d, i, j) {
var g = d3.select(this);
+ // If selection is a transition, create subtransitions.
+ var transition = selection.delay ? function(o) {
+ var id = d3_transitionInheritId;
+ try {
+ d3_transitionInheritId = selection.id;
+ return o.transition()
+ .delay(selection[j][i].delay)
+ .duration(selection[j][i].duration)
+ .ease(selection.ease());
+ } finally {
+ d3_transitionInheritId = id;
+ }
+ } : Object;
+
// Ticks.
var ticks = scale.ticks.apply(scale, tickArguments_),
tickFormat = tickFormat_ == null ? scale.tickFormat.apply(scale, tickArguments_) : tickFormat_;
@@ -3580,37 +3697,33 @@ d3.svg.axis = function() {
switch (orient) {
case "bottom": {
tickTransform = d3_svg_axisX;
- subtickUpdate.attr("y2", tickMinorSize);
- tickEnter.select("text").attr("dy", ".71em").attr("text-anchor", "middle");
- tickUpdate.select("line").attr("y2", tickMajorSize);
- tickUpdate.select("text").attr("y", Math.max(tickMajorSize, 0) + tickPadding);
+ subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
+ tickUpdate.select("line").attr("x2", 0).attr("y2", tickMajorSize);
+ tickUpdate.select("text").attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding).attr("dy", ".71em").attr("text-anchor", "middle");
pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
break;
}
case "top": {
tickTransform = d3_svg_axisX;
- subtickUpdate.attr("y2", -tickMinorSize);
- tickEnter.select("text").attr("text-anchor", "middle");
- tickUpdate.select("line").attr("y2", -tickMajorSize);
- tickUpdate.select("text").attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
+ subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
+ tickUpdate.select("line").attr("x2", 0).attr("y2", -tickMajorSize);
+ tickUpdate.select("text").attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("dy", "0em").attr("text-anchor", "middle");
pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
break;
}
case "left": {
tickTransform = d3_svg_axisY;
- subtickUpdate.attr("x2", -tickMinorSize);
- tickEnter.select("text").attr("dy", ".32em").attr("text-anchor", "end");
- tickUpdate.select("line").attr("x2", -tickMajorSize);
- tickUpdate.select("text").attr("x", -(Math.max(tickMajorSize, 0) + tickPadding));
+ subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
+ tickUpdate.select("line").attr("x2", -tickMajorSize).attr("y2", 0);
+ tickUpdate.select("text").attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0).attr("dy", ".32em").attr("text-anchor", "end");
pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
break;
}
case "right": {
tickTransform = d3_svg_axisY;
- subtickUpdate.attr("x2", tickMinorSize);
- tickEnter.select("text").attr("dy", ".32em");
- tickUpdate.select("line").attr("x2", tickMajorSize);
- tickUpdate.select("text").attr("x", Math.max(tickMajorSize, 0) + tickPadding);
+ subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
+ tickUpdate.select("line").attr("x2", tickMajorSize).attr("y2", 0);
+ tickUpdate.select("text").attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0).attr("dy", ".32em").attr("text-anchor", "start");
pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
break;
}
@@ -3623,13 +3736,6 @@ d3.svg.axis = function() {
subtickEnter.call(tickTransform, scale0);
subtickUpdate.call(tickTransform, scale);
subtickExit.call(tickTransform, scale);
-
- function transition(o) {
- return selection.delay ? o.transition()
- .delay(selection[j][i].delay)
- .duration(selection[j][i].duration)
- .ease(selection.ease()) : o;
- }
});
}