@d3plus/dom 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -0
- package/es/index.js +13 -0
- package/es/src/assign.js +39 -0
- package/es/src/attrize.js +9 -0
- package/es/src/date.js +51 -0
- package/es/src/elem.js +38 -0
- package/es/src/fontExists.js +60 -0
- package/es/src/getSize.js +41 -0
- package/es/src/inViewport.js +14 -0
- package/es/src/isObject.js +18 -0
- package/es/src/parseSides.js +29 -0
- package/es/src/prefix.js +10 -0
- package/es/src/rtl.js +7 -0
- package/es/src/stylize.js +9 -0
- package/es/src/textWidth.js +41 -0
- package/package.json +40 -0
- package/umd/d3plus-dom.full.js +2690 -0
- package/umd/d3plus-dom.full.js.map +1 -0
- package/umd/d3plus-dom.full.min.js +219 -0
- package/umd/d3plus-dom.js +463 -0
- package/umd/d3plus-dom.js.map +1 -0
- package/umd/d3plus-dom.min.js +108 -0
|
@@ -0,0 +1,2690 @@
|
|
|
1
|
+
/*
|
|
2
|
+
@d3plus/dom v3.0.0
|
|
3
|
+
JavaScript functions for manipulating and analyzing DOM elements.
|
|
4
|
+
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
|
+
@license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
(function (factory) {
|
|
9
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
10
|
+
factory();
|
|
11
|
+
})((function () { 'use strict';
|
|
12
|
+
|
|
13
|
+
if (typeof window !== "undefined") {
|
|
14
|
+
(function () {
|
|
15
|
+
try {
|
|
16
|
+
if (typeof SVGElement === 'undefined' || Boolean(SVGElement.prototype.innerHTML)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function serializeNode (node) {
|
|
24
|
+
switch (node.nodeType) {
|
|
25
|
+
case 1:
|
|
26
|
+
return serializeElementNode(node);
|
|
27
|
+
case 3:
|
|
28
|
+
return serializeTextNode(node);
|
|
29
|
+
case 8:
|
|
30
|
+
return serializeCommentNode(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function serializeTextNode (node) {
|
|
35
|
+
return node.textContent.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function serializeCommentNode (node) {
|
|
39
|
+
return '<!--' + node.nodeValue + '-->'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function serializeElementNode (node) {
|
|
43
|
+
var output = '';
|
|
44
|
+
|
|
45
|
+
output += '<' + node.tagName;
|
|
46
|
+
|
|
47
|
+
if (node.hasAttributes()) {
|
|
48
|
+
[].forEach.call(node.attributes, function(attrNode) {
|
|
49
|
+
output += ' ' + attrNode.name + '="' + attrNode.value + '"';
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
output += '>';
|
|
54
|
+
|
|
55
|
+
if (node.hasChildNodes()) {
|
|
56
|
+
[].forEach.call(node.childNodes, function(childNode) {
|
|
57
|
+
output += serializeNode(childNode);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
output += '</' + node.tagName + '>';
|
|
62
|
+
|
|
63
|
+
return output;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Object.defineProperty(SVGElement.prototype, 'innerHTML', {
|
|
67
|
+
get: function () {
|
|
68
|
+
var output = '';
|
|
69
|
+
|
|
70
|
+
[].forEach.call(this.childNodes, function(childNode) {
|
|
71
|
+
output += serializeNode(childNode);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return output;
|
|
75
|
+
},
|
|
76
|
+
set: function (markup) {
|
|
77
|
+
while (this.firstChild) {
|
|
78
|
+
this.removeChild(this.firstChild);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
var dXML = new DOMParser();
|
|
83
|
+
dXML.async = false;
|
|
84
|
+
|
|
85
|
+
var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markup + '</svg>';
|
|
86
|
+
var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement;
|
|
87
|
+
|
|
88
|
+
[].forEach.call(svgDocElement.childNodes, function(childNode) {
|
|
89
|
+
this.appendChild(this.ownerDocument.importNode(childNode, true));
|
|
90
|
+
}.bind(this));
|
|
91
|
+
} catch (e) {
|
|
92
|
+
throw new Error('Error parsing markup string');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
Object.defineProperty(SVGElement.prototype, 'innerSVG', {
|
|
98
|
+
get: function () {
|
|
99
|
+
return this.innerHTML;
|
|
100
|
+
},
|
|
101
|
+
set: function (markup) {
|
|
102
|
+
this.innerHTML = markup;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
})();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
(function (global, factory) {
|
|
112
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
113
|
+
typeof define === 'function' && define.amd ? define('@d3plus/dom', ['exports'], factory) :
|
|
114
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}));
|
|
115
|
+
})(this, (function (exports) {
|
|
116
|
+
/**
|
|
117
|
+
@function isObject
|
|
118
|
+
@desc Detects if a variable is a javascript Object.
|
|
119
|
+
@param {*} item
|
|
120
|
+
*/ function isObject(item) {
|
|
121
|
+
return item && typeof item === "object" && (typeof window === "undefined" || item !== window && item !== window.document && !(item instanceof Element)) && !Array.isArray(item) ? true : false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
@function validObject
|
|
126
|
+
@desc Determines if the object passed is the document or window.
|
|
127
|
+
@param {Object} obj
|
|
128
|
+
@private
|
|
129
|
+
*/ function validObject(obj) {
|
|
130
|
+
if (typeof window === "undefined") return true;
|
|
131
|
+
else return obj !== window && obj !== document;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
@function assign
|
|
135
|
+
@desc A deeply recursive version of `Object.assign`.
|
|
136
|
+
@param {...Object} objects
|
|
137
|
+
@example <caption>this</caption>
|
|
138
|
+
assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}}));
|
|
139
|
+
@example <caption>returns this</caption>
|
|
140
|
+
{id: "bar", deep: {group: "A", value: 20}}
|
|
141
|
+
*/ function assign(...objects) {
|
|
142
|
+
const target = objects[0];
|
|
143
|
+
for(let i = 1; i < objects.length; i++){
|
|
144
|
+
const source = objects[i];
|
|
145
|
+
if (!isObject(source)) continue;
|
|
146
|
+
Object.keys(source).forEach((prop)=>{
|
|
147
|
+
const value = source[prop];
|
|
148
|
+
if (isObject(value) && validObject(value)) {
|
|
149
|
+
if (Object.prototype.hasOwnProperty.call(target, prop) && isObject(target[prop])) target[prop] = assign({}, target[prop], value);
|
|
150
|
+
else target[prop] = assign({}, value);
|
|
151
|
+
} else if (Array.isArray(value)) target[prop] = value.slice();
|
|
152
|
+
else target[prop] = value;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return target;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
@function attrize
|
|
160
|
+
@desc Applies each key/value in an object as an attr.
|
|
161
|
+
@param {D3selection} elem The D3 element to apply the styles to.
|
|
162
|
+
@param {Object} attrs An object of key/value attr pairs.
|
|
163
|
+
*/ function attrize(e, a = {}) {
|
|
164
|
+
for(const k in a)if (({}).hasOwnProperty.call(a, k)) e.attr(k, a[k]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
@function date
|
|
169
|
+
@summary Parses numbers and strings to valid Javascript Date objects.
|
|
170
|
+
@description Returns a javascript Date object for a given a Number (representing either a 4-digit year or milliseconds since epoch), a String representing a Quarter (ie. "Q2 1987", mapping to the last day in that quarter), or a String that is in [valid dateString format](http://dygraphs.com/date-formats.html). Besides the 4-digit year parsing, this function is useful when needing to parse negative (BC) years, which the vanilla Date object cannot parse.
|
|
171
|
+
@param {Number|String} *date*
|
|
172
|
+
*/ function date(d) {
|
|
173
|
+
// returns if falsey or already Date object
|
|
174
|
+
if ([
|
|
175
|
+
false,
|
|
176
|
+
undefined,
|
|
177
|
+
NaN
|
|
178
|
+
].includes(d) || d.constructor === Date) return d;
|
|
179
|
+
else if (d.constructor === Number && `${d}`.length > 5 && d % 1 === 0) return new Date(d);
|
|
180
|
+
let s = `${d}`;
|
|
181
|
+
// tests for MM/DD/YYYY and MM-DD-YYYY format
|
|
182
|
+
const dayFormat = new RegExp(/^\d{1,2}[./-]\d{1,2}[./-](-*\d{1,4})$/g).exec(s);
|
|
183
|
+
if (dayFormat) {
|
|
184
|
+
const year = dayFormat[1];
|
|
185
|
+
if (year.indexOf("-") === 0) s = s.replace(year, year.substring(1));
|
|
186
|
+
const date = new Date(s);
|
|
187
|
+
date.setFullYear(year);
|
|
188
|
+
return date;
|
|
189
|
+
}
|
|
190
|
+
// tests for full Date object string format
|
|
191
|
+
const strFormat = new RegExp(/^[A-z]{1,3} [A-z]{1,3} \d{1,2} (-*\d{1,4}) \d{1,2}:\d{1,2}:\d{1,2} [A-z]{1,3}-*\d{1,4} \([A-z]{1,3}\)/g).exec(s);
|
|
192
|
+
if (strFormat) {
|
|
193
|
+
const year = strFormat[1];
|
|
194
|
+
if (year.indexOf("-") === 0) s = s.replace(year, year.substring(1));
|
|
195
|
+
const date = new Date(s);
|
|
196
|
+
date.setFullYear(year);
|
|
197
|
+
return date;
|
|
198
|
+
}
|
|
199
|
+
// tests for quarterly formats (ie. "QX YYYY")
|
|
200
|
+
const quarterPrefix = new RegExp(/^([qQ]{1}[1-4]{1}|[1-4]{1}[qQ]{1})[\s|-]{0,1}(-*\d{1,4})$/g).exec(s);
|
|
201
|
+
const quarterSuffix = new RegExp(/^(-*\d{1,4})[\s|-]{0,1}([qQ]{1}[1-4]{1}|[1-4]{1}[qQ]{1})$/g).exec(s);
|
|
202
|
+
if (quarterPrefix || quarterSuffix) {
|
|
203
|
+
const quarter = +(quarterPrefix ? quarterPrefix[1] : quarterSuffix[2]).toLowerCase().replace("q", "");
|
|
204
|
+
const year = +(quarterPrefix ? quarterPrefix[2] : quarterSuffix[1]);
|
|
205
|
+
const date = new Date(year, quarter * 3 - 3, 1);
|
|
206
|
+
date.setFullYear(year);
|
|
207
|
+
return date;
|
|
208
|
+
}
|
|
209
|
+
// detects if only passing a year value
|
|
210
|
+
if (!s.includes("/") && !s.includes(" ") && (!s.includes("-") || !s.indexOf("-"))) {
|
|
211
|
+
const date = new Date(+s, 0, 1);
|
|
212
|
+
date.setFullYear(d);
|
|
213
|
+
return date;
|
|
214
|
+
}
|
|
215
|
+
// falls back to Date object
|
|
216
|
+
return new Date(s);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var xhtml = "http://www.w3.org/1999/xhtml";
|
|
220
|
+
var namespaces = {
|
|
221
|
+
svg: "http://www.w3.org/2000/svg",
|
|
222
|
+
xhtml: xhtml,
|
|
223
|
+
xlink: "http://www.w3.org/1999/xlink",
|
|
224
|
+
xml: "http://www.w3.org/XML/1998/namespace",
|
|
225
|
+
xmlns: "http://www.w3.org/2000/xmlns/"
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
function namespace(name) {
|
|
229
|
+
var prefix = name += "", i = prefix.indexOf(":");
|
|
230
|
+
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
|
|
231
|
+
return namespaces.hasOwnProperty(prefix) ? {
|
|
232
|
+
space: namespaces[prefix],
|
|
233
|
+
local: name
|
|
234
|
+
} : name; // eslint-disable-line no-prototype-builtins
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function creatorInherit(name) {
|
|
238
|
+
return function() {
|
|
239
|
+
var document = this.ownerDocument, uri = this.namespaceURI;
|
|
240
|
+
return uri === xhtml && document.documentElement.namespaceURI === xhtml ? document.createElement(name) : document.createElementNS(uri, name);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function creatorFixed(fullname) {
|
|
244
|
+
return function() {
|
|
245
|
+
return this.ownerDocument.createElementNS(fullname.space, fullname.local);
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function creator(name) {
|
|
249
|
+
var fullname = namespace(name);
|
|
250
|
+
return (fullname.local ? creatorFixed : creatorInherit)(fullname);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function none() {}
|
|
254
|
+
function selector(selector) {
|
|
255
|
+
return selector == null ? none : function() {
|
|
256
|
+
return this.querySelector(selector);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function selection_select(select) {
|
|
261
|
+
if (typeof select !== "function") select = selector(select);
|
|
262
|
+
for(var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j){
|
|
263
|
+
for(var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i){
|
|
264
|
+
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
|
265
|
+
if ("__data__" in node) subnode.__data__ = node.__data__;
|
|
266
|
+
subgroup[i] = subnode;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return new Selection$1(subgroups, this._parents);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Given something array like (or null), returns something that is strictly an
|
|
274
|
+
// array. This is used to ensure that array-like objects passed to d3.selectAll
|
|
275
|
+
// or selection.selectAll are converted into proper arrays when creating a
|
|
276
|
+
// selection; we don’t ever want to create a selection backed by a live
|
|
277
|
+
// HTMLCollection or NodeList. However, note that selection.selectAll will use a
|
|
278
|
+
// static NodeList as a group, since it safely derived from querySelectorAll.
|
|
279
|
+
function array(x) {
|
|
280
|
+
return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function empty() {
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
function selectorAll(selector) {
|
|
287
|
+
return selector == null ? empty : function() {
|
|
288
|
+
return this.querySelectorAll(selector);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function arrayAll(select) {
|
|
293
|
+
return function() {
|
|
294
|
+
return array(select.apply(this, arguments));
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function selection_selectAll(select) {
|
|
298
|
+
if (typeof select === "function") select = arrayAll(select);
|
|
299
|
+
else select = selectorAll(select);
|
|
300
|
+
for(var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j){
|
|
301
|
+
for(var group = groups[j], n = group.length, node, i = 0; i < n; ++i){
|
|
302
|
+
if (node = group[i]) {
|
|
303
|
+
subgroups.push(select.call(node, node.__data__, i, group));
|
|
304
|
+
parents.push(node);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return new Selection$1(subgroups, parents);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function matcher(selector) {
|
|
312
|
+
return function() {
|
|
313
|
+
return this.matches(selector);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function childMatcher(selector) {
|
|
317
|
+
return function(node) {
|
|
318
|
+
return node.matches(selector);
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
var find = Array.prototype.find;
|
|
323
|
+
function childFind(match) {
|
|
324
|
+
return function() {
|
|
325
|
+
return find.call(this.children, match);
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function childFirst() {
|
|
329
|
+
return this.firstElementChild;
|
|
330
|
+
}
|
|
331
|
+
function selection_selectChild(match) {
|
|
332
|
+
return this.select(match == null ? childFirst : childFind(typeof match === "function" ? match : childMatcher(match)));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
var filter = Array.prototype.filter;
|
|
336
|
+
function children() {
|
|
337
|
+
return Array.from(this.children);
|
|
338
|
+
}
|
|
339
|
+
function childrenFilter(match) {
|
|
340
|
+
return function() {
|
|
341
|
+
return filter.call(this.children, match);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function selection_selectChildren(match) {
|
|
345
|
+
return this.selectAll(match == null ? children : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function selection_filter(match) {
|
|
349
|
+
if (typeof match !== "function") match = matcher(match);
|
|
350
|
+
for(var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j){
|
|
351
|
+
for(var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i){
|
|
352
|
+
if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
|
353
|
+
subgroup.push(node);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return new Selection$1(subgroups, this._parents);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function sparse(update) {
|
|
361
|
+
return new Array(update.length);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function selection_enter() {
|
|
365
|
+
return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
|
|
366
|
+
}
|
|
367
|
+
function EnterNode(parent, datum) {
|
|
368
|
+
this.ownerDocument = parent.ownerDocument;
|
|
369
|
+
this.namespaceURI = parent.namespaceURI;
|
|
370
|
+
this._next = null;
|
|
371
|
+
this._parent = parent;
|
|
372
|
+
this.__data__ = datum;
|
|
373
|
+
}
|
|
374
|
+
EnterNode.prototype = {
|
|
375
|
+
constructor: EnterNode,
|
|
376
|
+
appendChild: function(child) {
|
|
377
|
+
return this._parent.insertBefore(child, this._next);
|
|
378
|
+
},
|
|
379
|
+
insertBefore: function(child, next) {
|
|
380
|
+
return this._parent.insertBefore(child, next);
|
|
381
|
+
},
|
|
382
|
+
querySelector: function(selector) {
|
|
383
|
+
return this._parent.querySelector(selector);
|
|
384
|
+
},
|
|
385
|
+
querySelectorAll: function(selector) {
|
|
386
|
+
return this._parent.querySelectorAll(selector);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
function constant$1(x) {
|
|
391
|
+
return function() {
|
|
392
|
+
return x;
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function bindIndex(parent, group, enter, update, exit, data) {
|
|
397
|
+
var i = 0, node, groupLength = group.length, dataLength = data.length;
|
|
398
|
+
// Put any non-null nodes that fit into update.
|
|
399
|
+
// Put any null nodes into enter.
|
|
400
|
+
// Put any remaining data into enter.
|
|
401
|
+
for(; i < dataLength; ++i){
|
|
402
|
+
if (node = group[i]) {
|
|
403
|
+
node.__data__ = data[i];
|
|
404
|
+
update[i] = node;
|
|
405
|
+
} else {
|
|
406
|
+
enter[i] = new EnterNode(parent, data[i]);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// Put any non-null nodes that don’t fit into exit.
|
|
410
|
+
for(; i < groupLength; ++i){
|
|
411
|
+
if (node = group[i]) {
|
|
412
|
+
exit[i] = node;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function bindKey(parent, group, enter, update, exit, data, key) {
|
|
417
|
+
var i, node, nodeByKeyValue = new Map, groupLength = group.length, dataLength = data.length, keyValues = new Array(groupLength), keyValue;
|
|
418
|
+
// Compute the key for each node.
|
|
419
|
+
// If multiple nodes have the same key, the duplicates are added to exit.
|
|
420
|
+
for(i = 0; i < groupLength; ++i){
|
|
421
|
+
if (node = group[i]) {
|
|
422
|
+
keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
|
|
423
|
+
if (nodeByKeyValue.has(keyValue)) {
|
|
424
|
+
exit[i] = node;
|
|
425
|
+
} else {
|
|
426
|
+
nodeByKeyValue.set(keyValue, node);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
// Compute the key for each datum.
|
|
431
|
+
// If there a node associated with this key, join and add it to update.
|
|
432
|
+
// If there is not (or the key is a duplicate), add it to enter.
|
|
433
|
+
for(i = 0; i < dataLength; ++i){
|
|
434
|
+
keyValue = key.call(parent, data[i], i, data) + "";
|
|
435
|
+
if (node = nodeByKeyValue.get(keyValue)) {
|
|
436
|
+
update[i] = node;
|
|
437
|
+
node.__data__ = data[i];
|
|
438
|
+
nodeByKeyValue.delete(keyValue);
|
|
439
|
+
} else {
|
|
440
|
+
enter[i] = new EnterNode(parent, data[i]);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
// Add any remaining nodes that were not bound to data to exit.
|
|
444
|
+
for(i = 0; i < groupLength; ++i){
|
|
445
|
+
if ((node = group[i]) && nodeByKeyValue.get(keyValues[i]) === node) {
|
|
446
|
+
exit[i] = node;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function datum(node) {
|
|
451
|
+
return node.__data__;
|
|
452
|
+
}
|
|
453
|
+
function selection_data(value, key) {
|
|
454
|
+
if (!arguments.length) return Array.from(this, datum);
|
|
455
|
+
var bind = key ? bindKey : bindIndex, parents = this._parents, groups = this._groups;
|
|
456
|
+
if (typeof value !== "function") value = constant$1(value);
|
|
457
|
+
for(var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j){
|
|
458
|
+
var parent = parents[j], group = groups[j], groupLength = group.length, data = arraylike(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);
|
|
459
|
+
bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
|
|
460
|
+
// Now connect the enter nodes to their following update node, such that
|
|
461
|
+
// appendChild can insert the materialized enter node before this node,
|
|
462
|
+
// rather than at the end of the parent node.
|
|
463
|
+
for(var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0){
|
|
464
|
+
if (previous = enterGroup[i0]) {
|
|
465
|
+
if (i0 >= i1) i1 = i0 + 1;
|
|
466
|
+
while(!(next = updateGroup[i1]) && ++i1 < dataLength);
|
|
467
|
+
previous._next = next || null;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
update = new Selection$1(update, parents);
|
|
472
|
+
update._enter = enter;
|
|
473
|
+
update._exit = exit;
|
|
474
|
+
return update;
|
|
475
|
+
}
|
|
476
|
+
// Given some data, this returns an array-like view of it: an object that
|
|
477
|
+
// exposes a length property and allows numeric indexing. Note that unlike
|
|
478
|
+
// selectAll, this isn’t worried about “live” collections because the resulting
|
|
479
|
+
// array will only be used briefly while data is being bound. (It is possible to
|
|
480
|
+
// cause the data to change while iterating by using a key function, but please
|
|
481
|
+
// don’t; we’d rather avoid a gratuitous copy.)
|
|
482
|
+
function arraylike(data) {
|
|
483
|
+
return typeof data === "object" && "length" in data ? data // Array, TypedArray, NodeList, array-like
|
|
484
|
+
: Array.from(data); // Map, Set, iterable, string, or anything else
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function selection_exit() {
|
|
488
|
+
return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function selection_join(onenter, onupdate, onexit) {
|
|
492
|
+
var enter = this.enter(), update = this, exit = this.exit();
|
|
493
|
+
if (typeof onenter === "function") {
|
|
494
|
+
enter = onenter(enter);
|
|
495
|
+
if (enter) enter = enter.selection();
|
|
496
|
+
} else {
|
|
497
|
+
enter = enter.append(onenter + "");
|
|
498
|
+
}
|
|
499
|
+
if (onupdate != null) {
|
|
500
|
+
update = onupdate(update);
|
|
501
|
+
if (update) update = update.selection();
|
|
502
|
+
}
|
|
503
|
+
if (onexit == null) exit.remove();
|
|
504
|
+
else onexit(exit);
|
|
505
|
+
return enter && update ? enter.merge(update).order() : update;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function selection_merge(context) {
|
|
509
|
+
var selection = context.selection ? context.selection() : context;
|
|
510
|
+
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){
|
|
511
|
+
for(var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i){
|
|
512
|
+
if (node = group0[i] || group1[i]) {
|
|
513
|
+
merge[i] = node;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
for(; j < m0; ++j){
|
|
518
|
+
merges[j] = groups0[j];
|
|
519
|
+
}
|
|
520
|
+
return new Selection$1(merges, this._parents);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function selection_order() {
|
|
524
|
+
for(var groups = this._groups, j = -1, m = groups.length; ++j < m;){
|
|
525
|
+
for(var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;){
|
|
526
|
+
if (node = group[i]) {
|
|
527
|
+
if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
|
|
528
|
+
next = node;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return this;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function selection_sort(compare) {
|
|
536
|
+
if (!compare) compare = ascending;
|
|
537
|
+
function compareNode(a, b) {
|
|
538
|
+
return a && b ? compare(a.__data__, b.__data__) : !a - !b;
|
|
539
|
+
}
|
|
540
|
+
for(var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j){
|
|
541
|
+
for(var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i){
|
|
542
|
+
if (node = group[i]) {
|
|
543
|
+
sortgroup[i] = node;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
sortgroup.sort(compareNode);
|
|
547
|
+
}
|
|
548
|
+
return new Selection$1(sortgroups, this._parents).order();
|
|
549
|
+
}
|
|
550
|
+
function ascending(a, b) {
|
|
551
|
+
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function selection_call() {
|
|
555
|
+
var callback = arguments[0];
|
|
556
|
+
arguments[0] = this;
|
|
557
|
+
callback.apply(null, arguments);
|
|
558
|
+
return this;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function selection_nodes() {
|
|
562
|
+
return Array.from(this);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function selection_node() {
|
|
566
|
+
for(var groups = this._groups, j = 0, m = groups.length; j < m; ++j){
|
|
567
|
+
for(var group = groups[j], i = 0, n = group.length; i < n; ++i){
|
|
568
|
+
var node = group[i];
|
|
569
|
+
if (node) return node;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function selection_size() {
|
|
576
|
+
let size = 0;
|
|
577
|
+
for (const node of this)++size; // eslint-disable-line no-unused-vars
|
|
578
|
+
return size;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function selection_empty() {
|
|
582
|
+
return !this.node();
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function selection_each(callback) {
|
|
586
|
+
for(var groups = this._groups, j = 0, m = groups.length; j < m; ++j){
|
|
587
|
+
for(var group = groups[j], i = 0, n = group.length, node; i < n; ++i){
|
|
588
|
+
if (node = group[i]) callback.call(node, node.__data__, i, group);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return this;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function attrRemove$1(name) {
|
|
595
|
+
return function() {
|
|
596
|
+
this.removeAttribute(name);
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
function attrRemoveNS$1(fullname) {
|
|
600
|
+
return function() {
|
|
601
|
+
this.removeAttributeNS(fullname.space, fullname.local);
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
function attrConstant$1(name, value) {
|
|
605
|
+
return function() {
|
|
606
|
+
this.setAttribute(name, value);
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
function attrConstantNS$1(fullname, value) {
|
|
610
|
+
return function() {
|
|
611
|
+
this.setAttributeNS(fullname.space, fullname.local, value);
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
function attrFunction$1(name, value) {
|
|
615
|
+
return function() {
|
|
616
|
+
var v = value.apply(this, arguments);
|
|
617
|
+
if (v == null) this.removeAttribute(name);
|
|
618
|
+
else this.setAttribute(name, v);
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function attrFunctionNS$1(fullname, value) {
|
|
622
|
+
return function() {
|
|
623
|
+
var v = value.apply(this, arguments);
|
|
624
|
+
if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
|
|
625
|
+
else this.setAttributeNS(fullname.space, fullname.local, v);
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function selection_attr(name, value) {
|
|
629
|
+
var fullname = namespace(name);
|
|
630
|
+
if (arguments.length < 2) {
|
|
631
|
+
var node = this.node();
|
|
632
|
+
return fullname.local ? node.getAttributeNS(fullname.space, fullname.local) : node.getAttribute(fullname);
|
|
633
|
+
}
|
|
634
|
+
return this.each((value == null ? fullname.local ? attrRemoveNS$1 : attrRemove$1 : typeof value === "function" ? fullname.local ? attrFunctionNS$1 : attrFunction$1 : fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, value));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function defaultView(node) {
|
|
638
|
+
return node.ownerDocument && node.ownerDocument.defaultView // node is a Node
|
|
639
|
+
|| node.document && node // node is a Window
|
|
640
|
+
|| node.defaultView; // node is a Document
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function styleRemove$1(name) {
|
|
644
|
+
return function() {
|
|
645
|
+
this.style.removeProperty(name);
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function styleConstant$1(name, value, priority) {
|
|
649
|
+
return function() {
|
|
650
|
+
this.style.setProperty(name, value, priority);
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
function styleFunction$1(name, value, priority) {
|
|
654
|
+
return function() {
|
|
655
|
+
var v = value.apply(this, arguments);
|
|
656
|
+
if (v == null) this.style.removeProperty(name);
|
|
657
|
+
else this.style.setProperty(name, v, priority);
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function selection_style(name, value, priority) {
|
|
661
|
+
return arguments.length > 1 ? this.each((value == null ? styleRemove$1 : typeof value === "function" ? styleFunction$1 : styleConstant$1)(name, value, priority == null ? "" : priority)) : styleValue(this.node(), name);
|
|
662
|
+
}
|
|
663
|
+
function styleValue(node, name) {
|
|
664
|
+
return node.style.getPropertyValue(name) || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function propertyRemove(name) {
|
|
668
|
+
return function() {
|
|
669
|
+
delete this[name];
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function propertyConstant(name, value) {
|
|
673
|
+
return function() {
|
|
674
|
+
this[name] = value;
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function propertyFunction(name, value) {
|
|
678
|
+
return function() {
|
|
679
|
+
var v = value.apply(this, arguments);
|
|
680
|
+
if (v == null) delete this[name];
|
|
681
|
+
else this[name] = v;
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
function selection_property(name, value) {
|
|
685
|
+
return arguments.length > 1 ? this.each((value == null ? propertyRemove : typeof value === "function" ? propertyFunction : propertyConstant)(name, value)) : this.node()[name];
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function classArray(string) {
|
|
689
|
+
return string.trim().split(/^|\s+/);
|
|
690
|
+
}
|
|
691
|
+
function classList(node) {
|
|
692
|
+
return node.classList || new ClassList(node);
|
|
693
|
+
}
|
|
694
|
+
function ClassList(node) {
|
|
695
|
+
this._node = node;
|
|
696
|
+
this._names = classArray(node.getAttribute("class") || "");
|
|
697
|
+
}
|
|
698
|
+
ClassList.prototype = {
|
|
699
|
+
add: function(name) {
|
|
700
|
+
var i = this._names.indexOf(name);
|
|
701
|
+
if (i < 0) {
|
|
702
|
+
this._names.push(name);
|
|
703
|
+
this._node.setAttribute("class", this._names.join(" "));
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
remove: function(name) {
|
|
707
|
+
var i = this._names.indexOf(name);
|
|
708
|
+
if (i >= 0) {
|
|
709
|
+
this._names.splice(i, 1);
|
|
710
|
+
this._node.setAttribute("class", this._names.join(" "));
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
contains: function(name) {
|
|
714
|
+
return this._names.indexOf(name) >= 0;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
function classedAdd(node, names) {
|
|
718
|
+
var list = classList(node), i = -1, n = names.length;
|
|
719
|
+
while(++i < n)list.add(names[i]);
|
|
720
|
+
}
|
|
721
|
+
function classedRemove(node, names) {
|
|
722
|
+
var list = classList(node), i = -1, n = names.length;
|
|
723
|
+
while(++i < n)list.remove(names[i]);
|
|
724
|
+
}
|
|
725
|
+
function classedTrue(names) {
|
|
726
|
+
return function() {
|
|
727
|
+
classedAdd(this, names);
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
function classedFalse(names) {
|
|
731
|
+
return function() {
|
|
732
|
+
classedRemove(this, names);
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function classedFunction(names, value) {
|
|
736
|
+
return function() {
|
|
737
|
+
(value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function selection_classed(name, value) {
|
|
741
|
+
var names = classArray(name + "");
|
|
742
|
+
if (arguments.length < 2) {
|
|
743
|
+
var list = classList(this.node()), i = -1, n = names.length;
|
|
744
|
+
while(++i < n)if (!list.contains(names[i])) return false;
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
return this.each((typeof value === "function" ? classedFunction : value ? classedTrue : classedFalse)(names, value));
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function textRemove() {
|
|
751
|
+
this.textContent = "";
|
|
752
|
+
}
|
|
753
|
+
function textConstant$1(value) {
|
|
754
|
+
return function() {
|
|
755
|
+
this.textContent = value;
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
function textFunction$1(value) {
|
|
759
|
+
return function() {
|
|
760
|
+
var v = value.apply(this, arguments);
|
|
761
|
+
this.textContent = v == null ? "" : v;
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
function selection_text(value) {
|
|
765
|
+
return arguments.length ? this.each(value == null ? textRemove : (typeof value === "function" ? textFunction$1 : textConstant$1)(value)) : this.node().textContent;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
function htmlRemove() {
|
|
769
|
+
this.innerHTML = "";
|
|
770
|
+
}
|
|
771
|
+
function htmlConstant(value) {
|
|
772
|
+
return function() {
|
|
773
|
+
this.innerHTML = value;
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
function htmlFunction(value) {
|
|
777
|
+
return function() {
|
|
778
|
+
var v = value.apply(this, arguments);
|
|
779
|
+
this.innerHTML = v == null ? "" : v;
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
function selection_html(value) {
|
|
783
|
+
return arguments.length ? this.each(value == null ? htmlRemove : (typeof value === "function" ? htmlFunction : htmlConstant)(value)) : this.node().innerHTML;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
function raise() {
|
|
787
|
+
if (this.nextSibling) this.parentNode.appendChild(this);
|
|
788
|
+
}
|
|
789
|
+
function selection_raise() {
|
|
790
|
+
return this.each(raise);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function lower() {
|
|
794
|
+
if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
|
|
795
|
+
}
|
|
796
|
+
function selection_lower() {
|
|
797
|
+
return this.each(lower);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
function selection_append(name) {
|
|
801
|
+
var create = typeof name === "function" ? name : creator(name);
|
|
802
|
+
return this.select(function() {
|
|
803
|
+
return this.appendChild(create.apply(this, arguments));
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function constantNull() {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
function selection_insert(name, before) {
|
|
811
|
+
var create = typeof name === "function" ? name : creator(name), select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
|
|
812
|
+
return this.select(function() {
|
|
813
|
+
return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function remove() {
|
|
818
|
+
var parent = this.parentNode;
|
|
819
|
+
if (parent) parent.removeChild(this);
|
|
820
|
+
}
|
|
821
|
+
function selection_remove() {
|
|
822
|
+
return this.each(remove);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function selection_cloneShallow() {
|
|
826
|
+
var clone = this.cloneNode(false), parent = this.parentNode;
|
|
827
|
+
return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
|
828
|
+
}
|
|
829
|
+
function selection_cloneDeep() {
|
|
830
|
+
var clone = this.cloneNode(true), parent = this.parentNode;
|
|
831
|
+
return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
|
832
|
+
}
|
|
833
|
+
function selection_clone(deep) {
|
|
834
|
+
return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
function selection_datum(value) {
|
|
838
|
+
return arguments.length ? this.property("__data__", value) : this.node().__data__;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function contextListener(listener) {
|
|
842
|
+
return function(event) {
|
|
843
|
+
listener.call(this, event, this.__data__);
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function parseTypenames$1(typenames) {
|
|
847
|
+
return typenames.trim().split(/^|\s+/).map(function(t) {
|
|
848
|
+
var name = "", i = t.indexOf(".");
|
|
849
|
+
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
|
850
|
+
return {
|
|
851
|
+
type: t,
|
|
852
|
+
name: name
|
|
853
|
+
};
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
function onRemove(typename) {
|
|
857
|
+
return function() {
|
|
858
|
+
var on = this.__on;
|
|
859
|
+
if (!on) return;
|
|
860
|
+
for(var j = 0, i = -1, m = on.length, o; j < m; ++j){
|
|
861
|
+
if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
|
|
862
|
+
this.removeEventListener(o.type, o.listener, o.options);
|
|
863
|
+
} else {
|
|
864
|
+
on[++i] = o;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if (++i) on.length = i;
|
|
868
|
+
else delete this.__on;
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
function onAdd(typename, value, options) {
|
|
872
|
+
return function() {
|
|
873
|
+
var on = this.__on, o, listener = contextListener(value);
|
|
874
|
+
if (on) for(var j = 0, m = on.length; j < m; ++j){
|
|
875
|
+
if ((o = on[j]).type === typename.type && o.name === typename.name) {
|
|
876
|
+
this.removeEventListener(o.type, o.listener, o.options);
|
|
877
|
+
this.addEventListener(o.type, o.listener = listener, o.options = options);
|
|
878
|
+
o.value = value;
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
this.addEventListener(typename.type, listener, options);
|
|
883
|
+
o = {
|
|
884
|
+
type: typename.type,
|
|
885
|
+
name: typename.name,
|
|
886
|
+
value: value,
|
|
887
|
+
listener: listener,
|
|
888
|
+
options: options
|
|
889
|
+
};
|
|
890
|
+
if (!on) this.__on = [
|
|
891
|
+
o
|
|
892
|
+
];
|
|
893
|
+
else on.push(o);
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function selection_on(typename, value, options) {
|
|
897
|
+
var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
|
|
898
|
+
if (arguments.length < 2) {
|
|
899
|
+
var on = this.node().__on;
|
|
900
|
+
if (on) for(var j = 0, m = on.length, o; j < m; ++j){
|
|
901
|
+
for(i = 0, o = on[j]; i < n; ++i){
|
|
902
|
+
if ((t = typenames[i]).type === o.type && t.name === o.name) {
|
|
903
|
+
return o.value;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
on = value ? onAdd : onRemove;
|
|
910
|
+
for(i = 0; i < n; ++i)this.each(on(typenames[i], value, options));
|
|
911
|
+
return this;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function dispatchEvent(node, type, params) {
|
|
915
|
+
var window = defaultView(node), event = window.CustomEvent;
|
|
916
|
+
if (typeof event === "function") {
|
|
917
|
+
event = new event(type, params);
|
|
918
|
+
} else {
|
|
919
|
+
event = window.document.createEvent("Event");
|
|
920
|
+
if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
|
|
921
|
+
else event.initEvent(type, false, false);
|
|
922
|
+
}
|
|
923
|
+
node.dispatchEvent(event);
|
|
924
|
+
}
|
|
925
|
+
function dispatchConstant(type, params) {
|
|
926
|
+
return function() {
|
|
927
|
+
return dispatchEvent(this, type, params);
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
function dispatchFunction(type, params) {
|
|
931
|
+
return function() {
|
|
932
|
+
return dispatchEvent(this, type, params.apply(this, arguments));
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
function selection_dispatch(type, params) {
|
|
936
|
+
return this.each((typeof params === "function" ? dispatchFunction : dispatchConstant)(type, params));
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function* selection_iterator() {
|
|
940
|
+
for(var groups = this._groups, j = 0, m = groups.length; j < m; ++j){
|
|
941
|
+
for(var group = groups[j], i = 0, n = group.length, node; i < n; ++i){
|
|
942
|
+
if (node = group[i]) yield node;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
var root = [
|
|
948
|
+
null
|
|
949
|
+
];
|
|
950
|
+
function Selection$1(groups, parents) {
|
|
951
|
+
this._groups = groups;
|
|
952
|
+
this._parents = parents;
|
|
953
|
+
}
|
|
954
|
+
function selection() {
|
|
955
|
+
return new Selection$1([
|
|
956
|
+
[
|
|
957
|
+
document.documentElement
|
|
958
|
+
]
|
|
959
|
+
], root);
|
|
960
|
+
}
|
|
961
|
+
function selection_selection() {
|
|
962
|
+
return this;
|
|
963
|
+
}
|
|
964
|
+
Selection$1.prototype = selection.prototype = {
|
|
965
|
+
constructor: Selection$1,
|
|
966
|
+
select: selection_select,
|
|
967
|
+
selectAll: selection_selectAll,
|
|
968
|
+
selectChild: selection_selectChild,
|
|
969
|
+
selectChildren: selection_selectChildren,
|
|
970
|
+
filter: selection_filter,
|
|
971
|
+
data: selection_data,
|
|
972
|
+
enter: selection_enter,
|
|
973
|
+
exit: selection_exit,
|
|
974
|
+
join: selection_join,
|
|
975
|
+
merge: selection_merge,
|
|
976
|
+
selection: selection_selection,
|
|
977
|
+
order: selection_order,
|
|
978
|
+
sort: selection_sort,
|
|
979
|
+
call: selection_call,
|
|
980
|
+
nodes: selection_nodes,
|
|
981
|
+
node: selection_node,
|
|
982
|
+
size: selection_size,
|
|
983
|
+
empty: selection_empty,
|
|
984
|
+
each: selection_each,
|
|
985
|
+
attr: selection_attr,
|
|
986
|
+
style: selection_style,
|
|
987
|
+
property: selection_property,
|
|
988
|
+
classed: selection_classed,
|
|
989
|
+
text: selection_text,
|
|
990
|
+
html: selection_html,
|
|
991
|
+
raise: selection_raise,
|
|
992
|
+
lower: selection_lower,
|
|
993
|
+
append: selection_append,
|
|
994
|
+
insert: selection_insert,
|
|
995
|
+
remove: selection_remove,
|
|
996
|
+
clone: selection_clone,
|
|
997
|
+
datum: selection_datum,
|
|
998
|
+
on: selection_on,
|
|
999
|
+
dispatch: selection_dispatch,
|
|
1000
|
+
[Symbol.iterator]: selection_iterator
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
function select(selector) {
|
|
1004
|
+
return typeof selector === "string" ? new Selection$1([
|
|
1005
|
+
[
|
|
1006
|
+
document.querySelector(selector)
|
|
1007
|
+
]
|
|
1008
|
+
], [
|
|
1009
|
+
document.documentElement
|
|
1010
|
+
]) : new Selection$1([
|
|
1011
|
+
[
|
|
1012
|
+
selector
|
|
1013
|
+
]
|
|
1014
|
+
], root);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
var noop = {
|
|
1018
|
+
value: ()=>{}
|
|
1019
|
+
};
|
|
1020
|
+
function dispatch() {
|
|
1021
|
+
for(var i = 0, n = arguments.length, _ = {}, t; i < n; ++i){
|
|
1022
|
+
if (!(t = arguments[i] + "") || t in _ || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
|
|
1023
|
+
_[t] = [];
|
|
1024
|
+
}
|
|
1025
|
+
return new Dispatch(_);
|
|
1026
|
+
}
|
|
1027
|
+
function Dispatch(_) {
|
|
1028
|
+
this._ = _;
|
|
1029
|
+
}
|
|
1030
|
+
function parseTypenames(typenames, types) {
|
|
1031
|
+
return typenames.trim().split(/^|\s+/).map(function(t) {
|
|
1032
|
+
var name = "", i = t.indexOf(".");
|
|
1033
|
+
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
|
1034
|
+
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
|
1035
|
+
return {
|
|
1036
|
+
type: t,
|
|
1037
|
+
name: name
|
|
1038
|
+
};
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
Dispatch.prototype = dispatch.prototype = {
|
|
1042
|
+
constructor: Dispatch,
|
|
1043
|
+
on: function(typename, callback) {
|
|
1044
|
+
var _ = this._, T = parseTypenames(typename + "", _), t, i = -1, n = T.length;
|
|
1045
|
+
// If no callback was specified, return the callback of the given type and name.
|
|
1046
|
+
if (arguments.length < 2) {
|
|
1047
|
+
while(++i < n)if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
// If a type was specified, set the callback for the given type and name.
|
|
1051
|
+
// Otherwise, if a null callback was specified, remove callbacks of the given name.
|
|
1052
|
+
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
|
1053
|
+
while(++i < n){
|
|
1054
|
+
if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
|
|
1055
|
+
else if (callback == null) for(t in _)_[t] = set$1(_[t], typename.name, null);
|
|
1056
|
+
}
|
|
1057
|
+
return this;
|
|
1058
|
+
},
|
|
1059
|
+
copy: function() {
|
|
1060
|
+
var copy = {}, _ = this._;
|
|
1061
|
+
for(var t in _)copy[t] = _[t].slice();
|
|
1062
|
+
return new Dispatch(copy);
|
|
1063
|
+
},
|
|
1064
|
+
call: function(type, that) {
|
|
1065
|
+
if ((n = arguments.length - 2) > 0) for(var args = new Array(n), i = 0, n, t; i < n; ++i)args[i] = arguments[i + 2];
|
|
1066
|
+
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
|
1067
|
+
for(t = this._[type], i = 0, n = t.length; i < n; ++i)t[i].value.apply(that, args);
|
|
1068
|
+
},
|
|
1069
|
+
apply: function(type, that, args) {
|
|
1070
|
+
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
|
1071
|
+
for(var t = this._[type], i = 0, n = t.length; i < n; ++i)t[i].value.apply(that, args);
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
function get$1(type, name) {
|
|
1075
|
+
for(var i = 0, n = type.length, c; i < n; ++i){
|
|
1076
|
+
if ((c = type[i]).name === name) {
|
|
1077
|
+
return c.value;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
function set$1(type, name, callback) {
|
|
1082
|
+
for(var i = 0, n = type.length; i < n; ++i){
|
|
1083
|
+
if (type[i].name === name) {
|
|
1084
|
+
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
if (callback != null) type.push({
|
|
1089
|
+
name: name,
|
|
1090
|
+
value: callback
|
|
1091
|
+
});
|
|
1092
|
+
return type;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
var frame = 0, timeout$1 = 0, interval = 0, pokeDelay = 1000, taskHead, taskTail, clockLast = 0, clockNow = 0, clockSkew = 0, clock = typeof performance === "object" && performance.now ? performance : Date, setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) {
|
|
1096
|
+
setTimeout(f, 17);
|
|
1097
|
+
};
|
|
1098
|
+
function now() {
|
|
1099
|
+
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
|
1100
|
+
}
|
|
1101
|
+
function clearNow() {
|
|
1102
|
+
clockNow = 0;
|
|
1103
|
+
}
|
|
1104
|
+
function Timer() {
|
|
1105
|
+
this._call = this._time = this._next = null;
|
|
1106
|
+
}
|
|
1107
|
+
Timer.prototype = timer.prototype = {
|
|
1108
|
+
constructor: Timer,
|
|
1109
|
+
restart: function(callback, delay, time) {
|
|
1110
|
+
if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
|
1111
|
+
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
|
1112
|
+
if (!this._next && taskTail !== this) {
|
|
1113
|
+
if (taskTail) taskTail._next = this;
|
|
1114
|
+
else taskHead = this;
|
|
1115
|
+
taskTail = this;
|
|
1116
|
+
}
|
|
1117
|
+
this._call = callback;
|
|
1118
|
+
this._time = time;
|
|
1119
|
+
sleep();
|
|
1120
|
+
},
|
|
1121
|
+
stop: function() {
|
|
1122
|
+
if (this._call) {
|
|
1123
|
+
this._call = null;
|
|
1124
|
+
this._time = Infinity;
|
|
1125
|
+
sleep();
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
function timer(callback, delay, time) {
|
|
1130
|
+
var t = new Timer;
|
|
1131
|
+
t.restart(callback, delay, time);
|
|
1132
|
+
return t;
|
|
1133
|
+
}
|
|
1134
|
+
function timerFlush() {
|
|
1135
|
+
now(); // Get the current time, if not already set.
|
|
1136
|
+
++frame; // Pretend we’ve set an alarm, if we haven’t already.
|
|
1137
|
+
var t = taskHead, e;
|
|
1138
|
+
while(t){
|
|
1139
|
+
if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
|
|
1140
|
+
t = t._next;
|
|
1141
|
+
}
|
|
1142
|
+
--frame;
|
|
1143
|
+
}
|
|
1144
|
+
function wake() {
|
|
1145
|
+
clockNow = (clockLast = clock.now()) + clockSkew;
|
|
1146
|
+
frame = timeout$1 = 0;
|
|
1147
|
+
try {
|
|
1148
|
+
timerFlush();
|
|
1149
|
+
} finally{
|
|
1150
|
+
frame = 0;
|
|
1151
|
+
nap();
|
|
1152
|
+
clockNow = 0;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
function poke() {
|
|
1156
|
+
var now = clock.now(), delay = now - clockLast;
|
|
1157
|
+
if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
|
|
1158
|
+
}
|
|
1159
|
+
function nap() {
|
|
1160
|
+
var t0, t1 = taskHead, t2, time = Infinity;
|
|
1161
|
+
while(t1){
|
|
1162
|
+
if (t1._call) {
|
|
1163
|
+
if (time > t1._time) time = t1._time;
|
|
1164
|
+
t0 = t1, t1 = t1._next;
|
|
1165
|
+
} else {
|
|
1166
|
+
t2 = t1._next, t1._next = null;
|
|
1167
|
+
t1 = t0 ? t0._next = t2 : taskHead = t2;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
taskTail = t0;
|
|
1171
|
+
sleep(time);
|
|
1172
|
+
}
|
|
1173
|
+
function sleep(time) {
|
|
1174
|
+
if (frame) return; // Soonest alarm already set, or will be.
|
|
1175
|
+
if (timeout$1) timeout$1 = clearTimeout(timeout$1);
|
|
1176
|
+
var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
|
|
1177
|
+
if (delay > 24) {
|
|
1178
|
+
if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
|
|
1179
|
+
if (interval) interval = clearInterval(interval);
|
|
1180
|
+
} else {
|
|
1181
|
+
if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
|
|
1182
|
+
frame = 1, setFrame(wake);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
function timeout(callback, delay, time) {
|
|
1187
|
+
var t = new Timer;
|
|
1188
|
+
delay = delay == null ? 0 : +delay;
|
|
1189
|
+
t.restart((elapsed)=>{
|
|
1190
|
+
t.stop();
|
|
1191
|
+
callback(elapsed + delay);
|
|
1192
|
+
}, delay, time);
|
|
1193
|
+
return t;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
var emptyOn = dispatch("start", "end", "cancel", "interrupt");
|
|
1197
|
+
var emptyTween = [];
|
|
1198
|
+
var CREATED = 0;
|
|
1199
|
+
var SCHEDULED = 1;
|
|
1200
|
+
var STARTING = 2;
|
|
1201
|
+
var STARTED = 3;
|
|
1202
|
+
var RUNNING = 4;
|
|
1203
|
+
var ENDING = 5;
|
|
1204
|
+
var ENDED = 6;
|
|
1205
|
+
function schedule(node, name, id, index, group, timing) {
|
|
1206
|
+
var schedules = node.__transition;
|
|
1207
|
+
if (!schedules) node.__transition = {};
|
|
1208
|
+
else if (id in schedules) return;
|
|
1209
|
+
create(node, id, {
|
|
1210
|
+
name: name,
|
|
1211
|
+
index: index,
|
|
1212
|
+
group: group,
|
|
1213
|
+
on: emptyOn,
|
|
1214
|
+
tween: emptyTween,
|
|
1215
|
+
time: timing.time,
|
|
1216
|
+
delay: timing.delay,
|
|
1217
|
+
duration: timing.duration,
|
|
1218
|
+
ease: timing.ease,
|
|
1219
|
+
timer: null,
|
|
1220
|
+
state: CREATED
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
function init(node, id) {
|
|
1224
|
+
var schedule = get(node, id);
|
|
1225
|
+
if (schedule.state > CREATED) throw new Error("too late; already scheduled");
|
|
1226
|
+
return schedule;
|
|
1227
|
+
}
|
|
1228
|
+
function set(node, id) {
|
|
1229
|
+
var schedule = get(node, id);
|
|
1230
|
+
if (schedule.state > STARTED) throw new Error("too late; already running");
|
|
1231
|
+
return schedule;
|
|
1232
|
+
}
|
|
1233
|
+
function get(node, id) {
|
|
1234
|
+
var schedule = node.__transition;
|
|
1235
|
+
if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
|
|
1236
|
+
return schedule;
|
|
1237
|
+
}
|
|
1238
|
+
function create(node, id, self) {
|
|
1239
|
+
var schedules = node.__transition, tween;
|
|
1240
|
+
// Initialize the self timer when the transition is created.
|
|
1241
|
+
// Note the actual delay is not known until the first callback!
|
|
1242
|
+
schedules[id] = self;
|
|
1243
|
+
self.timer = timer(schedule, 0, self.time);
|
|
1244
|
+
function schedule(elapsed) {
|
|
1245
|
+
self.state = SCHEDULED;
|
|
1246
|
+
self.timer.restart(start, self.delay, self.time);
|
|
1247
|
+
// If the elapsed delay is less than our first sleep, start immediately.
|
|
1248
|
+
if (self.delay <= elapsed) start(elapsed - self.delay);
|
|
1249
|
+
}
|
|
1250
|
+
function start(elapsed) {
|
|
1251
|
+
var i, j, n, o;
|
|
1252
|
+
// If the state is not SCHEDULED, then we previously errored on start.
|
|
1253
|
+
if (self.state !== SCHEDULED) return stop();
|
|
1254
|
+
for(i in schedules){
|
|
1255
|
+
o = schedules[i];
|
|
1256
|
+
if (o.name !== self.name) continue;
|
|
1257
|
+
// While this element already has a starting transition during this frame,
|
|
1258
|
+
// defer starting an interrupting transition until that transition has a
|
|
1259
|
+
// chance to tick (and possibly end); see d3/d3-transition#54!
|
|
1260
|
+
if (o.state === STARTED) return timeout(start);
|
|
1261
|
+
// Interrupt the active transition, if any.
|
|
1262
|
+
if (o.state === RUNNING) {
|
|
1263
|
+
o.state = ENDED;
|
|
1264
|
+
o.timer.stop();
|
|
1265
|
+
o.on.call("interrupt", node, node.__data__, o.index, o.group);
|
|
1266
|
+
delete schedules[i];
|
|
1267
|
+
} else if (+i < id) {
|
|
1268
|
+
o.state = ENDED;
|
|
1269
|
+
o.timer.stop();
|
|
1270
|
+
o.on.call("cancel", node, node.__data__, o.index, o.group);
|
|
1271
|
+
delete schedules[i];
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
// Defer the first tick to end of the current frame; see d3/d3#1576.
|
|
1275
|
+
// Note the transition may be canceled after start and before the first tick!
|
|
1276
|
+
// Note this must be scheduled before the start event; see d3/d3-transition#16!
|
|
1277
|
+
// Assuming this is successful, subsequent callbacks go straight to tick.
|
|
1278
|
+
timeout(function() {
|
|
1279
|
+
if (self.state === STARTED) {
|
|
1280
|
+
self.state = RUNNING;
|
|
1281
|
+
self.timer.restart(tick, self.delay, self.time);
|
|
1282
|
+
tick(elapsed);
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
// Dispatch the start event.
|
|
1286
|
+
// Note this must be done before the tween are initialized.
|
|
1287
|
+
self.state = STARTING;
|
|
1288
|
+
self.on.call("start", node, node.__data__, self.index, self.group);
|
|
1289
|
+
if (self.state !== STARTING) return; // interrupted
|
|
1290
|
+
self.state = STARTED;
|
|
1291
|
+
// Initialize the tween, deleting null tween.
|
|
1292
|
+
tween = new Array(n = self.tween.length);
|
|
1293
|
+
for(i = 0, j = -1; i < n; ++i){
|
|
1294
|
+
if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
|
|
1295
|
+
tween[++j] = o;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
tween.length = j + 1;
|
|
1299
|
+
}
|
|
1300
|
+
function tick(elapsed) {
|
|
1301
|
+
var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1), i = -1, n = tween.length;
|
|
1302
|
+
while(++i < n){
|
|
1303
|
+
tween[i].call(node, t);
|
|
1304
|
+
}
|
|
1305
|
+
// Dispatch the end event.
|
|
1306
|
+
if (self.state === ENDING) {
|
|
1307
|
+
self.on.call("end", node, node.__data__, self.index, self.group);
|
|
1308
|
+
stop();
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
function stop() {
|
|
1312
|
+
self.state = ENDED;
|
|
1313
|
+
self.timer.stop();
|
|
1314
|
+
delete schedules[id];
|
|
1315
|
+
for(var i in schedules)return; // eslint-disable-line no-unused-vars
|
|
1316
|
+
delete node.__transition;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function interrupt(node, name) {
|
|
1321
|
+
var schedules = node.__transition, schedule, active, empty = true, i;
|
|
1322
|
+
if (!schedules) return;
|
|
1323
|
+
name = name == null ? null : name + "";
|
|
1324
|
+
for(i in schedules){
|
|
1325
|
+
if ((schedule = schedules[i]).name !== name) {
|
|
1326
|
+
empty = false;
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
active = schedule.state > STARTING && schedule.state < ENDING;
|
|
1330
|
+
schedule.state = ENDED;
|
|
1331
|
+
schedule.timer.stop();
|
|
1332
|
+
schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
|
|
1333
|
+
delete schedules[i];
|
|
1334
|
+
}
|
|
1335
|
+
if (empty) delete node.__transition;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
function selection_interrupt(name) {
|
|
1339
|
+
return this.each(function() {
|
|
1340
|
+
interrupt(this, name);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
function define(constructor, factory, prototype) {
|
|
1345
|
+
constructor.prototype = factory.prototype = prototype;
|
|
1346
|
+
prototype.constructor = constructor;
|
|
1347
|
+
}
|
|
1348
|
+
function extend(parent, definition) {
|
|
1349
|
+
var prototype = Object.create(parent.prototype);
|
|
1350
|
+
for(var key in definition)prototype[key] = definition[key];
|
|
1351
|
+
return prototype;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
function Color() {}
|
|
1355
|
+
var darker = 0.7;
|
|
1356
|
+
var brighter = 1 / darker;
|
|
1357
|
+
var reI = "\\s*([+-]?\\d+)\\s*", reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*", reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*", reHex = /^#([0-9a-f]{3,8})$/, reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`), reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`), reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`), reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`), reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`), reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
|
|
1358
|
+
var named = {
|
|
1359
|
+
aliceblue: 0xf0f8ff,
|
|
1360
|
+
antiquewhite: 0xfaebd7,
|
|
1361
|
+
aqua: 0x00ffff,
|
|
1362
|
+
aquamarine: 0x7fffd4,
|
|
1363
|
+
azure: 0xf0ffff,
|
|
1364
|
+
beige: 0xf5f5dc,
|
|
1365
|
+
bisque: 0xffe4c4,
|
|
1366
|
+
black: 0x000000,
|
|
1367
|
+
blanchedalmond: 0xffebcd,
|
|
1368
|
+
blue: 0x0000ff,
|
|
1369
|
+
blueviolet: 0x8a2be2,
|
|
1370
|
+
brown: 0xa52a2a,
|
|
1371
|
+
burlywood: 0xdeb887,
|
|
1372
|
+
cadetblue: 0x5f9ea0,
|
|
1373
|
+
chartreuse: 0x7fff00,
|
|
1374
|
+
chocolate: 0xd2691e,
|
|
1375
|
+
coral: 0xff7f50,
|
|
1376
|
+
cornflowerblue: 0x6495ed,
|
|
1377
|
+
cornsilk: 0xfff8dc,
|
|
1378
|
+
crimson: 0xdc143c,
|
|
1379
|
+
cyan: 0x00ffff,
|
|
1380
|
+
darkblue: 0x00008b,
|
|
1381
|
+
darkcyan: 0x008b8b,
|
|
1382
|
+
darkgoldenrod: 0xb8860b,
|
|
1383
|
+
darkgray: 0xa9a9a9,
|
|
1384
|
+
darkgreen: 0x006400,
|
|
1385
|
+
darkgrey: 0xa9a9a9,
|
|
1386
|
+
darkkhaki: 0xbdb76b,
|
|
1387
|
+
darkmagenta: 0x8b008b,
|
|
1388
|
+
darkolivegreen: 0x556b2f,
|
|
1389
|
+
darkorange: 0xff8c00,
|
|
1390
|
+
darkorchid: 0x9932cc,
|
|
1391
|
+
darkred: 0x8b0000,
|
|
1392
|
+
darksalmon: 0xe9967a,
|
|
1393
|
+
darkseagreen: 0x8fbc8f,
|
|
1394
|
+
darkslateblue: 0x483d8b,
|
|
1395
|
+
darkslategray: 0x2f4f4f,
|
|
1396
|
+
darkslategrey: 0x2f4f4f,
|
|
1397
|
+
darkturquoise: 0x00ced1,
|
|
1398
|
+
darkviolet: 0x9400d3,
|
|
1399
|
+
deeppink: 0xff1493,
|
|
1400
|
+
deepskyblue: 0x00bfff,
|
|
1401
|
+
dimgray: 0x696969,
|
|
1402
|
+
dimgrey: 0x696969,
|
|
1403
|
+
dodgerblue: 0x1e90ff,
|
|
1404
|
+
firebrick: 0xb22222,
|
|
1405
|
+
floralwhite: 0xfffaf0,
|
|
1406
|
+
forestgreen: 0x228b22,
|
|
1407
|
+
fuchsia: 0xff00ff,
|
|
1408
|
+
gainsboro: 0xdcdcdc,
|
|
1409
|
+
ghostwhite: 0xf8f8ff,
|
|
1410
|
+
gold: 0xffd700,
|
|
1411
|
+
goldenrod: 0xdaa520,
|
|
1412
|
+
gray: 0x808080,
|
|
1413
|
+
green: 0x008000,
|
|
1414
|
+
greenyellow: 0xadff2f,
|
|
1415
|
+
grey: 0x808080,
|
|
1416
|
+
honeydew: 0xf0fff0,
|
|
1417
|
+
hotpink: 0xff69b4,
|
|
1418
|
+
indianred: 0xcd5c5c,
|
|
1419
|
+
indigo: 0x4b0082,
|
|
1420
|
+
ivory: 0xfffff0,
|
|
1421
|
+
khaki: 0xf0e68c,
|
|
1422
|
+
lavender: 0xe6e6fa,
|
|
1423
|
+
lavenderblush: 0xfff0f5,
|
|
1424
|
+
lawngreen: 0x7cfc00,
|
|
1425
|
+
lemonchiffon: 0xfffacd,
|
|
1426
|
+
lightblue: 0xadd8e6,
|
|
1427
|
+
lightcoral: 0xf08080,
|
|
1428
|
+
lightcyan: 0xe0ffff,
|
|
1429
|
+
lightgoldenrodyellow: 0xfafad2,
|
|
1430
|
+
lightgray: 0xd3d3d3,
|
|
1431
|
+
lightgreen: 0x90ee90,
|
|
1432
|
+
lightgrey: 0xd3d3d3,
|
|
1433
|
+
lightpink: 0xffb6c1,
|
|
1434
|
+
lightsalmon: 0xffa07a,
|
|
1435
|
+
lightseagreen: 0x20b2aa,
|
|
1436
|
+
lightskyblue: 0x87cefa,
|
|
1437
|
+
lightslategray: 0x778899,
|
|
1438
|
+
lightslategrey: 0x778899,
|
|
1439
|
+
lightsteelblue: 0xb0c4de,
|
|
1440
|
+
lightyellow: 0xffffe0,
|
|
1441
|
+
lime: 0x00ff00,
|
|
1442
|
+
limegreen: 0x32cd32,
|
|
1443
|
+
linen: 0xfaf0e6,
|
|
1444
|
+
magenta: 0xff00ff,
|
|
1445
|
+
maroon: 0x800000,
|
|
1446
|
+
mediumaquamarine: 0x66cdaa,
|
|
1447
|
+
mediumblue: 0x0000cd,
|
|
1448
|
+
mediumorchid: 0xba55d3,
|
|
1449
|
+
mediumpurple: 0x9370db,
|
|
1450
|
+
mediumseagreen: 0x3cb371,
|
|
1451
|
+
mediumslateblue: 0x7b68ee,
|
|
1452
|
+
mediumspringgreen: 0x00fa9a,
|
|
1453
|
+
mediumturquoise: 0x48d1cc,
|
|
1454
|
+
mediumvioletred: 0xc71585,
|
|
1455
|
+
midnightblue: 0x191970,
|
|
1456
|
+
mintcream: 0xf5fffa,
|
|
1457
|
+
mistyrose: 0xffe4e1,
|
|
1458
|
+
moccasin: 0xffe4b5,
|
|
1459
|
+
navajowhite: 0xffdead,
|
|
1460
|
+
navy: 0x000080,
|
|
1461
|
+
oldlace: 0xfdf5e6,
|
|
1462
|
+
olive: 0x808000,
|
|
1463
|
+
olivedrab: 0x6b8e23,
|
|
1464
|
+
orange: 0xffa500,
|
|
1465
|
+
orangered: 0xff4500,
|
|
1466
|
+
orchid: 0xda70d6,
|
|
1467
|
+
palegoldenrod: 0xeee8aa,
|
|
1468
|
+
palegreen: 0x98fb98,
|
|
1469
|
+
paleturquoise: 0xafeeee,
|
|
1470
|
+
palevioletred: 0xdb7093,
|
|
1471
|
+
papayawhip: 0xffefd5,
|
|
1472
|
+
peachpuff: 0xffdab9,
|
|
1473
|
+
peru: 0xcd853f,
|
|
1474
|
+
pink: 0xffc0cb,
|
|
1475
|
+
plum: 0xdda0dd,
|
|
1476
|
+
powderblue: 0xb0e0e6,
|
|
1477
|
+
purple: 0x800080,
|
|
1478
|
+
rebeccapurple: 0x663399,
|
|
1479
|
+
red: 0xff0000,
|
|
1480
|
+
rosybrown: 0xbc8f8f,
|
|
1481
|
+
royalblue: 0x4169e1,
|
|
1482
|
+
saddlebrown: 0x8b4513,
|
|
1483
|
+
salmon: 0xfa8072,
|
|
1484
|
+
sandybrown: 0xf4a460,
|
|
1485
|
+
seagreen: 0x2e8b57,
|
|
1486
|
+
seashell: 0xfff5ee,
|
|
1487
|
+
sienna: 0xa0522d,
|
|
1488
|
+
silver: 0xc0c0c0,
|
|
1489
|
+
skyblue: 0x87ceeb,
|
|
1490
|
+
slateblue: 0x6a5acd,
|
|
1491
|
+
slategray: 0x708090,
|
|
1492
|
+
slategrey: 0x708090,
|
|
1493
|
+
snow: 0xfffafa,
|
|
1494
|
+
springgreen: 0x00ff7f,
|
|
1495
|
+
steelblue: 0x4682b4,
|
|
1496
|
+
tan: 0xd2b48c,
|
|
1497
|
+
teal: 0x008080,
|
|
1498
|
+
thistle: 0xd8bfd8,
|
|
1499
|
+
tomato: 0xff6347,
|
|
1500
|
+
turquoise: 0x40e0d0,
|
|
1501
|
+
violet: 0xee82ee,
|
|
1502
|
+
wheat: 0xf5deb3,
|
|
1503
|
+
white: 0xffffff,
|
|
1504
|
+
whitesmoke: 0xf5f5f5,
|
|
1505
|
+
yellow: 0xffff00,
|
|
1506
|
+
yellowgreen: 0x9acd32
|
|
1507
|
+
};
|
|
1508
|
+
define(Color, color, {
|
|
1509
|
+
copy (channels) {
|
|
1510
|
+
return Object.assign(new this.constructor, this, channels);
|
|
1511
|
+
},
|
|
1512
|
+
displayable () {
|
|
1513
|
+
return this.rgb().displayable();
|
|
1514
|
+
},
|
|
1515
|
+
hex: color_formatHex,
|
|
1516
|
+
formatHex: color_formatHex,
|
|
1517
|
+
formatHex8: color_formatHex8,
|
|
1518
|
+
formatHsl: color_formatHsl,
|
|
1519
|
+
formatRgb: color_formatRgb,
|
|
1520
|
+
toString: color_formatRgb
|
|
1521
|
+
});
|
|
1522
|
+
function color_formatHex() {
|
|
1523
|
+
return this.rgb().formatHex();
|
|
1524
|
+
}
|
|
1525
|
+
function color_formatHex8() {
|
|
1526
|
+
return this.rgb().formatHex8();
|
|
1527
|
+
}
|
|
1528
|
+
function color_formatHsl() {
|
|
1529
|
+
return hslConvert(this).formatHsl();
|
|
1530
|
+
}
|
|
1531
|
+
function color_formatRgb() {
|
|
1532
|
+
return this.rgb().formatRgb();
|
|
1533
|
+
}
|
|
1534
|
+
function color(format) {
|
|
1535
|
+
var m, l;
|
|
1536
|
+
format = (format + "").trim().toLowerCase();
|
|
1537
|
+
return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
|
|
1538
|
+
: l === 3 ? new Rgb(m >> 8 & 0xf | m >> 4 & 0xf0, m >> 4 & 0xf | m & 0xf0, (m & 0xf) << 4 | m & 0xf, 1) // #f00
|
|
1539
|
+
: l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
|
|
1540
|
+
: l === 4 ? rgba(m >> 12 & 0xf | m >> 8 & 0xf0, m >> 8 & 0xf | m >> 4 & 0xf0, m >> 4 & 0xf | m & 0xf0, ((m & 0xf) << 4 | m & 0xf) / 0xff) // #f000
|
|
1541
|
+
: null // invalid hex
|
|
1542
|
+
) : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
|
|
1543
|
+
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
|
|
1544
|
+
: (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
|
|
1545
|
+
: (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
|
|
1546
|
+
: (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
|
|
1547
|
+
: (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
|
|
1548
|
+
: named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
|
|
1549
|
+
: format === "transparent" ? new Rgb(NaN, NaN, NaN, 0) : null;
|
|
1550
|
+
}
|
|
1551
|
+
function rgbn(n) {
|
|
1552
|
+
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
|
|
1553
|
+
}
|
|
1554
|
+
function rgba(r, g, b, a) {
|
|
1555
|
+
if (a <= 0) r = g = b = NaN;
|
|
1556
|
+
return new Rgb(r, g, b, a);
|
|
1557
|
+
}
|
|
1558
|
+
function rgbConvert(o) {
|
|
1559
|
+
if (!(o instanceof Color)) o = color(o);
|
|
1560
|
+
if (!o) return new Rgb;
|
|
1561
|
+
o = o.rgb();
|
|
1562
|
+
return new Rgb(o.r, o.g, o.b, o.opacity);
|
|
1563
|
+
}
|
|
1564
|
+
function rgb(r, g, b, opacity) {
|
|
1565
|
+
return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
|
|
1566
|
+
}
|
|
1567
|
+
function Rgb(r, g, b, opacity) {
|
|
1568
|
+
this.r = +r;
|
|
1569
|
+
this.g = +g;
|
|
1570
|
+
this.b = +b;
|
|
1571
|
+
this.opacity = +opacity;
|
|
1572
|
+
}
|
|
1573
|
+
define(Rgb, rgb, extend(Color, {
|
|
1574
|
+
brighter (k) {
|
|
1575
|
+
k = k == null ? brighter : Math.pow(brighter, k);
|
|
1576
|
+
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
|
1577
|
+
},
|
|
1578
|
+
darker (k) {
|
|
1579
|
+
k = k == null ? darker : Math.pow(darker, k);
|
|
1580
|
+
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
|
1581
|
+
},
|
|
1582
|
+
rgb () {
|
|
1583
|
+
return this;
|
|
1584
|
+
},
|
|
1585
|
+
clamp () {
|
|
1586
|
+
return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
|
|
1587
|
+
},
|
|
1588
|
+
displayable () {
|
|
1589
|
+
return -0.5 <= this.r && this.r < 255.5 && -0.5 <= this.g && this.g < 255.5 && -0.5 <= this.b && this.b < 255.5 && 0 <= this.opacity && this.opacity <= 1;
|
|
1590
|
+
},
|
|
1591
|
+
hex: rgb_formatHex,
|
|
1592
|
+
formatHex: rgb_formatHex,
|
|
1593
|
+
formatHex8: rgb_formatHex8,
|
|
1594
|
+
formatRgb: rgb_formatRgb,
|
|
1595
|
+
toString: rgb_formatRgb
|
|
1596
|
+
}));
|
|
1597
|
+
function rgb_formatHex() {
|
|
1598
|
+
return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
|
|
1599
|
+
}
|
|
1600
|
+
function rgb_formatHex8() {
|
|
1601
|
+
return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
|
|
1602
|
+
}
|
|
1603
|
+
function rgb_formatRgb() {
|
|
1604
|
+
const a = clampa(this.opacity);
|
|
1605
|
+
return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
|
|
1606
|
+
}
|
|
1607
|
+
function clampa(opacity) {
|
|
1608
|
+
return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
|
|
1609
|
+
}
|
|
1610
|
+
function clampi(value) {
|
|
1611
|
+
return Math.max(0, Math.min(255, Math.round(value) || 0));
|
|
1612
|
+
}
|
|
1613
|
+
function hex(value) {
|
|
1614
|
+
value = clampi(value);
|
|
1615
|
+
return (value < 16 ? "0" : "") + value.toString(16);
|
|
1616
|
+
}
|
|
1617
|
+
function hsla(h, s, l, a) {
|
|
1618
|
+
if (a <= 0) h = s = l = NaN;
|
|
1619
|
+
else if (l <= 0 || l >= 1) h = s = NaN;
|
|
1620
|
+
else if (s <= 0) h = NaN;
|
|
1621
|
+
return new Hsl(h, s, l, a);
|
|
1622
|
+
}
|
|
1623
|
+
function hslConvert(o) {
|
|
1624
|
+
if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
|
|
1625
|
+
if (!(o instanceof Color)) o = color(o);
|
|
1626
|
+
if (!o) return new Hsl;
|
|
1627
|
+
if (o instanceof Hsl) return o;
|
|
1628
|
+
o = o.rgb();
|
|
1629
|
+
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;
|
|
1630
|
+
if (s) {
|
|
1631
|
+
if (r === max) h = (g - b) / s + (g < b) * 6;
|
|
1632
|
+
else if (g === max) h = (b - r) / s + 2;
|
|
1633
|
+
else h = (r - g) / s + 4;
|
|
1634
|
+
s /= l < 0.5 ? max + min : 2 - max - min;
|
|
1635
|
+
h *= 60;
|
|
1636
|
+
} else {
|
|
1637
|
+
s = l > 0 && l < 1 ? 0 : h;
|
|
1638
|
+
}
|
|
1639
|
+
return new Hsl(h, s, l, o.opacity);
|
|
1640
|
+
}
|
|
1641
|
+
function hsl(h, s, l, opacity) {
|
|
1642
|
+
return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
|
|
1643
|
+
}
|
|
1644
|
+
function Hsl(h, s, l, opacity) {
|
|
1645
|
+
this.h = +h;
|
|
1646
|
+
this.s = +s;
|
|
1647
|
+
this.l = +l;
|
|
1648
|
+
this.opacity = +opacity;
|
|
1649
|
+
}
|
|
1650
|
+
define(Hsl, hsl, extend(Color, {
|
|
1651
|
+
brighter (k) {
|
|
1652
|
+
k = k == null ? brighter : Math.pow(brighter, k);
|
|
1653
|
+
return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
|
1654
|
+
},
|
|
1655
|
+
darker (k) {
|
|
1656
|
+
k = k == null ? darker : Math.pow(darker, k);
|
|
1657
|
+
return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
|
1658
|
+
},
|
|
1659
|
+
rgb () {
|
|
1660
|
+
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;
|
|
1661
|
+
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);
|
|
1662
|
+
},
|
|
1663
|
+
clamp () {
|
|
1664
|
+
return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
|
|
1665
|
+
},
|
|
1666
|
+
displayable () {
|
|
1667
|
+
return (0 <= this.s && this.s <= 1 || isNaN(this.s)) && 0 <= this.l && this.l <= 1 && 0 <= this.opacity && this.opacity <= 1;
|
|
1668
|
+
},
|
|
1669
|
+
formatHsl () {
|
|
1670
|
+
const a = clampa(this.opacity);
|
|
1671
|
+
return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
|
|
1672
|
+
}
|
|
1673
|
+
}));
|
|
1674
|
+
function clamph(value) {
|
|
1675
|
+
value = (value || 0) % 360;
|
|
1676
|
+
return value < 0 ? value + 360 : value;
|
|
1677
|
+
}
|
|
1678
|
+
function clampt(value) {
|
|
1679
|
+
return Math.max(0, Math.min(1, value || 0));
|
|
1680
|
+
}
|
|
1681
|
+
/* From FvD 13.37, CSS Color Module Level 3 */ function hsl2rgb(h, m1, m2) {
|
|
1682
|
+
return (h < 60 ? m1 + (m2 - m1) * h / 60 : h < 180 ? m2 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 : m1) * 255;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
var constant = ((x)=>()=>x);
|
|
1686
|
+
|
|
1687
|
+
function linear(a, d) {
|
|
1688
|
+
return function(t) {
|
|
1689
|
+
return a + t * d;
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
function exponential(a, b, y) {
|
|
1693
|
+
return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
|
|
1694
|
+
return Math.pow(a + t * b, y);
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
function gamma(y) {
|
|
1698
|
+
return (y = +y) === 1 ? nogamma : function(a, b) {
|
|
1699
|
+
return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
function nogamma(a, b) {
|
|
1703
|
+
var d = b - a;
|
|
1704
|
+
return d ? linear(a, d) : constant(isNaN(a) ? b : a);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
var interpolateRgb = (function rgbGamma(y) {
|
|
1708
|
+
var color = gamma(y);
|
|
1709
|
+
function rgb$1(start, end) {
|
|
1710
|
+
var r = color((start = rgb(start)).r, (end = rgb(end)).r), g = color(start.g, end.g), b = color(start.b, end.b), opacity = nogamma(start.opacity, end.opacity);
|
|
1711
|
+
return function(t) {
|
|
1712
|
+
start.r = r(t);
|
|
1713
|
+
start.g = g(t);
|
|
1714
|
+
start.b = b(t);
|
|
1715
|
+
start.opacity = opacity(t);
|
|
1716
|
+
return start + "";
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
rgb$1.gamma = rgbGamma;
|
|
1720
|
+
return rgb$1;
|
|
1721
|
+
})(1);
|
|
1722
|
+
|
|
1723
|
+
function interpolateNumber(a, b) {
|
|
1724
|
+
return a = +a, b = +b, function(t) {
|
|
1725
|
+
return a * (1 - t) + b * t;
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, reB = new RegExp(reA.source, "g");
|
|
1730
|
+
function zero(b) {
|
|
1731
|
+
return function() {
|
|
1732
|
+
return b;
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
function one(b) {
|
|
1736
|
+
return function(t) {
|
|
1737
|
+
return b(t) + "";
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
function interpolateString(a, b) {
|
|
1741
|
+
var bi = reA.lastIndex = reB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = []; // number interpolators
|
|
1742
|
+
// Coerce inputs to strings.
|
|
1743
|
+
a = a + "", b = b + "";
|
|
1744
|
+
// Interpolate pairs of numbers in a & b.
|
|
1745
|
+
while((am = reA.exec(a)) && (bm = reB.exec(b))){
|
|
1746
|
+
if ((bs = bm.index) > bi) {
|
|
1747
|
+
bs = b.slice(bi, bs);
|
|
1748
|
+
if (s[i]) s[i] += bs; // coalesce with previous string
|
|
1749
|
+
else s[++i] = bs;
|
|
1750
|
+
}
|
|
1751
|
+
if ((am = am[0]) === (bm = bm[0])) {
|
|
1752
|
+
if (s[i]) s[i] += bm; // coalesce with previous string
|
|
1753
|
+
else s[++i] = bm;
|
|
1754
|
+
} else {
|
|
1755
|
+
s[++i] = null;
|
|
1756
|
+
q.push({
|
|
1757
|
+
i: i,
|
|
1758
|
+
x: interpolateNumber(am, bm)
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
bi = reB.lastIndex;
|
|
1762
|
+
}
|
|
1763
|
+
// Add remains of b.
|
|
1764
|
+
if (bi < b.length) {
|
|
1765
|
+
bs = b.slice(bi);
|
|
1766
|
+
if (s[i]) s[i] += bs; // coalesce with previous string
|
|
1767
|
+
else s[++i] = bs;
|
|
1768
|
+
}
|
|
1769
|
+
// Special optimization for only a single match.
|
|
1770
|
+
// Otherwise, interpolate each of the numbers and rejoin the string.
|
|
1771
|
+
return s.length < 2 ? q[0] ? one(q[0].x) : zero(b) : (b = q.length, function(t) {
|
|
1772
|
+
for(var i = 0, o; i < b; ++i)s[(o = q[i]).i] = o.x(t);
|
|
1773
|
+
return s.join("");
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
var degrees = 180 / Math.PI;
|
|
1778
|
+
var identity = {
|
|
1779
|
+
translateX: 0,
|
|
1780
|
+
translateY: 0,
|
|
1781
|
+
rotate: 0,
|
|
1782
|
+
skewX: 0,
|
|
1783
|
+
scaleX: 1,
|
|
1784
|
+
scaleY: 1
|
|
1785
|
+
};
|
|
1786
|
+
function decompose(a, b, c, d, e, f) {
|
|
1787
|
+
var scaleX, scaleY, skewX;
|
|
1788
|
+
if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
|
|
1789
|
+
if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
|
|
1790
|
+
if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
|
|
1791
|
+
if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
|
|
1792
|
+
return {
|
|
1793
|
+
translateX: e,
|
|
1794
|
+
translateY: f,
|
|
1795
|
+
rotate: Math.atan2(b, a) * degrees,
|
|
1796
|
+
skewX: Math.atan(skewX) * degrees,
|
|
1797
|
+
scaleX: scaleX,
|
|
1798
|
+
scaleY: scaleY
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
var svgNode;
|
|
1803
|
+
/* eslint-disable no-undef */ function parseCss(value) {
|
|
1804
|
+
const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
|
|
1805
|
+
return m.isIdentity ? identity : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
1806
|
+
}
|
|
1807
|
+
function parseSvg(value) {
|
|
1808
|
+
if (value == null) return identity;
|
|
1809
|
+
if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
1810
|
+
svgNode.setAttribute("transform", value);
|
|
1811
|
+
if (!(value = svgNode.transform.baseVal.consolidate())) return identity;
|
|
1812
|
+
value = value.matrix;
|
|
1813
|
+
return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
function interpolateTransform(parse, pxComma, pxParen, degParen) {
|
|
1817
|
+
function pop(s) {
|
|
1818
|
+
return s.length ? s.pop() + " " : "";
|
|
1819
|
+
}
|
|
1820
|
+
function translate(xa, ya, xb, yb, s, q) {
|
|
1821
|
+
if (xa !== xb || ya !== yb) {
|
|
1822
|
+
var i = s.push("translate(", null, pxComma, null, pxParen);
|
|
1823
|
+
q.push({
|
|
1824
|
+
i: i - 4,
|
|
1825
|
+
x: interpolateNumber(xa, xb)
|
|
1826
|
+
}, {
|
|
1827
|
+
i: i - 2,
|
|
1828
|
+
x: interpolateNumber(ya, yb)
|
|
1829
|
+
});
|
|
1830
|
+
} else if (xb || yb) {
|
|
1831
|
+
s.push("translate(" + xb + pxComma + yb + pxParen);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
function rotate(a, b, s, q) {
|
|
1835
|
+
if (a !== b) {
|
|
1836
|
+
if (a - b > 180) b += 360;
|
|
1837
|
+
else if (b - a > 180) a += 360; // shortest path
|
|
1838
|
+
q.push({
|
|
1839
|
+
i: s.push(pop(s) + "rotate(", null, degParen) - 2,
|
|
1840
|
+
x: interpolateNumber(a, b)
|
|
1841
|
+
});
|
|
1842
|
+
} else if (b) {
|
|
1843
|
+
s.push(pop(s) + "rotate(" + b + degParen);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
function skewX(a, b, s, q) {
|
|
1847
|
+
if (a !== b) {
|
|
1848
|
+
q.push({
|
|
1849
|
+
i: s.push(pop(s) + "skewX(", null, degParen) - 2,
|
|
1850
|
+
x: interpolateNumber(a, b)
|
|
1851
|
+
});
|
|
1852
|
+
} else if (b) {
|
|
1853
|
+
s.push(pop(s) + "skewX(" + b + degParen);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
function scale(xa, ya, xb, yb, s, q) {
|
|
1857
|
+
if (xa !== xb || ya !== yb) {
|
|
1858
|
+
var i = s.push(pop(s) + "scale(", null, ",", null, ")");
|
|
1859
|
+
q.push({
|
|
1860
|
+
i: i - 4,
|
|
1861
|
+
x: interpolateNumber(xa, xb)
|
|
1862
|
+
}, {
|
|
1863
|
+
i: i - 2,
|
|
1864
|
+
x: interpolateNumber(ya, yb)
|
|
1865
|
+
});
|
|
1866
|
+
} else if (xb !== 1 || yb !== 1) {
|
|
1867
|
+
s.push(pop(s) + "scale(" + xb + "," + yb + ")");
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
return function(a, b) {
|
|
1871
|
+
var s = [], q = []; // number interpolators
|
|
1872
|
+
a = parse(a), b = parse(b);
|
|
1873
|
+
translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
|
|
1874
|
+
rotate(a.rotate, b.rotate, s, q);
|
|
1875
|
+
skewX(a.skewX, b.skewX, s, q);
|
|
1876
|
+
scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
|
|
1877
|
+
a = b = null; // gc
|
|
1878
|
+
return function(t) {
|
|
1879
|
+
var i = -1, n = q.length, o;
|
|
1880
|
+
while(++i < n)s[(o = q[i]).i] = o.x(t);
|
|
1881
|
+
return s.join("");
|
|
1882
|
+
};
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
|
|
1886
|
+
var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
|
|
1887
|
+
|
|
1888
|
+
function tweenRemove(id, name) {
|
|
1889
|
+
var tween0, tween1;
|
|
1890
|
+
return function() {
|
|
1891
|
+
var schedule = set(this, id), tween = schedule.tween;
|
|
1892
|
+
// If this node shared tween with the previous node,
|
|
1893
|
+
// just assign the updated shared tween and we’re done!
|
|
1894
|
+
// Otherwise, copy-on-write.
|
|
1895
|
+
if (tween !== tween0) {
|
|
1896
|
+
tween1 = tween0 = tween;
|
|
1897
|
+
for(var i = 0, n = tween1.length; i < n; ++i){
|
|
1898
|
+
if (tween1[i].name === name) {
|
|
1899
|
+
tween1 = tween1.slice();
|
|
1900
|
+
tween1.splice(i, 1);
|
|
1901
|
+
break;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
schedule.tween = tween1;
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
function tweenFunction(id, name, value) {
|
|
1909
|
+
var tween0, tween1;
|
|
1910
|
+
if (typeof value !== "function") throw new Error;
|
|
1911
|
+
return function() {
|
|
1912
|
+
var schedule = set(this, id), tween = schedule.tween;
|
|
1913
|
+
// If this node shared tween with the previous node,
|
|
1914
|
+
// just assign the updated shared tween and we’re done!
|
|
1915
|
+
// Otherwise, copy-on-write.
|
|
1916
|
+
if (tween !== tween0) {
|
|
1917
|
+
tween1 = (tween0 = tween).slice();
|
|
1918
|
+
for(var t = {
|
|
1919
|
+
name: name,
|
|
1920
|
+
value: value
|
|
1921
|
+
}, i = 0, n = tween1.length; i < n; ++i){
|
|
1922
|
+
if (tween1[i].name === name) {
|
|
1923
|
+
tween1[i] = t;
|
|
1924
|
+
break;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
if (i === n) tween1.push(t);
|
|
1928
|
+
}
|
|
1929
|
+
schedule.tween = tween1;
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
function transition_tween(name, value) {
|
|
1933
|
+
var id = this._id;
|
|
1934
|
+
name += "";
|
|
1935
|
+
if (arguments.length < 2) {
|
|
1936
|
+
var tween = get(this.node(), id).tween;
|
|
1937
|
+
for(var i = 0, n = tween.length, t; i < n; ++i){
|
|
1938
|
+
if ((t = tween[i]).name === name) {
|
|
1939
|
+
return t.value;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return null;
|
|
1943
|
+
}
|
|
1944
|
+
return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
|
|
1945
|
+
}
|
|
1946
|
+
function tweenValue(transition, name, value) {
|
|
1947
|
+
var id = transition._id;
|
|
1948
|
+
transition.each(function() {
|
|
1949
|
+
var schedule = set(this, id);
|
|
1950
|
+
(schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
|
|
1951
|
+
});
|
|
1952
|
+
return function(node) {
|
|
1953
|
+
return get(node, id).value[name];
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
function interpolate(a, b) {
|
|
1958
|
+
var c;
|
|
1959
|
+
return (typeof b === "number" ? interpolateNumber : b instanceof color ? interpolateRgb : (c = color(b)) ? (b = c, interpolateRgb) : interpolateString)(a, b);
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
function attrRemove(name) {
|
|
1963
|
+
return function() {
|
|
1964
|
+
this.removeAttribute(name);
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
function attrRemoveNS(fullname) {
|
|
1968
|
+
return function() {
|
|
1969
|
+
this.removeAttributeNS(fullname.space, fullname.local);
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
function attrConstant(name, interpolate, value1) {
|
|
1973
|
+
var string00, string1 = value1 + "", interpolate0;
|
|
1974
|
+
return function() {
|
|
1975
|
+
var string0 = this.getAttribute(name);
|
|
1976
|
+
return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate(string00 = string0, value1);
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
function attrConstantNS(fullname, interpolate, value1) {
|
|
1980
|
+
var string00, string1 = value1 + "", interpolate0;
|
|
1981
|
+
return function() {
|
|
1982
|
+
var string0 = this.getAttributeNS(fullname.space, fullname.local);
|
|
1983
|
+
return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate(string00 = string0, value1);
|
|
1984
|
+
};
|
|
1985
|
+
}
|
|
1986
|
+
function attrFunction(name, interpolate, value) {
|
|
1987
|
+
var string00, string10, interpolate0;
|
|
1988
|
+
return function() {
|
|
1989
|
+
var string0, value1 = value(this), string1;
|
|
1990
|
+
if (value1 == null) return void this.removeAttribute(name);
|
|
1991
|
+
string0 = this.getAttribute(name);
|
|
1992
|
+
string1 = value1 + "";
|
|
1993
|
+
return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
function attrFunctionNS(fullname, interpolate, value) {
|
|
1997
|
+
var string00, string10, interpolate0;
|
|
1998
|
+
return function() {
|
|
1999
|
+
var string0, value1 = value(this), string1;
|
|
2000
|
+
if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
|
|
2001
|
+
string0 = this.getAttributeNS(fullname.space, fullname.local);
|
|
2002
|
+
string1 = value1 + "";
|
|
2003
|
+
return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
function transition_attr(name, value) {
|
|
2007
|
+
var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
|
|
2008
|
+
return this.attrTween(name, typeof value === "function" ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value)) : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname) : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
function attrInterpolate(name, i) {
|
|
2012
|
+
return function(t) {
|
|
2013
|
+
this.setAttribute(name, i.call(this, t));
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
function attrInterpolateNS(fullname, i) {
|
|
2017
|
+
return function(t) {
|
|
2018
|
+
this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
function attrTweenNS(fullname, value) {
|
|
2022
|
+
var t0, i0;
|
|
2023
|
+
function tween() {
|
|
2024
|
+
var i = value.apply(this, arguments);
|
|
2025
|
+
if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
|
|
2026
|
+
return t0;
|
|
2027
|
+
}
|
|
2028
|
+
tween._value = value;
|
|
2029
|
+
return tween;
|
|
2030
|
+
}
|
|
2031
|
+
function attrTween(name, value) {
|
|
2032
|
+
var t0, i0;
|
|
2033
|
+
function tween() {
|
|
2034
|
+
var i = value.apply(this, arguments);
|
|
2035
|
+
if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
|
|
2036
|
+
return t0;
|
|
2037
|
+
}
|
|
2038
|
+
tween._value = value;
|
|
2039
|
+
return tween;
|
|
2040
|
+
}
|
|
2041
|
+
function transition_attrTween(name, value) {
|
|
2042
|
+
var key = "attr." + name;
|
|
2043
|
+
if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
|
2044
|
+
if (value == null) return this.tween(key, null);
|
|
2045
|
+
if (typeof value !== "function") throw new Error;
|
|
2046
|
+
var fullname = namespace(name);
|
|
2047
|
+
return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
function delayFunction(id, value) {
|
|
2051
|
+
return function() {
|
|
2052
|
+
init(this, id).delay = +value.apply(this, arguments);
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
function delayConstant(id, value) {
|
|
2056
|
+
return value = +value, function() {
|
|
2057
|
+
init(this, id).delay = value;
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
function transition_delay(value) {
|
|
2061
|
+
var id = this._id;
|
|
2062
|
+
return arguments.length ? this.each((typeof value === "function" ? delayFunction : delayConstant)(id, value)) : get(this.node(), id).delay;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
function durationFunction(id, value) {
|
|
2066
|
+
return function() {
|
|
2067
|
+
set(this, id).duration = +value.apply(this, arguments);
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
2070
|
+
function durationConstant(id, value) {
|
|
2071
|
+
return value = +value, function() {
|
|
2072
|
+
set(this, id).duration = value;
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
function transition_duration(value) {
|
|
2076
|
+
var id = this._id;
|
|
2077
|
+
return arguments.length ? this.each((typeof value === "function" ? durationFunction : durationConstant)(id, value)) : get(this.node(), id).duration;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
function easeConstant(id, value) {
|
|
2081
|
+
if (typeof value !== "function") throw new Error;
|
|
2082
|
+
return function() {
|
|
2083
|
+
set(this, id).ease = value;
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
function transition_ease(value) {
|
|
2087
|
+
var id = this._id;
|
|
2088
|
+
return arguments.length ? this.each(easeConstant(id, value)) : get(this.node(), id).ease;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
function easeVarying(id, value) {
|
|
2092
|
+
return function() {
|
|
2093
|
+
var v = value.apply(this, arguments);
|
|
2094
|
+
if (typeof v !== "function") throw new Error;
|
|
2095
|
+
set(this, id).ease = v;
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
function transition_easeVarying(value) {
|
|
2099
|
+
if (typeof value !== "function") throw new Error;
|
|
2100
|
+
return this.each(easeVarying(this._id, value));
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
function transition_filter(match) {
|
|
2104
|
+
if (typeof match !== "function") match = matcher(match);
|
|
2105
|
+
for(var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j){
|
|
2106
|
+
for(var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i){
|
|
2107
|
+
if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
|
2108
|
+
subgroup.push(node);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
return new Transition(subgroups, this._parents, this._name, this._id);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
function transition_merge(transition) {
|
|
2116
|
+
if (transition._id !== this._id) throw new Error;
|
|
2117
|
+
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){
|
|
2118
|
+
for(var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i){
|
|
2119
|
+
if (node = group0[i] || group1[i]) {
|
|
2120
|
+
merge[i] = node;
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
for(; j < m0; ++j){
|
|
2125
|
+
merges[j] = groups0[j];
|
|
2126
|
+
}
|
|
2127
|
+
return new Transition(merges, this._parents, this._name, this._id);
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
function start(name) {
|
|
2131
|
+
return (name + "").trim().split(/^|\s+/).every(function(t) {
|
|
2132
|
+
var i = t.indexOf(".");
|
|
2133
|
+
if (i >= 0) t = t.slice(0, i);
|
|
2134
|
+
return !t || t === "start";
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
function onFunction(id, name, listener) {
|
|
2138
|
+
var on0, on1, sit = start(name) ? init : set;
|
|
2139
|
+
return function() {
|
|
2140
|
+
var schedule = sit(this, id), on = schedule.on;
|
|
2141
|
+
// If this node shared a dispatch with the previous node,
|
|
2142
|
+
// just assign the updated shared dispatch and we’re done!
|
|
2143
|
+
// Otherwise, copy-on-write.
|
|
2144
|
+
if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
|
|
2145
|
+
schedule.on = on1;
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
function transition_on(name, listener) {
|
|
2149
|
+
var id = this._id;
|
|
2150
|
+
return arguments.length < 2 ? get(this.node(), id).on.on(name) : this.each(onFunction(id, name, listener));
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
function removeFunction(id) {
|
|
2154
|
+
return function() {
|
|
2155
|
+
var parent = this.parentNode;
|
|
2156
|
+
for(var i in this.__transition)if (+i !== id) return;
|
|
2157
|
+
if (parent) parent.removeChild(this);
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
function transition_remove() {
|
|
2161
|
+
return this.on("end.remove", removeFunction(this._id));
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
function transition_select(select) {
|
|
2165
|
+
var name = this._name, id = this._id;
|
|
2166
|
+
if (typeof select !== "function") select = selector(select);
|
|
2167
|
+
for(var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j){
|
|
2168
|
+
for(var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i){
|
|
2169
|
+
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
|
2170
|
+
if ("__data__" in node) subnode.__data__ = node.__data__;
|
|
2171
|
+
subgroup[i] = subnode;
|
|
2172
|
+
schedule(subgroup[i], name, id, i, subgroup, get(node, id));
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
return new Transition(subgroups, this._parents, name, id);
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
function transition_selectAll(select) {
|
|
2180
|
+
var name = this._name, id = this._id;
|
|
2181
|
+
if (typeof select !== "function") select = selectorAll(select);
|
|
2182
|
+
for(var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j){
|
|
2183
|
+
for(var group = groups[j], n = group.length, node, i = 0; i < n; ++i){
|
|
2184
|
+
if (node = group[i]) {
|
|
2185
|
+
for(var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k){
|
|
2186
|
+
if (child = children[k]) {
|
|
2187
|
+
schedule(child, name, id, k, children, inherit);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
subgroups.push(children);
|
|
2191
|
+
parents.push(node);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
return new Transition(subgroups, parents, name, id);
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
var Selection = selection.prototype.constructor;
|
|
2199
|
+
function transition_selection() {
|
|
2200
|
+
return new Selection(this._groups, this._parents);
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
function styleNull(name, interpolate) {
|
|
2204
|
+
var string00, string10, interpolate0;
|
|
2205
|
+
return function() {
|
|
2206
|
+
var string0 = styleValue(this, name), string1 = (this.style.removeProperty(name), styleValue(this, name));
|
|
2207
|
+
return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : interpolate0 = interpolate(string00 = string0, string10 = string1);
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
function styleRemove(name) {
|
|
2211
|
+
return function() {
|
|
2212
|
+
this.style.removeProperty(name);
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
function styleConstant(name, interpolate, value1) {
|
|
2216
|
+
var string00, string1 = value1 + "", interpolate0;
|
|
2217
|
+
return function() {
|
|
2218
|
+
var string0 = styleValue(this, name);
|
|
2219
|
+
return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate(string00 = string0, value1);
|
|
2220
|
+
};
|
|
2221
|
+
}
|
|
2222
|
+
function styleFunction(name, interpolate, value) {
|
|
2223
|
+
var string00, string10, interpolate0;
|
|
2224
|
+
return function() {
|
|
2225
|
+
var string0 = styleValue(this, name), value1 = value(this), string1 = value1 + "";
|
|
2226
|
+
if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
|
|
2227
|
+
return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
function styleMaybeRemove(id, name) {
|
|
2231
|
+
var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
|
|
2232
|
+
return function() {
|
|
2233
|
+
var schedule = set(this, id), on = schedule.on, listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
|
|
2234
|
+
// If this node shared a dispatch with the previous node,
|
|
2235
|
+
// just assign the updated shared dispatch and we’re done!
|
|
2236
|
+
// Otherwise, copy-on-write.
|
|
2237
|
+
if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
|
|
2238
|
+
schedule.on = on1;
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
function transition_style(name, value, priority) {
|
|
2242
|
+
var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
|
|
2243
|
+
return value == null ? this.styleTween(name, styleNull(name, i)).on("end.style." + name, styleRemove(name)) : typeof value === "function" ? this.styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value))).each(styleMaybeRemove(this._id, name)) : this.styleTween(name, styleConstant(name, i, value), priority).on("end.style." + name, null);
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
function styleInterpolate(name, i, priority) {
|
|
2247
|
+
return function(t) {
|
|
2248
|
+
this.style.setProperty(name, i.call(this, t), priority);
|
|
2249
|
+
};
|
|
2250
|
+
}
|
|
2251
|
+
function styleTween(name, value, priority) {
|
|
2252
|
+
var t, i0;
|
|
2253
|
+
function tween() {
|
|
2254
|
+
var i = value.apply(this, arguments);
|
|
2255
|
+
if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
|
|
2256
|
+
return t;
|
|
2257
|
+
}
|
|
2258
|
+
tween._value = value;
|
|
2259
|
+
return tween;
|
|
2260
|
+
}
|
|
2261
|
+
function transition_styleTween(name, value, priority) {
|
|
2262
|
+
var key = "style." + (name += "");
|
|
2263
|
+
if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
|
2264
|
+
if (value == null) return this.tween(key, null);
|
|
2265
|
+
if (typeof value !== "function") throw new Error;
|
|
2266
|
+
return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
function textConstant(value) {
|
|
2270
|
+
return function() {
|
|
2271
|
+
this.textContent = value;
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
function textFunction(value) {
|
|
2275
|
+
return function() {
|
|
2276
|
+
var value1 = value(this);
|
|
2277
|
+
this.textContent = value1 == null ? "" : value1;
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
function transition_text(value) {
|
|
2281
|
+
return this.tween("text", typeof value === "function" ? textFunction(tweenValue(this, "text", value)) : textConstant(value == null ? "" : value + ""));
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
function textInterpolate(i) {
|
|
2285
|
+
return function(t) {
|
|
2286
|
+
this.textContent = i.call(this, t);
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
function textTween(value) {
|
|
2290
|
+
var t0, i0;
|
|
2291
|
+
function tween() {
|
|
2292
|
+
var i = value.apply(this, arguments);
|
|
2293
|
+
if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
|
|
2294
|
+
return t0;
|
|
2295
|
+
}
|
|
2296
|
+
tween._value = value;
|
|
2297
|
+
return tween;
|
|
2298
|
+
}
|
|
2299
|
+
function transition_textTween(value) {
|
|
2300
|
+
var key = "text";
|
|
2301
|
+
if (arguments.length < 1) return (key = this.tween(key)) && key._value;
|
|
2302
|
+
if (value == null) return this.tween(key, null);
|
|
2303
|
+
if (typeof value !== "function") throw new Error;
|
|
2304
|
+
return this.tween(key, textTween(value));
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
function transition_transition() {
|
|
2308
|
+
var name = this._name, id0 = this._id, id1 = newId();
|
|
2309
|
+
for(var groups = this._groups, m = groups.length, j = 0; j < m; ++j){
|
|
2310
|
+
for(var group = groups[j], n = group.length, node, i = 0; i < n; ++i){
|
|
2311
|
+
if (node = group[i]) {
|
|
2312
|
+
var inherit = get(node, id0);
|
|
2313
|
+
schedule(node, name, id1, i, group, {
|
|
2314
|
+
time: inherit.time + inherit.delay + inherit.duration,
|
|
2315
|
+
delay: 0,
|
|
2316
|
+
duration: inherit.duration,
|
|
2317
|
+
ease: inherit.ease
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
return new Transition(groups, this._parents, name, id1);
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
function transition_end() {
|
|
2326
|
+
var on0, on1, that = this, id = that._id, size = that.size();
|
|
2327
|
+
return new Promise(function(resolve, reject) {
|
|
2328
|
+
var cancel = {
|
|
2329
|
+
value: reject
|
|
2330
|
+
}, end = {
|
|
2331
|
+
value: function() {
|
|
2332
|
+
if (--size === 0) resolve();
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
that.each(function() {
|
|
2336
|
+
var schedule = set(this, id), on = schedule.on;
|
|
2337
|
+
// If this node shared a dispatch with the previous node,
|
|
2338
|
+
// just assign the updated shared dispatch and we’re done!
|
|
2339
|
+
// Otherwise, copy-on-write.
|
|
2340
|
+
if (on !== on0) {
|
|
2341
|
+
on1 = (on0 = on).copy();
|
|
2342
|
+
on1._.cancel.push(cancel);
|
|
2343
|
+
on1._.interrupt.push(cancel);
|
|
2344
|
+
on1._.end.push(end);
|
|
2345
|
+
}
|
|
2346
|
+
schedule.on = on1;
|
|
2347
|
+
});
|
|
2348
|
+
// The selection was empty, resolve end immediately
|
|
2349
|
+
if (size === 0) resolve();
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
var id = 0;
|
|
2354
|
+
function Transition(groups, parents, name, id) {
|
|
2355
|
+
this._groups = groups;
|
|
2356
|
+
this._parents = parents;
|
|
2357
|
+
this._name = name;
|
|
2358
|
+
this._id = id;
|
|
2359
|
+
}
|
|
2360
|
+
function transition(name) {
|
|
2361
|
+
return selection().transition(name);
|
|
2362
|
+
}
|
|
2363
|
+
function newId() {
|
|
2364
|
+
return ++id;
|
|
2365
|
+
}
|
|
2366
|
+
var selection_prototype = selection.prototype;
|
|
2367
|
+
Transition.prototype = transition.prototype = {
|
|
2368
|
+
constructor: Transition,
|
|
2369
|
+
select: transition_select,
|
|
2370
|
+
selectAll: transition_selectAll,
|
|
2371
|
+
selectChild: selection_prototype.selectChild,
|
|
2372
|
+
selectChildren: selection_prototype.selectChildren,
|
|
2373
|
+
filter: transition_filter,
|
|
2374
|
+
merge: transition_merge,
|
|
2375
|
+
selection: transition_selection,
|
|
2376
|
+
transition: transition_transition,
|
|
2377
|
+
call: selection_prototype.call,
|
|
2378
|
+
nodes: selection_prototype.nodes,
|
|
2379
|
+
node: selection_prototype.node,
|
|
2380
|
+
size: selection_prototype.size,
|
|
2381
|
+
empty: selection_prototype.empty,
|
|
2382
|
+
each: selection_prototype.each,
|
|
2383
|
+
on: transition_on,
|
|
2384
|
+
attr: transition_attr,
|
|
2385
|
+
attrTween: transition_attrTween,
|
|
2386
|
+
style: transition_style,
|
|
2387
|
+
styleTween: transition_styleTween,
|
|
2388
|
+
text: transition_text,
|
|
2389
|
+
textTween: transition_textTween,
|
|
2390
|
+
remove: transition_remove,
|
|
2391
|
+
tween: transition_tween,
|
|
2392
|
+
delay: transition_delay,
|
|
2393
|
+
duration: transition_duration,
|
|
2394
|
+
ease: transition_ease,
|
|
2395
|
+
easeVarying: transition_easeVarying,
|
|
2396
|
+
end: transition_end,
|
|
2397
|
+
[Symbol.iterator]: selection_prototype[Symbol.iterator]
|
|
2398
|
+
};
|
|
2399
|
+
|
|
2400
|
+
function cubicInOut(t) {
|
|
2401
|
+
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
var defaultTiming = {
|
|
2405
|
+
time: null,
|
|
2406
|
+
delay: 0,
|
|
2407
|
+
duration: 250,
|
|
2408
|
+
ease: cubicInOut
|
|
2409
|
+
};
|
|
2410
|
+
function inherit(node, id) {
|
|
2411
|
+
var timing;
|
|
2412
|
+
while(!(timing = node.__transition) || !(timing = timing[id])){
|
|
2413
|
+
if (!(node = node.parentNode)) {
|
|
2414
|
+
throw new Error(`transition ${id} not found`);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
return timing;
|
|
2418
|
+
}
|
|
2419
|
+
function selection_transition(name) {
|
|
2420
|
+
var id, timing;
|
|
2421
|
+
if (name instanceof Transition) {
|
|
2422
|
+
id = name._id, name = name._name;
|
|
2423
|
+
} else {
|
|
2424
|
+
id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
|
|
2425
|
+
}
|
|
2426
|
+
for(var groups = this._groups, m = groups.length, j = 0; j < m; ++j){
|
|
2427
|
+
for(var group = groups[j], n = group.length, node, i = 0; i < n; ++i){
|
|
2428
|
+
if (node = group[i]) {
|
|
2429
|
+
schedule(node, name, id, i, group, timing || inherit(node, id));
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
return new Transition(groups, this._parents, name, id);
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
selection.prototype.interrupt = selection_interrupt;
|
|
2437
|
+
selection.prototype.transition = selection_transition;
|
|
2438
|
+
|
|
2439
|
+
/**
|
|
2440
|
+
@function elem
|
|
2441
|
+
@desc Manages the enter/update/exit pattern for a single DOM element.
|
|
2442
|
+
@param {String} selector A D3 selector, which must include the tagname and a class and/or ID.
|
|
2443
|
+
@param {Object} params Additional parameters.
|
|
2444
|
+
@param {Boolean} [params.condition = true] Whether or not the element should be rendered (or removed).
|
|
2445
|
+
@param {Object} [params.enter = {}] A collection of key/value pairs that map to attributes to be given on enter.
|
|
2446
|
+
@param {Object} [params.exit = {}] A collection of key/value pairs that map to attributes to be given on exit.
|
|
2447
|
+
@param {D3Selection} [params.parent = d3.select("body")] The parent element for this new element to be appended to.
|
|
2448
|
+
@param {Number} [params.duration = 0] The duration for the d3 transition.
|
|
2449
|
+
@param {Object} [params.update = {}] A collection of key/value pairs that map to attributes to be given on update.
|
|
2450
|
+
*/ function elem(selector, p) {
|
|
2451
|
+
// overrides default params
|
|
2452
|
+
p = Object.assign({}, {
|
|
2453
|
+
condition: true,
|
|
2454
|
+
enter: {},
|
|
2455
|
+
exit: {},
|
|
2456
|
+
duration: 0,
|
|
2457
|
+
parent: select("body"),
|
|
2458
|
+
update: {}
|
|
2459
|
+
}, p);
|
|
2460
|
+
const className = /\.([^#]+)/g.exec(selector), id = /#([^.]+)/g.exec(selector), t = transition().duration(p.duration), tag = /^([^.^#]+)/g.exec(selector)[1];
|
|
2461
|
+
const elem = p.parent.selectAll(selector.includes(":") ? selector.split(":")[1] : selector).data(p.condition ? [
|
|
2462
|
+
null
|
|
2463
|
+
] : []);
|
|
2464
|
+
const enter = elem.enter().append(tag).call(attrize, p.enter);
|
|
2465
|
+
if (id) enter.attr("id", id[1]);
|
|
2466
|
+
if (className) enter.attr("class", className[1]);
|
|
2467
|
+
if (p.duration) elem.exit().transition(t).call(attrize, p.exit).remove();
|
|
2468
|
+
else elem.exit().call(attrize, p.exit).remove();
|
|
2469
|
+
const update = enter.merge(elem);
|
|
2470
|
+
if (p.duration) update.transition(t).call(attrize, p.update);
|
|
2471
|
+
else update.call(attrize, p.update);
|
|
2472
|
+
return update;
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
/**
|
|
2476
|
+
* Strips HTML and "un-escapes" escape characters.
|
|
2477
|
+
* @param {String} input
|
|
2478
|
+
*/ function htmlDecode(input) {
|
|
2479
|
+
if (input.replace(/\s+/g, "") === "") return input;
|
|
2480
|
+
const doc = new DOMParser().parseFromString(input.replace(/<[^>]+>/g, ""), "text/html");
|
|
2481
|
+
return doc.documentElement ? doc.documentElement.textContent : input;
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
@function textWidth
|
|
2485
|
+
@desc Given a text string, returns the predicted pixel width of the string when placed into DOM.
|
|
2486
|
+
@param {String|Array} text Can be either a single string or an array of strings to analyze.
|
|
2487
|
+
@param {Object} [style] An object of CSS font styles to apply. Accepts any of the valid [CSS font property](http://www.w3schools.com/cssref/pr_font_font.asp) values.
|
|
2488
|
+
*/ function textWidth(text, style) {
|
|
2489
|
+
style = Object.assign({
|
|
2490
|
+
"font-size": 10,
|
|
2491
|
+
"font-family": "sans-serif",
|
|
2492
|
+
"font-style": "normal",
|
|
2493
|
+
"font-weight": 400,
|
|
2494
|
+
"font-variant": "normal"
|
|
2495
|
+
}, style);
|
|
2496
|
+
const context = document.createElement("canvas").getContext("2d");
|
|
2497
|
+
const font = [];
|
|
2498
|
+
font.push(style["font-style"]);
|
|
2499
|
+
font.push(style["font-variant"]);
|
|
2500
|
+
font.push(style["font-weight"]);
|
|
2501
|
+
font.push(typeof style["font-size"] === "string" ? style["font-size"] : `${style["font-size"]}px`);
|
|
2502
|
+
font.push(style["font-family"]);
|
|
2503
|
+
context.font = font.join(" ");
|
|
2504
|
+
if (text instanceof Array) return text.map((t)=>context.measureText(htmlDecode(t)).width);
|
|
2505
|
+
return context.measureText(htmlDecode(text)).width;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
/**
|
|
2509
|
+
@function trim
|
|
2510
|
+
@desc Cross-browser implementation of [trim](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim).
|
|
2511
|
+
@param {String} str
|
|
2512
|
+
*/ function trim(str) {
|
|
2513
|
+
return str.toString().replace(/^\s+|\s+$/g, "");
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
const alpha = "abcdefghiABCDEFGHI_!@#$%^&*()_+1234567890", checked = {}, height = 32;
|
|
2517
|
+
let dejavu, macos, monospace, proportional;
|
|
2518
|
+
/**
|
|
2519
|
+
@function fontExists
|
|
2520
|
+
@desc Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or `false` if none are installed on the user's machine.
|
|
2521
|
+
@param {String|Array} font Can be either a valid CSS font-family string (single or comma-separated names) or an Array of string names.
|
|
2522
|
+
*/ const fontExists = (font)=>{
|
|
2523
|
+
if (!dejavu) {
|
|
2524
|
+
dejavu = textWidth(alpha, {
|
|
2525
|
+
"font-family": "DejaVuSans",
|
|
2526
|
+
"font-size": height
|
|
2527
|
+
});
|
|
2528
|
+
macos = textWidth(alpha, {
|
|
2529
|
+
"font-family": "-apple-system",
|
|
2530
|
+
"font-size": height
|
|
2531
|
+
});
|
|
2532
|
+
monospace = textWidth(alpha, {
|
|
2533
|
+
"font-family": "monospace",
|
|
2534
|
+
"font-size": height
|
|
2535
|
+
});
|
|
2536
|
+
proportional = textWidth(alpha, {
|
|
2537
|
+
"font-family": "sans-serif",
|
|
2538
|
+
"font-size": height
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
if (!(font instanceof Array)) font = font.split(",");
|
|
2542
|
+
font = font.map((f)=>trim(f));
|
|
2543
|
+
for(let i = 0; i < font.length; i++){
|
|
2544
|
+
const fam = font[i];
|
|
2545
|
+
if (checked[fam] || [
|
|
2546
|
+
"-apple-system",
|
|
2547
|
+
"monospace",
|
|
2548
|
+
"sans-serif",
|
|
2549
|
+
"DejaVuSans"
|
|
2550
|
+
].includes(fam)) return fam;
|
|
2551
|
+
else if (checked[fam] === false) continue;
|
|
2552
|
+
const width = textWidth(alpha, {
|
|
2553
|
+
"font-family": fam,
|
|
2554
|
+
"font-size": height
|
|
2555
|
+
});
|
|
2556
|
+
checked[fam] = width !== monospace;
|
|
2557
|
+
if (checked[fam]) checked[fam] = width !== proportional;
|
|
2558
|
+
if (macos && checked[fam]) checked[fam] = width !== macos;
|
|
2559
|
+
if (dejavu && checked[fam]) checked[fam] = width !== dejavu;
|
|
2560
|
+
if (checked[fam]) return fam;
|
|
2561
|
+
}
|
|
2562
|
+
return false;
|
|
2563
|
+
};
|
|
2564
|
+
|
|
2565
|
+
/**
|
|
2566
|
+
@desc Given an HTMLElement and a "width" or "height" string, this function returns the current calculated size for the DOM element.
|
|
2567
|
+
@private
|
|
2568
|
+
*/ function _elementSize(element, s) {
|
|
2569
|
+
if (!element) return undefined;
|
|
2570
|
+
if (element.tagName === undefined || [
|
|
2571
|
+
"BODY",
|
|
2572
|
+
"HTML"
|
|
2573
|
+
].indexOf(element.tagName) >= 0) {
|
|
2574
|
+
let val = window[`inner${s.charAt(0).toUpperCase() + s.slice(1)}`];
|
|
2575
|
+
const elem = select(element);
|
|
2576
|
+
if (s === "width") {
|
|
2577
|
+
val -= parseFloat(elem.style("margin-left"), 10);
|
|
2578
|
+
val -= parseFloat(elem.style("margin-right"), 10);
|
|
2579
|
+
val -= parseFloat(elem.style("padding-left"), 10);
|
|
2580
|
+
val -= parseFloat(elem.style("padding-right"), 10);
|
|
2581
|
+
} else {
|
|
2582
|
+
val -= parseFloat(elem.style("margin-top"), 10);
|
|
2583
|
+
val -= parseFloat(elem.style("margin-bottom"), 10);
|
|
2584
|
+
val -= parseFloat(elem.style("padding-top"), 10);
|
|
2585
|
+
val -= parseFloat(elem.style("padding-bottom"), 10);
|
|
2586
|
+
}
|
|
2587
|
+
return val;
|
|
2588
|
+
} else {
|
|
2589
|
+
const val = parseFloat(select(element).style(s), 10);
|
|
2590
|
+
if (typeof val === "number" && val > 0) return val;
|
|
2591
|
+
else return _elementSize(element.parentNode, s);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
@function getSize
|
|
2596
|
+
@desc Finds the available width and height for a specified HTMLElement, traversing it's parents until it finds something with constrained dimensions. Falls back to the inner dimensions of the browser window if none is found.
|
|
2597
|
+
@param {HTMLElement} elem The HTMLElement to find dimensions for.
|
|
2598
|
+
@private
|
|
2599
|
+
*/ function getSize(elem) {
|
|
2600
|
+
return [
|
|
2601
|
+
_elementSize(elem, "width"),
|
|
2602
|
+
_elementSize(elem, "height")
|
|
2603
|
+
];
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
/**
|
|
2607
|
+
@module inViewport
|
|
2608
|
+
@desc Returns a *Boolean* denoting whether or not a given DOM element is visible in the current window.
|
|
2609
|
+
@param {DOMElement} elem The DOM element to analyze.
|
|
2610
|
+
@param {Number} [buffer = 0] A pixel offset from the edge of the top and bottom of the screen. If a positive value, the element will be deemed visible when it is that many pixels away from entering the viewport. If negative, the element will have to enter the viewport by that many pixels before being deemed visible.
|
|
2611
|
+
@private
|
|
2612
|
+
*/ function inViewport(elem, buffer = 0) {
|
|
2613
|
+
const pageX = window.pageXOffset !== undefined ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft;
|
|
2614
|
+
const pageY = window.pageYOffset !== undefined ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
|
|
2615
|
+
const bounds = elem.getBoundingClientRect();
|
|
2616
|
+
const height = bounds.height, left = bounds.left + pageX, top = bounds.top + pageY, width = bounds.width;
|
|
2617
|
+
return pageY + window.innerHeight > top + buffer && pageY + buffer < top + height && pageX + window.innerWidth > left + buffer && pageX + buffer < left + width;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
/**
|
|
2621
|
+
@function parseSides
|
|
2622
|
+
@desc Converts a string of directional CSS shorthand values into an object with the values expanded.
|
|
2623
|
+
@param {String|Number} sides The CSS shorthand string to expand.
|
|
2624
|
+
*/ function parseSides(sides) {
|
|
2625
|
+
let values;
|
|
2626
|
+
if (typeof sides === "number") values = [
|
|
2627
|
+
sides
|
|
2628
|
+
];
|
|
2629
|
+
else values = sides.split(/\s+/);
|
|
2630
|
+
if (values.length === 1) values = [
|
|
2631
|
+
values[0],
|
|
2632
|
+
values[0],
|
|
2633
|
+
values[0],
|
|
2634
|
+
values[0]
|
|
2635
|
+
];
|
|
2636
|
+
else if (values.length === 2) values = values.concat(values);
|
|
2637
|
+
else if (values.length === 3) values.push(values[1]);
|
|
2638
|
+
return [
|
|
2639
|
+
"top",
|
|
2640
|
+
"right",
|
|
2641
|
+
"bottom",
|
|
2642
|
+
"left"
|
|
2643
|
+
].reduce((acc, direction, i)=>{
|
|
2644
|
+
const value = parseFloat(values[i]);
|
|
2645
|
+
acc[direction] = value || 0;
|
|
2646
|
+
return acc;
|
|
2647
|
+
}, {});
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
/**
|
|
2651
|
+
@function prefix
|
|
2652
|
+
@desc Returns the appropriate CSS vendor prefix, given the current browser.
|
|
2653
|
+
*/ function prefix() {
|
|
2654
|
+
if ("-webkit-transform" in document.body.style) return "-webkit-";
|
|
2655
|
+
else if ("-moz-transform" in document.body.style) return "-moz-";
|
|
2656
|
+
else if ("-ms-transform" in document.body.style) return "-ms-";
|
|
2657
|
+
else if ("-o-transform" in document.body.style) return "-o-";
|
|
2658
|
+
else return "";
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2661
|
+
/**
|
|
2662
|
+
@function rtl
|
|
2663
|
+
@desc Returns `true` if the HTML or body element has either the "dir" HTML attribute or the "direction" CSS property set to "rtl".
|
|
2664
|
+
*/ var rtl = (()=>select("html").attr("dir") === "rtl" || select("body").attr("dir") === "rtl" || select("html").style("direction") === "rtl" || select("body").style("direction") === "rtl");
|
|
2665
|
+
|
|
2666
|
+
/**
|
|
2667
|
+
@function stylize
|
|
2668
|
+
@desc Applies each key/value in an object as a style.
|
|
2669
|
+
@param {D3selection} elem The D3 element to apply the styles to.
|
|
2670
|
+
@param {Object} styles An object of key/value style pairs.
|
|
2671
|
+
*/ function stylize(e, s = {}) {
|
|
2672
|
+
for(const k in s)if (({}).hasOwnProperty.call(s, k)) e.style(k, s[k]);
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
exports.assign = assign;
|
|
2676
|
+
exports.attrize = attrize;
|
|
2677
|
+
exports.date = date;
|
|
2678
|
+
exports.elem = elem;
|
|
2679
|
+
exports.fontExists = fontExists;
|
|
2680
|
+
exports.getSize = getSize;
|
|
2681
|
+
exports.inViewport = inViewport;
|
|
2682
|
+
exports.isObject = isObject;
|
|
2683
|
+
exports.parseSides = parseSides;
|
|
2684
|
+
exports.prefix = prefix;
|
|
2685
|
+
exports.rtl = rtl;
|
|
2686
|
+
exports.stylize = stylize;
|
|
2687
|
+
exports.textWidth = textWidth;
|
|
2688
|
+
|
|
2689
|
+
}));
|
|
2690
|
+
//# sourceMappingURL=d3plus-dom.full.js.map
|