Comparing version 2.9.7 to 2.10.0
{ | ||
"name": "d3", | ||
"version": "2.9.7", | ||
"version": "2.10.0", | ||
"description": "A small, free JavaScript library for manipulating documents based on data.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
function d3_collapse(s) { | ||
return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " "); | ||
return s.trim().replace(/\s+/g, " "); | ||
} |
@@ -1,1 +0,1 @@ | ||
d3 = {version: "2.9.7"}; // semver | ||
d3 = {version: "2.10.0"}; // semver |
@@ -41,3 +41,3 @@ // TODO align | ||
// Convert negative to positive, and record the sign prefix. | ||
var negative = (value < 0) && (value = -value) ? "\u2212" : sign; | ||
var negative = (value < 0) && (value = -value) ? "-" : sign; | ||
@@ -44,0 +44,0 @@ // Apply the scale, computing it from the value's exponent for si format. |
@@ -96,4 +96,2 @@ d3.interpolate = function(a, b) { | ||
d3.interpolateTransform = function(a, b) { | ||
if ((n = d3_interpolateTransformSimilar(a, b))) return n; | ||
var s = [], // string constants and placeholders | ||
@@ -150,108 +148,2 @@ q = [], // number interpolators | ||
var d3_interpolateTransformTypes = [ | ||
"", | ||
"", | ||
"translate", | ||
"scale", | ||
"rotate", | ||
"skewX", | ||
"skewY" | ||
]; | ||
// If both the ‘from’ and ‘to’ transforms have the same number of transform | ||
// functions and corresponding functions in each transform list are of the same | ||
// type, each transform function is animated with its corresponding destination | ||
// function in isolation using the rules described above. The individual values | ||
// are then applied as a list to produce resulting transform value. | ||
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 one of the ‘from’ or ‘to’ transforms is "none", the ‘none’ is replaced | ||
// by an equivalent identity function list for the corresponding transform | ||
// function list. Otherwise, if the transform function lists do not have the | ||
// same number of items, the transforms are each converted into the | ||
// equivalent matrix value and animation proceeds using the rule for a | ||
// single function above. | ||
if (m !== n) { | ||
if (!m) b = d3_interpolateTransformIdentity(a); | ||
else if (!n) a = d3_interpolateTransformIdentity(b), n = m; | ||
else return; | ||
} | ||
// If both the ‘from’ and ‘to’ transforms are "none", there is no | ||
// interpolation necessary. | ||
else if (!m) return; | ||
while (++i < n) { | ||
ta = a.getItem(i); | ||
tb = b.getItem(i); | ||
type = ta.type; | ||
// If the transform functions are not the same type, or the type is | ||
// unknown, fallback to the decomposed transform transition. | ||
if (type !== tb.type || !type) return; // unknown | ||
switch (type) { | ||
// For matrix, the matrix is decomposed using the method described by | ||
// unmatrix into separate translation, scale, rotation and skew | ||
// matrices, then each decomposed matrix is interpolated numerically, | ||
// and finally combined in order to produce a resulting 3x2 matrix. | ||
case 1: { // matrix | ||
sa.push(new d3_transform(ta.matrix)); | ||
sb.push(new d3_transform(tb.matrix)); | ||
continue; | ||
} | ||
// For translate, scale, rotate and skew functions the individual | ||
// components of the function are interpolated numerically. | ||
case 2: { // translate | ||
ra = ta.matrix.e + "," + ta.matrix.f; | ||
rb = tb.matrix.e + "," + tb.matrix.f; | ||
break; | ||
} | ||
case 3: { // scale | ||
ra = ta.matrix.a + "," + ta.matrix.d; | ||
rb = tb.matrix.a + "," + tb.matrix.d; | ||
break; | ||
} | ||
default: { // rotate, skew | ||
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) { | ||
@@ -286,6 +178,35 @@ a = d3.rgb(a); | ||
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; // shortest path | ||
return function(t) { | ||
return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + ""; | ||
}; | ||
}; | ||
d3.interpolateArray = function(a, b) { | ||
@@ -331,4 +252,4 @@ var x = [], | ||
function d3_interpolateByName(n) { | ||
return n == "transform" | ||
function d3_interpolateByName(name) { | ||
return name == "transform" | ||
? d3.interpolateTransform | ||
@@ -335,0 +256,0 @@ : d3.interpolate; |
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() { | ||
@@ -12,5 +13,20 @@ var x, y, r; | ||
} 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; | ||
}; | ||
} | ||
}; |
@@ -127,2 +127,16 @@ d3.rgb = function(r, g, b) { | ||
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((0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / d3_lab_X), | ||
y = d3_xyz_lab((0.2126729 * r + 0.7151522 * g + 0.0721750 * b) / d3_lab_Y), | ||
z = d3_xyz_lab((0.0193339 * r + 0.1191920 * g + 0.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) <= 0.04045 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4); | ||
} | ||
function d3_rgb_parseNumber(c) { // either integer or percentage | ||
@@ -129,0 +143,0 @@ var f = parseFloat(c); |
d3_selectionPrototype.attr = function(name, value) { | ||
name = d3.ns.qualify(name); | ||
if (arguments.length < 2) { | ||
// If no value is specified, return the first value. | ||
if (arguments.length < 2) { | ||
var node = this.node(); | ||
return name.local | ||
? node.getAttributeNS(name.space, name.local) | ||
: node.getAttribute(name); | ||
// For attr(string), return the attribute value for the first node. | ||
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 attr(object), the object specifies the names and values of the | ||
// attributes to set or remove. The values may be functions that are | ||
// evaluated for each element. | ||
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); | ||
// For attr(string, null), remove the attribute with the specified name. | ||
function attrNull() { | ||
this.removeAttribute(name); | ||
} | ||
function attrNullNS() { | ||
@@ -20,6 +34,6 @@ this.removeAttributeNS(name.space, name.local); | ||
// For attr(string, string), set the attribute with the specified name. | ||
function attrConstant() { | ||
this.setAttribute(name, value); | ||
} | ||
function attrConstantNS() { | ||
@@ -29,2 +43,4 @@ this.setAttributeNS(name.space, name.local, value); | ||
// For attr(string, function), evaluate the function for each element, and set | ||
// or remove the attribute as appropriate. | ||
function attrFunction() { | ||
@@ -35,3 +51,2 @@ var x = value.apply(this, arguments); | ||
} | ||
function attrFunctionNS() { | ||
@@ -43,6 +58,6 @@ var x = value.apply(this, arguments); | ||
return this.each(value == null | ||
return value == null | ||
? (name.local ? attrNullNS : attrNull) : (typeof value === "function" | ||
? (name.local ? attrFunctionNS : attrFunction) | ||
: (name.local ? attrConstantNS : attrConstant))); | ||
}; | ||
: (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) { | ||
// For classed(string), return true only if the first node has the specified | ||
// class or classes. Note that even if the browser supports DOMTokenList, it | ||
// probably doesn't support it on SVG elements (which can be animated). | ||
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 classed(object), the object specifies the names of classes to add or | ||
// remove. The values may be functions that are evaluated for each element. | ||
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; | ||
} | ||
// Otherwise, both a name and a value are specified, and are handled as below. | ||
return this.each(d3_selection_classed(name, value)); | ||
}; | ||
function d3_selection_classedRe(name) { | ||
return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g"); | ||
} | ||
// Multiple class names are allowed (e.g., "foo bar"). | ||
function d3_selection_classed(name, value) { | ||
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g"); | ||
name = name.trim().split(/\s+/).map(d3_selection_classedName); | ||
var n = name.length; | ||
// If no value is specified, return the first value. | ||
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 classedConstant() { | ||
var i = -1; | ||
while (++i < n) name[i](this, value); | ||
} | ||
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; | ||
} | ||
// When the value is a function, the function is still evaluated only once per | ||
// element even if there are multiple class names. | ||
function classedFunction() { | ||
var i = -1, x = value.apply(this, arguments); | ||
while (++i < n) name[i](this, x); | ||
} | ||
function classedRemove() { | ||
if (c = this.classList) return c.remove(name); | ||
var c = this.className, | ||
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 (cv) { | ||
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 this.className = cv; | ||
else node.className = cv; | ||
} | ||
} | ||
function classedFunction() { | ||
(value.apply(this, arguments) | ||
? classedAdd | ||
: classedRemove).call(this); | ||
} | ||
return this.each(typeof value === "function" | ||
? classedFunction : value | ||
? classedAdd | ||
: classedRemove); | ||
}; | ||
} |
@@ -1,33 +0,46 @@ | ||
// type can be namespaced, e.g., "click.foo" | ||
// listener can be null for removal | ||
d3_selectionPrototype.on = function(type, listener, capture) { | ||
if (arguments.length < 3) capture = false; | ||
var n = arguments.length; | ||
if (n < 3) { | ||
// parse the type specifier | ||
// For on(object) or on(object, boolean), the object specifies the event | ||
// types and listeners to add or remove. The optional boolean specifies | ||
// whether the listener captures events. | ||
if (typeof type !== "string") { | ||
if (n < 2) listener = false; | ||
for (capture in type) this.each(d3_selection_on(capture, type[capture], listener)); | ||
return this; | ||
} | ||
// For on(string), return the listener for the first node. | ||
if (n < 2) return (n = this.node()["__on" + type]) && n._; | ||
// For on(string, function), use the default capture. | ||
capture = false; | ||
} | ||
// Otherwise, a type, listener and capture are specified, and handled as below. | ||
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 called with only one argument, return the current listener | ||
if (arguments.length < 2) return (i = this.node()[name]) && i._; | ||
function onRemove() { | ||
var wrapper = this[name]; | ||
if (wrapper) { | ||
this.removeEventListener(type, wrapper, wrapper.$); | ||
delete this[name]; | ||
} | ||
} | ||
// remove the old event listener, and add the new event listener | ||
return this.each(function() { | ||
function onAdd() { | ||
var node = this, | ||
args = arguments, | ||
o = node[name]; | ||
args = arguments; | ||
// remove the old listener, if any (using the previously-set capture) | ||
if (o) { | ||
node.removeEventListener(type, o, o.$); | ||
delete node[name]; | ||
} | ||
onRemove.call(this); | ||
this.addEventListener(type, this[name] = wrapper, wrapper.$ = capture); | ||
wrapper._ = listener; | ||
// add the new listener, if any (remembering the capture flag) | ||
if (listener) { | ||
node.addEventListener(type, node[name] = l, l.$ = capture); | ||
l._ = listener; // stash the unwrapped listener for get | ||
} | ||
// wrapped event listener that propagates data changes | ||
function l(e) { | ||
function wrapper(e) { | ||
var o = d3.event; // Events can be reentrant (e.g., focus). | ||
@@ -42,3 +55,5 @@ d3.event = e; | ||
} | ||
}); | ||
}; | ||
} | ||
return listener ? onAdd : onRemove; | ||
} |
d3_selectionPrototype.property = function(name, value) { | ||
if (arguments.length < 2) { | ||
// If no value is specified, return the first value. | ||
if (arguments.length < 2) return this.node()[name]; | ||
// For property(string), return the property value for the first node. | ||
if (typeof name === "string") return this.node()[name]; | ||
// For property(object), the object specifies the names and values of the | ||
// properties to set or remove. The values may be functions that are | ||
// evaluated for each element. | ||
for (value in name) this.each(d3_selection_property(value, name[value])); | ||
return this; | ||
} | ||
// Otherwise, both a name and a value are specified, and are handled as below. | ||
return this.each(d3_selection_property(name, value)); | ||
}; | ||
function d3_selection_property(name, value) { | ||
// For property(name, null), remove the property with the specified name. | ||
function propertyNull() { | ||
@@ -10,2 +25,3 @@ delete this[name]; | ||
// For property(name, string), set the property with the specified name. | ||
function propertyConstant() { | ||
@@ -15,2 +31,4 @@ this[name] = value; | ||
// For property(name, function), evaluate the function for each element, and | ||
// set or remove the property as appropriate. | ||
function propertyFunction() { | ||
@@ -22,5 +40,5 @@ var x = value.apply(this, arguments); | ||
return this.each(value == null | ||
return value == null | ||
? propertyNull : (typeof value === "function" | ||
? propertyFunction : propertyConstant)); | ||
}; | ||
? propertyFunction : propertyConstant); | ||
} |
d3_selectionPrototype.style = function(name, value, priority) { | ||
if (arguments.length < 3) priority = ""; | ||
var n = arguments.length; | ||
if (n < 3) { | ||
// If no value is specified, return the first value. | ||
if (arguments.length < 2) return window | ||
.getComputedStyle(this.node(), null) | ||
.getPropertyValue(name); | ||
// For style(object) or style(object, string), the object specifies the | ||
// names and values of the attributes to set or remove. The values may be | ||
// functions that are evaluated for each element. The optional string | ||
// specifies the priority. | ||
if (typeof name !== "string") { | ||
if (n < 2) value = ""; | ||
for (priority in name) this.each(d3_selection_style(priority, name[priority], value)); | ||
return this; | ||
} | ||
// For style(string), return the computed style value for the first node. | ||
if (n < 2) return window | ||
.getComputedStyle(this.node(), null) | ||
.getPropertyValue(name); | ||
// For style(string, string) or style(string, function), use the default | ||
// priority. The priority is ignored for style(string, null). | ||
priority = ""; | ||
} | ||
// Otherwise, a name, value and priority are specified, and handled as below. | ||
return this.each(d3_selection_style(name, value, priority)); | ||
}; | ||
function d3_selection_style(name, value, priority) { | ||
// For style(name, null) or style(name, null, priority), remove the style | ||
// property with the specified name. The priority is ignored. | ||
function styleNull() { | ||
@@ -13,2 +37,4 @@ this.style.removeProperty(name); | ||
// For style(name, string) or style(name, string, priority), set the style | ||
// property with the specified name, using the specified priority. | ||
function styleConstant() { | ||
@@ -18,2 +44,5 @@ this.style.setProperty(name, value, priority); | ||
// For style(name, function) or style(name, function, priority), evaluate the | ||
// function for each element, and set or remove the style property as | ||
// appropriate. When setting, use the specified priority. | ||
function styleFunction() { | ||
@@ -25,5 +54,5 @@ var x = value.apply(this, arguments); | ||
return this.each(value == null | ||
return value == null | ||
? styleNull : (typeof value === "function" | ||
? styleFunction : styleConstant)); | ||
}; | ||
? styleFunction : styleConstant); | ||
} |
d3_transitionPrototype.attr = function(name, value) { | ||
return this.attrTween(name, d3_transitionTween(name, value)); | ||
if (arguments.length < 2) { | ||
// For attr(object), the object specifies the names and values of the | ||
// attributes to transition. The values may be functions that are | ||
// evaluated for each element. | ||
for (value in name) this.attrTween(value, d3_tweenByName(name[value], value)); | ||
return this; | ||
} | ||
return this.attrTween(name, d3_tweenByName(value, name)); | ||
}; | ||
@@ -10,3 +19,3 @@ | ||
var f = tween.call(this, d, i, this.getAttribute(name)); | ||
return f === d3_transitionRemove | ||
return f === d3_tweenRemove | ||
? (this.removeAttribute(name), null) | ||
@@ -18,3 +27,3 @@ : f && function(t) { this.setAttribute(name, f(t)); }; | ||
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local)); | ||
return f === d3_transitionRemove | ||
return f === d3_tweenRemove | ||
? (this.removeAttributeNS(name.space, name.local), null) | ||
@@ -21,0 +30,0 @@ : f && function(t) { this.setAttributeNS(name.space, name.local, f(t)); }; |
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) { | ||
// For style(object) or style(object, string), the object specifies the | ||
// names and values of the attributes to set or remove. The values may be | ||
// functions that are evaluated for each element. The optional string | ||
// specifies the priority. | ||
if (typeof name !== "string") { | ||
if (n < 2) value = ""; | ||
for (priority in name) this.styleTween(priority, d3_tweenByName(name[priority], priority), value); | ||
return this; | ||
} | ||
// For style(string, string) or style(string, function), use the default | ||
// priority. The priority is ignored for style(string, null). | ||
priority = ""; | ||
} | ||
// Otherwise, a name, value and priority are specified, and handled as below. | ||
return this.styleTween(name, d3_tweenByName(value, name), priority); | ||
}; | ||
@@ -10,3 +28,3 @@ | ||
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name)); | ||
return f === d3_transitionRemove | ||
return f === d3_tweenRemove | ||
? (this.style.removeProperty(name), null) | ||
@@ -13,0 +31,0 @@ : f && function(t) { this.style.setProperty(name, f(t), priority); }; |
@@ -88,27 +88,2 @@ function d3_transition(groups, id, time) { | ||
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 = [], | ||
@@ -115,0 +90,0 @@ d3_transitionNextId = 0, |
d3.layout.pack = function() { | ||
var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), | ||
padding = 0, | ||
size = [1, 1]; | ||
@@ -12,10 +13,22 @@ | ||
root.y = 0; | ||
d3_layout_packTree(root); | ||
d3_layout_treeVisitAfter(root, function(d) { d.r = Math.sqrt(d.value); }); | ||
d3_layout_treeVisitAfter(root, d3_layout_packSiblings); | ||
// Scale the layout to fit the requested size. | ||
// Compute the scale factor the initial layout. | ||
var w = size[0], | ||
h = size[1], | ||
k = 1 / Math.max(2 * root.r / w, 2 * root.r / h); | ||
d3_layout_packTransform(root, w / 2, h / 2, k); | ||
k = Math.max(2 * root.r / w, 2 * root.r / h); | ||
// When padding, recompute the layout using scaled padding. | ||
if (padding > 0) { | ||
var dr = padding * k / 2; | ||
d3_layout_treeVisitAfter(root, function(d) { d.r += dr; }); | ||
d3_layout_treeVisitAfter(root, d3_layout_packSiblings); | ||
d3_layout_treeVisitAfter(root, function(d) { d.r -= dr; }); | ||
k = Math.max(2 * root.r / w, 2 * root.r / h); | ||
} | ||
// Scale the layout to fit the requested size. | ||
d3_layout_packTransform(root, w / 2, h / 2, 1 / k); | ||
return nodes; | ||
@@ -30,2 +43,8 @@ } | ||
pack.padding = function(_) { | ||
if (!arguments.length) return padding; | ||
padding = +_; | ||
return pack; | ||
}; | ||
return d3_layout_hierarchyRebind(pack, hierarchy); | ||
@@ -58,9 +77,11 @@ }; | ||
function d3_layout_packCircle(nodes) { | ||
var xMin = Infinity, | ||
function d3_layout_packSiblings(node) { | ||
if (!(nodes = node.children) || !(n = nodes.length)) return; | ||
var nodes, | ||
xMin = Infinity, | ||
xMax = -Infinity, | ||
yMin = Infinity, | ||
yMax = -Infinity, | ||
n = nodes.length, | ||
a, b, c, j, k; | ||
a, b, c, i, j, k, n; | ||
@@ -101,3 +122,3 @@ function bound(node) { | ||
// Now iterate through the rest. | ||
for (var i = 3; i < n; i++) { | ||
for (i = 3; i < n; i++) { | ||
d3_layout_packPlace(a, b, c = nodes[i]); | ||
@@ -135,17 +156,16 @@ | ||
// Re-center the circles and return the encompassing radius. | ||
// Re-center the circles and compute the encompassing radius. | ||
var cx = (xMin + xMax) / 2, | ||
cy = (yMin + yMax) / 2, | ||
cr = 0; | ||
for (var i = 0; i < n; i++) { | ||
var node = nodes[i]; | ||
node.x -= cx; | ||
node.y -= cy; | ||
cr = Math.max(cr, node.r + Math.sqrt(node.x * node.x + node.y * node.y)); | ||
for (i = 0; i < n; i++) { | ||
c = nodes[i]; | ||
c.x -= cx; | ||
c.y -= cy; | ||
cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y)); | ||
} | ||
node.r = cr; | ||
// Remove node links. | ||
nodes.forEach(d3_layout_packUnlink); | ||
return cr; | ||
} | ||
@@ -162,12 +182,2 @@ | ||
function d3_layout_packTree(node) { | ||
var children = node.children; | ||
if (children && children.length) { | ||
children.forEach(d3_layout_packTree); | ||
node.r = d3_layout_packCircle(children); | ||
} else { | ||
node.r = Math.sqrt(node.value); | ||
} | ||
} | ||
function d3_layout_packTransform(node, x, y, k) { | ||
@@ -174,0 +184,0 @@ var children = node.children; |
@@ -80,3 +80,3 @@ d3.scale.linear = function() { | ||
dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1); | ||
return { | ||
return dx && { | ||
floor: function(x) { return Math.floor(x / dx) * dx; }, | ||
@@ -83,0 +83,0 @@ ceil: function(x) { return Math.ceil(x / dx) * dx; } |
@@ -9,8 +9,7 @@ function d3_scale_nice(domain, nice) { | ||
if (x1 < x0) { | ||
dx = i0; i0 = i1; i1 = dx; | ||
dx = x0; x0 = x1; x1 = dx; | ||
dx = i0, i0 = i1, i1 = dx; | ||
dx = x0, x0 = x1, x1 = dx; | ||
} | ||
if (dx = x1 - x0) { | ||
nice = nice(dx); | ||
if (nice = nice(x1 - x0)) { | ||
domain[i0] = nice.floor(x0); | ||
@@ -17,0 +16,0 @@ domain[i1] = nice.ceil(x1); |
d3.scale.ordinal = function() { | ||
return d3_scale_ordinal([], {t: "range", x: []}); | ||
return d3_scale_ordinal([], {t: "range", a: [[]]}); | ||
}; | ||
@@ -24,3 +24,3 @@ | ||
while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi)); | ||
return scale[ranger.t](ranger.x, ranger.p); | ||
return scale[ranger.t].apply(scale, ranger.a); | ||
}; | ||
@@ -32,3 +32,3 @@ | ||
rangeBand = 0; | ||
ranger = {t: "range", x: x}; | ||
ranger = {t: "range", a: arguments}; | ||
return scale; | ||
@@ -44,25 +44,27 @@ }; | ||
rangeBand = 0; | ||
ranger = {t: "rangePoints", x: x, p: padding}; | ||
ranger = {t: "rangePoints", a: arguments}; | ||
return scale; | ||
}; | ||
scale.rangeBands = function(x, padding) { | ||
scale.rangeBands = function(x, padding, outerPadding) { | ||
if (arguments.length < 2) padding = 0; | ||
if (arguments.length < 3) outerPadding = padding; | ||
var reverse = x[1] < x[0], | ||
start = x[reverse - 0], | ||
stop = x[1 - reverse], | ||
step = (stop - start) / (domain.length + padding); | ||
range = steps(start + step * padding, step); | ||
step = (stop - start) / (domain.length - padding + 2 * outerPadding); | ||
range = steps(start + step * outerPadding, step); | ||
if (reverse) range.reverse(); | ||
rangeBand = step * (1 - padding); | ||
ranger = {t: "rangeBands", x: x, p: padding}; | ||
ranger = {t: "rangeBands", a: arguments}; | ||
return scale; | ||
}; | ||
scale.rangeRoundBands = function(x, padding) { | ||
scale.rangeRoundBands = function(x, padding, outerPadding) { | ||
if (arguments.length < 2) padding = 0; | ||
if (arguments.length < 3) outerPadding = padding; | ||
var reverse = x[1] < x[0], | ||
start = x[reverse - 0], | ||
stop = x[1 - reverse], | ||
step = Math.floor((stop - start) / (domain.length + padding)), | ||
step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), | ||
error = stop - start - (domain.length - padding) * step; | ||
@@ -72,3 +74,3 @@ range = steps(start + Math.round(error / 2), step); | ||
rangeBand = Math.round(step * (1 - padding)); | ||
ranger = {t: "rangeRoundBands", x: x, p: padding}; | ||
ranger = {t: "rangeRoundBands", a: arguments}; | ||
return scale; | ||
@@ -82,3 +84,3 @@ }; | ||
scale.rangeExtent = function() { | ||
return d3_scaleExtent(ranger.x); | ||
return d3_scaleExtent(ranger.a[0]); | ||
}; | ||
@@ -85,0 +87,0 @@ |
@@ -7,5 +7,5 @@ function d3_svg_area(projection) { | ||
defined = d3_true, | ||
interpolate = d3_svg_lineInterpolatorDefault, | ||
i0 = d3_svg_lineLinear, | ||
i1 = d3_svg_lineLinear, | ||
interpolate = d3_svg_lineLinear, | ||
interpolateKey = interpolate.key, | ||
interpolateReverse = interpolate, | ||
L = "L", | ||
@@ -29,4 +29,4 @@ tension = .7; | ||
function segment() { | ||
segments.push("M", i0(projection(points1), tension), | ||
L, i1(projection(points0.reverse()), tension), | ||
segments.push("M", interpolate(projection(points1), tension), | ||
L, interpolateReverse(projection(points0.reverse()), tension), | ||
"Z"); | ||
@@ -94,7 +94,7 @@ } | ||
area.interpolate = function(_) { | ||
if (!arguments.length) return interpolate; | ||
if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault; | ||
i0 = d3_svg_lineInterpolators.get(interpolate = _); | ||
i1 = i0.reverse || i0; | ||
L = /-closed$/.test(_) ? "M" : "L"; | ||
if (!arguments.length) return interpolateKey; | ||
if (typeof _ === "function") interpolateKey = interpolate = _; | ||
else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key; | ||
interpolateReverse = interpolate.reverse || interpolate; | ||
L = interpolate.closed ? "M" : "L"; | ||
return area; | ||
@@ -116,3 +116,3 @@ }; | ||
d3.svg.area = function() { | ||
return d3_svg_area(Object); | ||
return d3_svg_area(d3_identity); | ||
}; |
@@ -5,4 +5,4 @@ function d3_svg_line(projection) { | ||
defined = d3_true, | ||
interpolate = d3_svg_lineInterpolatorDefault, | ||
interpolator = d3_svg_lineLinear, | ||
interpolate = d3_svg_lineLinear, | ||
interpolateKey = interpolate.key, | ||
tension = .7; | ||
@@ -20,3 +20,3 @@ | ||
function segment() { | ||
segments.push("M", interpolator(projection(points), tension)); | ||
segments.push("M", interpolate(projection(points), tension)); | ||
} | ||
@@ -57,5 +57,5 @@ | ||
line.interpolate = function(_) { | ||
if (!arguments.length) return interpolate; | ||
if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault; | ||
interpolator = d3_svg_lineInterpolators.get(interpolate = _); | ||
if (!arguments.length) return interpolateKey; | ||
if (typeof _ === "function") interpolateKey = interpolate = _; | ||
else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key; | ||
return line; | ||
@@ -87,4 +87,2 @@ }; | ||
var d3_svg_lineInterpolatorDefault = "linear"; | ||
// The various interpolators supported by the `line` class. | ||
@@ -106,2 +104,7 @@ var d3_svg_lineInterpolators = d3.map({ | ||
d3_svg_lineInterpolators.forEach(function(key, value) { | ||
value.key = key; | ||
value.closed = /-closed$/.test(key); | ||
}); | ||
// Linear interpolation; generates "L" commands. | ||
@@ -363,3 +366,3 @@ function d3_svg_lineLinear(points) { | ||
while (++i < j) { | ||
m[i] = d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1])); | ||
m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2; | ||
} | ||
@@ -366,0 +369,0 @@ m[i] = d; |
@@ -63,2 +63,12 @@ d3.time.format = function(template) { | ||
function d3_time_formatRe(names) { | ||
return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i"); | ||
} | ||
function d3_time_formatLookup(names) { | ||
var map = new d3_Map, i = -1, n = names.length; | ||
while (++i < n) map.set(names[i].toLowerCase(), i); | ||
return map; | ||
} | ||
var d3_time_zfill2 = d3.format("02d"), | ||
@@ -69,8 +79,15 @@ d3_time_zfill3 = d3.format("03d"), | ||
var d3_time_dayRe = d3_time_formatRe(d3_time_days), | ||
d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), | ||
d3_time_monthRe = d3_time_formatRe(d3_time_months), | ||
d3_time_monthLookup = d3_time_formatLookup(d3_time_months), | ||
d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), | ||
d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations); | ||
var d3_time_formats = { | ||
a: function(d) { return d3_time_weekdays[d.getDay()].substring(0, 3); }, | ||
A: function(d) { return d3_time_weekdays[d.getDay()]; }, | ||
b: function(d) { return d3_time_months[d.getMonth()].substring(0, 3); }, | ||
a: function(d) { return d3_time_dayAbbreviations[d.getDay()]; }, | ||
A: function(d) { return d3_time_days[d.getDay()]; }, | ||
b: function(d) { return d3_time_monthAbbreviations[d.getMonth()]; }, | ||
B: function(d) { return d3_time_months[d.getMonth()]; }, | ||
c: d3.time.format("%a %b %e %H:%M:%S %Y"), | ||
c: d3.time.format(d3_time_formatDateTime), | ||
d: function(d) { return d3_time_zfill2(d.getDate()); }, | ||
@@ -89,4 +106,4 @@ e: function(d) { return d3_time_sfill2(d.getDate()); }, | ||
W: function(d) { return d3_time_zfill2(d3.time.mondayOfYear(d)); }, | ||
x: d3.time.format("%m/%d/%y"), | ||
X: d3.time.format("%H:%M:%S"), | ||
x: d3.time.format(d3_time_formatDate), | ||
X: d3.time.format(d3_time_formatTime), | ||
y: function(d) { return d3_time_zfill2(d.getFullYear() % 100); }, | ||
@@ -128,3 +145,5 @@ Y: function(d) { return d3_time_zfill4(d.getFullYear() % 10000); }, | ||
function d3_time_parseWeekdayAbbrev(date, string, i) { | ||
return d3_time_weekdayAbbrevRe.test(string.substring(i, i += 3)) ? i : -1; | ||
d3_time_dayAbbrevRe.lastIndex = 0; | ||
var n = d3_time_dayAbbrevRe.exec(string.substring(i)); | ||
return n ? i += n[0].length : -1; | ||
} | ||
@@ -134,69 +153,19 @@ | ||
function d3_time_parseWeekday(date, string, i) { | ||
d3_time_weekdayRe.lastIndex = 0; | ||
var n = d3_time_weekdayRe.exec(string.substring(i, i + 10)); | ||
d3_time_dayRe.lastIndex = 0; | ||
var n = d3_time_dayRe.exec(string.substring(i)); | ||
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_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); | ||
d3_time_monthAbbrevRe.lastIndex = 0; | ||
var n = d3_time_monthAbbrevRe.exec(string.substring(i)); | ||
return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1; | ||
} | ||
var d3_time_monthAbbrevLookup = d3.map({ | ||
jan: 0, | ||
feb: 1, | ||
mar: 2, | ||
apr: 3, | ||
may: 4, | ||
jun: 5, | ||
jul: 6, | ||
aug: 7, | ||
sep: 8, | ||
oct: 9, | ||
nov: 10, | ||
dec: 11 | ||
}); | ||
function d3_time_parseMonth(date, string, i) { | ||
d3_time_monthRe.lastIndex = 0; | ||
var n = d3_time_monthRe.exec(string.substring(i, i + 12)); | ||
var n = d3_time_monthRe.exec(string.substring(i)); | ||
return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1; | ||
} | ||
var d3_time_monthRe = /^(?:January|February|March|April|May|June|July|August|September|October|November|December)/ig; | ||
var d3_time_monthLookup = d3.map({ | ||
january: 0, | ||
february: 1, | ||
march: 2, | ||
april: 3, | ||
may: 4, | ||
june: 5, | ||
july: 6, | ||
august: 7, | ||
september: 8, | ||
october: 9, | ||
november: 10, | ||
december: 11 | ||
}); | ||
var d3_time_months = [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July", | ||
"August", | ||
"September", | ||
"October", | ||
"November", | ||
"December" | ||
]; | ||
function d3_time_parseLocaleFull(date, string, i) { | ||
@@ -268,3 +237,3 @@ return d3_time_parse(date, d3_time_formats.c.toString(), string, i); | ||
// Note: we don't look at the next directive. | ||
var d3_time_numberRe = /\s*\d+/; | ||
var d3_time_numberRe = /^\s*\d+/; | ||
@@ -271,0 +240,0 @@ function d3_time_parseAmPm(date, string, i) { |
@@ -18,4 +18,3 @@ function d3_time_scale(linear, methods, format) { | ||
scale.nice = function(m) { | ||
var extent = d3_time_scaleExtent(scale.domain()); | ||
return scale.domain([m.floor(extent[0]), m.ceil(extent[1])]); | ||
return scale.domain(d3_scale_nice(scale.domain(), function() { return m; })); | ||
}; | ||
@@ -22,0 +21,0 @@ |
d3.time = {}; | ||
var d3_time = Date; | ||
var d3_time = Date, | ||
d3_time_daySymbols = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; | ||
@@ -5,0 +6,0 @@ function d3_time_utc() { |
@@ -1,2 +0,2 @@ | ||
d3_time_weekdays.forEach(function(day, i) { | ||
d3_time_daySymbols.forEach(function(day, i) { | ||
day = day.toLowerCase(); | ||
@@ -3,0 +3,0 @@ i = 7 - i; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
633862
196
16042
1