|
(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 xhtml = "http://www.w3.org/1999/xhtml"; |
|
|
|
var namespaces = { |
|
svg: "http://www.w3.org/2000/svg", |
|
xhtml: xhtml, |
|
xlink: "http://www.w3.org/1999/xlink", |
|
xml: "http://www.w3.org/XML/1998/namespace", |
|
xmlns: "http://www.w3.org/2000/xmlns/" |
|
}; |
|
|
|
function namespace(name) { |
|
var prefix = name += "", i = prefix.indexOf(":"); |
|
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1); |
|
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; |
|
} |
|
|
|
function creatorInherit(name) { |
|
return function() { |
|
var document = this.ownerDocument, |
|
uri = this.namespaceURI; |
|
return uri === xhtml && document.documentElement.namespaceURI === xhtml |
|
? document.createElement(name) |
|
: document.createElementNS(uri, name); |
|
}; |
|
} |
|
|
|
function creatorFixed(fullname) { |
|
return function() { |
|
return this.ownerDocument.createElementNS(fullname.space, fullname.local); |
|
}; |
|
} |
|
|
|
function creator(name) { |
|
var fullname = namespace(name); |
|
return (fullname.local |
|
? creatorFixed |
|
: creatorInherit)(fullname); |
|
} |
|
|
|
var matcher = function(selector) { |
|
return function() { |
|
return this.matches(selector); |
|
}; |
|
}; |
|
|
|
if (typeof document !== "undefined") { |
|
var element = document.documentElement; |
|
if (!element.matches) { |
|
var vendorMatches = element.webkitMatchesSelector |
|
|| element.msMatchesSelector |
|
|| element.mozMatchesSelector |
|
|| element.oMatchesSelector; |
|
matcher = function(selector) { |
|
return function() { |
|
return vendorMatches.call(this, selector); |
|
}; |
|
}; |
|
} |
|
} |
|
|
|
var matcher$1 = matcher; |
|
|
|
var filterEvents = {}; |
|
|
|
exports.event = null; |
|
|
|
if (typeof document !== "undefined") { |
|
var element$1 = document.documentElement; |
|
if (!("onmouseenter" in element$1)) { |
|
filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"}; |
|
} |
|
} |
|
|
|
function filterContextListener(listener, index, group) { |
|
listener = contextListener(listener, index, group); |
|
return function(event) { |
|
var related = event.relatedTarget; |
|
if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) { |
|
listener.call(this, event); |
|
} |
|
}; |
|
} |
|
|
|
function contextListener(listener, index, group) { |
|
return function(event1) { |
|
var event0 = exports.event; // Events can be reentrant (e.g., focus). |
|
exports.event = event1; |
|
try { |
|
listener.call(this, this.__data__, index, group); |
|
} finally { |
|
exports.event = event0; |
|
} |
|
}; |
|
} |
|
|
|
function parseTypenames(typenames) { |
|
return typenames.trim().split(/^|\s+/).map(function(t) { |
|
var name = "", i = t.indexOf("."); |
|
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i); |
|
return {type: t, name: name}; |
|
}); |
|
} |
|
|
|
function onRemove(typename) { |
|
return function() { |
|
var on = this.__on; |
|
if (!on) return; |
|
for (var j = 0, i = -1, m = on.length, o; j < m; ++j) { |
|
if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) { |
|
this.removeEventListener(o.type, o.listener, o.capture); |
|
} else { |
|
on[++i] = o; |
|
} |
|
} |
|
if (++i) on.length = i; |
|
else delete this.__on; |
|
}; |
|
} |
|
|
|
function onAdd(typename, value, capture) { |
|
var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener; |
|
return function(d, i, group) { |
|
var on = this.__on, o, listener = wrap(value, i, group); |
|
if (on) for (var j = 0, m = on.length; j < m; ++j) { |
|
if ((o = on[j]).type === typename.type && o.name === typename.name) { |
|
this.removeEventListener(o.type, o.listener, o.capture); |
|
this.addEventListener(o.type, o.listener = listener, o.capture = capture); |
|
o.value = value; |
|
return; |
|
} |
|
} |
|
this.addEventListener(typename.type, listener, capture); |
|
o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture}; |
|
if (!on) this.__on = [o]; |
|
else on.push(o); |
|
}; |
|
} |
|
|
|
function selection_on(typename, value, capture) { |
|
var typenames = parseTypenames(typename + ""), i, n = typenames.length, t; |
|
|
|
if (arguments.length < 2) { |
|
var on = this.node().__on; |
|
if (on) for (var j = 0, m = on.length, o; j < m; ++j) { |
|
for (i = 0, o = on[j]; i < n; ++i) { |
|
if ((t = typenames[i]).type === o.type && t.name === o.name) { |
|
return o.value; |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
on = value ? onAdd : onRemove; |
|
if (capture == null) capture = false; |
|
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture)); |
|
return this; |
|
} |
|
|
|
function selector(selector) { |
|
return function() { |
|
return this.querySelector(selector); |
|
}; |
|
} |
|
|
|
function selection_select(select) { |
|
if (typeof select !== "function") select = selector(select); |
|
|
|
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) { |
|
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) { |
|
if ("__data__" in node) subnode.__data__ = node.__data__; |
|
subgroup[i] = subnode; |
|
} |
|
} |
|
} |
|
|
|
return new Selection(subgroups, this._parents); |
|
} |
|
|
|
function selectorAll(selector) { |
|
return function() { |
|
return this.querySelectorAll(selector); |
|
}; |
|
} |
|
|
|
function selection_selectAll(select) { |
|
if (typeof select !== "function") select = selectorAll(select); |
|
|
|
for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
|
if (node = group[i]) { |
|
subgroups.push(select.call(node, node.__data__, i, group)); |
|
parents.push(node); |
|
} |
|
} |
|
} |
|
|
|
return new Selection(subgroups, parents); |
|
} |
|
|
|
function selection_filter(match) { |
|
if (typeof match !== "function") match = matcher$1(match); |
|
|
|
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) { |
|
if ((node = group[i]) && match.call(node, node.__data__, i, group)) { |
|
subgroup.push(node); |
|
} |
|
} |
|
} |
|
|
|
return new Selection(subgroups, this._parents); |
|
} |
|
|
|
function constant(x) { |
|
return function() { |
|
return x; |
|
}; |
|
} |
|
|
|
var keyPrefix = "$"; // Protect against keys like “__proto__”. |
|
|
|
function bindIndex(parent, group, enter, update, exit, data) { |
|
var i = 0, |
|
node, |
|
groupLength = group.length, |
|
dataLength = data.length; |
|
|
|
// Put any non-null nodes that fit into update. |
|
// Put any null nodes into enter. |
|
// Put any remaining data into enter. |
|
for (; i < dataLength; ++i) { |
|
if (node = group[i]) { |
|
node.__data__ = data[i]; |
|
update[i] = node; |
|
} else { |
|
enter[i] = new EnterNode(parent, data[i]); |
|
} |
|
} |
|
|
|
// Put any non-null nodes that don’t fit into exit. |
|
for (; i < groupLength; ++i) { |
|
if (node = group[i]) { |
|
exit[i] = node; |
|
} |
|
} |
|
} |
|
|
|
function bindKey(parent, group, enter, update, exit, data, key) { |
|
var i, |
|
node, |
|
nodeByKeyValue = {}, |
|
groupLength = group.length, |
|
dataLength = data.length, |
|
keyValues = new Array(groupLength), |
|
keyValue; |
|
|
|
// Compute the key for each node. |
|
// If multiple nodes have the same key, the duplicates are added to exit. |
|
for (i = 0; i < groupLength; ++i) { |
|
if (node = group[i]) { |
|
keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group); |
|
if (keyValue in nodeByKeyValue) { |
|
exit[i] = node; |
|
} else { |
|
nodeByKeyValue[keyValue] = node; |
|
} |
|
} |
|
} |
|
|
|
// Compute the key for each datum. |
|
// If there a node associated with this key, join and add it to update. |
|
// If there is not (or the key is a duplicate), add it to enter. |
|
for (i = 0; i < dataLength; ++i) { |
|
keyValue = keyPrefix + key.call(parent, data[i], i, data); |
|
if (node = nodeByKeyValue[keyValue]) { |
|
update[i] = node; |
|
node.__data__ = data[i]; |
|
nodeByKeyValue[keyValue] = null; |
|
} else { |
|
enter[i] = new EnterNode(parent, data[i]); |
|
} |
|
} |
|
|
|
// Add any remaining nodes that were not bound to data to exit. |
|
for (i = 0; i < groupLength; ++i) { |
|
if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) { |
|
exit[i] = node; |
|
} |
|
} |
|
} |
|
|
|
function selection_data(value, key) { |
|
if (!value) { |
|
data = new Array(this.size()), j = -1; |
|
this.each(function(d) { data[++j] = d; }); |
|
return data; |
|
} |
|
|
|
var bind = key ? bindKey : bindIndex, |
|
parents = this._parents, |
|
groups = this._groups; |
|
|
|
if (typeof value !== "function") value = constant(value); |
|
|
|
for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) { |
|
var parent = parents[j], |
|
group = groups[j], |
|
groupLength = group.length, |
|
data = value.call(parent, parent && parent.__data__, j, parents), |
|
dataLength = data.length, |
|
enterGroup = enter[j] = new Array(dataLength), |
|
updateGroup = update[j] = new Array(dataLength), |
|
exitGroup = exit[j] = new Array(groupLength); |
|
|
|
bind(parent, group, enterGroup, updateGroup, exitGroup, data, key); |
|
|
|
// Now connect the enter nodes to their following update node, such that |
|
// appendChild can insert the materialized enter node before this node, |
|
// rather than at the end of the parent node. |
|
for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) { |
|
if (previous = enterGroup[i0]) { |
|
if (i0 >= i1) i1 = i0 + 1; |
|
while (!(next = updateGroup[i1]) && ++i1 < dataLength); |
|
previous._next = next || null; |
|
} |
|
} |
|
} |
|
|
|
update = new Selection(update, parents); |
|
update._enter = enter; |
|
update._exit = exit; |
|
return update; |
|
} |
|
|
|
function EnterNode(parent, datum) { |
|
this.ownerDocument = parent.ownerDocument; |
|
this.namespaceURI = parent.namespaceURI; |
|
this._next = null; |
|
this._parent = parent; |
|
this.__data__ = datum; |
|
} |
|
|
|
EnterNode.prototype = { |
|
constructor: EnterNode, |
|
appendChild: function(child) { return this._parent.insertBefore(child, this._next); }, |
|
insertBefore: function(child, next) { return this._parent.insertBefore(child, next); }, |
|
querySelector: function(selector) { return this._parent.querySelector(selector); }, |
|
querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); } |
|
}; |
|
|
|
function sparse(update) { |
|
return new Array(update.length); |
|
} |
|
|
|
function selection_enter() { |
|
return new Selection(this._enter || this._groups.map(sparse), this._parents); |
|
} |
|
|
|
function selection_exit() { |
|
return new Selection(this._exit || this._groups.map(sparse), this._parents); |
|
} |
|
|
|
function selection_merge(selection) { |
|
|
|
for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { |
|
for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) { |
|
if (node = group0[i] || group1[i]) { |
|
merge[i] = node; |
|
} |
|
} |
|
} |
|
|
|
for (; j < m0; ++j) { |
|
merges[j] = groups0[j]; |
|
} |
|
|
|
return new Selection(merges, this._parents); |
|
} |
|
|
|
function selection_order() { |
|
|
|
for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) { |
|
for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) { |
|
if (node = group[i]) { |
|
if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next); |
|
next = node; |
|
} |
|
} |
|
} |
|
|
|
return this; |
|
} |
|
|
|
function selection_sort(compare) { |
|
if (!compare) compare = ascending; |
|
|
|
function compareNode(a, b) { |
|
return a && b ? compare(a.__data__, b.__data__) : !a - !b; |
|
} |
|
|
|
for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) { |
|
if (node = group[i]) { |
|
sortgroup[i] = node; |
|
} |
|
} |
|
sortgroup.sort(compareNode); |
|
} |
|
|
|
return new Selection(sortgroups, this._parents).order(); |
|
} |
|
|
|
function ascending(a, b) { |
|
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; |
|
} |
|
|
|
function selection_call() { |
|
var callback = arguments[0]; |
|
arguments[0] = this; |
|
callback.apply(null, arguments); |
|
return this; |
|
} |
|
|
|
function selection_nodes() { |
|
var nodes = new Array(this.size()), i = -1; |
|
this.each(function() { nodes[++i] = this; }); |
|
return nodes; |
|
} |
|
|
|
function selection_node() { |
|
|
|
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { |
|
for (var group = groups[j], i = 0, n = group.length; i < n; ++i) { |
|
var node = group[i]; |
|
if (node) return node; |
|
} |
|
} |
|
|
|
return null; |
|
} |
|
|
|
function selection_size() { |
|
var size = 0; |
|
this.each(function() { ++size; }); |
|
return size; |
|
} |
|
|
|
function selection_empty() { |
|
return !this.node(); |
|
} |
|
|
|
function selection_each(callback) { |
|
|
|
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { |
|
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) { |
|
if (node = group[i]) callback.call(node, node.__data__, i, group); |
|
} |
|
} |
|
|
|
return this; |
|
} |
|
|
|
function attrRemove(name) { |
|
return function() { |
|
this.removeAttribute(name); |
|
}; |
|
} |
|
|
|
function attrRemoveNS(fullname) { |
|
return function() { |
|
this.removeAttributeNS(fullname.space, fullname.local); |
|
}; |
|
} |
|
|
|
function attrConstant(name, value) { |
|
return function() { |
|
this.setAttribute(name, value); |
|
}; |
|
} |
|
|
|
function attrConstantNS(fullname, value) { |
|
return function() { |
|
this.setAttributeNS(fullname.space, fullname.local, value); |
|
}; |
|
} |
|
|
|
function attrFunction(name, value) { |
|
return function() { |
|
var v = value.apply(this, arguments); |
|
if (v == null) this.removeAttribute(name); |
|
else this.setAttribute(name, v); |
|
}; |
|
} |
|
|
|
function attrFunctionNS(fullname, value) { |
|
return function() { |
|
var v = value.apply(this, arguments); |
|
if (v == null) this.removeAttributeNS(fullname.space, fullname.local); |
|
else this.setAttributeNS(fullname.space, fullname.local, v); |
|
}; |
|
} |
|
|
|
function selection_attr(name, value) { |
|
var fullname = namespace(name); |
|
|
|
if (arguments.length < 2) { |
|
var node = this.node(); |
|
return fullname.local |
|
? node.getAttributeNS(fullname.space, fullname.local) |
|
: node.getAttribute(fullname); |
|
} |
|
|
|
return this.each((value == null |
|
? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function" |
|
? (fullname.local ? attrFunctionNS : attrFunction) |
|
: (fullname.local ? attrConstantNS : attrConstant)))(fullname, value)); |
|
} |
|
|
|
function window(node) { |
|
return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node |
|
|| (node.document && node) // node is a Window |
|
|| node.defaultView; // node is a Document |
|
} |
|
|
|
function styleRemove(name) { |
|
return function() { |
|
this.style.removeProperty(name); |
|
}; |
|
} |
|
|
|
function styleConstant(name, value, priority) { |
|
return function() { |
|
this.style.setProperty(name, value, priority); |
|
}; |
|
} |
|
|
|
function styleFunction(name, value, priority) { |
|
return function() { |
|
var v = value.apply(this, arguments); |
|
if (v == null) this.style.removeProperty(name); |
|
else this.style.setProperty(name, v, priority); |
|
}; |
|
} |
|
|
|
function selection_style(name, value, priority) { |
|
var node; |
|
return arguments.length > 1 |
|
? this.each((value == null |
|
? styleRemove : typeof value === "function" |
|
? styleFunction |
|
: styleConstant)(name, value, priority == null ? "" : priority)) |
|
: window(node = this.node()) |
|
.getComputedStyle(node, null) |
|
.getPropertyValue(name); |
|
} |
|
|
|
function propertyRemove(name) { |
|
return function() { |
|
delete this[name]; |
|
}; |
|
} |
|
|
|
function propertyConstant(name, value) { |
|
return function() { |
|
this[name] = value; |
|
}; |
|
} |
|
|
|
function propertyFunction(name, value) { |
|
return function() { |
|
var v = value.apply(this, arguments); |
|
if (v == null) delete this[name]; |
|
else this[name] = v; |
|
}; |
|
} |
|
|
|
function selection_property(name, value) { |
|
return arguments.length > 1 |
|
? this.each((value == null |
|
? propertyRemove : typeof value === "function" |
|
? propertyFunction |
|
: propertyConstant)(name, value)) |
|
: this.node()[name]; |
|
} |
|
|
|
function classArray(string) { |
|
return string.trim().split(/^|\s+/); |
|
} |
|
|
|
function classList(node) { |
|
return node.classList || new ClassList(node); |
|
} |
|
|
|
function ClassList(node) { |
|
this._node = node; |
|
this._names = classArray(node.getAttribute("class") || ""); |
|
} |
|
|
|
ClassList.prototype = { |
|
add: function(name) { |
|
var i = this._names.indexOf(name); |
|
if (i < 0) { |
|
this._names.push(name); |
|
this._node.setAttribute("class", this._names.join(" ")); |
|
} |
|
}, |
|
remove: function(name) { |
|
var i = this._names.indexOf(name); |
|
if (i >= 0) { |
|
this._names.splice(i, 1); |
|
this._node.setAttribute("class", this._names.join(" ")); |
|
} |
|
}, |
|
contains: function(name) { |
|
return this._names.indexOf(name) >= 0; |
|
} |
|
}; |
|
|
|
function classedAdd(node, names) { |
|
var list = classList(node), i = -1, n = names.length; |
|
while (++i < n) list.add(names[i]); |
|
} |
|
|
|
function classedRemove(node, names) { |
|
var list = classList(node), i = -1, n = names.length; |
|
while (++i < n) list.remove(names[i]); |
|
} |
|
|
|
function classedTrue(names) { |
|
return function() { |
|
classedAdd(this, names); |
|
}; |
|
} |
|
|
|
function classedFalse(names) { |
|
return function() { |
|
classedRemove(this, names); |
|
}; |
|
} |
|
|
|
function classedFunction(names, value) { |
|
return function() { |
|
(value.apply(this, arguments) ? classedAdd : classedRemove)(this, names); |
|
}; |
|
} |
|
|
|
function selection_classed(name, value) { |
|
var names = classArray(name + ""); |
|
|
|
if (arguments.length < 2) { |
|
var list = classList(this.node()), i = -1, n = names.length; |
|
while (++i < n) if (!list.contains(names[i])) return false; |
|
return true; |
|
} |
|
|
|
return this.each((typeof value === "function" |
|
? classedFunction : value |
|
? classedTrue |
|
: classedFalse)(names, value)); |
|
} |
|
|
|
function textRemove() { |
|
this.textContent = ""; |
|
} |
|
|
|
function textConstant(value) { |
|
return function() { |
|
this.textContent = value; |
|
}; |
|
} |
|
|
|
function textFunction(value) { |
|
return function() { |
|
var v = value.apply(this, arguments); |
|
this.textContent = v == null ? "" : v; |
|
}; |
|
} |
|
|
|
function selection_text(value) { |
|
return arguments.length |
|
? this.each(value == null |
|
? textRemove : (typeof value === "function" |
|
? textFunction |
|
: textConstant)(value)) |
|
: this.node().textContent; |
|
} |
|
|
|
function htmlRemove() { |
|
this.innerHTML = ""; |
|
} |
|
|
|
function htmlConstant(value) { |
|
return function() { |
|
this.innerHTML = value; |
|
}; |
|
} |
|
|
|
function htmlFunction(value) { |
|
return function() { |
|
var v = value.apply(this, arguments); |
|
this.innerHTML = v == null ? "" : v; |
|
}; |
|
} |
|
|
|
function selection_html(value) { |
|
return arguments.length |
|
? this.each(value == null |
|
? htmlRemove : (typeof value === "function" |
|
? htmlFunction |
|
: htmlConstant)(value)) |
|
: this.node().innerHTML; |
|
} |
|
|
|
function raise() { |
|
if (this.nextSibling) this.parentNode.appendChild(this); |
|
} |
|
|
|
function selection_raise() { |
|
return this.each(raise); |
|
} |
|
|
|
function lower() { |
|
if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild); |
|
} |
|
|
|
function selection_lower() { |
|
return this.each(lower); |
|
} |
|
|
|
function selection_append(name) { |
|
var create = typeof name === "function" ? name : creator(name); |
|
return this.select(function() { |
|
return this.appendChild(create.apply(this, arguments)); |
|
}); |
|
} |
|
|
|
function constantNull() { |
|
return null; |
|
} |
|
|
|
function selection_insert(name, before) { |
|
var create = typeof name === "function" ? name : creator(name), |
|
select = before == null ? constantNull : typeof before === "function" ? before : selector(before); |
|
return this.select(function() { |
|
return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null); |
|
}); |
|
} |
|
|
|
function remove() { |
|
var parent = this.parentNode; |
|
if (parent) parent.removeChild(this); |
|
} |
|
|
|
function selection_remove() { |
|
return this.each(remove); |
|
} |
|
|
|
function selection_datum(value) { |
|
return arguments.length |
|
? this.property("__data__", value) |
|
: this.node().__data__; |
|
} |
|
|
|
function dispatchEvent(node, type, params) { |
|
var window$$ = window(node), |
|
event = window$$.CustomEvent; |
|
|
|
if (event) { |
|
event = new event(type, params); |
|
} else { |
|
event = window$$.document.createEvent("Event"); |
|
if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail; |
|
else event.initEvent(type, false, false); |
|
} |
|
|
|
node.dispatchEvent(event); |
|
} |
|
|
|
function dispatchConstant(type, params) { |
|
return function() { |
|
return dispatchEvent(this, type, params); |
|
}; |
|
} |
|
|
|
function dispatchFunction(type, params) { |
|
return function() { |
|
return dispatchEvent(this, type, params.apply(this, arguments)); |
|
}; |
|
} |
|
|
|
function selection_dispatch(type, params) { |
|
return this.each((typeof params === "function" |
|
? dispatchFunction |
|
: dispatchConstant)(type, params)); |
|
} |
|
|
|
var root = [null]; |
|
|
|
function Selection(groups, parents) { |
|
this._groups = groups; |
|
this._parents = parents; |
|
} |
|
|
|
function selection() { |
|
return new Selection([[document.documentElement]], root); |
|
} |
|
|
|
Selection.prototype = selection.prototype = { |
|
constructor: Selection, |
|
select: selection_select, |
|
selectAll: selection_selectAll, |
|
filter: selection_filter, |
|
data: selection_data, |
|
enter: selection_enter, |
|
exit: selection_exit, |
|
merge: selection_merge, |
|
order: selection_order, |
|
sort: selection_sort, |
|
call: selection_call, |
|
nodes: selection_nodes, |
|
node: selection_node, |
|
size: selection_size, |
|
empty: selection_empty, |
|
each: selection_each, |
|
attr: selection_attr, |
|
style: selection_style, |
|
property: selection_property, |
|
classed: selection_classed, |
|
text: selection_text, |
|
html: selection_html, |
|
raise: selection_raise, |
|
lower: selection_lower, |
|
append: selection_append, |
|
insert: selection_insert, |
|
remove: selection_remove, |
|
datum: selection_datum, |
|
on: selection_on, |
|
dispatch: selection_dispatch |
|
}; |
|
|
|
function select(selector) { |
|
return typeof selector === "string" |
|
? new Selection([[document.querySelector(selector)]], [document.documentElement]) |
|
: new Selection([[selector]], root); |
|
} |
|
|
|
function selectAll(selector) { |
|
return typeof selector === "string" |
|
? new Selection([document.querySelectorAll(selector)], [document.documentElement]) |
|
: new Selection([selector], root); |
|
} |
|
|
|
function selection_attrs(map) { |
|
if (typeof map === "function") return this.each(function() { |
|
var x = map.apply(this, arguments); |
|
for (var name in x) { |
|
var value = x[name]; |
|
name = namespace(name); |
|
if (value == null) { |
|
if (name.local) this.removeAttributeNS(name.space, name.local); |
|
else this.removeAttribute(name); |
|
} else { |
|
if (name.local) this.setAttributeNS(name.space, name.local, value); |
|
else this.setAttribute(name, value); |
|
} |
|
} |
|
}); |
|
|
|
for (var name in map) { |
|
this.attr(name, map[name]); |
|
} |
|
|
|
return this; |
|
} |
|
|
|
function selection_styles(map, priority) { |
|
if (arguments.length < 2) priority = ""; |
|
|
|
if (typeof map === "function") return this.each(function() { |
|
var x = map.apply(this, arguments); |
|
for (var name in x) { |
|
var value = x[name]; |
|
if (value == null) { |
|
this.style.removeProperty(name); |
|
} else { |
|
this.style.setProperty(name, value, priority); |
|
} |
|
} |
|
}); |
|
|
|
for (var name in map) { |
|
this.style(name, map[name], priority); |
|
} |
|
|
|
return this; |
|
} |
|
|
|
function selection_properties(map) { |
|
if (typeof map === "function") return this.each(function() { |
|
var x = map.apply(this, arguments); |
|
for (var name in x) { |
|
var value = x[name]; |
|
if (value == null) { |
|
delete this[name]; |
|
} else { |
|
this[name] = value; |
|
} |
|
} |
|
}); |
|
|
|
for (var name in map) { |
|
this.property(name, map[name]); |
|
} |
|
|
|
return this; |
|
} |
|
|
|
selection.prototype.attrs = selection_attrs; |
|
selection.prototype.styles = selection_styles; |
|
selection.prototype.properties = selection_properties; |
|
|
|
if (selection.prototype.transition){ |
|
selection.prototype.transition.attrs = selection_attrs; |
|
selection.prototype.transition.styles = selection_attrs; |
|
selection.prototype.transition.properties = selection_attrs; |
|
} |
|
|
|
var noop = {value: function() {}}; |
|
|
|
function dispatch() { |
|
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) { |
|
if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t); |
|
_[t] = []; |
|
} |
|
return new Dispatch(_); |
|
} |
|
|
|
function Dispatch(_) { |
|
this._ = _; |
|
} |
|
|
|
function parseTypenames$1(typenames, types) { |
|
return typenames.trim().split(/^|\s+/).map(function(t) { |
|
var name = "", i = t.indexOf("."); |
|
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i); |
|
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t); |
|
return {type: t, name: name}; |
|
}); |
|
} |
|
|
|
Dispatch.prototype = dispatch.prototype = { |
|
constructor: Dispatch, |
|
on: function(typename, callback) { |
|
var _ = this._, |
|
T = parseTypenames$1(typename + "", _), |
|
t, |
|
i = -1, |
|
n = T.length; |
|
|
|
// If no callback was specified, return the callback of the given type and name. |
|
if (arguments.length < 2) { |
|
while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t; |
|
return; |
|
} |
|
|
|
// If a type was specified, set the callback for the given type and name. |
|
// Otherwise, if a null callback was specified, remove callbacks of the given name. |
|
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback); |
|
while (++i < n) { |
|
if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback); |
|
else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null); |
|
} |
|
|
|
return this; |
|
}, |
|
copy: function() { |
|
var copy = {}, _ = this._; |
|
for (var t in _) copy[t] = _[t].slice(); |
|
return new Dispatch(copy); |
|
}, |
|
call: function(type, that) { |
|
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2]; |
|
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); |
|
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args); |
|
}, |
|
apply: function(type, that, args) { |
|
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); |
|
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args); |
|
} |
|
}; |
|
|
|
function get$1(type, name) { |
|
for (var i = 0, n = type.length, c; i < n; ++i) { |
|
if ((c = type[i]).name === name) { |
|
return c.value; |
|
} |
|
} |
|
} |
|
|
|
function set$1(type, name, callback) { |
|
for (var i = 0, n = type.length; i < n; ++i) { |
|
if (type[i].name === name) { |
|
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1)); |
|
break; |
|
} |
|
} |
|
if (callback != null) type.push({name: name, value: callback}); |
|
return type; |
|
} |
|
|
|
var frame = 0; |
|
var timeout = 0; |
|
var interval = 0; |
|
var pokeDelay = 1000; |
|
var taskHead; |
|
var taskTail; |
|
var clockLast = 0; |
|
var clockNow = 0; |
|
var clockSkew = 0; |
|
var clock = typeof performance === "object" ? performance : Date; |
|
var setFrame = typeof requestAnimationFrame === "function" |
|
? (clock === Date ? function(f) { requestAnimationFrame(function() { f(clock.now()); }); } : requestAnimationFrame) |
|
: function(f) { setTimeout(f, 17); }; |
|
function now() { |
|
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew); |
|
} |
|
|
|
function clearNow() { |
|
clockNow = 0; |
|
} |
|
|
|
function Timer() { |
|
this._call = |
|
this._time = |
|
this._next = null; |
|
} |
|
|
|
Timer.prototype = timer.prototype = { |
|
constructor: Timer, |
|
restart: function(callback, delay, time) { |
|
if (typeof callback !== "function") throw new TypeError("callback is not a function"); |
|
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay); |
|
if (!this._next && taskTail !== this) { |
|
if (taskTail) taskTail._next = this; |
|
else taskHead = this; |
|
taskTail = this; |
|
} |
|
this._call = callback; |
|
this._time = time; |
|
sleep(); |
|
}, |
|
stop: function() { |
|
if (this._call) { |
|
this._call = null; |
|
this._time = Infinity; |
|
sleep(); |
|
} |
|
} |
|
}; |
|
|
|
function timer(callback, delay, time) { |
|
var t = new Timer; |
|
t.restart(callback, delay, time); |
|
return t; |
|
} |
|
|
|
function timerFlush() { |
|
now(); // Get the current time, if not already set. |
|
++frame; // Pretend we’ve set an alarm, if we haven’t already. |
|
var t = taskHead, e; |
|
while (t) { |
|
if ((e = clockNow - t._time) >= 0) t._call.call(null, e); |
|
t = t._next; |
|
} |
|
--frame; |
|
} |
|
|
|
function wake(time) { |
|
clockNow = (clockLast = time || clock.now()) + clockSkew; |
|
frame = timeout = 0; |
|
try { |
|
timerFlush(); |
|
} finally { |
|
frame = 0; |
|
nap(); |
|
clockNow = 0; |
|
} |
|
} |
|
|
|
function poke() { |
|
var now = clock.now(), delay = now - clockLast; |
|
if (delay > pokeDelay) clockSkew -= delay, clockLast = now; |
|
} |
|
|
|
function nap() { |
|
var t0, t1 = taskHead, t2, time = Infinity; |
|
while (t1) { |
|
if (t1._call) { |
|
if (time > t1._time) time = t1._time; |
|
t0 = t1, t1 = t1._next; |
|
} else { |
|
t2 = t1._next, t1._next = null; |
|
t1 = t0 ? t0._next = t2 : taskHead = t2; |
|
} |
|
} |
|
taskTail = t0; |
|
sleep(time); |
|
} |
|
|
|
function sleep(time) { |
|
if (frame) return; // Soonest alarm already set, or will be. |
|
if (timeout) timeout = clearTimeout(timeout); |
|
var delay = time - clockNow; |
|
if (delay > 24) { |
|
if (time < Infinity) timeout = setTimeout(wake, delay); |
|
if (interval) interval = clearInterval(interval); |
|
} else { |
|
if (!interval) interval = setInterval(poke, pokeDelay); |
|
frame = 1, setFrame(wake); |
|
} |
|
} |
|
|
|
function timeout$1(callback, delay, time) { |
|
var t = new Timer; |
|
delay = delay == null ? 0 : +delay; |
|
t.restart(function(elapsed) { |
|
t.stop(); |
|
callback(elapsed + delay); |
|
}, delay, time); |
|
return t; |
|
} |
|
|
|
var emptyOn = dispatch("start", "end", "interrupt"); |
|
var emptyTween = []; |
|
|
|
var CREATED = 0; |
|
var SCHEDULED = 1; |
|
var STARTING = 2; |
|
var STARTED = 3; |
|
var ENDING = 4; |
|
var ENDED = 5; |
|
|
|
function schedule(node, name, id, index, group, timing) { |
|
var schedules = node.__transition; |
|
if (!schedules) node.__transition = {}; |
|
else if (id in schedules) return; |
|
create(node, id, { |
|
name: name, |
|
index: index, // For context during callback. |
|
group: group, // For context during callback. |
|
on: emptyOn, |
|
tween: emptyTween, |
|
time: timing.time, |
|
delay: timing.delay, |
|
duration: timing.duration, |
|
ease: timing.ease, |
|
timer: null, |
|
state: CREATED |
|
}); |
|
} |
|
|
|
function init(node, id) { |
|
var schedule = node.__transition; |
|
if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late"); |
|
return schedule; |
|
} |
|
|
|
function set(node, id) { |
|
var schedule = node.__transition; |
|
if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late"); |
|
return schedule; |
|
} |
|
|
|
function get(node, id) { |
|
var schedule = node.__transition; |
|
if (!schedule || !(schedule = schedule[id])) throw new Error("too late"); |
|
return schedule; |
|
} |
|
|
|
function create(node, id, self) { |
|
var schedules = node.__transition, |
|
tween; |
|
|
|
// Initialize the self timer when the transition is created. |
|
// Note the actual delay is not known until the first callback! |
|
schedules[id] = self; |
|
self.timer = timer(schedule, 0, self.time); |
|
|
|
// If the delay is greater than this first sleep, sleep some more; |
|
// otherwise, start immediately. |
|
function schedule(elapsed) { |
|
self.state = SCHEDULED; |
|
if (self.delay <= elapsed) start(elapsed - self.delay); |
|
else self.timer.restart(start, self.delay, self.time); |
|
} |
|
|
|
function start(elapsed) { |
|
var i, j, n, o; |
|
|
|
for (i in schedules) { |
|
o = schedules[i]; |
|
if (o.name !== self.name) continue; |
|
|
|
// Interrupt the active transition, if any. |
|
// Dispatch the interrupt event. |
|
if (o.state === STARTED) { |
|
o.state = ENDED; |
|
o.timer.stop(); |
|
o.on.call("interrupt", node, node.__data__, o.index, o.group); |
|
delete schedules[i]; |
|
} |
|
|
|
// Cancel any pre-empted transitions. No interrupt event is dispatched |
|
// because the cancelled transitions never started. Note that this also |
|
// removes this transition from the pending list! |
|
else if (+i < id) { |
|
o.state = ENDED; |
|
o.timer.stop(); |
|
delete schedules[i]; |
|
} |
|
} |
|
|
|
// Defer the first tick to end of the current frame; see mbostock/d3#1576. |
|
// Note the transition may be canceled after start and before the first tick! |
|
// Note this must be scheduled before the start event; see d3/d3-transition#16! |
|
// Assuming this is successful, subsequent callbacks go straight to tick. |
|
timeout$1(function() { |
|
if (self.state === STARTED) { |
|
self.timer.restart(tick, self.delay, self.time); |
|
tick(elapsed); |
|
} |
|
}); |
|
|
|
// Dispatch the start event. |
|
// Note this must be done before the tween are initialized. |
|
self.state = STARTING; |
|
self.on.call("start", node, node.__data__, self.index, self.group); |
|
if (self.state !== STARTING) return; // interrupted |
|
self.state = STARTED; |
|
|
|
// Initialize the tween, deleting null tween. |
|
tween = new Array(n = self.tween.length); |
|
for (i = 0, j = -1; i < n; ++i) { |
|
if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) { |
|
tween[++j] = o; |
|
} |
|
} |
|
tween.length = j + 1; |
|
} |
|
|
|
function tick(elapsed) { |
|
var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.state = ENDING, 1), |
|
i = -1, |
|
n = tween.length; |
|
|
|
while (++i < n) { |
|
tween[i].call(null, t); |
|
} |
|
|
|
// Dispatch the end event. |
|
if (self.state === ENDING) { |
|
self.state = ENDED; |
|
self.timer.stop(); |
|
self.on.call("end", node, node.__data__, self.index, self.group); |
|
for (i in schedules) if (+i !== id) return void delete schedules[id]; |
|
delete node.__transition; |
|
} |
|
} |
|
} |
|
|
|
function interrupt(node, name) { |
|
var schedules = node.__transition, |
|
schedule, |
|
active, |
|
empty = true, |
|
i; |
|
|
|
if (!schedules) return; |
|
|
|
name = name == null ? null : name + ""; |
|
|
|
for (i in schedules) { |
|
if ((schedule = schedules[i]).name !== name) { empty = false; continue; } |
|
active = schedule.state === STARTED; |
|
schedule.state = ENDED; |
|
schedule.timer.stop(); |
|
if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group); |
|
delete schedules[i]; |
|
} |
|
|
|
if (empty) delete node.__transition; |
|
} |
|
|
|
function selection_interrupt(name) { |
|
return this.each(function() { |
|
interrupt(this, name); |
|
}); |
|
} |
|
|
|
function define(constructor, factory, prototype) { |
|
constructor.prototype = factory.prototype = prototype; |
|
prototype.constructor = constructor; |
|
} |
|
|
|
function extend(parent, definition) { |
|
var prototype = Object.create(parent.prototype); |
|
for (var key in definition) prototype[key] = definition[key]; |
|
return prototype; |
|
} |
|
|
|
function Color() {} |
|
|
|
var darker = 0.7; |
|
var brighter = 1 / darker; |
|
|
|
var reHex3 = /^#([0-9a-f]{3})$/; |
|
var reHex6 = /^#([0-9a-f]{6})$/; |
|
var reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/; |
|
var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/; |
|
var reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/; |
|
var reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/; |
|
var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/; |
|
var reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/; |
|
var named = { |
|
aliceblue: 0xf0f8ff, |
|
antiquewhite: 0xfaebd7, |
|
aqua: 0x00ffff, |
|
aquamarine: 0x7fffd4, |
|
azure: 0xf0ffff, |
|
beige: 0xf5f5dc, |
|
bisque: 0xffe4c4, |
|
black: 0x000000, |
|
blanchedalmond: 0xffebcd, |
|
blue: 0x0000ff, |
|
blueviolet: 0x8a2be2, |
|
brown: 0xa52a2a, |
|
burlywood: 0xdeb887, |
|
cadetblue: 0x5f9ea0, |
|
chartreuse: 0x7fff00, |
|
chocolate: 0xd2691e, |
|
coral: 0xff7f50, |
|
cornflowerblue: 0x6495ed, |
|
cornsilk: 0xfff8dc, |
|
crimson: 0xdc143c, |
|
cyan: 0x00ffff, |
|
darkblue: 0x00008b, |
|
darkcyan: 0x008b8b, |
|
darkgoldenrod: 0xb8860b, |
|
darkgray: 0xa9a9a9, |
|
darkgreen: 0x006400, |
|
darkgrey: 0xa9a9a9, |
|
darkkhaki: 0xbdb76b, |
|
darkmagenta: 0x8b008b, |
|
darkolivegreen: 0x556b2f, |
|
darkorange: 0xff8c00, |
|
darkorchid: 0x9932cc, |
|
darkred: 0x8b0000, |
|
darksalmon: 0xe9967a, |
|
darkseagreen: 0x8fbc8f, |
|
darkslateblue: 0x483d8b, |
|
darkslategray: 0x2f4f4f, |
|
darkslategrey: 0x2f4f4f, |
|
darkturquoise: 0x00ced1, |
|
darkviolet: 0x9400d3, |
|
deeppink: 0xff1493, |
|
deepskyblue: 0x00bfff, |
|
dimgray: 0x696969, |
|
dimgrey: 0x696969, |
|
dodgerblue: 0x1e90ff, |
|
firebrick: 0xb22222, |
|
floralwhite: 0xfffaf0, |
|
forestgreen: 0x228b22, |
|
fuchsia: 0xff00ff, |
|
gainsboro: 0xdcdcdc, |
|
ghostwhite: 0xf8f8ff, |
|
gold: 0xffd700, |
|
goldenrod: 0xdaa520, |
|
gray: 0x808080, |
|
green: 0x008000, |
|
greenyellow: 0xadff2f, |
|
grey: 0x808080, |
|
honeydew: 0xf0fff0, |
|
hotpink: 0xff69b4, |
|
indianred: 0xcd5c5c, |
|
indigo: 0x4b0082, |
|
ivory: 0xfffff0, |
|
khaki: 0xf0e68c, |
|
lavender: 0xe6e6fa, |
|
lavenderblush: 0xfff0f5, |
|
lawngreen: 0x7cfc00, |
|
lemonchiffon: 0xfffacd, |
|
lightblue: 0xadd8e6, |
|
lightcoral: 0xf08080, |
|
lightcyan: 0xe0ffff, |
|
lightgoldenrodyellow: 0xfafad2, |
|
lightgray: 0xd3d3d3, |
|
lightgreen: 0x90ee90, |
|
lightgrey: 0xd3d3d3, |
|
lightpink: 0xffb6c1, |
|
lightsalmon: 0xffa07a, |
|
lightseagreen: 0x20b2aa, |
|
lightskyblue: 0x87cefa, |
|
lightslategray: 0x778899, |
|
lightslategrey: 0x778899, |
|
lightsteelblue: 0xb0c4de, |
|
lightyellow: 0xffffe0, |
|
lime: 0x00ff00, |
|
limegreen: 0x32cd32, |
|
linen: 0xfaf0e6, |
|
magenta: 0xff00ff, |
|
maroon: 0x800000, |
|
mediumaquamarine: 0x66cdaa, |
|
mediumblue: 0x0000cd, |
|
mediumorchid: 0xba55d3, |
|
mediumpurple: 0x9370db, |
|
mediumseagreen: 0x3cb371, |
|
mediumslateblue: 0x7b68ee, |
|
mediumspringgreen: 0x00fa9a, |
|
mediumturquoise: 0x48d1cc, |
|
mediumvioletred: 0xc71585, |
|
midnightblue: 0x191970, |
|
mintcream: 0xf5fffa, |
|
mistyrose: 0xffe4e1, |
|
moccasin: 0xffe4b5, |
|
navajowhite: 0xffdead, |
|
navy: 0x000080, |
|
oldlace: 0xfdf5e6, |
|
olive: 0x808000, |
|
olivedrab: 0x6b8e23, |
|
orange: 0xffa500, |
|
orangered: 0xff4500, |
|
orchid: 0xda70d6, |
|
palegoldenrod: 0xeee8aa, |
|
palegreen: 0x98fb98, |
|
paleturquoise: 0xafeeee, |
|
palevioletred: 0xdb7093, |
|
papayawhip: 0xffefd5, |
|
peachpuff: 0xffdab9, |
|
peru: 0xcd853f, |
|
pink: 0xffc0cb, |
|
plum: 0xdda0dd, |
|
powderblue: 0xb0e0e6, |
|
purple: 0x800080, |
|
rebeccapurple: 0x663399, |
|
red: 0xff0000, |
|
rosybrown: 0xbc8f8f, |
|
royalblue: 0x4169e1, |
|
saddlebrown: 0x8b4513, |
|
salmon: 0xfa8072, |
|
sandybrown: 0xf4a460, |
|
seagreen: 0x2e8b57, |
|
seashell: 0xfff5ee, |
|
sienna: 0xa0522d, |
|
silver: 0xc0c0c0, |
|
skyblue: 0x87ceeb, |
|
slateblue: 0x6a5acd, |
|
slategray: 0x708090, |
|
slategrey: 0x708090, |
|
snow: 0xfffafa, |
|
springgreen: 0x00ff7f, |
|
steelblue: 0x4682b4, |
|
tan: 0xd2b48c, |
|
teal: 0x008080, |
|
thistle: 0xd8bfd8, |
|
tomato: 0xff6347, |
|
turquoise: 0x40e0d0, |
|
violet: 0xee82ee, |
|
wheat: 0xf5deb3, |
|
white: 0xffffff, |
|
whitesmoke: 0xf5f5f5, |
|
yellow: 0xffff00, |
|
yellowgreen: 0x9acd32 |
|
}; |
|
|
|
define(Color, color, { |
|
displayable: function() { |
|
return this.rgb().displayable(); |
|
}, |
|
toString: function() { |
|
return this.rgb() + ""; |
|
} |
|
}); |
|
|
|
function color(format) { |
|
var m; |
|
format = (format + "").trim().toLowerCase(); |
|
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00 |
|
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000 |
|
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0) |
|
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%) |
|
: (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1) |
|
: (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1) |
|
: (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%) |
|
: (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1) |
|
: named.hasOwnProperty(format) ? rgbn(named[format]) |
|
: format === "transparent" ? new Rgb(NaN, NaN, NaN, 0) |
|
: null; |
|
} |
|
|
|
function rgbn(n) { |
|
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1); |
|
} |
|
|
|
function rgba(r, g, b, a) { |
|
if (a <= 0) r = g = b = NaN; |
|
return new Rgb(r, g, b, a); |
|
} |
|
|
|
function rgbConvert(o) { |
|
if (!(o instanceof Color)) o = color(o); |
|
if (!o) return new Rgb; |
|
o = o.rgb(); |
|
return new Rgb(o.r, o.g, o.b, o.opacity); |
|
} |
|
|
|
function colorRgb(r, g, b, opacity) { |
|
return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity); |
|
} |
|
|
|
function Rgb(r, g, b, opacity) { |
|
this.r = +r; |
|
this.g = +g; |
|
this.b = +b; |
|
this.opacity = +opacity; |
|
} |
|
|
|
define(Rgb, colorRgb, extend(Color, { |
|
brighter: function(k) { |
|
k = k == null ? brighter : Math.pow(brighter, k); |
|
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity); |
|
}, |
|
darker: function(k) { |
|
k = k == null ? darker : Math.pow(darker, k); |
|
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity); |
|
}, |
|
rgb: function() { |
|
return this; |
|
}, |
|
displayable: function() { |
|
return (0 <= this.r && this.r <= 255) |
|
&& (0 <= this.g && this.g <= 255) |
|
&& (0 <= this.b && this.b <= 255) |
|
&& (0 <= this.opacity && this.opacity <= 1); |
|
}, |
|
toString: function() { |
|
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a)); |
|
return (a === 1 ? "rgb(" : "rgba(") |
|
+ Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", " |
|
+ Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", " |
|
+ Math.max(0, Math.min(255, Math.round(this.b) || 0)) |
|
+ (a === 1 ? ")" : ", " + a + ")"); |
|
} |
|
})); |
|
|
|
function hsla(h, s, l, a) { |
|
if (a <= 0) h = s = l = NaN; |
|
else if (l <= 0 || l >= 1) h = s = NaN; |
|
else if (s <= 0) h = NaN; |
|
return new Hsl(h, s, l, a); |
|
} |
|
|
|
function hslConvert(o) { |
|
if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity); |
|
if (!(o instanceof Color)) o = color(o); |
|
if (!o) return new Hsl; |
|
if (o instanceof Hsl) return o; |
|
o = o.rgb(); |
|
var r = o.r / 255, |
|
g = o.g / 255, |
|
b = o.b / 255, |
|
min = Math.min(r, g, b), |
|
max = Math.max(r, g, b), |
|
h = NaN, |
|
s = max - min, |
|
l = (max + min) / 2; |
|
if (s) { |
|
if (r === max) h = (g - b) / s + (g < b) * 6; |
|
else if (g === max) h = (b - r) / s + 2; |
|
else h = (r - g) / s + 4; |
|
s /= l < 0.5 ? max + min : 2 - max - min; |
|
h *= 60; |
|
} else { |
|
s = l > 0 && l < 1 ? 0 : h; |
|
} |
|
return new Hsl(h, s, l, o.opacity); |
|
} |
|
|
|
function colorHsl(h, s, l, opacity) { |
|
return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity); |
|
} |
|
|
|
function Hsl(h, s, l, opacity) { |
|
this.h = +h; |
|
this.s = +s; |
|
this.l = +l; |
|
this.opacity = +opacity; |
|
} |
|
|
|
define(Hsl, colorHsl, extend(Color, { |
|
brighter: function(k) { |
|
k = k == null ? brighter : Math.pow(brighter, k); |
|
return new Hsl(this.h, this.s, this.l * k, this.opacity); |
|
}, |
|
darker: function(k) { |
|
k = k == null ? darker : Math.pow(darker, k); |
|
return new Hsl(this.h, this.s, this.l * k, this.opacity); |
|
}, |
|
rgb: function() { |
|
var h = this.h % 360 + (this.h < 0) * 360, |
|
s = isNaN(h) || isNaN(this.s) ? 0 : this.s, |
|
l = this.l, |
|
m2 = l + (l < 0.5 ? l : 1 - l) * s, |
|
m1 = 2 * l - m2; |
|
return new Rgb( |
|
hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2), |
|
hsl2rgb(h, m1, m2), |
|
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2), |
|
this.opacity |
|
); |
|
}, |
|
displayable: function() { |
|
return (0 <= this.s && this.s <= 1 || isNaN(this.s)) |
|
&& (0 <= this.l && this.l <= 1) |
|
&& (0 <= this.opacity && this.opacity <= 1); |
|
} |
|
})); |
|
|
|
/* From FvD 13.37, CSS Color Module Level 3 */ |
|
function hsl2rgb(h, m1, m2) { |
|
return (h < 60 ? m1 + (m2 - m1) * h / 60 |
|
: h < 180 ? m2 |
|
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 |
|
: m1) * 255; |
|
} |
|
|
|
var deg2rad = Math.PI / 180; |
|
var rad2deg = 180 / Math.PI; |
|
|
|
var Kn = 18; |
|
var Xn = 0.950470; |
|
var Yn = 1; |
|
var Zn = 1.088830; |
|
var t0 = 4 / 29; |
|
var t1 = 6 / 29; |
|
var t2 = 3 * t1 * t1; |
|
var t3 = t1 * t1 * t1; |
|
function labConvert(o) { |
|
if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity); |
|
if (o instanceof Hcl) { |
|
var h = o.h * deg2rad; |
|
return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity); |
|
} |
|
if (!(o instanceof Rgb)) o = rgbConvert(o); |
|
var b = rgb2xyz(o.r), |
|
a = rgb2xyz(o.g), |
|
l = rgb2xyz(o.b), |
|
x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn), |
|
y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn), |
|
z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn); |
|
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity); |
|
} |
|
|
|
function lab(l, a, b, opacity) { |
|
return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity); |
|
} |
|
|
|
function Lab(l, a, b, opacity) { |
|
this.l = +l; |
|
this.a = +a; |
|
this.b = +b; |
|
this.opacity = +opacity; |
|
} |
|
|
|
define(Lab, lab, extend(Color, { |
|
brighter: function(k) { |
|
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity); |
|
}, |
|
darker: function(k) { |
|
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity); |
|
}, |
|
rgb: function() { |
|
var y = (this.l + 16) / 116, |
|
x = isNaN(this.a) ? y : y + this.a / 500, |
|
z = isNaN(this.b) ? y : y - this.b / 200; |
|
y = Yn * lab2xyz(y); |
|
x = Xn * lab2xyz(x); |
|
z = Zn * lab2xyz(z); |
|
return new Rgb( |
|
xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB |
|
xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z), |
|
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z), |
|
this.opacity |
|
); |
|
} |
|
})); |
|
|
|
function xyz2lab(t) { |
|
return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0; |
|
} |
|
|
|
function lab2xyz(t) { |
|
return t > t1 ? t * t * t : t2 * (t - t0); |
|
} |
|
|
|
function xyz2rgb(x) { |
|
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055); |
|
} |
|
|
|
function rgb2xyz(x) { |
|
return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4); |
|
} |
|
|
|
function hclConvert(o) { |
|
if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity); |
|
if (!(o instanceof Lab)) o = labConvert(o); |
|
var h = Math.atan2(o.b, o.a) * rad2deg; |
|
return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity); |
|
} |
|
|
|
function colorHcl(h, c, l, opacity) { |
|
return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity); |
|
} |
|
|
|
function Hcl(h, c, l, opacity) { |
|
this.h = +h; |
|
this.c = +c; |
|
this.l = +l; |
|
this.opacity = +opacity; |
|
} |
|
|
|
define(Hcl, colorHcl, extend(Color, { |
|
brighter: function(k) { |
|
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity); |
|
}, |
|
darker: function(k) { |
|
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity); |
|
}, |
|
rgb: function() { |
|
return labConvert(this).rgb(); |
|
} |
|
})); |
|
|
|
var A = -0.14861; |
|
var B = +1.78277; |
|
var C = -0.29227; |
|
var D = -0.90649; |
|
var E = +1.97294; |
|
var ED = E * D; |
|
var EB = E * B; |
|
var BC_DA = B * C - D * A; |
|
function cubehelixConvert(o) { |
|
if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); |
|
if (!(o instanceof Rgb)) o = rgbConvert(o); |
|
var r = o.r / 255, |
|
g = o.g / 255, |
|
b = o.b / 255, |
|
l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), |
|
bl = b - l, |
|
k = (E * (g - l) - C * bl) / D, |
|
s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 |
|
h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; |
|
return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); |
|
} |
|
|
|
function cubehelix(h, s, l, opacity) { |
|
return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity); |
|
} |
|
|
|
function Cubehelix(h, s, l, opacity) { |
|
this.h = +h; |
|
this.s = +s; |
|
this.l = +l; |
|
this.opacity = +opacity; |
|
} |
|
|
|
define(Cubehelix, cubehelix, extend(Color, { |
|
brighter: function(k) { |
|
k = k == null ? brighter : Math.pow(brighter, k); |
|
return new Cubehelix(this.h, this.s, this.l * k, this.opacity); |
|
}, |
|
darker: function(k) { |
|
k = k == null ? darker : Math.pow(darker, k); |
|
return new Cubehelix(this.h, this.s, this.l * k, this.opacity); |
|
}, |
|
rgb: function() { |
|
var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, |
|
l = +this.l, |
|
a = isNaN(this.s) ? 0 : this.s * l * (1 - l), |
|
cosh = Math.cos(h), |
|
sinh = Math.sin(h); |
|
return new Rgb( |
|
255 * (l + a * (A * cosh + B * sinh)), |
|
255 * (l + a * (C * cosh + D * sinh)), |
|
255 * (l + a * (E * cosh)), |
|
this.opacity |
|
); |
|
} |
|
})); |
|
|
|
function constant$1(x) { |
|
return function() { |
|
return x; |
|
}; |
|
} |
|
|
|
function linear(a, d) { |
|
return function(t) { |
|
return a + t * d; |
|
}; |
|
} |
|
|
|
function exponential(a, b, y) { |
|
return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) { |
|
return Math.pow(a + t * b, y); |
|
}; |
|
} |
|
|
|
function hue(a, b) { |
|
var d = b - a; |
|
return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$1(isNaN(a) ? b : a); |
|
} |
|
|
|
function gamma(y) { |
|
return (y = +y) === 1 ? nogamma : function(a, b) { |
|
return b - a ? exponential(a, b, y) : constant$1(isNaN(a) ? b : a); |
|
}; |
|
} |
|
|
|
function nogamma(a, b) { |
|
var d = b - a; |
|
return d ? linear(a, d) : constant$1(isNaN(a) ? b : a); |
|
} |
|
|
|
var interpolateRgb = (function rgbGamma(y) { |
|
var color = gamma(y); |
|
|
|
function rgb(start, end) { |
|
var r = color((start = colorRgb(start)).r, (end = colorRgb(end)).r), |
|
g = color(start.g, end.g), |
|
b = color(start.b, end.b), |
|
opacity = color(start.opacity, end.opacity); |
|
return function(t) { |
|
start.r = r(t); |
|
start.g = g(t); |
|
start.b = b(t); |
|
start.opacity = opacity(t); |
|
return start + ""; |
|
}; |
|
} |
|
|
|
rgb.gamma = rgbGamma; |
|
|
|
return rgb; |
|
})(1); |
|
|
|
function interpolateNumber(a, b) { |
|
return a = +a, b -= a, function(t) { |
|
return a + b * t; |
|
}; |
|
} |
|
|
|
var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g; |
|
var reB = new RegExp(reA.source, "g"); |
|
function zero(b) { |
|
return function() { |
|
return b; |
|
}; |
|
} |
|
|
|
function one(b) { |
|
return function(t) { |
|
return b(t) + ""; |
|
}; |
|
} |
|
|
|
function interpolateString(a, b) { |
|
var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b |
|
am, // current match in a |
|
bm, // current match in b |
|
bs, // string preceding current number in b, if any |
|
i = -1, // index in s |
|
s = [], // string constants and placeholders |
|
q = []; // number interpolators |
|
|
|
// Coerce inputs to strings. |
|
a = a + "", b = b + ""; |
|
|
|
// Interpolate pairs of numbers in a & b. |
|
while ((am = reA.exec(a)) |
|
&& (bm = reB.exec(b))) { |
|
if ((bs = bm.index) > bi) { // a string precedes the next number in b |
|
bs = b.slice(bi, bs); |
|
if (s[i]) s[i] += bs; // coalesce with previous string |
|
else s[++i] = bs; |
|
} |
|
if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match |
|
if (s[i]) s[i] += bm; // coalesce with previous string |
|
else s[++i] = bm; |
|
} else { // interpolate non-matching numbers |
|
s[++i] = null; |
|
q.push({i: i, x: interpolateNumber(am, bm)}); |
|
} |
|
bi = reB.lastIndex; |
|
} |
|
|
|
// Add remains of b. |
|
if (bi < b.length) { |
|
bs = b.slice(bi); |
|
if (s[i]) s[i] += bs; // coalesce with previous string |
|
else s[++i] = bs; |
|
} |
|
|
|
// Special optimization for only a single match. |
|
// Otherwise, interpolate each of the numbers and rejoin the string. |
|
return s.length < 2 ? (q[0] |
|
? one(q[0].x) |
|
: zero(b)) |
|
: (b = q.length, function(t) { |
|
for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t); |
|
return s.join(""); |
|
}); |
|
} |
|
|
|
var degrees = 180 / Math.PI; |
|
|
|
var identity = { |
|
translateX: 0, |
|
translateY: 0, |
|
rotate: 0, |
|
skewX: 0, |
|
scaleX: 1, |
|
scaleY: 1 |
|
}; |
|
|
|
function decompose(a, b, c, d, e, f) { |
|
var scaleX, scaleY, skewX; |
|
if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX; |
|
if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX; |
|
if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY; |
|
if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX; |
|
return { |
|
translateX: e, |
|
translateY: f, |
|
rotate: Math.atan2(b, a) * degrees, |
|
skewX: Math.atan(skewX) * degrees, |
|
scaleX: scaleX, |
|
scaleY: scaleY |
|
}; |
|
} |
|
|
|
var cssNode; |
|
var cssRoot; |
|
var cssView; |
|
var svgNode; |
|
function parseCss(value) { |
|
if (value === "none") return identity; |
|
if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView; |
|
cssNode.style.transform = value; |
|
value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform"); |
|
cssRoot.removeChild(cssNode); |
|
value = value.slice(7, -1).split(","); |
|
return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]); |
|
} |
|
|
|
function parseSvg(value) { |
|
if (value == null) return identity; |
|
if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g"); |
|
svgNode.setAttribute("transform", value); |
|
if (!(value = svgNode.transform.baseVal.consolidate())) return identity; |
|
value = value.matrix; |
|
return decompose(value.a, value.b, value.c, value.d, value.e, value.f); |
|
} |
|
|
|
function interpolateTransform(parse, pxComma, pxParen, degParen) { |
|
|
|
function pop(s) { |
|
return s.length ? s.pop() + " " : ""; |
|
} |
|
|
|
function translate(xa, ya, xb, yb, s, q) { |
|
if (xa !== xb || ya !== yb) { |
|
var i = s.push("translate(", null, pxComma, null, pxParen); |
|
q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)}); |
|
} else if (xb || yb) { |
|
s.push("translate(" + xb + pxComma + yb + pxParen); |
|
} |
|
} |
|
|
|
function rotate(a, b, s, q) { |
|
if (a !== b) { |
|
if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path |
|
q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)}); |
|
} else if (b) { |
|
s.push(pop(s) + "rotate(" + b + degParen); |
|
} |
|
} |
|
|
|
function skewX(a, b, s, q) { |
|
if (a !== b) { |
|
q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)}); |
|
} else if (b) { |
|
s.push(pop(s) + "skewX(" + b + degParen); |
|
} |
|
} |
|
|
|
function scale(xa, ya, xb, yb, s, q) { |
|
if (xa !== xb || ya !== yb) { |
|
var i = s.push(pop(s) + "scale(", null, ",", null, ")"); |
|
q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)}); |
|
} else if (xb !== 1 || yb !== 1) { |
|
s.push(pop(s) + "scale(" + xb + "," + yb + ")"); |
|
} |
|
} |
|
|
|
return function(a, b) { |
|
var s = [], // string constants and placeholders |
|
q = []; // number interpolators |
|
a = parse(a), b = parse(b); |
|
translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q); |
|
rotate(a.rotate, b.rotate, s, q); |
|
skewX(a.skewX, b.skewX, s, q); |
|
scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q); |
|
a = b = null; // gc |
|
return function(t) { |
|
var i = -1, n = q.length, o; |
|
while (++i < n) s[(o = q[i]).i] = o.x(t); |
|
return s.join(""); |
|
}; |
|
}; |
|
} |
|
|
|
var interpolateTransform$1 = interpolateTransform(parseCss, "px, ", "px)", "deg)"); |
|
var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")"); |
|
|
|
function cubehelix$1(hue) { |
|
return (function cubehelixGamma(y) { |
|
y = +y; |
|
|
|
function cubehelix$$(start, end) { |
|
var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h), |
|
s = nogamma(start.s, end.s), |
|
l = nogamma(start.l, end.l), |
|
opacity = nogamma(start.opacity, end.opacity); |
|
return function(t) { |
|
start.h = h(t); |
|
start.s = s(t); |
|
start.l = l(Math.pow(t, y)); |
|
start.opacity = opacity(t); |
|
return start + ""; |
|
}; |
|
} |
|
|
|
cubehelix$$.gamma = cubehelixGamma; |
|
|
|
return cubehelix$$; |
|
})(1); |
|
} |
|
|
|
cubehelix$1(hue); |
|
var cubehelixLong = cubehelix$1(nogamma); |
|
|
|
function tweenRemove(id, name) { |
|
var tween0, tween1; |
|
return function() { |
|
var schedule = set(this, id), |
|
tween = schedule.tween; |
|
|
|
// If this node shared tween with the previous node, |
|
// just assign the updated shared tween and we’re done! |
|
// Otherwise, copy-on-write. |
|
if (tween !== tween0) { |
|
tween1 = tween0 = tween; |
|
for (var i = 0, n = tween1.length; i < n; ++i) { |
|
if (tween1[i].name === name) { |
|
tween1 = tween1.slice(); |
|
tween1.splice(i, 1); |
|
break; |
|
} |
|
} |
|
} |
|
|
|
schedule.tween = tween1; |
|
}; |
|
} |
|
|
|
function tweenFunction(id, name, value) { |
|
var tween0, tween1; |
|
if (typeof value !== "function") throw new Error; |
|
return function() { |
|
var schedule = set(this, id), |
|
tween = schedule.tween; |
|
|
|
// If this node shared tween with the previous node, |
|
// just assign the updated shared tween and we’re done! |
|
// Otherwise, copy-on-write. |
|
if (tween !== tween0) { |
|
tween1 = (tween0 = tween).slice(); |
|
for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) { |
|
if (tween1[i].name === name) { |
|
tween1[i] = t; |
|
break; |
|
} |
|
} |
|
if (i === n) tween1.push(t); |
|
} |
|
|
|
schedule.tween = tween1; |
|
}; |
|
} |
|
|
|
function transition_tween(name, value) { |
|
var id = this._id; |
|
|
|
name += ""; |
|
|
|
if (arguments.length < 2) { |
|
var tween = get(this.node(), id).tween; |
|
for (var i = 0, n = tween.length, t; i < n; ++i) { |
|
if ((t = tween[i]).name === name) { |
|
return t.value; |
|
} |
|
} |
|
return null; |
|
} |
|
|
|
return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value)); |
|
} |
|
|
|
function tweenValue(transition, name, value) { |
|
var id = transition._id; |
|
|
|
transition.each(function() { |
|
var schedule = set(this, id); |
|
(schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments); |
|
}); |
|
|
|
return function(node) { |
|
return get(node, id).value[name]; |
|
}; |
|
} |
|
|
|
function interpolate(a, b) { |
|
var c; |
|
return (typeof b === "number" ? interpolateNumber |
|
: b instanceof color ? interpolateRgb |
|
: (c = color(b)) ? (b = c, interpolateRgb) |
|
: interpolateString)(a, b); |
|
} |
|
|
|
function attrRemove$1(name) { |
|
return function() { |
|
this.removeAttribute(name); |
|
}; |
|
} |
|
|
|
function attrRemoveNS$1(fullname) { |
|
return function() { |
|
this.removeAttributeNS(fullname.space, fullname.local); |
|
}; |
|
} |
|
|
|
function attrConstant$1(name, interpolate, value1) { |
|
var value00, |
|
interpolate0; |
|
return function() { |
|
var value0 = this.getAttribute(name); |
|
return value0 === value1 ? null |
|
: value0 === value00 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value1); |
|
}; |
|
} |
|
|
|
function attrConstantNS$1(fullname, interpolate, value1) { |
|
var value00, |
|
interpolate0; |
|
return function() { |
|
var value0 = this.getAttributeNS(fullname.space, fullname.local); |
|
return value0 === value1 ? null |
|
: value0 === value00 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value1); |
|
}; |
|
} |
|
|
|
function attrFunction$1(name, interpolate, value) { |
|
var value00, |
|
value10, |
|
interpolate0; |
|
return function() { |
|
var value0, value1 = value(this); |
|
if (value1 == null) return void this.removeAttribute(name); |
|
value0 = this.getAttribute(name); |
|
return value0 === value1 ? null |
|
: value0 === value00 && value1 === value10 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value10 = value1); |
|
}; |
|
} |
|
|
|
function attrFunctionNS$1(fullname, interpolate, value) { |
|
var value00, |
|
value10, |
|
interpolate0; |
|
return function() { |
|
var value0, value1 = value(this); |
|
if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local); |
|
value0 = this.getAttributeNS(fullname.space, fullname.local); |
|
return value0 === value1 ? null |
|
: value0 === value00 && value1 === value10 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value10 = value1); |
|
}; |
|
} |
|
|
|
function transition_attr(name, value) { |
|
var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate; |
|
return this.attrTween(name, typeof value === "function" |
|
? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value)) |
|
: value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname) |
|
: (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value)); |
|
} |
|
|
|
function attrTweenNS(fullname, value) { |
|
function tween() { |
|
var node = this, i = value.apply(node, arguments); |
|
return i && function(t) { |
|
node.setAttributeNS(fullname.space, fullname.local, i(t)); |
|
}; |
|
} |
|
tween._value = value; |
|
return tween; |
|
} |
|
|
|
function attrTween(name, value) { |
|
function tween() { |
|
var node = this, i = value.apply(node, arguments); |
|
return i && function(t) { |
|
node.setAttribute(name, i(t)); |
|
}; |
|
} |
|
tween._value = value; |
|
return tween; |
|
} |
|
|
|
function transition_attrTween(name, value) { |
|
var key = "attr." + name; |
|
if (arguments.length < 2) return (key = this.tween(key)) && key._value; |
|
if (value == null) return this.tween(key, null); |
|
if (typeof value !== "function") throw new Error; |
|
var fullname = namespace(name); |
|
return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value)); |
|
} |
|
|
|
function delayFunction(id, value) { |
|
return function() { |
|
init(this, id).delay = +value.apply(this, arguments); |
|
}; |
|
} |
|
|
|
function delayConstant(id, value) { |
|
return value = +value, function() { |
|
init(this, id).delay = value; |
|
}; |
|
} |
|
|
|
function transition_delay(value) { |
|
var id = this._id; |
|
|
|
return arguments.length |
|
? this.each((typeof value === "function" |
|
? delayFunction |
|
: delayConstant)(id, value)) |
|
: get(this.node(), id).delay; |
|
} |
|
|
|
function durationFunction(id, value) { |
|
return function() { |
|
set(this, id).duration = +value.apply(this, arguments); |
|
}; |
|
} |
|
|
|
function durationConstant(id, value) { |
|
return value = +value, function() { |
|
set(this, id).duration = value; |
|
}; |
|
} |
|
|
|
function transition_duration(value) { |
|
var id = this._id; |
|
|
|
return arguments.length |
|
? this.each((typeof value === "function" |
|
? durationFunction |
|
: durationConstant)(id, value)) |
|
: get(this.node(), id).duration; |
|
} |
|
|
|
function easeConstant(id, value) { |
|
if (typeof value !== "function") throw new Error; |
|
return function() { |
|
set(this, id).ease = value; |
|
}; |
|
} |
|
|
|
function transition_ease(value) { |
|
var id = this._id; |
|
|
|
return arguments.length |
|
? this.each(easeConstant(id, value)) |
|
: get(this.node(), id).ease; |
|
} |
|
|
|
function transition_filter(match) { |
|
if (typeof match !== "function") match = matcher$1(match); |
|
|
|
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, i = 0; i < n; ++i) { |
|
if ((node = group[i]) && match.call(node, node.__data__, i, group)) { |
|
subgroup[i] = node; |
|
} |
|
} |
|
} |
|
|
|
return new Transition(subgroups, this._parents, this._name, this._id); |
|
} |
|
|
|
function transition_merge(transition) { |
|
if (transition._id !== this._id) throw new Error; |
|
|
|
for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { |
|
for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) { |
|
if (node = group0[i] || group1[i]) { |
|
merge[i] = node; |
|
} |
|
} |
|
} |
|
|
|
for (; j < m0; ++j) { |
|
merges[j] = groups0[j]; |
|
} |
|
|
|
return new Transition(merges, this._parents, this._name, this._id); |
|
} |
|
|
|
function start(name) { |
|
return (name + "").trim().split(/^|\s+/).every(function(t) { |
|
var i = t.indexOf("."); |
|
if (i >= 0) t = t.slice(0, i); |
|
return !t || t === "start"; |
|
}); |
|
} |
|
|
|
function onFunction(id, name, listener) { |
|
var on0, on1, sit = start(name) ? init : set; |
|
return function() { |
|
var schedule = sit(this, id), |
|
on = schedule.on; |
|
|
|
// If this node shared a dispatch with the previous node, |
|
// just assign the updated shared dispatch and we’re done! |
|
// Otherwise, copy-on-write. |
|
if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener); |
|
|
|
schedule.on = on1; |
|
}; |
|
} |
|
|
|
function transition_on(name, listener) { |
|
var id = this._id; |
|
|
|
return arguments.length < 2 |
|
? get(this.node(), id).on.on(name) |
|
: this.each(onFunction(id, name, listener)); |
|
} |
|
|
|
function removeFunction(id) { |
|
return function() { |
|
var parent = this.parentNode; |
|
for (var i in this.__transition) if (+i !== id) return; |
|
if (parent) parent.removeChild(this); |
|
}; |
|
} |
|
|
|
function transition_remove() { |
|
return this.on("end.remove", removeFunction(this._id)); |
|
} |
|
|
|
function transition_select(select) { |
|
var name = this._name, |
|
id = this._id; |
|
|
|
if (typeof select !== "function") select = selector(select); |
|
|
|
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) { |
|
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) { |
|
if ("__data__" in node) subnode.__data__ = node.__data__; |
|
subgroup[i] = subnode; |
|
schedule(subgroup[i], name, id, i, subgroup, get(node, id)); |
|
} |
|
} |
|
} |
|
|
|
return new Transition(subgroups, this._parents, name, id); |
|
} |
|
|
|
function transition_selectAll(select) { |
|
var name = this._name, |
|
id = this._id; |
|
|
|
if (typeof select !== "function") select = selectorAll(select); |
|
|
|
for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
|
if (node = group[i]) { |
|
for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) { |
|
if (child = children[k]) { |
|
schedule(child, name, id, k, children, inherit); |
|
} |
|
} |
|
subgroups.push(children); |
|
parents.push(node); |
|
} |
|
} |
|
} |
|
|
|
return new Transition(subgroups, parents, name, id); |
|
} |
|
|
|
var Selection$1 = selection.prototype.constructor; |
|
|
|
function transition_selection() { |
|
return new Selection$1(this._groups, this._parents); |
|
} |
|
|
|
function styleRemove$1(name, interpolate) { |
|
var value00, |
|
value10, |
|
interpolate0; |
|
return function() { |
|
var style = window(this).getComputedStyle(this, null), |
|
value0 = style.getPropertyValue(name), |
|
value1 = (this.style.removeProperty(name), style.getPropertyValue(name)); |
|
return value0 === value1 ? null |
|
: value0 === value00 && value1 === value10 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value10 = value1); |
|
}; |
|
} |
|
|
|
function styleRemoveEnd(name) { |
|
return function() { |
|
this.style.removeProperty(name); |
|
}; |
|
} |
|
|
|
function styleConstant$1(name, interpolate, value1) { |
|
var value00, |
|
interpolate0; |
|
return function() { |
|
var value0 = window(this).getComputedStyle(this, null).getPropertyValue(name); |
|
return value0 === value1 ? null |
|
: value0 === value00 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value1); |
|
}; |
|
} |
|
|
|
function styleFunction$1(name, interpolate, value) { |
|
var value00, |
|
value10, |
|
interpolate0; |
|
return function() { |
|
var style = window(this).getComputedStyle(this, null), |
|
value0 = style.getPropertyValue(name), |
|
value1 = value(this); |
|
if (value1 == null) value1 = (this.style.removeProperty(name), style.getPropertyValue(name)); |
|
return value0 === value1 ? null |
|
: value0 === value00 && value1 === value10 ? interpolate0 |
|
: interpolate0 = interpolate(value00 = value0, value10 = value1); |
|
}; |
|
} |
|
|
|
function transition_style(name, value, priority) { |
|
var i = (name += "") === "transform" ? interpolateTransform$1 : interpolate; |
|
return value == null ? this |
|
.styleTween(name, styleRemove$1(name, i)) |
|
.on("end.style." + name, styleRemoveEnd(name)) |
|
: this.styleTween(name, typeof value === "function" |
|
? styleFunction$1(name, i, tweenValue(this, "style." + name, value)) |
|
: styleConstant$1(name, i, value), priority); |
|
} |
|
|
|
function styleTween(name, value, priority) { |
|
function tween() { |
|
var node = this, i = value.apply(node, arguments); |
|
return i && function(t) { |
|
node.style.setProperty(name, i(t), priority); |
|
}; |
|
} |
|
tween._value = value; |
|
return tween; |
|
} |
|
|
|
function transition_styleTween(name, value, priority) { |
|
var key = "style." + (name += ""); |
|
if (arguments.length < 2) return (key = this.tween(key)) && key._value; |
|
if (value == null) return this.tween(key, null); |
|
if (typeof value !== "function") throw new Error; |
|
return this.tween(key, styleTween(name, value, priority == null ? "" : priority)); |
|
} |
|
|
|
function textConstant$1(value) { |
|
return function() { |
|
this.textContent = value; |
|
}; |
|
} |
|
|
|
function textFunction$1(value) { |
|
return function() { |
|
var value1 = value(this); |
|
this.textContent = value1 == null ? "" : value1; |
|
}; |
|
} |
|
|
|
function transition_text(value) { |
|
return this.tween("text", typeof value === "function" |
|
? textFunction$1(tweenValue(this, "text", value)) |
|
: textConstant$1(value == null ? "" : value + "")); |
|
} |
|
|
|
function transition_transition() { |
|
var name = this._name, |
|
id0 = this._id, |
|
id1 = newId(); |
|
|
|
for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
|
if (node = group[i]) { |
|
var inherit = get(node, id0); |
|
schedule(node, name, id1, i, group, { |
|
time: inherit.time + inherit.delay + inherit.duration, |
|
delay: 0, |
|
duration: inherit.duration, |
|
ease: inherit.ease |
|
}); |
|
} |
|
} |
|
} |
|
|
|
return new Transition(groups, this._parents, name, id1); |
|
} |
|
|
|
var id = 0; |
|
|
|
function Transition(groups, parents, name, id) { |
|
this._groups = groups; |
|
this._parents = parents; |
|
this._name = name; |
|
this._id = id; |
|
} |
|
|
|
function transition(name) { |
|
return selection().transition(name); |
|
} |
|
|
|
function newId() { |
|
return ++id; |
|
} |
|
|
|
var selection_prototype = selection.prototype; |
|
|
|
Transition.prototype = transition.prototype = { |
|
constructor: Transition, |
|
select: transition_select, |
|
selectAll: transition_selectAll, |
|
filter: transition_filter, |
|
merge: transition_merge, |
|
selection: transition_selection, |
|
transition: transition_transition, |
|
call: selection_prototype.call, |
|
nodes: selection_prototype.nodes, |
|
node: selection_prototype.node, |
|
size: selection_prototype.size, |
|
empty: selection_prototype.empty, |
|
each: selection_prototype.each, |
|
on: transition_on, |
|
attr: transition_attr, |
|
attrTween: transition_attrTween, |
|
style: transition_style, |
|
styleTween: transition_styleTween, |
|
text: transition_text, |
|
remove: transition_remove, |
|
tween: transition_tween, |
|
delay: transition_delay, |
|
duration: transition_duration, |
|
ease: transition_ease |
|
}; |
|
|
|
function cubicInOut(t) { |
|
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2; |
|
} |
|
|
|
var exponent = 3; |
|
|
|
var polyIn = (function custom(e) { |
|
e = +e; |
|
|
|
function polyIn(t) { |
|
return Math.pow(t, e); |
|
} |
|
|
|
polyIn.exponent = custom; |
|
|
|
return polyIn; |
|
})(exponent); |
|
|
|
var polyOut = (function custom(e) { |
|
e = +e; |
|
|
|
function polyOut(t) { |
|
return 1 - Math.pow(1 - t, e); |
|
} |
|
|
|
polyOut.exponent = custom; |
|
|
|
return polyOut; |
|
})(exponent); |
|
|
|
var polyInOut = (function custom(e) { |
|
e = +e; |
|
|
|
function polyInOut(t) { |
|
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2; |
|
} |
|
|
|
polyInOut.exponent = custom; |
|
|
|
return polyInOut; |
|
})(exponent); |
|
|
|
var overshoot = 1.70158; |
|
|
|
var backIn = (function custom(s) { |
|
s = +s; |
|
|
|
function backIn(t) { |
|
return t * t * ((s + 1) * t - s); |
|
} |
|
|
|
backIn.overshoot = custom; |
|
|
|
return backIn; |
|
})(overshoot); |
|
|
|
var backOut = (function custom(s) { |
|
s = +s; |
|
|
|
function backOut(t) { |
|
return --t * t * ((s + 1) * t + s) + 1; |
|
} |
|
|
|
backOut.overshoot = custom; |
|
|
|
return backOut; |
|
})(overshoot); |
|
|
|
var backInOut = (function custom(s) { |
|
s = +s; |
|
|
|
function backInOut(t) { |
|
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2; |
|
} |
|
|
|
backInOut.overshoot = custom; |
|
|
|
return backInOut; |
|
})(overshoot); |
|
|
|
var tau = 2 * Math.PI; |
|
var amplitude = 1; |
|
var period = 0.3; |
|
var elasticIn = (function custom(a, p) { |
|
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau); |
|
|
|
function elasticIn(t) { |
|
return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p); |
|
} |
|
|
|
elasticIn.amplitude = function(a) { return custom(a, p * tau); }; |
|
elasticIn.period = function(p) { return custom(a, p); }; |
|
|
|
return elasticIn; |
|
})(amplitude, period); |
|
|
|
var elasticOut = (function custom(a, p) { |
|
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau); |
|
|
|
function elasticOut(t) { |
|
return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p); |
|
} |
|
|
|
elasticOut.amplitude = function(a) { return custom(a, p * tau); }; |
|
elasticOut.period = function(p) { return custom(a, p); }; |
|
|
|
return elasticOut; |
|
})(amplitude, period); |
|
|
|
var elasticInOut = (function custom(a, p) { |
|
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau); |
|
|
|
function elasticInOut(t) { |
|
return ((t = t * 2 - 1) < 0 |
|
? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p) |
|
: 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2; |
|
} |
|
|
|
elasticInOut.amplitude = function(a) { return custom(a, p * tau); }; |
|
elasticInOut.period = function(p) { return custom(a, p); }; |
|
|
|
return elasticInOut; |
|
})(amplitude, period); |
|
|
|
var defaultTiming = { |
|
time: null, // Set on use. |
|
delay: 0, |
|
duration: 250, |
|
ease: cubicInOut |
|
}; |
|
|
|
function inherit(node, id) { |
|
var timing; |
|
while (!(timing = node.__transition) || !(timing = timing[id])) { |
|
if (!(node = node.parentNode)) { |
|
return defaultTiming.time = now(), defaultTiming; |
|
} |
|
} |
|
return timing; |
|
} |
|
|
|
function selection_transition(name) { |
|
var id, |
|
timing; |
|
|
|
if (name instanceof Transition) { |
|
id = name._id, name = name._name; |
|
} else { |
|
id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + ""; |
|
} |
|
|
|
for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) { |
|
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
|
if (node = group[i]) { |
|
schedule(node, name, id, i, group, timing || inherit(node, id)); |
|
} |
|
} |
|
} |
|
|
|
return new Transition(groups, this._parents, name, id); |
|
} |
|
|
|
selection.prototype.interrupt = selection_interrupt; |
|
selection.prototype.transition = selection_transition; |
|
|
|
exports.selection = selection; |
|
exports.select = select; |
|
exports.selectAll = selectAll; |
|
|
|
Object.defineProperty(exports, '__esModule', { value: true }); |
|
|
|
})); |