tree.rb 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/d3js_layout_partition/data.js +787 -0
- data/examples/d3js_layout_partition/index.html +119 -0
- data/examples/d3js_layout_partition/run.sh +2 -0
- data/examples/{d3_treemap → d3js_layout_partition}/style.css +0 -0
- data/examples/d3js_layout_treemap/data.js +787 -0
- data/examples/d3js_layout_treemap/index.html +179 -0
- data/examples/d3js_layout_treemap/run.sh +2 -0
- data/examples/d3js_layout_treemap/style.css +89 -0
- data/examples/{directory_walker/directory_without_subdirectory.rb → ruby_examples/find_directory_without_subdirectory.rb} +2 -2
- data/examples/{directory_walker → ruby_examples}/find_files.rb +2 -2
- data/examples/{directory_walker → ruby_examples}/print_files.rb +2 -2
- data/lib/tree_rb/cli/cli_tree.rb +25 -11
- data/lib/tree_rb/erb_render.rb +21 -0
- data/lib/tree_rb/version.rb +1 -1
- data/lib/tree_rb_cli.rb +2 -0
- metadata +14 -14
- data/examples/d3_treemap/d3.js +0 -4149
- data/examples/d3_treemap/d3.layout.js +0 -1890
- data/examples/d3_treemap/d3_tree_rb_output.json +0 -380
- data/examples/d3_treemap/d3_treemap.html +0 -177
- data/examples/d3_treemap/prova.html +0 -84
- data/examples/prova/flare.js +0 -381
- data/examples/prova/prova.html +0 -99
- data/examples/prova1/prova1.html +0 -22
data/examples/d3_treemap/d3.js
DELETED
@@ -1,4149 +0,0 @@
|
|
1
|
-
(function(){if (!Date.now) Date.now = function() {
|
2
|
-
return +new Date;
|
3
|
-
};
|
4
|
-
try {
|
5
|
-
document.createElement("div").style.setProperty("opacity", 0, "");
|
6
|
-
} catch (error) {
|
7
|
-
var d3_style_prototype = CSSStyleDeclaration.prototype,
|
8
|
-
d3_style_setProperty = d3_style_prototype.setProperty;
|
9
|
-
d3_style_prototype.setProperty = function(name, value, priority) {
|
10
|
-
d3_style_setProperty.call(this, name, value + "", priority);
|
11
|
-
};
|
12
|
-
}
|
13
|
-
d3 = {version: "2.4.4"}; // semver
|
14
|
-
var d3_array = d3_arraySlice; // conversion for NodeLists
|
15
|
-
|
16
|
-
function d3_arrayCopy(pseudoarray) {
|
17
|
-
var i = -1, n = pseudoarray.length, array = [];
|
18
|
-
while (++i < n) array.push(pseudoarray[i]);
|
19
|
-
return array;
|
20
|
-
}
|
21
|
-
|
22
|
-
function d3_arraySlice(pseudoarray) {
|
23
|
-
return Array.prototype.slice.call(pseudoarray);
|
24
|
-
}
|
25
|
-
|
26
|
-
try {
|
27
|
-
d3_array(document.documentElement.childNodes)[0].nodeType;
|
28
|
-
} catch(e) {
|
29
|
-
d3_array = d3_arrayCopy;
|
30
|
-
}
|
31
|
-
|
32
|
-
var d3_arraySubclass = [].__proto__?
|
33
|
-
|
34
|
-
// Until ECMAScript supports array subclassing, prototype injection works well.
|
35
|
-
function(array, prototype) {
|
36
|
-
array.__proto__ = prototype;
|
37
|
-
}:
|
38
|
-
|
39
|
-
// And if your browser doesn't support __proto__, we'll use direct extension.
|
40
|
-
function(array, prototype) {
|
41
|
-
for (var property in prototype) array[property] = prototype[property];
|
42
|
-
};
|
43
|
-
function d3_this() {
|
44
|
-
return this;
|
45
|
-
}
|
46
|
-
d3.functor = function(v) {
|
47
|
-
return typeof v === "function" ? v : function() { return v; };
|
48
|
-
};
|
49
|
-
// A getter-setter method that preserves the appropriate `this` context.
|
50
|
-
d3.rebind = function(object, method) {
|
51
|
-
return function() {
|
52
|
-
var x = method.apply(object, arguments);
|
53
|
-
return arguments.length ? object : x;
|
54
|
-
};
|
55
|
-
};
|
56
|
-
d3.ascending = function(a, b) {
|
57
|
-
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
58
|
-
};
|
59
|
-
d3.descending = function(a, b) {
|
60
|
-
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
61
|
-
};
|
62
|
-
d3.mean = function(array, f) {
|
63
|
-
var n = array.length,
|
64
|
-
a,
|
65
|
-
m = 0,
|
66
|
-
i = -1,
|
67
|
-
j = 0;
|
68
|
-
if (arguments.length === 1) {
|
69
|
-
while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
|
70
|
-
} else {
|
71
|
-
while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
|
72
|
-
}
|
73
|
-
return j ? m : undefined;
|
74
|
-
};
|
75
|
-
d3.median = function(array, f) {
|
76
|
-
if (arguments.length > 1) array = array.map(f);
|
77
|
-
array = array.filter(d3_number);
|
78
|
-
return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
|
79
|
-
};
|
80
|
-
d3.min = function(array, f) {
|
81
|
-
var i = -1,
|
82
|
-
n = array.length,
|
83
|
-
a,
|
84
|
-
b;
|
85
|
-
if (arguments.length === 1) {
|
86
|
-
while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
|
87
|
-
while (++i < n) if ((b = array[i]) != null && a > b) a = b;
|
88
|
-
} else {
|
89
|
-
while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
|
90
|
-
while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
|
91
|
-
}
|
92
|
-
return a;
|
93
|
-
};
|
94
|
-
d3.max = function(array, f) {
|
95
|
-
var i = -1,
|
96
|
-
n = array.length,
|
97
|
-
a,
|
98
|
-
b;
|
99
|
-
if (arguments.length === 1) {
|
100
|
-
while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
|
101
|
-
while (++i < n) if ((b = array[i]) != null && b > a) a = b;
|
102
|
-
} else {
|
103
|
-
while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
|
104
|
-
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
|
105
|
-
}
|
106
|
-
return a;
|
107
|
-
};
|
108
|
-
function d3_number(x) {
|
109
|
-
return x != null && !isNaN(x);
|
110
|
-
}
|
111
|
-
d3.sum = function(array, f) {
|
112
|
-
var s = 0,
|
113
|
-
n = array.length,
|
114
|
-
a,
|
115
|
-
i = -1;
|
116
|
-
|
117
|
-
if (arguments.length === 1) {
|
118
|
-
while (++i < n) if (!isNaN(a = +array[i])) s += a;
|
119
|
-
} else {
|
120
|
-
while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
|
121
|
-
}
|
122
|
-
|
123
|
-
return s;
|
124
|
-
};
|
125
|
-
// R-7 per <http://en.wikipedia.org/wiki/Quantile>
|
126
|
-
d3.quantile = function(values, p) {
|
127
|
-
var H = (values.length - 1) * p + 1,
|
128
|
-
h = Math.floor(H),
|
129
|
-
v = values[h - 1],
|
130
|
-
e = H - h;
|
131
|
-
return e ? v + e * (values[h] - v) : v;
|
132
|
-
};
|
133
|
-
d3.zip = function() {
|
134
|
-
if (!(n = arguments.length)) return [];
|
135
|
-
for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m;) {
|
136
|
-
for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n;) {
|
137
|
-
zip[j] = arguments[j][i];
|
138
|
-
}
|
139
|
-
}
|
140
|
-
return zips;
|
141
|
-
};
|
142
|
-
|
143
|
-
function d3_zipLength(d) {
|
144
|
-
return d.length;
|
145
|
-
}
|
146
|
-
// Locate the insertion point for x in a to maintain sorted order. The
|
147
|
-
// arguments lo and hi may be used to specify a subset of the array which should
|
148
|
-
// be considered; by default the entire array is used. If x is already present
|
149
|
-
// in a, the insertion point will be before (to the left of) any existing
|
150
|
-
// entries. The return value is suitable for use as the first argument to
|
151
|
-
// `array.splice` assuming that a is already sorted.
|
152
|
-
//
|
153
|
-
// The returned insertion point i partitions the array a into two halves so that
|
154
|
-
// all v < x for v in a[lo:i] for the left side and all v >= x for v in a[i:hi]
|
155
|
-
// for the right side.
|
156
|
-
d3.bisectLeft = function(a, x, lo, hi) {
|
157
|
-
if (arguments.length < 3) lo = 0;
|
158
|
-
if (arguments.length < 4) hi = a.length;
|
159
|
-
while (lo < hi) {
|
160
|
-
var mid = (lo + hi) >> 1;
|
161
|
-
if (a[mid] < x) lo = mid + 1;
|
162
|
-
else hi = mid;
|
163
|
-
}
|
164
|
-
return lo;
|
165
|
-
};
|
166
|
-
|
167
|
-
// Similar to bisectLeft, but returns an insertion point which comes after (to
|
168
|
-
// the right of) any existing entries of x in a.
|
169
|
-
//
|
170
|
-
// The returned insertion point i partitions the array into two halves so that
|
171
|
-
// all v <= x for v in a[lo:i] for the left side and all v > x for v in a[i:hi]
|
172
|
-
// for the right side.
|
173
|
-
d3.bisect =
|
174
|
-
d3.bisectRight = function(a, x, lo, hi) {
|
175
|
-
if (arguments.length < 3) lo = 0;
|
176
|
-
if (arguments.length < 4) hi = a.length;
|
177
|
-
while (lo < hi) {
|
178
|
-
var mid = (lo + hi) >> 1;
|
179
|
-
if (x < a[mid]) hi = mid;
|
180
|
-
else lo = mid + 1;
|
181
|
-
}
|
182
|
-
return lo;
|
183
|
-
};
|
184
|
-
d3.first = function(array, f) {
|
185
|
-
var i = 0,
|
186
|
-
n = array.length,
|
187
|
-
a = array[0],
|
188
|
-
b;
|
189
|
-
if (arguments.length === 1) f = d3.ascending;
|
190
|
-
while (++i < n) {
|
191
|
-
if (f.call(array, a, b = array[i]) > 0) {
|
192
|
-
a = b;
|
193
|
-
}
|
194
|
-
}
|
195
|
-
return a;
|
196
|
-
};
|
197
|
-
d3.last = function(array, f) {
|
198
|
-
var i = 0,
|
199
|
-
n = array.length,
|
200
|
-
a = array[0],
|
201
|
-
b;
|
202
|
-
if (arguments.length === 1) f = d3.ascending;
|
203
|
-
while (++i < n) {
|
204
|
-
if (f.call(array, a, b = array[i]) <= 0) {
|
205
|
-
a = b;
|
206
|
-
}
|
207
|
-
}
|
208
|
-
return a;
|
209
|
-
};
|
210
|
-
d3.nest = function() {
|
211
|
-
var nest = {},
|
212
|
-
keys = [],
|
213
|
-
sortKeys = [],
|
214
|
-
sortValues,
|
215
|
-
rollup;
|
216
|
-
|
217
|
-
function map(array, depth) {
|
218
|
-
if (depth >= keys.length) return rollup
|
219
|
-
? rollup.call(nest, array) : (sortValues
|
220
|
-
? array.sort(sortValues)
|
221
|
-
: array);
|
222
|
-
|
223
|
-
var i = -1,
|
224
|
-
n = array.length,
|
225
|
-
key = keys[depth++],
|
226
|
-
keyValue,
|
227
|
-
object,
|
228
|
-
o = {};
|
229
|
-
|
230
|
-
while (++i < n) {
|
231
|
-
if ((keyValue = key(object = array[i])) in o) {
|
232
|
-
o[keyValue].push(object);
|
233
|
-
} else {
|
234
|
-
o[keyValue] = [object];
|
235
|
-
}
|
236
|
-
}
|
237
|
-
|
238
|
-
for (keyValue in o) {
|
239
|
-
o[keyValue] = map(o[keyValue], depth);
|
240
|
-
}
|
241
|
-
|
242
|
-
return o;
|
243
|
-
}
|
244
|
-
|
245
|
-
function entries(map, depth) {
|
246
|
-
if (depth >= keys.length) return map;
|
247
|
-
|
248
|
-
var a = [],
|
249
|
-
sortKey = sortKeys[depth++],
|
250
|
-
key;
|
251
|
-
|
252
|
-
for (key in map) {
|
253
|
-
a.push({key: key, values: entries(map[key], depth)});
|
254
|
-
}
|
255
|
-
|
256
|
-
if (sortKey) a.sort(function(a, b) {
|
257
|
-
return sortKey(a.key, b.key);
|
258
|
-
});
|
259
|
-
|
260
|
-
return a;
|
261
|
-
}
|
262
|
-
|
263
|
-
nest.map = function(array) {
|
264
|
-
return map(array, 0);
|
265
|
-
};
|
266
|
-
|
267
|
-
nest.entries = function(array) {
|
268
|
-
return entries(map(array, 0), 0);
|
269
|
-
};
|
270
|
-
|
271
|
-
nest.key = function(d) {
|
272
|
-
keys.push(d);
|
273
|
-
return nest;
|
274
|
-
};
|
275
|
-
|
276
|
-
// Specifies the order for the most-recently specified key.
|
277
|
-
// Note: only applies to entries. Map keys are unordered!
|
278
|
-
nest.sortKeys = function(order) {
|
279
|
-
sortKeys[keys.length - 1] = order;
|
280
|
-
return nest;
|
281
|
-
};
|
282
|
-
|
283
|
-
// Specifies the order for leaf values.
|
284
|
-
// Applies to both maps and entries array.
|
285
|
-
nest.sortValues = function(order) {
|
286
|
-
sortValues = order;
|
287
|
-
return nest;
|
288
|
-
};
|
289
|
-
|
290
|
-
nest.rollup = function(f) {
|
291
|
-
rollup = f;
|
292
|
-
return nest;
|
293
|
-
};
|
294
|
-
|
295
|
-
return nest;
|
296
|
-
};
|
297
|
-
d3.keys = function(map) {
|
298
|
-
var keys = [];
|
299
|
-
for (var key in map) keys.push(key);
|
300
|
-
return keys;
|
301
|
-
};
|
302
|
-
d3.values = function(map) {
|
303
|
-
var values = [];
|
304
|
-
for (var key in map) values.push(map[key]);
|
305
|
-
return values;
|
306
|
-
};
|
307
|
-
d3.entries = function(map) {
|
308
|
-
var entries = [];
|
309
|
-
for (var key in map) entries.push({key: key, value: map[key]});
|
310
|
-
return entries;
|
311
|
-
};
|
312
|
-
d3.permute = function(array, indexes) {
|
313
|
-
var permutes = [],
|
314
|
-
i = -1,
|
315
|
-
n = indexes.length;
|
316
|
-
while (++i < n) permutes[i] = array[indexes[i]];
|
317
|
-
return permutes;
|
318
|
-
};
|
319
|
-
d3.merge = function(arrays) {
|
320
|
-
return Array.prototype.concat.apply([], arrays);
|
321
|
-
};
|
322
|
-
d3.split = function(array, f) {
|
323
|
-
var arrays = [],
|
324
|
-
values = [],
|
325
|
-
value,
|
326
|
-
i = -1,
|
327
|
-
n = array.length;
|
328
|
-
if (arguments.length < 2) f = d3_splitter;
|
329
|
-
while (++i < n) {
|
330
|
-
if (f.call(values, value = array[i], i)) {
|
331
|
-
values = [];
|
332
|
-
} else {
|
333
|
-
if (!values.length) arrays.push(values);
|
334
|
-
values.push(value);
|
335
|
-
}
|
336
|
-
}
|
337
|
-
return arrays;
|
338
|
-
};
|
339
|
-
|
340
|
-
function d3_splitter(d) {
|
341
|
-
return d == null;
|
342
|
-
}
|
343
|
-
function d3_collapse(s) {
|
344
|
-
return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " ");
|
345
|
-
}
|
346
|
-
/**
|
347
|
-
* @param {number} start
|
348
|
-
* @param {number=} stop
|
349
|
-
* @param {number=} step
|
350
|
-
*/
|
351
|
-
d3.range = function(start, stop, step) {
|
352
|
-
if (arguments.length < 3) {
|
353
|
-
step = 1;
|
354
|
-
if (arguments.length < 2) {
|
355
|
-
stop = start;
|
356
|
-
start = 0;
|
357
|
-
}
|
358
|
-
}
|
359
|
-
if ((stop - start) / step == Infinity) throw new Error("infinite range");
|
360
|
-
var range = [],
|
361
|
-
i = -1,
|
362
|
-
j;
|
363
|
-
if (step < 0) while ((j = start + step * ++i) > stop) range.push(j);
|
364
|
-
else while ((j = start + step * ++i) < stop) range.push(j);
|
365
|
-
return range;
|
366
|
-
};
|
367
|
-
d3.requote = function(s) {
|
368
|
-
return s.replace(d3_requote_re, "\\$&");
|
369
|
-
};
|
370
|
-
|
371
|
-
var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
|
372
|
-
d3.round = function(x, n) {
|
373
|
-
return n
|
374
|
-
? Math.round(x * Math.pow(10, n)) * Math.pow(10, -n)
|
375
|
-
: Math.round(x);
|
376
|
-
};
|
377
|
-
d3.xhr = function(url, mime, callback) {
|
378
|
-
var req = new XMLHttpRequest;
|
379
|
-
if (arguments.length < 3) callback = mime;
|
380
|
-
else if (mime && req.overrideMimeType) req.overrideMimeType(mime);
|
381
|
-
req.open("GET", url, true);
|
382
|
-
req.onreadystatechange = function() {
|
383
|
-
if (req.readyState === 4) callback(req.status < 300 ? req : null);
|
384
|
-
};
|
385
|
-
req.send(null);
|
386
|
-
};
|
387
|
-
d3.text = function(url, mime, callback) {
|
388
|
-
function ready(req) {
|
389
|
-
callback(req && req.responseText);
|
390
|
-
}
|
391
|
-
if (arguments.length < 3) {
|
392
|
-
callback = mime;
|
393
|
-
mime = null;
|
394
|
-
}
|
395
|
-
d3.xhr(url, mime, ready);
|
396
|
-
};
|
397
|
-
d3.json = function(url, callback) {
|
398
|
-
d3.text(url, "application/json", function(text) {
|
399
|
-
callback(text ? JSON.parse(text) : null);
|
400
|
-
});
|
401
|
-
};
|
402
|
-
d3.html = function(url, callback) {
|
403
|
-
d3.text(url, "text/html", function(text) {
|
404
|
-
if (text != null) { // Treat empty string as valid HTML.
|
405
|
-
var range = document.createRange();
|
406
|
-
range.selectNode(document.body);
|
407
|
-
text = range.createContextualFragment(text);
|
408
|
-
}
|
409
|
-
callback(text);
|
410
|
-
});
|
411
|
-
};
|
412
|
-
d3.xml = function(url, mime, callback) {
|
413
|
-
function ready(req) {
|
414
|
-
callback(req && req.responseXML);
|
415
|
-
}
|
416
|
-
if (arguments.length < 3) {
|
417
|
-
callback = mime;
|
418
|
-
mime = null;
|
419
|
-
}
|
420
|
-
d3.xhr(url, mime, ready);
|
421
|
-
};
|
422
|
-
d3.ns = {
|
423
|
-
|
424
|
-
prefix: {
|
425
|
-
svg: "http://www.w3.org/2000/svg",
|
426
|
-
xhtml: "http://www.w3.org/1999/xhtml",
|
427
|
-
xlink: "http://www.w3.org/1999/xlink",
|
428
|
-
xml: "http://www.w3.org/XML/1998/namespace",
|
429
|
-
xmlns: "http://www.w3.org/2000/xmlns/"
|
430
|
-
},
|
431
|
-
|
432
|
-
qualify: function(name) {
|
433
|
-
var i = name.indexOf(":");
|
434
|
-
return i < 0 ? name : {
|
435
|
-
space: d3.ns.prefix[name.substring(0, i)],
|
436
|
-
local: name.substring(i + 1)
|
437
|
-
};
|
438
|
-
}
|
439
|
-
|
440
|
-
};
|
441
|
-
/** @param {...string} types */
|
442
|
-
d3.dispatch = function(types) {
|
443
|
-
var dispatch = {},
|
444
|
-
type;
|
445
|
-
for (var i = 0, n = arguments.length; i < n; i++) {
|
446
|
-
type = arguments[i];
|
447
|
-
dispatch[type] = d3_dispatch(type);
|
448
|
-
}
|
449
|
-
return dispatch;
|
450
|
-
};
|
451
|
-
|
452
|
-
function d3_dispatch(type) {
|
453
|
-
var dispatch = {},
|
454
|
-
listeners = [];
|
455
|
-
|
456
|
-
dispatch.add = function(listener) {
|
457
|
-
for (var i = 0; i < listeners.length; i++) {
|
458
|
-
if (listeners[i].listener == listener) return dispatch; // already registered
|
459
|
-
}
|
460
|
-
listeners.push({listener: listener, on: true});
|
461
|
-
return dispatch;
|
462
|
-
};
|
463
|
-
|
464
|
-
dispatch.remove = function(listener) {
|
465
|
-
for (var i = 0; i < listeners.length; i++) {
|
466
|
-
var l = listeners[i];
|
467
|
-
if (l.listener == listener) {
|
468
|
-
l.on = false;
|
469
|
-
listeners = listeners.slice(0, i).concat(listeners.slice(i + 1));
|
470
|
-
break;
|
471
|
-
}
|
472
|
-
}
|
473
|
-
return dispatch;
|
474
|
-
};
|
475
|
-
|
476
|
-
dispatch.dispatch = function() {
|
477
|
-
var ls = listeners; // defensive reference
|
478
|
-
for (var i = 0, n = ls.length; i < n; i++) {
|
479
|
-
var l = ls[i];
|
480
|
-
if (l.on) l.listener.apply(this, arguments);
|
481
|
-
}
|
482
|
-
};
|
483
|
-
|
484
|
-
return dispatch;
|
485
|
-
};
|
486
|
-
// TODO align
|
487
|
-
d3.format = function(specifier) {
|
488
|
-
var match = d3_format_re.exec(specifier),
|
489
|
-
fill = match[1] || " ",
|
490
|
-
sign = match[3] || "",
|
491
|
-
zfill = match[5],
|
492
|
-
width = +match[6],
|
493
|
-
comma = match[7],
|
494
|
-
precision = match[8],
|
495
|
-
type = match[9],
|
496
|
-
scale = 1,
|
497
|
-
suffix = "",
|
498
|
-
integer = false;
|
499
|
-
|
500
|
-
if (precision) precision = +precision.substring(1);
|
501
|
-
|
502
|
-
if (zfill) {
|
503
|
-
fill = "0"; // TODO align = "=";
|
504
|
-
if (comma) width -= Math.floor((width - 1) / 4);
|
505
|
-
}
|
506
|
-
|
507
|
-
switch (type) {
|
508
|
-
case "n": comma = true; type = "g"; break;
|
509
|
-
case "%": scale = 100; suffix = "%"; type = "f"; break;
|
510
|
-
case "p": scale = 100; suffix = "%"; type = "r"; break;
|
511
|
-
case "d": integer = true; precision = 0; break;
|
512
|
-
case "s": scale = -1; type = "r"; break;
|
513
|
-
}
|
514
|
-
|
515
|
-
// If no precision is specified for r, fallback to general notation.
|
516
|
-
if (type == "r" && !precision) type = "g";
|
517
|
-
|
518
|
-
type = d3_format_types[type] || d3_format_typeDefault;
|
519
|
-
|
520
|
-
return function(value) {
|
521
|
-
|
522
|
-
// Return the empty string for floats formatted as ints.
|
523
|
-
if (integer && (value % 1)) return "";
|
524
|
-
|
525
|
-
// Convert negative to positive, and record the sign prefix.
|
526
|
-
var negative = (value < 0) && (value = -value) ? "\u2212" : sign;
|
527
|
-
|
528
|
-
// Apply the scale, computing it from the value's exponent for si format.
|
529
|
-
if (scale < 0) {
|
530
|
-
var prefix = d3.formatPrefix(value, precision);
|
531
|
-
value *= prefix.scale;
|
532
|
-
suffix = prefix.symbol;
|
533
|
-
} else {
|
534
|
-
value *= scale;
|
535
|
-
}
|
536
|
-
|
537
|
-
// Convert to the desired precision.
|
538
|
-
value = type(value, precision);
|
539
|
-
|
540
|
-
// If the fill character is 0, the sign and group is applied after the fill.
|
541
|
-
if (zfill) {
|
542
|
-
var length = value.length + negative.length;
|
543
|
-
if (length < width) value = new Array(width - length + 1).join(fill) + value;
|
544
|
-
if (comma) value = d3_format_group(value);
|
545
|
-
value = negative + value;
|
546
|
-
}
|
547
|
-
|
548
|
-
// Otherwise (e.g., space-filling), the sign and group is applied before.
|
549
|
-
else {
|
550
|
-
if (comma) value = d3_format_group(value);
|
551
|
-
value = negative + value;
|
552
|
-
var length = value.length;
|
553
|
-
if (length < width) value = new Array(width - length + 1).join(fill) + value;
|
554
|
-
}
|
555
|
-
|
556
|
-
return value + suffix;
|
557
|
-
};
|
558
|
-
};
|
559
|
-
|
560
|
-
// [[fill]align][sign][#][0][width][,][.precision][type]
|
561
|
-
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
|
562
|
-
|
563
|
-
var d3_format_types = {
|
564
|
-
g: function(x, p) { return x.toPrecision(p); },
|
565
|
-
e: function(x, p) { return x.toExponential(p); },
|
566
|
-
f: function(x, p) { return x.toFixed(p); },
|
567
|
-
r: function(x, p) { return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p))); }
|
568
|
-
};
|
569
|
-
|
570
|
-
function d3_format_precision(x, p) {
|
571
|
-
return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
|
572
|
-
}
|
573
|
-
|
574
|
-
function d3_format_typeDefault(x) {
|
575
|
-
return x + "";
|
576
|
-
}
|
577
|
-
|
578
|
-
// Apply comma grouping for thousands.
|
579
|
-
function d3_format_group(value) {
|
580
|
-
var i = value.lastIndexOf("."),
|
581
|
-
f = i >= 0 ? value.substring(i) : (i = value.length, ""),
|
582
|
-
t = [];
|
583
|
-
while (i > 0) t.push(value.substring(i -= 3, i + 3));
|
584
|
-
return t.reverse().join(",") + f;
|
585
|
-
}
|
586
|
-
var d3_formatPrefixes = ["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"].map(d3_formatPrefix);
|
587
|
-
|
588
|
-
d3.formatPrefix = function(value, precision) {
|
589
|
-
var i = 0;
|
590
|
-
if (value) {
|
591
|
-
if (value < 0) value *= -1;
|
592
|
-
if (precision) value = d3.round(value, d3_format_precision(value, precision));
|
593
|
-
i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
|
594
|
-
i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
|
595
|
-
}
|
596
|
-
return d3_formatPrefixes[8 + i / 3];
|
597
|
-
};
|
598
|
-
|
599
|
-
function d3_formatPrefix(d, i) {
|
600
|
-
return {
|
601
|
-
scale: Math.pow(10, (8 - i) * 3),
|
602
|
-
symbol: d
|
603
|
-
};
|
604
|
-
}
|
605
|
-
|
606
|
-
/*
|
607
|
-
* TERMS OF USE - EASING EQUATIONS
|
608
|
-
*
|
609
|
-
* Open source under the BSD License.
|
610
|
-
*
|
611
|
-
* Copyright 2001 Robert Penner
|
612
|
-
* All rights reserved.
|
613
|
-
*
|
614
|
-
* Redistribution and use in source and binary forms, with or without
|
615
|
-
* modification, are permitted provided that the following conditions are met:
|
616
|
-
*
|
617
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
618
|
-
* list of conditions and the following disclaimer.
|
619
|
-
*
|
620
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
621
|
-
* this list of conditions and the following disclaimer in the documentation
|
622
|
-
* and/or other materials provided with the distribution.
|
623
|
-
*
|
624
|
-
* - Neither the name of the author nor the names of contributors may be used to
|
625
|
-
* endorse or promote products derived from this software without specific
|
626
|
-
* prior written permission.
|
627
|
-
*
|
628
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
629
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
630
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
631
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
632
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
633
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
634
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
635
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
636
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
637
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
638
|
-
* POSSIBILITY OF SUCH DAMAGE.
|
639
|
-
*/
|
640
|
-
|
641
|
-
var d3_ease_quad = d3_ease_poly(2),
|
642
|
-
d3_ease_cubic = d3_ease_poly(3);
|
643
|
-
|
644
|
-
var d3_ease = {
|
645
|
-
linear: function() { return d3_ease_linear; },
|
646
|
-
poly: d3_ease_poly,
|
647
|
-
quad: function() { return d3_ease_quad; },
|
648
|
-
cubic: function() { return d3_ease_cubic; },
|
649
|
-
sin: function() { return d3_ease_sin; },
|
650
|
-
exp: function() { return d3_ease_exp; },
|
651
|
-
circle: function() { return d3_ease_circle; },
|
652
|
-
elastic: d3_ease_elastic,
|
653
|
-
back: d3_ease_back,
|
654
|
-
bounce: function() { return d3_ease_bounce; }
|
655
|
-
};
|
656
|
-
|
657
|
-
var d3_ease_mode = {
|
658
|
-
"in": function(f) { return f; },
|
659
|
-
"out": d3_ease_reverse,
|
660
|
-
"in-out": d3_ease_reflect,
|
661
|
-
"out-in": function(f) { return d3_ease_reflect(d3_ease_reverse(f)); }
|
662
|
-
};
|
663
|
-
|
664
|
-
d3.ease = function(name) {
|
665
|
-
var i = name.indexOf("-"),
|
666
|
-
t = i >= 0 ? name.substring(0, i) : name,
|
667
|
-
m = i >= 0 ? name.substring(i + 1) : "in";
|
668
|
-
return d3_ease_clamp(d3_ease_mode[m](d3_ease[t].apply(null, Array.prototype.slice.call(arguments, 1))));
|
669
|
-
};
|
670
|
-
|
671
|
-
function d3_ease_clamp(f) {
|
672
|
-
return function(t) {
|
673
|
-
return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
|
674
|
-
};
|
675
|
-
}
|
676
|
-
|
677
|
-
function d3_ease_reverse(f) {
|
678
|
-
return function(t) {
|
679
|
-
return 1 - f(1 - t);
|
680
|
-
};
|
681
|
-
}
|
682
|
-
|
683
|
-
function d3_ease_reflect(f) {
|
684
|
-
return function(t) {
|
685
|
-
return .5 * (t < .5 ? f(2 * t) : (2 - f(2 - 2 * t)));
|
686
|
-
};
|
687
|
-
}
|
688
|
-
|
689
|
-
function d3_ease_linear(t) {
|
690
|
-
return t;
|
691
|
-
}
|
692
|
-
|
693
|
-
function d3_ease_poly(e) {
|
694
|
-
return function(t) {
|
695
|
-
return Math.pow(t, e);
|
696
|
-
}
|
697
|
-
}
|
698
|
-
|
699
|
-
function d3_ease_sin(t) {
|
700
|
-
return 1 - Math.cos(t * Math.PI / 2);
|
701
|
-
}
|
702
|
-
|
703
|
-
function d3_ease_exp(t) {
|
704
|
-
return Math.pow(2, 10 * (t - 1));
|
705
|
-
}
|
706
|
-
|
707
|
-
function d3_ease_circle(t) {
|
708
|
-
return 1 - Math.sqrt(1 - t * t);
|
709
|
-
}
|
710
|
-
|
711
|
-
function d3_ease_elastic(a, p) {
|
712
|
-
var s;
|
713
|
-
if (arguments.length < 2) p = 0.45;
|
714
|
-
if (arguments.length < 1) { a = 1; s = p / 4; }
|
715
|
-
else s = p / (2 * Math.PI) * Math.asin(1 / a);
|
716
|
-
return function(t) {
|
717
|
-
return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * Math.PI / p);
|
718
|
-
};
|
719
|
-
}
|
720
|
-
|
721
|
-
function d3_ease_back(s) {
|
722
|
-
if (!s) s = 1.70158;
|
723
|
-
return function(t) {
|
724
|
-
return t * t * ((s + 1) * t - s);
|
725
|
-
};
|
726
|
-
}
|
727
|
-
|
728
|
-
function d3_ease_bounce(t) {
|
729
|
-
return t < 1 / 2.75 ? 7.5625 * t * t
|
730
|
-
: t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75
|
731
|
-
: t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375
|
732
|
-
: 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
|
733
|
-
}
|
734
|
-
d3.event = null;
|
735
|
-
d3.interpolate = function(a, b) {
|
736
|
-
var i = d3.interpolators.length, f;
|
737
|
-
while (--i >= 0 && !(f = d3.interpolators[i](a, b)));
|
738
|
-
return f;
|
739
|
-
};
|
740
|
-
|
741
|
-
d3.interpolateNumber = function(a, b) {
|
742
|
-
b -= a;
|
743
|
-
return function(t) { return a + b * t; };
|
744
|
-
};
|
745
|
-
|
746
|
-
d3.interpolateRound = function(a, b) {
|
747
|
-
b -= a;
|
748
|
-
return function(t) { return Math.round(a + b * t); };
|
749
|
-
};
|
750
|
-
|
751
|
-
d3.interpolateString = function(a, b) {
|
752
|
-
var m, // current match
|
753
|
-
i, // current index
|
754
|
-
j, // current index (for coallescing)
|
755
|
-
s0 = 0, // start index of current string prefix
|
756
|
-
s1 = 0, // end index of current string prefix
|
757
|
-
s = [], // string constants and placeholders
|
758
|
-
q = [], // number interpolators
|
759
|
-
n, // q.length
|
760
|
-
o;
|
761
|
-
|
762
|
-
// Reset our regular expression!
|
763
|
-
d3_interpolate_number.lastIndex = 0;
|
764
|
-
|
765
|
-
// Find all numbers in b.
|
766
|
-
for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
|
767
|
-
if (m.index) s.push(b.substring(s0, s1 = m.index));
|
768
|
-
q.push({i: s.length, x: m[0]});
|
769
|
-
s.push(null);
|
770
|
-
s0 = d3_interpolate_number.lastIndex;
|
771
|
-
}
|
772
|
-
if (s0 < b.length) s.push(b.substring(s0));
|
773
|
-
|
774
|
-
// Find all numbers in a.
|
775
|
-
for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
|
776
|
-
o = q[i];
|
777
|
-
if (o.x == m[0]) { // The numbers match, so coallesce.
|
778
|
-
if (o.i) {
|
779
|
-
if (s[o.i + 1] == null) { // This match is followed by another number.
|
780
|
-
s[o.i - 1] += o.x;
|
781
|
-
s.splice(o.i, 1);
|
782
|
-
for (j = i + 1; j < n; ++j) q[j].i--;
|
783
|
-
} else { // This match is followed by a string, so coallesce twice.
|
784
|
-
s[o.i - 1] += o.x + s[o.i + 1];
|
785
|
-
s.splice(o.i, 2);
|
786
|
-
for (j = i + 1; j < n; ++j) q[j].i -= 2;
|
787
|
-
}
|
788
|
-
} else {
|
789
|
-
if (s[o.i + 1] == null) { // This match is followed by another number.
|
790
|
-
s[o.i] = o.x;
|
791
|
-
} else { // This match is followed by a string, so coallesce twice.
|
792
|
-
s[o.i] = o.x + s[o.i + 1];
|
793
|
-
s.splice(o.i + 1, 1);
|
794
|
-
for (j = i + 1; j < n; ++j) q[j].i--;
|
795
|
-
}
|
796
|
-
}
|
797
|
-
q.splice(i, 1);
|
798
|
-
n--;
|
799
|
-
i--;
|
800
|
-
} else {
|
801
|
-
o.x = d3.interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
|
802
|
-
}
|
803
|
-
}
|
804
|
-
|
805
|
-
// Remove any numbers in b not found in a.
|
806
|
-
while (i < n) {
|
807
|
-
o = q.pop();
|
808
|
-
if (s[o.i + 1] == null) { // This match is followed by another number.
|
809
|
-
s[o.i] = o.x;
|
810
|
-
} else { // This match is followed by a string, so coallesce twice.
|
811
|
-
s[o.i] = o.x + s[o.i + 1];
|
812
|
-
s.splice(o.i + 1, 1);
|
813
|
-
}
|
814
|
-
n--;
|
815
|
-
}
|
816
|
-
|
817
|
-
// Special optimization for only a single match.
|
818
|
-
if (s.length === 1) {
|
819
|
-
return s[0] == null ? q[0].x : function() { return b; };
|
820
|
-
}
|
821
|
-
|
822
|
-
// Otherwise, interpolate each of the numbers and rejoin the string.
|
823
|
-
return function(t) {
|
824
|
-
for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
|
825
|
-
return s.join("");
|
826
|
-
};
|
827
|
-
};
|
828
|
-
|
829
|
-
d3.interpolateRgb = function(a, b) {
|
830
|
-
a = d3.rgb(a);
|
831
|
-
b = d3.rgb(b);
|
832
|
-
var ar = a.r,
|
833
|
-
ag = a.g,
|
834
|
-
ab = a.b,
|
835
|
-
br = b.r - ar,
|
836
|
-
bg = b.g - ag,
|
837
|
-
bb = b.b - ab;
|
838
|
-
return function(t) {
|
839
|
-
return "#"
|
840
|
-
+ d3_rgb_hex(Math.round(ar + br * t))
|
841
|
-
+ d3_rgb_hex(Math.round(ag + bg * t))
|
842
|
-
+ d3_rgb_hex(Math.round(ab + bb * t));
|
843
|
-
};
|
844
|
-
};
|
845
|
-
|
846
|
-
// interpolates HSL space, but outputs RGB string (for compatibility)
|
847
|
-
d3.interpolateHsl = function(a, b) {
|
848
|
-
a = d3.hsl(a);
|
849
|
-
b = d3.hsl(b);
|
850
|
-
var h0 = a.h,
|
851
|
-
s0 = a.s,
|
852
|
-
l0 = a.l,
|
853
|
-
h1 = b.h - h0,
|
854
|
-
s1 = b.s - s0,
|
855
|
-
l1 = b.l - l0;
|
856
|
-
return function(t) {
|
857
|
-
return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t).toString();
|
858
|
-
};
|
859
|
-
};
|
860
|
-
|
861
|
-
d3.interpolateArray = function(a, b) {
|
862
|
-
var x = [],
|
863
|
-
c = [],
|
864
|
-
na = a.length,
|
865
|
-
nb = b.length,
|
866
|
-
n0 = Math.min(a.length, b.length),
|
867
|
-
i;
|
868
|
-
for (i = 0; i < n0; ++i) x.push(d3.interpolate(a[i], b[i]));
|
869
|
-
for (; i < na; ++i) c[i] = a[i];
|
870
|
-
for (; i < nb; ++i) c[i] = b[i];
|
871
|
-
return function(t) {
|
872
|
-
for (i = 0; i < n0; ++i) c[i] = x[i](t);
|
873
|
-
return c;
|
874
|
-
};
|
875
|
-
};
|
876
|
-
|
877
|
-
d3.interpolateObject = function(a, b) {
|
878
|
-
var i = {},
|
879
|
-
c = {},
|
880
|
-
k;
|
881
|
-
for (k in a) {
|
882
|
-
if (k in b) {
|
883
|
-
i[k] = d3_interpolateByName(k)(a[k], b[k]);
|
884
|
-
} else {
|
885
|
-
c[k] = a[k];
|
886
|
-
}
|
887
|
-
}
|
888
|
-
for (k in b) {
|
889
|
-
if (!(k in a)) {
|
890
|
-
c[k] = b[k];
|
891
|
-
}
|
892
|
-
}
|
893
|
-
return function(t) {
|
894
|
-
for (k in i) c[k] = i[k](t);
|
895
|
-
return c;
|
896
|
-
};
|
897
|
-
}
|
898
|
-
|
899
|
-
var d3_interpolate_number = /[-+]?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:[eE][-]?\d+)?/g,
|
900
|
-
d3_interpolate_rgb = {background: 1, fill: 1, stroke: 1};
|
901
|
-
|
902
|
-
function d3_interpolateByName(n) {
|
903
|
-
return n in d3_interpolate_rgb || /\bcolor\b/.test(n)
|
904
|
-
? d3.interpolateRgb
|
905
|
-
: d3.interpolate;
|
906
|
-
}
|
907
|
-
|
908
|
-
d3.interpolators = [
|
909
|
-
d3.interpolateObject,
|
910
|
-
function(a, b) { return (b instanceof Array) && d3.interpolateArray(a, b); },
|
911
|
-
function(a, b) { return (typeof b === "string") && d3.interpolateString(String(a), b); },
|
912
|
-
function(a, b) { return (typeof b === "string" ? b in d3_rgb_names || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(String(a), b); },
|
913
|
-
function(a, b) { return (typeof b === "number") && d3.interpolateNumber(+a, b); }
|
914
|
-
];
|
915
|
-
function d3_uninterpolateNumber(a, b) {
|
916
|
-
b = b - (a = +a) ? 1 / (b - a) : 0;
|
917
|
-
return function(x) { return (x - a) * b; };
|
918
|
-
}
|
919
|
-
|
920
|
-
function d3_uninterpolateClamp(a, b) {
|
921
|
-
b = b - (a = +a) ? 1 / (b - a) : 0;
|
922
|
-
return function(x) { return Math.max(0, Math.min(1, (x - a) * b)); };
|
923
|
-
}
|
924
|
-
d3.rgb = function(r, g, b) {
|
925
|
-
return arguments.length === 1
|
926
|
-
? (r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b)
|
927
|
-
: d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb))
|
928
|
-
: d3_rgb(~~r, ~~g, ~~b);
|
929
|
-
};
|
930
|
-
|
931
|
-
function d3_rgb(r, g, b) {
|
932
|
-
return new d3_Rgb(r, g, b);
|
933
|
-
}
|
934
|
-
|
935
|
-
function d3_Rgb(r, g, b) {
|
936
|
-
this.r = r;
|
937
|
-
this.g = g;
|
938
|
-
this.b = b;
|
939
|
-
}
|
940
|
-
|
941
|
-
d3_Rgb.prototype.brighter = function(k) {
|
942
|
-
k = Math.pow(0.7, arguments.length ? k : 1);
|
943
|
-
var r = this.r,
|
944
|
-
g = this.g,
|
945
|
-
b = this.b,
|
946
|
-
i = 30;
|
947
|
-
if (!r && !g && !b) return d3_rgb(i, i, i);
|
948
|
-
if (r && r < i) r = i;
|
949
|
-
if (g && g < i) g = i;
|
950
|
-
if (b && b < i) b = i;
|
951
|
-
return d3_rgb(
|
952
|
-
Math.min(255, Math.floor(r / k)),
|
953
|
-
Math.min(255, Math.floor(g / k)),
|
954
|
-
Math.min(255, Math.floor(b / k)));
|
955
|
-
};
|
956
|
-
|
957
|
-
d3_Rgb.prototype.darker = function(k) {
|
958
|
-
k = Math.pow(0.7, arguments.length ? k : 1);
|
959
|
-
return d3_rgb(
|
960
|
-
Math.floor(k * this.r),
|
961
|
-
Math.floor(k * this.g),
|
962
|
-
Math.floor(k * this.b));
|
963
|
-
};
|
964
|
-
|
965
|
-
d3_Rgb.prototype.hsl = function() {
|
966
|
-
return d3_rgb_hsl(this.r, this.g, this.b);
|
967
|
-
};
|
968
|
-
|
969
|
-
d3_Rgb.prototype.toString = function() {
|
970
|
-
return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
|
971
|
-
};
|
972
|
-
|
973
|
-
function d3_rgb_hex(v) {
|
974
|
-
return v < 0x10
|
975
|
-
? "0" + Math.max(0, v).toString(16)
|
976
|
-
: Math.min(255, v).toString(16);
|
977
|
-
}
|
978
|
-
|
979
|
-
function d3_rgb_parse(format, rgb, hsl) {
|
980
|
-
var r = 0, // red channel; int in [0, 255]
|
981
|
-
g = 0, // green channel; int in [0, 255]
|
982
|
-
b = 0, // blue channel; int in [0, 255]
|
983
|
-
m1, // CSS color specification match
|
984
|
-
m2, // CSS color specification type (e.g., rgb)
|
985
|
-
name;
|
986
|
-
|
987
|
-
/* Handle hsl, rgb. */
|
988
|
-
m1 = /([a-z]+)\((.*)\)/i.exec(format);
|
989
|
-
if (m1) {
|
990
|
-
m2 = m1[2].split(",");
|
991
|
-
switch (m1[1]) {
|
992
|
-
case "hsl": {
|
993
|
-
return hsl(
|
994
|
-
parseFloat(m2[0]), // degrees
|
995
|
-
parseFloat(m2[1]) / 100, // percentage
|
996
|
-
parseFloat(m2[2]) / 100 // percentage
|
997
|
-
);
|
998
|
-
}
|
999
|
-
case "rgb": {
|
1000
|
-
return rgb(
|
1001
|
-
d3_rgb_parseNumber(m2[0]),
|
1002
|
-
d3_rgb_parseNumber(m2[1]),
|
1003
|
-
d3_rgb_parseNumber(m2[2])
|
1004
|
-
);
|
1005
|
-
}
|
1006
|
-
}
|
1007
|
-
}
|
1008
|
-
|
1009
|
-
/* Named colors. */
|
1010
|
-
if (name = d3_rgb_names[format]) return rgb(name.r, name.g, name.b);
|
1011
|
-
|
1012
|
-
/* Hexadecimal colors: #rgb and #rrggbb. */
|
1013
|
-
if (format != null && format.charAt(0) === "#") {
|
1014
|
-
if (format.length === 4) {
|
1015
|
-
r = format.charAt(1); r += r;
|
1016
|
-
g = format.charAt(2); g += g;
|
1017
|
-
b = format.charAt(3); b += b;
|
1018
|
-
} else if (format.length === 7) {
|
1019
|
-
r = format.substring(1, 3);
|
1020
|
-
g = format.substring(3, 5);
|
1021
|
-
b = format.substring(5, 7);
|
1022
|
-
}
|
1023
|
-
r = parseInt(r, 16);
|
1024
|
-
g = parseInt(g, 16);
|
1025
|
-
b = parseInt(b, 16);
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
return rgb(r, g, b);
|
1029
|
-
}
|
1030
|
-
|
1031
|
-
function d3_rgb_hsl(r, g, b) {
|
1032
|
-
var min = Math.min(r /= 255, g /= 255, b /= 255),
|
1033
|
-
max = Math.max(r, g, b),
|
1034
|
-
d = max - min,
|
1035
|
-
h,
|
1036
|
-
s,
|
1037
|
-
l = (max + min) / 2;
|
1038
|
-
if (d) {
|
1039
|
-
s = l < .5 ? d / (max + min) : d / (2 - max - min);
|
1040
|
-
if (r == max) h = (g - b) / d + (g < b ? 6 : 0);
|
1041
|
-
else if (g == max) h = (b - r) / d + 2;
|
1042
|
-
else h = (r - g) / d + 4;
|
1043
|
-
h *= 60;
|
1044
|
-
} else {
|
1045
|
-
s = h = 0;
|
1046
|
-
}
|
1047
|
-
return d3_hsl(h, s, l);
|
1048
|
-
}
|
1049
|
-
|
1050
|
-
function d3_rgb_parseNumber(c) { // either integer or percentage
|
1051
|
-
var f = parseFloat(c);
|
1052
|
-
return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
|
1053
|
-
}
|
1054
|
-
|
1055
|
-
var d3_rgb_names = {
|
1056
|
-
aliceblue: "#f0f8ff",
|
1057
|
-
antiquewhite: "#faebd7",
|
1058
|
-
aqua: "#00ffff",
|
1059
|
-
aquamarine: "#7fffd4",
|
1060
|
-
azure: "#f0ffff",
|
1061
|
-
beige: "#f5f5dc",
|
1062
|
-
bisque: "#ffe4c4",
|
1063
|
-
black: "#000000",
|
1064
|
-
blanchedalmond: "#ffebcd",
|
1065
|
-
blue: "#0000ff",
|
1066
|
-
blueviolet: "#8a2be2",
|
1067
|
-
brown: "#a52a2a",
|
1068
|
-
burlywood: "#deb887",
|
1069
|
-
cadetblue: "#5f9ea0",
|
1070
|
-
chartreuse: "#7fff00",
|
1071
|
-
chocolate: "#d2691e",
|
1072
|
-
coral: "#ff7f50",
|
1073
|
-
cornflowerblue: "#6495ed",
|
1074
|
-
cornsilk: "#fff8dc",
|
1075
|
-
crimson: "#dc143c",
|
1076
|
-
cyan: "#00ffff",
|
1077
|
-
darkblue: "#00008b",
|
1078
|
-
darkcyan: "#008b8b",
|
1079
|
-
darkgoldenrod: "#b8860b",
|
1080
|
-
darkgray: "#a9a9a9",
|
1081
|
-
darkgreen: "#006400",
|
1082
|
-
darkgrey: "#a9a9a9",
|
1083
|
-
darkkhaki: "#bdb76b",
|
1084
|
-
darkmagenta: "#8b008b",
|
1085
|
-
darkolivegreen: "#556b2f",
|
1086
|
-
darkorange: "#ff8c00",
|
1087
|
-
darkorchid: "#9932cc",
|
1088
|
-
darkred: "#8b0000",
|
1089
|
-
darksalmon: "#e9967a",
|
1090
|
-
darkseagreen: "#8fbc8f",
|
1091
|
-
darkslateblue: "#483d8b",
|
1092
|
-
darkslategray: "#2f4f4f",
|
1093
|
-
darkslategrey: "#2f4f4f",
|
1094
|
-
darkturquoise: "#00ced1",
|
1095
|
-
darkviolet: "#9400d3",
|
1096
|
-
deeppink: "#ff1493",
|
1097
|
-
deepskyblue: "#00bfff",
|
1098
|
-
dimgray: "#696969",
|
1099
|
-
dimgrey: "#696969",
|
1100
|
-
dodgerblue: "#1e90ff",
|
1101
|
-
firebrick: "#b22222",
|
1102
|
-
floralwhite: "#fffaf0",
|
1103
|
-
forestgreen: "#228b22",
|
1104
|
-
fuchsia: "#ff00ff",
|
1105
|
-
gainsboro: "#dcdcdc",
|
1106
|
-
ghostwhite: "#f8f8ff",
|
1107
|
-
gold: "#ffd700",
|
1108
|
-
goldenrod: "#daa520",
|
1109
|
-
gray: "#808080",
|
1110
|
-
green: "#008000",
|
1111
|
-
greenyellow: "#adff2f",
|
1112
|
-
grey: "#808080",
|
1113
|
-
honeydew: "#f0fff0",
|
1114
|
-
hotpink: "#ff69b4",
|
1115
|
-
indianred: "#cd5c5c",
|
1116
|
-
indigo: "#4b0082",
|
1117
|
-
ivory: "#fffff0",
|
1118
|
-
khaki: "#f0e68c",
|
1119
|
-
lavender: "#e6e6fa",
|
1120
|
-
lavenderblush: "#fff0f5",
|
1121
|
-
lawngreen: "#7cfc00",
|
1122
|
-
lemonchiffon: "#fffacd",
|
1123
|
-
lightblue: "#add8e6",
|
1124
|
-
lightcoral: "#f08080",
|
1125
|
-
lightcyan: "#e0ffff",
|
1126
|
-
lightgoldenrodyellow: "#fafad2",
|
1127
|
-
lightgray: "#d3d3d3",
|
1128
|
-
lightgreen: "#90ee90",
|
1129
|
-
lightgrey: "#d3d3d3",
|
1130
|
-
lightpink: "#ffb6c1",
|
1131
|
-
lightsalmon: "#ffa07a",
|
1132
|
-
lightseagreen: "#20b2aa",
|
1133
|
-
lightskyblue: "#87cefa",
|
1134
|
-
lightslategray: "#778899",
|
1135
|
-
lightslategrey: "#778899",
|
1136
|
-
lightsteelblue: "#b0c4de",
|
1137
|
-
lightyellow: "#ffffe0",
|
1138
|
-
lime: "#00ff00",
|
1139
|
-
limegreen: "#32cd32",
|
1140
|
-
linen: "#faf0e6",
|
1141
|
-
magenta: "#ff00ff",
|
1142
|
-
maroon: "#800000",
|
1143
|
-
mediumaquamarine: "#66cdaa",
|
1144
|
-
mediumblue: "#0000cd",
|
1145
|
-
mediumorchid: "#ba55d3",
|
1146
|
-
mediumpurple: "#9370db",
|
1147
|
-
mediumseagreen: "#3cb371",
|
1148
|
-
mediumslateblue: "#7b68ee",
|
1149
|
-
mediumspringgreen: "#00fa9a",
|
1150
|
-
mediumturquoise: "#48d1cc",
|
1151
|
-
mediumvioletred: "#c71585",
|
1152
|
-
midnightblue: "#191970",
|
1153
|
-
mintcream: "#f5fffa",
|
1154
|
-
mistyrose: "#ffe4e1",
|
1155
|
-
moccasin: "#ffe4b5",
|
1156
|
-
navajowhite: "#ffdead",
|
1157
|
-
navy: "#000080",
|
1158
|
-
oldlace: "#fdf5e6",
|
1159
|
-
olive: "#808000",
|
1160
|
-
olivedrab: "#6b8e23",
|
1161
|
-
orange: "#ffa500",
|
1162
|
-
orangered: "#ff4500",
|
1163
|
-
orchid: "#da70d6",
|
1164
|
-
palegoldenrod: "#eee8aa",
|
1165
|
-
palegreen: "#98fb98",
|
1166
|
-
paleturquoise: "#afeeee",
|
1167
|
-
palevioletred: "#db7093",
|
1168
|
-
papayawhip: "#ffefd5",
|
1169
|
-
peachpuff: "#ffdab9",
|
1170
|
-
peru: "#cd853f",
|
1171
|
-
pink: "#ffc0cb",
|
1172
|
-
plum: "#dda0dd",
|
1173
|
-
powderblue: "#b0e0e6",
|
1174
|
-
purple: "#800080",
|
1175
|
-
red: "#ff0000",
|
1176
|
-
rosybrown: "#bc8f8f",
|
1177
|
-
royalblue: "#4169e1",
|
1178
|
-
saddlebrown: "#8b4513",
|
1179
|
-
salmon: "#fa8072",
|
1180
|
-
sandybrown: "#f4a460",
|
1181
|
-
seagreen: "#2e8b57",
|
1182
|
-
seashell: "#fff5ee",
|
1183
|
-
sienna: "#a0522d",
|
1184
|
-
silver: "#c0c0c0",
|
1185
|
-
skyblue: "#87ceeb",
|
1186
|
-
slateblue: "#6a5acd",
|
1187
|
-
slategray: "#708090",
|
1188
|
-
slategrey: "#708090",
|
1189
|
-
snow: "#fffafa",
|
1190
|
-
springgreen: "#00ff7f",
|
1191
|
-
steelblue: "#4682b4",
|
1192
|
-
tan: "#d2b48c",
|
1193
|
-
teal: "#008080",
|
1194
|
-
thistle: "#d8bfd8",
|
1195
|
-
tomato: "#ff6347",
|
1196
|
-
turquoise: "#40e0d0",
|
1197
|
-
violet: "#ee82ee",
|
1198
|
-
wheat: "#f5deb3",
|
1199
|
-
white: "#ffffff",
|
1200
|
-
whitesmoke: "#f5f5f5",
|
1201
|
-
yellow: "#ffff00",
|
1202
|
-
yellowgreen: "#9acd32"
|
1203
|
-
};
|
1204
|
-
|
1205
|
-
for (var d3_rgb_name in d3_rgb_names) {
|
1206
|
-
d3_rgb_names[d3_rgb_name] = d3_rgb_parse(
|
1207
|
-
d3_rgb_names[d3_rgb_name],
|
1208
|
-
d3_rgb,
|
1209
|
-
d3_hsl_rgb);
|
1210
|
-
}
|
1211
|
-
d3.hsl = function(h, s, l) {
|
1212
|
-
return arguments.length === 1
|
1213
|
-
? (h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l)
|
1214
|
-
: d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl))
|
1215
|
-
: d3_hsl(+h, +s, +l);
|
1216
|
-
};
|
1217
|
-
|
1218
|
-
function d3_hsl(h, s, l) {
|
1219
|
-
return new d3_Hsl(h, s, l);
|
1220
|
-
}
|
1221
|
-
|
1222
|
-
function d3_Hsl(h, s, l) {
|
1223
|
-
this.h = h;
|
1224
|
-
this.s = s;
|
1225
|
-
this.l = l;
|
1226
|
-
}
|
1227
|
-
|
1228
|
-
d3_Hsl.prototype.brighter = function(k) {
|
1229
|
-
k = Math.pow(0.7, arguments.length ? k : 1);
|
1230
|
-
return d3_hsl(this.h, this.s, this.l / k);
|
1231
|
-
};
|
1232
|
-
|
1233
|
-
d3_Hsl.prototype.darker = function(k) {
|
1234
|
-
k = Math.pow(0.7, arguments.length ? k : 1);
|
1235
|
-
return d3_hsl(this.h, this.s, k * this.l);
|
1236
|
-
};
|
1237
|
-
|
1238
|
-
d3_Hsl.prototype.rgb = function() {
|
1239
|
-
return d3_hsl_rgb(this.h, this.s, this.l);
|
1240
|
-
};
|
1241
|
-
|
1242
|
-
d3_Hsl.prototype.toString = function() {
|
1243
|
-
return this.rgb().toString();
|
1244
|
-
};
|
1245
|
-
|
1246
|
-
function d3_hsl_rgb(h, s, l) {
|
1247
|
-
var m1,
|
1248
|
-
m2;
|
1249
|
-
|
1250
|
-
/* Some simple corrections for h, s and l. */
|
1251
|
-
h = h % 360; if (h < 0) h += 360;
|
1252
|
-
s = s < 0 ? 0 : s > 1 ? 1 : s;
|
1253
|
-
l = l < 0 ? 0 : l > 1 ? 1 : l;
|
1254
|
-
|
1255
|
-
/* From FvD 13.37, CSS Color Module Level 3 */
|
1256
|
-
m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
|
1257
|
-
m1 = 2 * l - m2;
|
1258
|
-
|
1259
|
-
function v(h) {
|
1260
|
-
if (h > 360) h -= 360;
|
1261
|
-
else if (h < 0) h += 360;
|
1262
|
-
if (h < 60) return m1 + (m2 - m1) * h / 60;
|
1263
|
-
if (h < 180) return m2;
|
1264
|
-
if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
|
1265
|
-
return m1;
|
1266
|
-
}
|
1267
|
-
|
1268
|
-
function vv(h) {
|
1269
|
-
return Math.round(v(h) * 255);
|
1270
|
-
}
|
1271
|
-
|
1272
|
-
return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
|
1273
|
-
}
|
1274
|
-
function d3_selection(groups) {
|
1275
|
-
d3_arraySubclass(groups, d3_selectionPrototype);
|
1276
|
-
return groups;
|
1277
|
-
}
|
1278
|
-
|
1279
|
-
var d3_select = function(s, n) { return n.querySelector(s); },
|
1280
|
-
d3_selectAll = function(s, n) { return n.querySelectorAll(s); };
|
1281
|
-
|
1282
|
-
// Prefer Sizzle, if available.
|
1283
|
-
if (typeof Sizzle === "function") {
|
1284
|
-
d3_select = function(s, n) { return Sizzle(s, n)[0]; };
|
1285
|
-
d3_selectAll = function(s, n) { return Sizzle.uniqueSort(Sizzle(s, n)); };
|
1286
|
-
}
|
1287
|
-
|
1288
|
-
var d3_selectionPrototype = [];
|
1289
|
-
|
1290
|
-
d3.selection = function() {
|
1291
|
-
return d3_selectionRoot;
|
1292
|
-
};
|
1293
|
-
|
1294
|
-
d3.selection.prototype = d3_selectionPrototype;
|
1295
|
-
d3_selectionPrototype.select = function(selector) {
|
1296
|
-
var subgroups = [],
|
1297
|
-
subgroup,
|
1298
|
-
subnode,
|
1299
|
-
group,
|
1300
|
-
node;
|
1301
|
-
|
1302
|
-
if (typeof selector !== "function") selector = d3_selection_selector(selector);
|
1303
|
-
|
1304
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
1305
|
-
subgroups.push(subgroup = []);
|
1306
|
-
subgroup.parentNode = (group = this[j]).parentNode;
|
1307
|
-
for (var i = -1, n = group.length; ++i < n;) {
|
1308
|
-
if (node = group[i]) {
|
1309
|
-
subgroup.push(subnode = selector.call(node, node.__data__, i));
|
1310
|
-
if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
|
1311
|
-
} else {
|
1312
|
-
subgroup.push(null);
|
1313
|
-
}
|
1314
|
-
}
|
1315
|
-
}
|
1316
|
-
|
1317
|
-
return d3_selection(subgroups);
|
1318
|
-
};
|
1319
|
-
|
1320
|
-
function d3_selection_selector(selector) {
|
1321
|
-
return function() {
|
1322
|
-
return d3_select(selector, this);
|
1323
|
-
};
|
1324
|
-
}
|
1325
|
-
d3_selectionPrototype.selectAll = function(selector) {
|
1326
|
-
var subgroups = [],
|
1327
|
-
subgroup,
|
1328
|
-
node;
|
1329
|
-
|
1330
|
-
if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
|
1331
|
-
|
1332
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
1333
|
-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
|
1334
|
-
if (node = group[i]) {
|
1335
|
-
subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
|
1336
|
-
subgroup.parentNode = node;
|
1337
|
-
}
|
1338
|
-
}
|
1339
|
-
}
|
1340
|
-
|
1341
|
-
return d3_selection(subgroups);
|
1342
|
-
};
|
1343
|
-
|
1344
|
-
function d3_selection_selectorAll(selector) {
|
1345
|
-
return function() {
|
1346
|
-
return d3_selectAll(selector, this);
|
1347
|
-
};
|
1348
|
-
}
|
1349
|
-
d3_selectionPrototype.attr = function(name, value) {
|
1350
|
-
name = d3.ns.qualify(name);
|
1351
|
-
|
1352
|
-
// If no value is specified, return the first value.
|
1353
|
-
if (arguments.length < 2) {
|
1354
|
-
var node = this.node();
|
1355
|
-
return name.local
|
1356
|
-
? node.getAttributeNS(name.space, name.local)
|
1357
|
-
: node.getAttribute(name);
|
1358
|
-
}
|
1359
|
-
|
1360
|
-
function attrNull() {
|
1361
|
-
this.removeAttribute(name);
|
1362
|
-
}
|
1363
|
-
|
1364
|
-
function attrNullNS() {
|
1365
|
-
this.removeAttributeNS(name.space, name.local);
|
1366
|
-
}
|
1367
|
-
|
1368
|
-
function attrConstant() {
|
1369
|
-
this.setAttribute(name, value);
|
1370
|
-
}
|
1371
|
-
|
1372
|
-
function attrConstantNS() {
|
1373
|
-
this.setAttributeNS(name.space, name.local, value);
|
1374
|
-
}
|
1375
|
-
|
1376
|
-
function attrFunction() {
|
1377
|
-
var x = value.apply(this, arguments);
|
1378
|
-
if (x == null) this.removeAttribute(name);
|
1379
|
-
else this.setAttribute(name, x);
|
1380
|
-
}
|
1381
|
-
|
1382
|
-
function attrFunctionNS() {
|
1383
|
-
var x = value.apply(this, arguments);
|
1384
|
-
if (x == null) this.removeAttributeNS(name.space, name.local);
|
1385
|
-
else this.setAttributeNS(name.space, name.local, x);
|
1386
|
-
}
|
1387
|
-
|
1388
|
-
return this.each(value == null
|
1389
|
-
? (name.local ? attrNullNS : attrNull) : (typeof value === "function"
|
1390
|
-
? (name.local ? attrFunctionNS : attrFunction)
|
1391
|
-
: (name.local ? attrConstantNS : attrConstant)));
|
1392
|
-
};
|
1393
|
-
d3_selectionPrototype.classed = function(name, value) {
|
1394
|
-
var names = name.split(d3_selection_classedWhitespace),
|
1395
|
-
n = names.length,
|
1396
|
-
i = -1;
|
1397
|
-
if (arguments.length > 1) {
|
1398
|
-
while (++i < n) d3_selection_classed.call(this, names[i], value);
|
1399
|
-
return this;
|
1400
|
-
} else {
|
1401
|
-
while (++i < n) if (!d3_selection_classed.call(this, names[i])) return false;
|
1402
|
-
return true;
|
1403
|
-
}
|
1404
|
-
};
|
1405
|
-
|
1406
|
-
var d3_selection_classedWhitespace = /\s+/g;
|
1407
|
-
|
1408
|
-
function d3_selection_classed(name, value) {
|
1409
|
-
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");
|
1410
|
-
|
1411
|
-
// If no value is specified, return the first value.
|
1412
|
-
if (arguments.length < 2) {
|
1413
|
-
var node = this.node();
|
1414
|
-
if (c = node.classList) return c.contains(name);
|
1415
|
-
var c = node.className;
|
1416
|
-
re.lastIndex = 0;
|
1417
|
-
return re.test(c.baseVal != null ? c.baseVal : c);
|
1418
|
-
}
|
1419
|
-
|
1420
|
-
function classedAdd() {
|
1421
|
-
if (c = this.classList) return c.add(name);
|
1422
|
-
var c = this.className,
|
1423
|
-
cb = c.baseVal != null,
|
1424
|
-
cv = cb ? c.baseVal : c;
|
1425
|
-
re.lastIndex = 0;
|
1426
|
-
if (!re.test(cv)) {
|
1427
|
-
cv = d3_collapse(cv + " " + name);
|
1428
|
-
if (cb) c.baseVal = cv;
|
1429
|
-
else this.className = cv;
|
1430
|
-
}
|
1431
|
-
}
|
1432
|
-
|
1433
|
-
function classedRemove() {
|
1434
|
-
if (c = this.classList) return c.remove(name);
|
1435
|
-
var c = this.className,
|
1436
|
-
cb = c.baseVal != null,
|
1437
|
-
cv = cb ? c.baseVal : c;
|
1438
|
-
cv = d3_collapse(cv.replace(re, " "));
|
1439
|
-
if (cb) c.baseVal = cv;
|
1440
|
-
else this.className = cv;
|
1441
|
-
}
|
1442
|
-
|
1443
|
-
function classedFunction() {
|
1444
|
-
(value.apply(this, arguments)
|
1445
|
-
? classedAdd
|
1446
|
-
: classedRemove).call(this);
|
1447
|
-
}
|
1448
|
-
|
1449
|
-
return this.each(typeof value === "function"
|
1450
|
-
? classedFunction : value
|
1451
|
-
? classedAdd
|
1452
|
-
: classedRemove);
|
1453
|
-
}
|
1454
|
-
d3_selectionPrototype.style = function(name, value, priority) {
|
1455
|
-
if (arguments.length < 3) priority = "";
|
1456
|
-
|
1457
|
-
// If no value is specified, return the first value.
|
1458
|
-
if (arguments.length < 2) return window
|
1459
|
-
.getComputedStyle(this.node(), null)
|
1460
|
-
.getPropertyValue(name);
|
1461
|
-
|
1462
|
-
function styleNull() {
|
1463
|
-
this.style.removeProperty(name);
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
function styleConstant() {
|
1467
|
-
this.style.setProperty(name, value, priority);
|
1468
|
-
}
|
1469
|
-
|
1470
|
-
function styleFunction() {
|
1471
|
-
var x = value.apply(this, arguments);
|
1472
|
-
if (x == null) this.style.removeProperty(name);
|
1473
|
-
else this.style.setProperty(name, x, priority);
|
1474
|
-
}
|
1475
|
-
|
1476
|
-
return this.each(value == null
|
1477
|
-
? styleNull : (typeof value === "function"
|
1478
|
-
? styleFunction : styleConstant));
|
1479
|
-
};
|
1480
|
-
d3_selectionPrototype.property = function(name, value) {
|
1481
|
-
|
1482
|
-
// If no value is specified, return the first value.
|
1483
|
-
if (arguments.length < 2) return this.node()[name];
|
1484
|
-
|
1485
|
-
function propertyNull() {
|
1486
|
-
delete this[name];
|
1487
|
-
}
|
1488
|
-
|
1489
|
-
function propertyConstant() {
|
1490
|
-
this[name] = value;
|
1491
|
-
}
|
1492
|
-
|
1493
|
-
function propertyFunction() {
|
1494
|
-
var x = value.apply(this, arguments);
|
1495
|
-
if (x == null) delete this[name];
|
1496
|
-
else this[name] = x;
|
1497
|
-
}
|
1498
|
-
|
1499
|
-
return this.each(value == null
|
1500
|
-
? propertyNull : (typeof value === "function"
|
1501
|
-
? propertyFunction : propertyConstant));
|
1502
|
-
};
|
1503
|
-
d3_selectionPrototype.text = function(value) {
|
1504
|
-
return arguments.length < 1 ? this.node().textContent
|
1505
|
-
: (this.each(typeof value === "function"
|
1506
|
-
? function() { this.textContent = value.apply(this, arguments); }
|
1507
|
-
: function() { this.textContent = value; }));
|
1508
|
-
};
|
1509
|
-
d3_selectionPrototype.html = function(value) {
|
1510
|
-
return arguments.length < 1 ? this.node().innerHTML
|
1511
|
-
: (this.each(typeof value === "function"
|
1512
|
-
? function() { this.innerHTML = value.apply(this, arguments); }
|
1513
|
-
: function() { this.innerHTML = value; }));
|
1514
|
-
};
|
1515
|
-
// TODO append(node)?
|
1516
|
-
// TODO append(function)?
|
1517
|
-
d3_selectionPrototype.append = function(name) {
|
1518
|
-
name = d3.ns.qualify(name);
|
1519
|
-
|
1520
|
-
function append() {
|
1521
|
-
return this.appendChild(document.createElement(name));
|
1522
|
-
}
|
1523
|
-
|
1524
|
-
function appendNS() {
|
1525
|
-
return this.appendChild(document.createElementNS(name.space, name.local));
|
1526
|
-
}
|
1527
|
-
|
1528
|
-
return this.select(name.local ? appendNS : append);
|
1529
|
-
};
|
1530
|
-
// TODO insert(node, function)?
|
1531
|
-
// TODO insert(function, string)?
|
1532
|
-
// TODO insert(function, function)?
|
1533
|
-
d3_selectionPrototype.insert = function(name, before) {
|
1534
|
-
name = d3.ns.qualify(name);
|
1535
|
-
|
1536
|
-
function insert() {
|
1537
|
-
return this.insertBefore(
|
1538
|
-
document.createElement(name),
|
1539
|
-
d3_select(before, this));
|
1540
|
-
}
|
1541
|
-
|
1542
|
-
function insertNS() {
|
1543
|
-
return this.insertBefore(
|
1544
|
-
document.createElementNS(name.space, name.local),
|
1545
|
-
d3_select(before, this));
|
1546
|
-
}
|
1547
|
-
|
1548
|
-
return this.select(name.local ? insertNS : insert);
|
1549
|
-
};
|
1550
|
-
// TODO remove(selector)?
|
1551
|
-
// TODO remove(node)?
|
1552
|
-
// TODO remove(function)?
|
1553
|
-
d3_selectionPrototype.remove = function() {
|
1554
|
-
return this.each(function() {
|
1555
|
-
var parent = this.parentNode;
|
1556
|
-
if (parent) parent.removeChild(this);
|
1557
|
-
});
|
1558
|
-
};
|
1559
|
-
// TODO data(null) for clearing data?
|
1560
|
-
d3_selectionPrototype.data = function(data, join) {
|
1561
|
-
var enter = [],
|
1562
|
-
update = [],
|
1563
|
-
exit = [];
|
1564
|
-
|
1565
|
-
function bind(group, groupData) {
|
1566
|
-
var i,
|
1567
|
-
n = group.length,
|
1568
|
-
m = groupData.length,
|
1569
|
-
n0 = Math.min(n, m),
|
1570
|
-
n1 = Math.max(n, m),
|
1571
|
-
updateNodes = [],
|
1572
|
-
enterNodes = [],
|
1573
|
-
exitNodes = [],
|
1574
|
-
node,
|
1575
|
-
nodeData;
|
1576
|
-
|
1577
|
-
if (join) {
|
1578
|
-
var nodeByKey = {},
|
1579
|
-
keys = [],
|
1580
|
-
key,
|
1581
|
-
j = groupData.length;
|
1582
|
-
|
1583
|
-
for (i = -1; ++i < n;) {
|
1584
|
-
key = join.call(node = group[i], node.__data__, i);
|
1585
|
-
if (key in nodeByKey) {
|
1586
|
-
exitNodes[j++] = node; // duplicate key
|
1587
|
-
} else {
|
1588
|
-
nodeByKey[key] = node;
|
1589
|
-
}
|
1590
|
-
keys.push(key);
|
1591
|
-
}
|
1592
|
-
|
1593
|
-
for (i = -1; ++i < m;) {
|
1594
|
-
node = nodeByKey[key = join.call(groupData, nodeData = groupData[i], i)];
|
1595
|
-
if (node) {
|
1596
|
-
node.__data__ = nodeData;
|
1597
|
-
updateNodes[i] = node;
|
1598
|
-
enterNodes[i] = exitNodes[i] = null;
|
1599
|
-
} else {
|
1600
|
-
enterNodes[i] = d3_selection_dataNode(nodeData);
|
1601
|
-
updateNodes[i] = exitNodes[i] = null;
|
1602
|
-
}
|
1603
|
-
delete nodeByKey[key];
|
1604
|
-
}
|
1605
|
-
|
1606
|
-
for (i = -1; ++i < n;) {
|
1607
|
-
if (keys[i] in nodeByKey) {
|
1608
|
-
exitNodes[i] = group[i];
|
1609
|
-
}
|
1610
|
-
}
|
1611
|
-
} else {
|
1612
|
-
for (i = -1; ++i < n0;) {
|
1613
|
-
node = group[i];
|
1614
|
-
nodeData = groupData[i];
|
1615
|
-
if (node) {
|
1616
|
-
node.__data__ = nodeData;
|
1617
|
-
updateNodes[i] = node;
|
1618
|
-
enterNodes[i] = exitNodes[i] = null;
|
1619
|
-
} else {
|
1620
|
-
enterNodes[i] = d3_selection_dataNode(nodeData);
|
1621
|
-
updateNodes[i] = exitNodes[i] = null;
|
1622
|
-
}
|
1623
|
-
}
|
1624
|
-
for (; i < m; ++i) {
|
1625
|
-
enterNodes[i] = d3_selection_dataNode(groupData[i]);
|
1626
|
-
updateNodes[i] = exitNodes[i] = null;
|
1627
|
-
}
|
1628
|
-
for (; i < n1; ++i) {
|
1629
|
-
exitNodes[i] = group[i];
|
1630
|
-
enterNodes[i] = updateNodes[i] = null;
|
1631
|
-
}
|
1632
|
-
}
|
1633
|
-
|
1634
|
-
enterNodes.update
|
1635
|
-
= updateNodes;
|
1636
|
-
|
1637
|
-
enterNodes.parentNode
|
1638
|
-
= updateNodes.parentNode
|
1639
|
-
= exitNodes.parentNode
|
1640
|
-
= group.parentNode;
|
1641
|
-
|
1642
|
-
enter.push(enterNodes);
|
1643
|
-
update.push(updateNodes);
|
1644
|
-
exit.push(exitNodes);
|
1645
|
-
}
|
1646
|
-
|
1647
|
-
var i = -1,
|
1648
|
-
n = this.length,
|
1649
|
-
group;
|
1650
|
-
if (typeof data === "function") {
|
1651
|
-
while (++i < n) {
|
1652
|
-
bind(group = this[i], data.call(group, group.parentNode.__data__, i));
|
1653
|
-
}
|
1654
|
-
} else {
|
1655
|
-
while (++i < n) {
|
1656
|
-
bind(group = this[i], data);
|
1657
|
-
}
|
1658
|
-
}
|
1659
|
-
|
1660
|
-
var selection = d3_selection(update);
|
1661
|
-
selection.enter = function() { return d3_selection_enter(enter); };
|
1662
|
-
selection.exit = function() { return d3_selection(exit); };
|
1663
|
-
return selection;
|
1664
|
-
};
|
1665
|
-
|
1666
|
-
function d3_selection_dataNode(data) {
|
1667
|
-
return {__data__: data};
|
1668
|
-
}
|
1669
|
-
function d3_selection_enter(selection) {
|
1670
|
-
d3_arraySubclass(selection, d3_selection_enterPrototype);
|
1671
|
-
return selection;
|
1672
|
-
}
|
1673
|
-
|
1674
|
-
var d3_selection_enterPrototype = [];
|
1675
|
-
|
1676
|
-
d3_selection_enterPrototype.append = d3_selectionPrototype.append;
|
1677
|
-
d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
|
1678
|
-
d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
|
1679
|
-
d3_selection_enterPrototype.select = function(selector) {
|
1680
|
-
var subgroups = [],
|
1681
|
-
subgroup,
|
1682
|
-
subnode,
|
1683
|
-
upgroup,
|
1684
|
-
group,
|
1685
|
-
node;
|
1686
|
-
|
1687
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
1688
|
-
upgroup = (group = this[j]).update;
|
1689
|
-
subgroups.push(subgroup = []);
|
1690
|
-
subgroup.parentNode = group.parentNode;
|
1691
|
-
for (var i = -1, n = group.length; ++i < n;) {
|
1692
|
-
if (node = group[i]) {
|
1693
|
-
subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
|
1694
|
-
subnode.__data__ = node.__data__;
|
1695
|
-
} else {
|
1696
|
-
subgroup.push(null);
|
1697
|
-
}
|
1698
|
-
}
|
1699
|
-
}
|
1700
|
-
|
1701
|
-
return d3_selection(subgroups);
|
1702
|
-
};
|
1703
|
-
// TODO preserve null elements to maintain index?
|
1704
|
-
d3_selectionPrototype.filter = function(filter) {
|
1705
|
-
var subgroups = [],
|
1706
|
-
subgroup,
|
1707
|
-
group,
|
1708
|
-
node;
|
1709
|
-
|
1710
|
-
for (var j = 0, m = this.length; j < m; j++) {
|
1711
|
-
subgroups.push(subgroup = []);
|
1712
|
-
subgroup.parentNode = (group = this[j]).parentNode;
|
1713
|
-
for (var i = 0, n = group.length; i < n; i++) {
|
1714
|
-
if ((node = group[i]) && filter.call(node, node.__data__, i)) {
|
1715
|
-
subgroup.push(node);
|
1716
|
-
}
|
1717
|
-
}
|
1718
|
-
}
|
1719
|
-
|
1720
|
-
return d3_selection(subgroups);
|
1721
|
-
};
|
1722
|
-
d3_selectionPrototype.map = function(map) {
|
1723
|
-
return this.each(function() {
|
1724
|
-
this.__data__ = map.apply(this, arguments);
|
1725
|
-
});
|
1726
|
-
};
|
1727
|
-
d3_selectionPrototype.sort = function(comparator) {
|
1728
|
-
comparator = d3_selection_sortComparator.apply(this, arguments);
|
1729
|
-
for (var j = 0, m = this.length; j < m; j++) {
|
1730
|
-
for (var group = this[j].sort(comparator), i = 1, n = group.length, prev = group[0]; i < n; i++) {
|
1731
|
-
var node = group[i];
|
1732
|
-
if (node) {
|
1733
|
-
if (prev) prev.parentNode.insertBefore(node, prev.nextSibling);
|
1734
|
-
prev = node;
|
1735
|
-
}
|
1736
|
-
}
|
1737
|
-
}
|
1738
|
-
return this;
|
1739
|
-
};
|
1740
|
-
|
1741
|
-
function d3_selection_sortComparator(comparator) {
|
1742
|
-
if (!arguments.length) comparator = d3.ascending;
|
1743
|
-
return function(a, b) {
|
1744
|
-
return comparator(a && a.__data__, b && b.__data__);
|
1745
|
-
};
|
1746
|
-
}
|
1747
|
-
// type can be namespaced, e.g., "click.foo"
|
1748
|
-
// listener can be null for removal
|
1749
|
-
d3_selectionPrototype.on = function(type, listener, capture) {
|
1750
|
-
if (arguments.length < 3) capture = false;
|
1751
|
-
|
1752
|
-
// parse the type specifier
|
1753
|
-
var name = "__on" + type, i = type.indexOf(".");
|
1754
|
-
if (i > 0) type = type.substring(0, i);
|
1755
|
-
|
1756
|
-
// if called with only one argument, return the current listener
|
1757
|
-
if (arguments.length < 2) return (i = this.node()[name]) && i._;
|
1758
|
-
|
1759
|
-
// remove the old event listener, and add the new event listener
|
1760
|
-
return this.each(function(d, i) {
|
1761
|
-
var node = this;
|
1762
|
-
|
1763
|
-
if (node[name]) node.removeEventListener(type, node[name], capture);
|
1764
|
-
if (listener) node.addEventListener(type, node[name] = l, capture);
|
1765
|
-
|
1766
|
-
// wrapped event listener that preserves i
|
1767
|
-
function l(e) {
|
1768
|
-
var o = d3.event; // Events can be reentrant (e.g., focus).
|
1769
|
-
d3.event = e;
|
1770
|
-
try {
|
1771
|
-
listener.call(node, node.__data__, i);
|
1772
|
-
} finally {
|
1773
|
-
d3.event = o;
|
1774
|
-
}
|
1775
|
-
}
|
1776
|
-
|
1777
|
-
// stash the unwrapped listener for retrieval
|
1778
|
-
l._ = listener;
|
1779
|
-
});
|
1780
|
-
};
|
1781
|
-
d3_selectionPrototype.each = function(callback) {
|
1782
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
1783
|
-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
|
1784
|
-
var node = group[i];
|
1785
|
-
if (node) callback.call(node, node.__data__, i, j);
|
1786
|
-
}
|
1787
|
-
}
|
1788
|
-
return this;
|
1789
|
-
};
|
1790
|
-
//
|
1791
|
-
// Note: assigning to the arguments array simultaneously changes the value of
|
1792
|
-
// the corresponding argument!
|
1793
|
-
//
|
1794
|
-
// TODO The `this` argument probably shouldn't be the first argument to the
|
1795
|
-
// callback, anyway, since it's redundant. However, that will require a major
|
1796
|
-
// version bump due to backwards compatibility, so I'm not changing it right
|
1797
|
-
// away.
|
1798
|
-
//
|
1799
|
-
d3_selectionPrototype.call = function(callback) {
|
1800
|
-
callback.apply(this, (arguments[0] = this, arguments));
|
1801
|
-
return this;
|
1802
|
-
};
|
1803
|
-
d3_selectionPrototype.empty = function() {
|
1804
|
-
return !this.node();
|
1805
|
-
};
|
1806
|
-
d3_selectionPrototype.node = function(callback) {
|
1807
|
-
for (var j = 0, m = this.length; j < m; j++) {
|
1808
|
-
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
|
1809
|
-
var node = group[i];
|
1810
|
-
if (node) return node;
|
1811
|
-
}
|
1812
|
-
}
|
1813
|
-
return null;
|
1814
|
-
};
|
1815
|
-
d3_selectionPrototype.transition = function() {
|
1816
|
-
var subgroups = [],
|
1817
|
-
subgroup,
|
1818
|
-
node;
|
1819
|
-
|
1820
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
1821
|
-
subgroups.push(subgroup = []);
|
1822
|
-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
|
1823
|
-
subgroup.push((node = group[i]) ? {node: node, delay: 0, duration: 250} : null);
|
1824
|
-
}
|
1825
|
-
}
|
1826
|
-
|
1827
|
-
return d3_transition(subgroups, d3_transitionInheritId || ++d3_transitionId, Date.now());
|
1828
|
-
};
|
1829
|
-
var d3_selectionRoot = d3_selection([[document]]);
|
1830
|
-
|
1831
|
-
d3_selectionRoot[0].parentNode = document.documentElement;
|
1832
|
-
|
1833
|
-
// TODO fast singleton implementation!
|
1834
|
-
// TODO select(function)
|
1835
|
-
d3.select = function(selector) {
|
1836
|
-
return typeof selector === "string"
|
1837
|
-
? d3_selectionRoot.select(selector)
|
1838
|
-
: d3_selection([[selector]]); // assume node
|
1839
|
-
};
|
1840
|
-
|
1841
|
-
// TODO selectAll(function)
|
1842
|
-
d3.selectAll = function(selector) {
|
1843
|
-
return typeof selector === "string"
|
1844
|
-
? d3_selectionRoot.selectAll(selector)
|
1845
|
-
: d3_selection([d3_array(selector)]); // assume node[]
|
1846
|
-
};
|
1847
|
-
function d3_transition(groups, id, time) {
|
1848
|
-
d3_arraySubclass(groups, d3_transitionPrototype);
|
1849
|
-
|
1850
|
-
var tweens = {},
|
1851
|
-
event = d3.dispatch("start", "end"),
|
1852
|
-
ease = d3_transitionEase;
|
1853
|
-
|
1854
|
-
groups.id = id;
|
1855
|
-
|
1856
|
-
groups.time = time;
|
1857
|
-
|
1858
|
-
groups.tween = function(name, tween) {
|
1859
|
-
if (arguments.length < 2) return tweens[name];
|
1860
|
-
if (tween == null) delete tweens[name];
|
1861
|
-
else tweens[name] = tween;
|
1862
|
-
return groups;
|
1863
|
-
};
|
1864
|
-
|
1865
|
-
groups.ease = function(value) {
|
1866
|
-
if (!arguments.length) return ease;
|
1867
|
-
ease = typeof value === "function" ? value : d3.ease.apply(d3, arguments);
|
1868
|
-
return groups;
|
1869
|
-
};
|
1870
|
-
|
1871
|
-
groups.each = function(type, listener) {
|
1872
|
-
if (arguments.length < 2) return d3_transition_each.call(groups, type);
|
1873
|
-
event[type].add(listener);
|
1874
|
-
return groups;
|
1875
|
-
};
|
1876
|
-
|
1877
|
-
d3.timer(function(elapsed) {
|
1878
|
-
groups.each(function(d, i, j) {
|
1879
|
-
var tweened = [],
|
1880
|
-
node = this,
|
1881
|
-
delay = groups[j][i].delay,
|
1882
|
-
duration = groups[j][i].duration,
|
1883
|
-
lock = node.__transition__ || (node.__transition__ = {active: 0, count: 0});
|
1884
|
-
|
1885
|
-
++lock.count;
|
1886
|
-
|
1887
|
-
delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time);
|
1888
|
-
|
1889
|
-
function start(elapsed) {
|
1890
|
-
if (lock.active > id) return stop();
|
1891
|
-
lock.active = id;
|
1892
|
-
|
1893
|
-
for (var tween in tweens) {
|
1894
|
-
if (tween = tweens[tween].call(node, d, i)) {
|
1895
|
-
tweened.push(tween);
|
1896
|
-
}
|
1897
|
-
}
|
1898
|
-
|
1899
|
-
event.start.dispatch.call(node, d, i);
|
1900
|
-
if (!tick(elapsed)) d3.timer(tick, 0, time);
|
1901
|
-
return 1;
|
1902
|
-
}
|
1903
|
-
|
1904
|
-
function tick(elapsed) {
|
1905
|
-
if (lock.active !== id) return stop();
|
1906
|
-
|
1907
|
-
var t = (elapsed - delay) / duration,
|
1908
|
-
e = ease(t),
|
1909
|
-
n = tweened.length;
|
1910
|
-
|
1911
|
-
while (n > 0) {
|
1912
|
-
tweened[--n].call(node, e);
|
1913
|
-
}
|
1914
|
-
|
1915
|
-
if (t >= 1) {
|
1916
|
-
stop();
|
1917
|
-
d3_transitionInheritId = id;
|
1918
|
-
event.end.dispatch.call(node, d, i);
|
1919
|
-
d3_transitionInheritId = 0;
|
1920
|
-
return 1;
|
1921
|
-
}
|
1922
|
-
}
|
1923
|
-
|
1924
|
-
function stop() {
|
1925
|
-
if (!--lock.count) delete node.__transition__;
|
1926
|
-
return 1;
|
1927
|
-
}
|
1928
|
-
});
|
1929
|
-
return 1;
|
1930
|
-
}, 0, time);
|
1931
|
-
|
1932
|
-
return groups;
|
1933
|
-
}
|
1934
|
-
|
1935
|
-
var d3_transitionRemove = {};
|
1936
|
-
|
1937
|
-
function d3_transitionNull(d, i, a) {
|
1938
|
-
return a != "" && d3_transitionRemove;
|
1939
|
-
}
|
1940
|
-
|
1941
|
-
function d3_transitionTween(b) {
|
1942
|
-
|
1943
|
-
function transitionFunction(d, i, a) {
|
1944
|
-
var v = b.call(this, d, i);
|
1945
|
-
return v == null
|
1946
|
-
? a != "" && d3_transitionRemove
|
1947
|
-
: a != v && d3.interpolate(a, v);
|
1948
|
-
}
|
1949
|
-
|
1950
|
-
function transitionString(d, i, a) {
|
1951
|
-
return a != b && d3.interpolate(a, b);
|
1952
|
-
}
|
1953
|
-
|
1954
|
-
return typeof b === "function" ? transitionFunction
|
1955
|
-
: b == null ? d3_transitionNull
|
1956
|
-
: (b += "", transitionString);
|
1957
|
-
}
|
1958
|
-
|
1959
|
-
var d3_transitionPrototype = [],
|
1960
|
-
d3_transitionId = 0,
|
1961
|
-
d3_transitionInheritId = 0,
|
1962
|
-
d3_transitionEase = d3.ease("cubic-in-out");
|
1963
|
-
|
1964
|
-
d3_transitionPrototype.call = d3_selectionPrototype.call;
|
1965
|
-
|
1966
|
-
d3.transition = function() {
|
1967
|
-
return d3_selectionRoot.transition();
|
1968
|
-
};
|
1969
|
-
|
1970
|
-
d3.transition.prototype = d3_transitionPrototype;
|
1971
|
-
d3_transitionPrototype.select = function(selector) {
|
1972
|
-
var subgroups = [],
|
1973
|
-
subgroup,
|
1974
|
-
subnode,
|
1975
|
-
node;
|
1976
|
-
|
1977
|
-
if (typeof selector !== "function") selector = d3_selection_selector(selector);
|
1978
|
-
|
1979
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
1980
|
-
subgroups.push(subgroup = []);
|
1981
|
-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
|
1982
|
-
if ((node = group[i]) && (subnode = selector.call(node.node, node.node.__data__, i))) {
|
1983
|
-
if ("__data__" in node.node) subnode.__data__ = node.node.__data__;
|
1984
|
-
subgroup.push({node: subnode, delay: node.delay, duration: node.duration});
|
1985
|
-
} else {
|
1986
|
-
subgroup.push(null);
|
1987
|
-
}
|
1988
|
-
}
|
1989
|
-
}
|
1990
|
-
|
1991
|
-
return d3_transition(subgroups, this.id, this.time).ease(this.ease());
|
1992
|
-
};
|
1993
|
-
d3_transitionPrototype.selectAll = function(selector) {
|
1994
|
-
var subgroups = [],
|
1995
|
-
subgroup,
|
1996
|
-
subnodes,
|
1997
|
-
node;
|
1998
|
-
|
1999
|
-
if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
|
2000
|
-
|
2001
|
-
for (var j = -1, m = this.length; ++j < m;) {
|
2002
|
-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
|
2003
|
-
if (node = group[i]) {
|
2004
|
-
subnodes = selector.call(node.node, node.node.__data__, i);
|
2005
|
-
subgroups.push(subgroup = []);
|
2006
|
-
for (var k = -1, o = subnodes.length; ++k < o;) {
|
2007
|
-
subgroup.push({node: subnodes[k], delay: node.delay, duration: node.duration});
|
2008
|
-
}
|
2009
|
-
}
|
2010
|
-
}
|
2011
|
-
}
|
2012
|
-
|
2013
|
-
return d3_transition(subgroups, this.id, this.time).ease(this.ease());
|
2014
|
-
};
|
2015
|
-
d3_transitionPrototype.attr = function(name, value) {
|
2016
|
-
return this.attrTween(name, d3_transitionTween(value));
|
2017
|
-
};
|
2018
|
-
|
2019
|
-
d3_transitionPrototype.attrTween = function(nameNS, tween) {
|
2020
|
-
var name = d3.ns.qualify(nameNS);
|
2021
|
-
|
2022
|
-
function attrTween(d, i) {
|
2023
|
-
var f = tween.call(this, d, i, this.getAttribute(name));
|
2024
|
-
return f === d3_transitionRemove
|
2025
|
-
? (this.removeAttribute(name), null)
|
2026
|
-
: f && function(t) { this.setAttribute(name, f(t)); };
|
2027
|
-
}
|
2028
|
-
|
2029
|
-
function attrTweenNS(d, i) {
|
2030
|
-
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
|
2031
|
-
return f === d3_transitionRemove
|
2032
|
-
? (this.removeAttributeNS(name.space, name.local), null)
|
2033
|
-
: f && function(t) { this.setAttributeNS(name.space, name.local, f(t)); };
|
2034
|
-
}
|
2035
|
-
|
2036
|
-
return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
|
2037
|
-
};
|
2038
|
-
d3_transitionPrototype.style = function(name, value, priority) {
|
2039
|
-
if (arguments.length < 3) priority = "";
|
2040
|
-
return this.styleTween(name, d3_transitionTween(value), priority);
|
2041
|
-
};
|
2042
|
-
|
2043
|
-
d3_transitionPrototype.styleTween = function(name, tween, priority) {
|
2044
|
-
if (arguments.length < 3) priority = "";
|
2045
|
-
return this.tween("style." + name, function(d, i) {
|
2046
|
-
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
|
2047
|
-
return f === d3_transitionRemove
|
2048
|
-
? (this.style.removeProperty(name), null)
|
2049
|
-
: f && function(t) { this.style.setProperty(name, f(t), priority); };
|
2050
|
-
});
|
2051
|
-
};
|
2052
|
-
d3_transitionPrototype.text = function(value) {
|
2053
|
-
return this.tween("text", function(d, i) {
|
2054
|
-
this.textContent = typeof value === "function"
|
2055
|
-
? value.call(this, d, i)
|
2056
|
-
: value;
|
2057
|
-
});
|
2058
|
-
};
|
2059
|
-
d3_transitionPrototype.remove = function() {
|
2060
|
-
return this.each("end", function() {
|
2061
|
-
var p;
|
2062
|
-
if (!this.__transition__ && (p = this.parentNode)) p.removeChild(this);
|
2063
|
-
});
|
2064
|
-
};
|
2065
|
-
d3_transitionPrototype.delay = function(value) {
|
2066
|
-
var groups = this;
|
2067
|
-
return groups.each(typeof value === "function"
|
2068
|
-
? function(d, i, j) { groups[j][i].delay = +value.apply(this, arguments); }
|
2069
|
-
: (value = +value, function(d, i, j) { groups[j][i].delay = value; }));
|
2070
|
-
};
|
2071
|
-
d3_transitionPrototype.duration = function(value) {
|
2072
|
-
var groups = this;
|
2073
|
-
return groups.each(typeof value === "function"
|
2074
|
-
? function(d, i, j) { groups[j][i].duration = +value.apply(this, arguments); }
|
2075
|
-
: (value = +value, function(d, i, j) { groups[j][i].duration = value; }));
|
2076
|
-
};
|
2077
|
-
function d3_transition_each(callback) {
|
2078
|
-
for (var j = 0, m = this.length; j < m; j++) {
|
2079
|
-
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
|
2080
|
-
var node = group[i];
|
2081
|
-
if (node) callback.call(node = node.node, node.__data__, i, j);
|
2082
|
-
}
|
2083
|
-
}
|
2084
|
-
return this;
|
2085
|
-
}
|
2086
|
-
d3_transitionPrototype.transition = function() {
|
2087
|
-
return this.select(d3_this);
|
2088
|
-
};
|
2089
|
-
var d3_timer_queue = null,
|
2090
|
-
d3_timer_interval, // is an interval (or frame) active?
|
2091
|
-
d3_timer_timeout; // is a timeout active?
|
2092
|
-
|
2093
|
-
// The timer will continue to fire until callback returns true.
|
2094
|
-
d3.timer = function(callback, delay, then) {
|
2095
|
-
var found = false,
|
2096
|
-
t0,
|
2097
|
-
t1 = d3_timer_queue;
|
2098
|
-
|
2099
|
-
if (arguments.length < 3) {
|
2100
|
-
if (arguments.length < 2) delay = 0;
|
2101
|
-
else if (!isFinite(delay)) return;
|
2102
|
-
then = Date.now();
|
2103
|
-
}
|
2104
|
-
|
2105
|
-
// See if the callback's already in the queue.
|
2106
|
-
while (t1) {
|
2107
|
-
if (t1.callback === callback) {
|
2108
|
-
t1.then = then;
|
2109
|
-
t1.delay = delay;
|
2110
|
-
found = true;
|
2111
|
-
break;
|
2112
|
-
}
|
2113
|
-
t0 = t1;
|
2114
|
-
t1 = t1.next;
|
2115
|
-
}
|
2116
|
-
|
2117
|
-
// Otherwise, add the callback to the queue.
|
2118
|
-
if (!found) d3_timer_queue = {
|
2119
|
-
callback: callback,
|
2120
|
-
then: then,
|
2121
|
-
delay: delay,
|
2122
|
-
next: d3_timer_queue
|
2123
|
-
};
|
2124
|
-
|
2125
|
-
// Start animatin'!
|
2126
|
-
if (!d3_timer_interval) {
|
2127
|
-
d3_timer_timeout = clearTimeout(d3_timer_timeout);
|
2128
|
-
d3_timer_interval = 1;
|
2129
|
-
d3_timer_frame(d3_timer_step);
|
2130
|
-
}
|
2131
|
-
}
|
2132
|
-
|
2133
|
-
function d3_timer_step() {
|
2134
|
-
var elapsed,
|
2135
|
-
now = Date.now(),
|
2136
|
-
t1 = d3_timer_queue;
|
2137
|
-
|
2138
|
-
while (t1) {
|
2139
|
-
elapsed = now - t1.then;
|
2140
|
-
if (elapsed >= t1.delay) t1.flush = t1.callback(elapsed);
|
2141
|
-
t1 = t1.next;
|
2142
|
-
}
|
2143
|
-
|
2144
|
-
var delay = d3_timer_flush() - now;
|
2145
|
-
if (delay > 24) {
|
2146
|
-
if (isFinite(delay)) {
|
2147
|
-
clearTimeout(d3_timer_timeout);
|
2148
|
-
d3_timer_timeout = setTimeout(d3_timer_step, delay);
|
2149
|
-
}
|
2150
|
-
d3_timer_interval = 0;
|
2151
|
-
} else {
|
2152
|
-
d3_timer_interval = 1;
|
2153
|
-
d3_timer_frame(d3_timer_step);
|
2154
|
-
}
|
2155
|
-
}
|
2156
|
-
|
2157
|
-
d3.timer.flush = function() {
|
2158
|
-
var elapsed,
|
2159
|
-
now = Date.now(),
|
2160
|
-
t1 = d3_timer_queue;
|
2161
|
-
|
2162
|
-
while (t1) {
|
2163
|
-
elapsed = now - t1.then;
|
2164
|
-
if (!t1.delay) t1.flush = t1.callback(elapsed);
|
2165
|
-
t1 = t1.next;
|
2166
|
-
}
|
2167
|
-
|
2168
|
-
d3_timer_flush();
|
2169
|
-
};
|
2170
|
-
|
2171
|
-
// Flush after callbacks, to avoid concurrent queue modification.
|
2172
|
-
function d3_timer_flush() {
|
2173
|
-
var t0 = null,
|
2174
|
-
t1 = d3_timer_queue,
|
2175
|
-
then = Infinity;
|
2176
|
-
while (t1) {
|
2177
|
-
if (t1.flush) {
|
2178
|
-
t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next;
|
2179
|
-
} else {
|
2180
|
-
then = Math.min(then, t1.then + t1.delay);
|
2181
|
-
t1 = (t0 = t1).next;
|
2182
|
-
}
|
2183
|
-
}
|
2184
|
-
return then;
|
2185
|
-
}
|
2186
|
-
|
2187
|
-
var d3_timer_frame = window.requestAnimationFrame
|
2188
|
-
|| window.webkitRequestAnimationFrame
|
2189
|
-
|| window.mozRequestAnimationFrame
|
2190
|
-
|| window.oRequestAnimationFrame
|
2191
|
-
|| window.msRequestAnimationFrame
|
2192
|
-
|| function(callback) { setTimeout(callback, 17); };
|
2193
|
-
function d3_noop() {}
|
2194
|
-
d3.scale = {};
|
2195
|
-
|
2196
|
-
function d3_scaleExtent(domain) {
|
2197
|
-
var start = domain[0], stop = domain[domain.length - 1];
|
2198
|
-
return start < stop ? [start, stop] : [stop, start];
|
2199
|
-
}
|
2200
|
-
function d3_scale_nice(domain, nice) {
|
2201
|
-
var i0 = 0,
|
2202
|
-
i1 = domain.length - 1,
|
2203
|
-
x0 = domain[i0],
|
2204
|
-
x1 = domain[i1],
|
2205
|
-
dx;
|
2206
|
-
|
2207
|
-
if (x1 < x0) {
|
2208
|
-
dx = i0; i0 = i1; i1 = dx;
|
2209
|
-
dx = x0; x0 = x1; x1 = dx;
|
2210
|
-
}
|
2211
|
-
|
2212
|
-
if (dx = x1 - x0) {
|
2213
|
-
nice = nice(dx);
|
2214
|
-
domain[i0] = nice.floor(x0);
|
2215
|
-
domain[i1] = nice.ceil(x1);
|
2216
|
-
}
|
2217
|
-
|
2218
|
-
return domain;
|
2219
|
-
}
|
2220
|
-
|
2221
|
-
function d3_scale_niceDefault() {
|
2222
|
-
return Math;
|
2223
|
-
}
|
2224
|
-
d3.scale.linear = function() {
|
2225
|
-
return d3_scale_linear([0, 1], [0, 1], d3.interpolate, false);
|
2226
|
-
};
|
2227
|
-
|
2228
|
-
function d3_scale_linear(domain, range, interpolate, clamp) {
|
2229
|
-
var output,
|
2230
|
-
input;
|
2231
|
-
|
2232
|
-
function rescale() {
|
2233
|
-
var linear = domain.length == 2 ? d3_scale_bilinear : d3_scale_polylinear,
|
2234
|
-
uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
|
2235
|
-
output = linear(domain, range, uninterpolate, interpolate);
|
2236
|
-
input = linear(range, domain, uninterpolate, d3.interpolate);
|
2237
|
-
return scale;
|
2238
|
-
}
|
2239
|
-
|
2240
|
-
function scale(x) {
|
2241
|
-
return output(x);
|
2242
|
-
}
|
2243
|
-
|
2244
|
-
// Note: requires range is coercible to number!
|
2245
|
-
scale.invert = function(y) {
|
2246
|
-
return input(y);
|
2247
|
-
};
|
2248
|
-
|
2249
|
-
scale.domain = function(x) {
|
2250
|
-
if (!arguments.length) return domain;
|
2251
|
-
domain = x.map(Number);
|
2252
|
-
return rescale();
|
2253
|
-
};
|
2254
|
-
|
2255
|
-
scale.range = function(x) {
|
2256
|
-
if (!arguments.length) return range;
|
2257
|
-
range = x;
|
2258
|
-
return rescale();
|
2259
|
-
};
|
2260
|
-
|
2261
|
-
scale.rangeRound = function(x) {
|
2262
|
-
return scale.range(x).interpolate(d3.interpolateRound);
|
2263
|
-
};
|
2264
|
-
|
2265
|
-
scale.clamp = function(x) {
|
2266
|
-
if (!arguments.length) return clamp;
|
2267
|
-
clamp = x;
|
2268
|
-
return rescale();
|
2269
|
-
};
|
2270
|
-
|
2271
|
-
scale.interpolate = function(x) {
|
2272
|
-
if (!arguments.length) return interpolate;
|
2273
|
-
interpolate = x;
|
2274
|
-
return rescale();
|
2275
|
-
};
|
2276
|
-
|
2277
|
-
scale.ticks = function(m) {
|
2278
|
-
return d3_scale_linearTicks(domain, m);
|
2279
|
-
};
|
2280
|
-
|
2281
|
-
scale.tickFormat = function(m) {
|
2282
|
-
return d3_scale_linearTickFormat(domain, m);
|
2283
|
-
};
|
2284
|
-
|
2285
|
-
scale.nice = function() {
|
2286
|
-
d3_scale_nice(domain, d3_scale_linearNice);
|
2287
|
-
return rescale();
|
2288
|
-
};
|
2289
|
-
|
2290
|
-
scale.copy = function() {
|
2291
|
-
return d3_scale_linear(domain, range, interpolate, clamp);
|
2292
|
-
};
|
2293
|
-
|
2294
|
-
return rescale();
|
2295
|
-
};
|
2296
|
-
|
2297
|
-
function d3_scale_linearRebind(scale, linear) {
|
2298
|
-
scale.range = d3.rebind(scale, linear.range);
|
2299
|
-
scale.rangeRound = d3.rebind(scale, linear.rangeRound);
|
2300
|
-
scale.interpolate = d3.rebind(scale, linear.interpolate);
|
2301
|
-
scale.clamp = d3.rebind(scale, linear.clamp);
|
2302
|
-
return scale;
|
2303
|
-
}
|
2304
|
-
|
2305
|
-
function d3_scale_linearNice(dx) {
|
2306
|
-
dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
|
2307
|
-
return {
|
2308
|
-
floor: function(x) { return Math.floor(x / dx) * dx; },
|
2309
|
-
ceil: function(x) { return Math.ceil(x / dx) * dx; }
|
2310
|
-
};
|
2311
|
-
}
|
2312
|
-
|
2313
|
-
// TODO Dates? Ugh.
|
2314
|
-
function d3_scale_linearTickRange(domain, m) {
|
2315
|
-
var extent = d3_scaleExtent(domain),
|
2316
|
-
span = extent[1] - extent[0],
|
2317
|
-
step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)),
|
2318
|
-
err = m / span * step;
|
2319
|
-
|
2320
|
-
// Filter ticks to get closer to the desired count.
|
2321
|
-
if (err <= .15) step *= 10;
|
2322
|
-
else if (err <= .35) step *= 5;
|
2323
|
-
else if (err <= .75) step *= 2;
|
2324
|
-
|
2325
|
-
// Round start and stop values to step interval.
|
2326
|
-
extent[0] = Math.ceil(extent[0] / step) * step;
|
2327
|
-
extent[1] = Math.floor(extent[1] / step) * step + step * .5; // inclusive
|
2328
|
-
extent[2] = step;
|
2329
|
-
return extent;
|
2330
|
-
}
|
2331
|
-
|
2332
|
-
function d3_scale_linearTicks(domain, m) {
|
2333
|
-
return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
|
2334
|
-
}
|
2335
|
-
|
2336
|
-
function d3_scale_linearTickFormat(domain, m) {
|
2337
|
-
return d3.format(",." + Math.max(0, -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01)) + "f");
|
2338
|
-
}
|
2339
|
-
function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
|
2340
|
-
var u = uninterpolate(domain[0], domain[1]),
|
2341
|
-
i = interpolate(range[0], range[1]);
|
2342
|
-
return function(x) {
|
2343
|
-
return i(u(x));
|
2344
|
-
};
|
2345
|
-
}
|
2346
|
-
function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
|
2347
|
-
var u = [],
|
2348
|
-
i = [],
|
2349
|
-
j = 0,
|
2350
|
-
n = domain.length;
|
2351
|
-
|
2352
|
-
while (++j < n) {
|
2353
|
-
u.push(uninterpolate(domain[j - 1], domain[j]));
|
2354
|
-
i.push(interpolate(range[j - 1], range[j]));
|
2355
|
-
}
|
2356
|
-
|
2357
|
-
return function(x) {
|
2358
|
-
var j = d3.bisect(domain, x, 1, domain.length - 1) - 1;
|
2359
|
-
return i[j](u[j](x));
|
2360
|
-
};
|
2361
|
-
}
|
2362
|
-
d3.scale.log = function() {
|
2363
|
-
return d3_scale_log(d3.scale.linear(), d3_scale_logp);
|
2364
|
-
};
|
2365
|
-
|
2366
|
-
function d3_scale_log(linear, log) {
|
2367
|
-
var pow = log.pow;
|
2368
|
-
|
2369
|
-
function scale(x) {
|
2370
|
-
return linear(log(x));
|
2371
|
-
}
|
2372
|
-
|
2373
|
-
scale.invert = function(x) {
|
2374
|
-
return pow(linear.invert(x));
|
2375
|
-
};
|
2376
|
-
|
2377
|
-
scale.domain = function(x) {
|
2378
|
-
if (!arguments.length) return linear.domain().map(pow);
|
2379
|
-
log = x[0] < 0 ? d3_scale_logn : d3_scale_logp;
|
2380
|
-
pow = log.pow;
|
2381
|
-
linear.domain(x.map(log));
|
2382
|
-
return scale;
|
2383
|
-
};
|
2384
|
-
|
2385
|
-
scale.nice = function() {
|
2386
|
-
linear.domain(d3_scale_nice(linear.domain(), d3_scale_niceDefault));
|
2387
|
-
return scale;
|
2388
|
-
};
|
2389
|
-
|
2390
|
-
scale.ticks = function() {
|
2391
|
-
var extent = d3_scaleExtent(linear.domain()),
|
2392
|
-
ticks = [];
|
2393
|
-
if (extent.every(isFinite)) {
|
2394
|
-
var i = Math.floor(extent[0]),
|
2395
|
-
j = Math.ceil(extent[1]),
|
2396
|
-
u = Math.round(pow(extent[0])),
|
2397
|
-
v = Math.round(pow(extent[1]));
|
2398
|
-
if (log === d3_scale_logn) {
|
2399
|
-
ticks.push(pow(i));
|
2400
|
-
for (; i++ < j;) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
|
2401
|
-
} else {
|
2402
|
-
for (; i < j; i++) for (var k = 1; k < 10; k++) ticks.push(pow(i) * k);
|
2403
|
-
ticks.push(pow(i));
|
2404
|
-
}
|
2405
|
-
for (i = 0; ticks[i] < u; i++) {} // strip small values
|
2406
|
-
for (j = ticks.length; ticks[j - 1] > v; j--) {} // strip big values
|
2407
|
-
ticks = ticks.slice(i, j);
|
2408
|
-
}
|
2409
|
-
return ticks;
|
2410
|
-
};
|
2411
|
-
|
2412
|
-
scale.tickFormat = function(n, format) {
|
2413
|
-
if (arguments.length < 2) format = d3_scale_logFormat;
|
2414
|
-
if (arguments.length < 1) return format;
|
2415
|
-
var k = n / scale.ticks().length,
|
2416
|
-
f = log === d3_scale_logn ? (e = -1e-15, Math.floor) : (e = 1e-15, Math.ceil),
|
2417
|
-
e;
|
2418
|
-
return function(d) {
|
2419
|
-
return d / pow(f(log(d) + e)) < k ? format(d) : "";
|
2420
|
-
};
|
2421
|
-
};
|
2422
|
-
|
2423
|
-
scale.copy = function() {
|
2424
|
-
return d3_scale_log(linear.copy(), log);
|
2425
|
-
};
|
2426
|
-
|
2427
|
-
return d3_scale_linearRebind(scale, linear);
|
2428
|
-
};
|
2429
|
-
|
2430
|
-
var d3_scale_logFormat = d3.format("e");
|
2431
|
-
|
2432
|
-
function d3_scale_logp(x) {
|
2433
|
-
return Math.log(x) / Math.LN10;
|
2434
|
-
}
|
2435
|
-
|
2436
|
-
function d3_scale_logn(x) {
|
2437
|
-
return -Math.log(-x) / Math.LN10;
|
2438
|
-
}
|
2439
|
-
|
2440
|
-
d3_scale_logp.pow = function(x) {
|
2441
|
-
return Math.pow(10, x);
|
2442
|
-
};
|
2443
|
-
|
2444
|
-
d3_scale_logn.pow = function(x) {
|
2445
|
-
return -Math.pow(10, -x);
|
2446
|
-
};
|
2447
|
-
d3.scale.pow = function() {
|
2448
|
-
return d3_scale_pow(d3.scale.linear(), 1);
|
2449
|
-
};
|
2450
|
-
|
2451
|
-
function d3_scale_pow(linear, exponent) {
|
2452
|
-
var powp = d3_scale_powPow(exponent),
|
2453
|
-
powb = d3_scale_powPow(1 / exponent);
|
2454
|
-
|
2455
|
-
function scale(x) {
|
2456
|
-
return linear(powp(x));
|
2457
|
-
}
|
2458
|
-
|
2459
|
-
scale.invert = function(x) {
|
2460
|
-
return powb(linear.invert(x));
|
2461
|
-
};
|
2462
|
-
|
2463
|
-
scale.domain = function(x) {
|
2464
|
-
if (!arguments.length) return linear.domain().map(powb);
|
2465
|
-
linear.domain(x.map(powp));
|
2466
|
-
return scale;
|
2467
|
-
};
|
2468
|
-
|
2469
|
-
scale.ticks = function(m) {
|
2470
|
-
return d3_scale_linearTicks(scale.domain(), m);
|
2471
|
-
};
|
2472
|
-
|
2473
|
-
scale.tickFormat = function(m) {
|
2474
|
-
return d3_scale_linearTickFormat(scale.domain(), m);
|
2475
|
-
};
|
2476
|
-
|
2477
|
-
scale.nice = function() {
|
2478
|
-
return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
|
2479
|
-
};
|
2480
|
-
|
2481
|
-
scale.exponent = function(x) {
|
2482
|
-
if (!arguments.length) return exponent;
|
2483
|
-
var domain = scale.domain();
|
2484
|
-
powp = d3_scale_powPow(exponent = x);
|
2485
|
-
powb = d3_scale_powPow(1 / exponent);
|
2486
|
-
return scale.domain(domain);
|
2487
|
-
};
|
2488
|
-
|
2489
|
-
scale.copy = function() {
|
2490
|
-
return d3_scale_pow(linear.copy(), exponent);
|
2491
|
-
};
|
2492
|
-
|
2493
|
-
return d3_scale_linearRebind(scale, linear);
|
2494
|
-
};
|
2495
|
-
|
2496
|
-
function d3_scale_powPow(e) {
|
2497
|
-
return function(x) {
|
2498
|
-
return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
|
2499
|
-
};
|
2500
|
-
}
|
2501
|
-
d3.scale.sqrt = function() {
|
2502
|
-
return d3.scale.pow().exponent(.5);
|
2503
|
-
};
|
2504
|
-
d3.scale.ordinal = function() {
|
2505
|
-
return d3_scale_ordinal([], {t: "range", x: []});
|
2506
|
-
};
|
2507
|
-
|
2508
|
-
function d3_scale_ordinal(domain, ranger) {
|
2509
|
-
var index,
|
2510
|
-
range,
|
2511
|
-
rangeBand;
|
2512
|
-
|
2513
|
-
function scale(x) {
|
2514
|
-
return range[((index[x] || (index[x] = domain.push(x))) - 1) % range.length];
|
2515
|
-
}
|
2516
|
-
|
2517
|
-
scale.domain = function(x) {
|
2518
|
-
if (!arguments.length) return domain;
|
2519
|
-
domain = [];
|
2520
|
-
index = {};
|
2521
|
-
var i = -1, n = x.length, xi;
|
2522
|
-
while (++i < n) if (!index[xi = x[i]]) index[xi] = domain.push(xi);
|
2523
|
-
return scale[ranger.t](ranger.x, ranger.p);
|
2524
|
-
};
|
2525
|
-
|
2526
|
-
scale.range = function(x) {
|
2527
|
-
if (!arguments.length) return range;
|
2528
|
-
range = x;
|
2529
|
-
rangeBand = 0;
|
2530
|
-
ranger = {t: "range", x: x};
|
2531
|
-
return scale;
|
2532
|
-
};
|
2533
|
-
|
2534
|
-
scale.rangePoints = function(x, padding) {
|
2535
|
-
if (arguments.length < 2) padding = 0;
|
2536
|
-
var start = x[0],
|
2537
|
-
stop = x[1],
|
2538
|
-
step = (stop - start) / (domain.length - 1 + padding);
|
2539
|
-
range = domain.length < 2 ? [(start + stop) / 2] : d3.range(start + step * padding / 2, stop + step / 2, step);
|
2540
|
-
rangeBand = 0;
|
2541
|
-
ranger = {t: "rangePoints", x: x, p: padding};
|
2542
|
-
return scale;
|
2543
|
-
};
|
2544
|
-
|
2545
|
-
scale.rangeBands = function(x, padding) {
|
2546
|
-
if (arguments.length < 2) padding = 0;
|
2547
|
-
var start = x[0],
|
2548
|
-
stop = x[1],
|
2549
|
-
step = (stop - start) / (domain.length + padding);
|
2550
|
-
range = d3.range(start + step * padding, stop, step);
|
2551
|
-
rangeBand = step * (1 - padding);
|
2552
|
-
ranger = {t: "rangeBands", x: x, p: padding};
|
2553
|
-
return scale;
|
2554
|
-
};
|
2555
|
-
|
2556
|
-
scale.rangeRoundBands = function(x, padding) {
|
2557
|
-
if (arguments.length < 2) padding = 0;
|
2558
|
-
var start = x[0],
|
2559
|
-
stop = x[1],
|
2560
|
-
step = Math.floor((stop - start) / (domain.length + padding)),
|
2561
|
-
err = stop - start - (domain.length - padding) * step;
|
2562
|
-
range = d3.range(start + Math.round(err / 2), stop, step);
|
2563
|
-
rangeBand = Math.round(step * (1 - padding));
|
2564
|
-
ranger = {t: "rangeRoundBands", x: x, p: padding};
|
2565
|
-
return scale;
|
2566
|
-
};
|
2567
|
-
|
2568
|
-
scale.rangeBand = function() {
|
2569
|
-
return rangeBand;
|
2570
|
-
};
|
2571
|
-
|
2572
|
-
scale.copy = function() {
|
2573
|
-
return d3_scale_ordinal(domain, ranger);
|
2574
|
-
};
|
2575
|
-
|
2576
|
-
return scale.domain(domain);
|
2577
|
-
};
|
2578
|
-
/*
|
2579
|
-
* This product includes color specifications and designs developed by Cynthia
|
2580
|
-
* Brewer (http://colorbrewer.org/). See lib/colorbrewer for more information.
|
2581
|
-
*/
|
2582
|
-
|
2583
|
-
d3.scale.category10 = function() {
|
2584
|
-
return d3.scale.ordinal().range(d3_category10);
|
2585
|
-
};
|
2586
|
-
|
2587
|
-
d3.scale.category20 = function() {
|
2588
|
-
return d3.scale.ordinal().range(d3_category20);
|
2589
|
-
};
|
2590
|
-
|
2591
|
-
d3.scale.category20b = function() {
|
2592
|
-
return d3.scale.ordinal().range(d3_category20b);
|
2593
|
-
};
|
2594
|
-
|
2595
|
-
d3.scale.category20c = function() {
|
2596
|
-
return d3.scale.ordinal().range(d3_category20c);
|
2597
|
-
};
|
2598
|
-
|
2599
|
-
var d3_category10 = [
|
2600
|
-
"#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
|
2601
|
-
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"
|
2602
|
-
];
|
2603
|
-
|
2604
|
-
var d3_category20 = [
|
2605
|
-
"#1f77b4", "#aec7e8",
|
2606
|
-
"#ff7f0e", "#ffbb78",
|
2607
|
-
"#2ca02c", "#98df8a",
|
2608
|
-
"#d62728", "#ff9896",
|
2609
|
-
"#9467bd", "#c5b0d5",
|
2610
|
-
"#8c564b", "#c49c94",
|
2611
|
-
"#e377c2", "#f7b6d2",
|
2612
|
-
"#7f7f7f", "#c7c7c7",
|
2613
|
-
"#bcbd22", "#dbdb8d",
|
2614
|
-
"#17becf", "#9edae5"
|
2615
|
-
];
|
2616
|
-
|
2617
|
-
var d3_category20b = [
|
2618
|
-
"#393b79", "#5254a3", "#6b6ecf", "#9c9ede",
|
2619
|
-
"#637939", "#8ca252", "#b5cf6b", "#cedb9c",
|
2620
|
-
"#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94",
|
2621
|
-
"#843c39", "#ad494a", "#d6616b", "#e7969c",
|
2622
|
-
"#7b4173", "#a55194", "#ce6dbd", "#de9ed6"
|
2623
|
-
];
|
2624
|
-
|
2625
|
-
var d3_category20c = [
|
2626
|
-
"#3182bd", "#6baed6", "#9ecae1", "#c6dbef",
|
2627
|
-
"#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2",
|
2628
|
-
"#31a354", "#74c476", "#a1d99b", "#c7e9c0",
|
2629
|
-
"#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb",
|
2630
|
-
"#636363", "#969696", "#bdbdbd", "#d9d9d9"
|
2631
|
-
];
|
2632
|
-
d3.scale.quantile = function() {
|
2633
|
-
return d3_scale_quantile([], []);
|
2634
|
-
};
|
2635
|
-
|
2636
|
-
function d3_scale_quantile(domain, range) {
|
2637
|
-
var thresholds;
|
2638
|
-
|
2639
|
-
function rescale() {
|
2640
|
-
var k = 0,
|
2641
|
-
n = domain.length,
|
2642
|
-
q = range.length;
|
2643
|
-
thresholds = [];
|
2644
|
-
while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
|
2645
|
-
return scale;
|
2646
|
-
}
|
2647
|
-
|
2648
|
-
function scale(x) {
|
2649
|
-
if (isNaN(x = +x)) return NaN;
|
2650
|
-
return range[d3.bisect(thresholds, x)];
|
2651
|
-
}
|
2652
|
-
|
2653
|
-
scale.domain = function(x) {
|
2654
|
-
if (!arguments.length) return domain;
|
2655
|
-
domain = x.filter(function(d) { return !isNaN(d); }).sort(d3.ascending);
|
2656
|
-
return rescale();
|
2657
|
-
};
|
2658
|
-
|
2659
|
-
scale.range = function(x) {
|
2660
|
-
if (!arguments.length) return range;
|
2661
|
-
range = x;
|
2662
|
-
return rescale();
|
2663
|
-
};
|
2664
|
-
|
2665
|
-
scale.quantiles = function() {
|
2666
|
-
return thresholds;
|
2667
|
-
};
|
2668
|
-
|
2669
|
-
scale.copy = function() {
|
2670
|
-
return d3_scale_quantile(domain, range); // copy on write!
|
2671
|
-
};
|
2672
|
-
|
2673
|
-
return rescale();
|
2674
|
-
};
|
2675
|
-
d3.scale.quantize = function() {
|
2676
|
-
return d3_scale_quantize(0, 1, [0, 1]);
|
2677
|
-
};
|
2678
|
-
|
2679
|
-
function d3_scale_quantize(x0, x1, range) {
|
2680
|
-
var kx, i;
|
2681
|
-
|
2682
|
-
function scale(x) {
|
2683
|
-
return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
|
2684
|
-
}
|
2685
|
-
|
2686
|
-
function rescale() {
|
2687
|
-
kx = range.length / (x1 - x0);
|
2688
|
-
i = range.length - 1;
|
2689
|
-
return scale;
|
2690
|
-
}
|
2691
|
-
|
2692
|
-
scale.domain = function(x) {
|
2693
|
-
if (!arguments.length) return [x0, x1];
|
2694
|
-
x0 = +x[0];
|
2695
|
-
x1 = +x[x.length - 1];
|
2696
|
-
return rescale();
|
2697
|
-
};
|
2698
|
-
|
2699
|
-
scale.range = function(x) {
|
2700
|
-
if (!arguments.length) return range;
|
2701
|
-
range = x;
|
2702
|
-
return rescale();
|
2703
|
-
};
|
2704
|
-
|
2705
|
-
scale.copy = function() {
|
2706
|
-
return d3_scale_quantize(x0, x1, range); // copy on write
|
2707
|
-
};
|
2708
|
-
|
2709
|
-
return rescale();
|
2710
|
-
};
|
2711
|
-
d3.svg = {};
|
2712
|
-
d3.svg.arc = function() {
|
2713
|
-
var innerRadius = d3_svg_arcInnerRadius,
|
2714
|
-
outerRadius = d3_svg_arcOuterRadius,
|
2715
|
-
startAngle = d3_svg_arcStartAngle,
|
2716
|
-
endAngle = d3_svg_arcEndAngle;
|
2717
|
-
|
2718
|
-
function arc() {
|
2719
|
-
var r0 = innerRadius.apply(this, arguments),
|
2720
|
-
r1 = outerRadius.apply(this, arguments),
|
2721
|
-
a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset,
|
2722
|
-
a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset,
|
2723
|
-
da = (a1 < a0 && (da = a0, a0 = a1, a1 = da), a1 - a0),
|
2724
|
-
df = da < Math.PI ? "0" : "1",
|
2725
|
-
c0 = Math.cos(a0),
|
2726
|
-
s0 = Math.sin(a0),
|
2727
|
-
c1 = Math.cos(a1),
|
2728
|
-
s1 = Math.sin(a1);
|
2729
|
-
return da >= d3_svg_arcMax
|
2730
|
-
? (r0
|
2731
|
-
? "M0," + r1
|
2732
|
-
+ "A" + r1 + "," + r1 + " 0 1,1 0," + (-r1)
|
2733
|
-
+ "A" + r1 + "," + r1 + " 0 1,1 0," + r1
|
2734
|
-
+ "M0," + r0
|
2735
|
-
+ "A" + r0 + "," + r0 + " 0 1,0 0," + (-r0)
|
2736
|
-
+ "A" + r0 + "," + r0 + " 0 1,0 0," + r0
|
2737
|
-
+ "Z"
|
2738
|
-
: "M0," + r1
|
2739
|
-
+ "A" + r1 + "," + r1 + " 0 1,1 0," + (-r1)
|
2740
|
-
+ "A" + r1 + "," + r1 + " 0 1,1 0," + r1
|
2741
|
-
+ "Z")
|
2742
|
-
: (r0
|
2743
|
-
? "M" + r1 * c0 + "," + r1 * s0
|
2744
|
-
+ "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1
|
2745
|
-
+ "L" + r0 * c1 + "," + r0 * s1
|
2746
|
-
+ "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0
|
2747
|
-
+ "Z"
|
2748
|
-
: "M" + r1 * c0 + "," + r1 * s0
|
2749
|
-
+ "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1
|
2750
|
-
+ "L0,0"
|
2751
|
-
+ "Z");
|
2752
|
-
}
|
2753
|
-
|
2754
|
-
arc.innerRadius = function(v) {
|
2755
|
-
if (!arguments.length) return innerRadius;
|
2756
|
-
innerRadius = d3.functor(v);
|
2757
|
-
return arc;
|
2758
|
-
};
|
2759
|
-
|
2760
|
-
arc.outerRadius = function(v) {
|
2761
|
-
if (!arguments.length) return outerRadius;
|
2762
|
-
outerRadius = d3.functor(v);
|
2763
|
-
return arc;
|
2764
|
-
};
|
2765
|
-
|
2766
|
-
arc.startAngle = function(v) {
|
2767
|
-
if (!arguments.length) return startAngle;
|
2768
|
-
startAngle = d3.functor(v);
|
2769
|
-
return arc;
|
2770
|
-
};
|
2771
|
-
|
2772
|
-
arc.endAngle = function(v) {
|
2773
|
-
if (!arguments.length) return endAngle;
|
2774
|
-
endAngle = d3.functor(v);
|
2775
|
-
return arc;
|
2776
|
-
};
|
2777
|
-
|
2778
|
-
arc.centroid = function() {
|
2779
|
-
var r = (innerRadius.apply(this, arguments)
|
2780
|
-
+ outerRadius.apply(this, arguments)) / 2,
|
2781
|
-
a = (startAngle.apply(this, arguments)
|
2782
|
-
+ endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
|
2783
|
-
return [Math.cos(a) * r, Math.sin(a) * r];
|
2784
|
-
};
|
2785
|
-
|
2786
|
-
return arc;
|
2787
|
-
};
|
2788
|
-
|
2789
|
-
var d3_svg_arcOffset = -Math.PI / 2,
|
2790
|
-
d3_svg_arcMax = 2 * Math.PI - 1e-6;
|
2791
|
-
|
2792
|
-
function d3_svg_arcInnerRadius(d) {
|
2793
|
-
return d.innerRadius;
|
2794
|
-
}
|
2795
|
-
|
2796
|
-
function d3_svg_arcOuterRadius(d) {
|
2797
|
-
return d.outerRadius;
|
2798
|
-
}
|
2799
|
-
|
2800
|
-
function d3_svg_arcStartAngle(d) {
|
2801
|
-
return d.startAngle;
|
2802
|
-
}
|
2803
|
-
|
2804
|
-
function d3_svg_arcEndAngle(d) {
|
2805
|
-
return d.endAngle;
|
2806
|
-
}
|
2807
|
-
function d3_svg_line(projection) {
|
2808
|
-
var x = d3_svg_lineX,
|
2809
|
-
y = d3_svg_lineY,
|
2810
|
-
interpolate = "linear",
|
2811
|
-
interpolator = d3_svg_lineInterpolators[interpolate],
|
2812
|
-
tension = .7;
|
2813
|
-
|
2814
|
-
function line(d) {
|
2815
|
-
return d.length < 1 ? null : "M" + interpolator(projection(d3_svg_linePoints(this, d, x, y)), tension);
|
2816
|
-
}
|
2817
|
-
|
2818
|
-
line.x = function(v) {
|
2819
|
-
if (!arguments.length) return x;
|
2820
|
-
x = v;
|
2821
|
-
return line;
|
2822
|
-
};
|
2823
|
-
|
2824
|
-
line.y = function(v) {
|
2825
|
-
if (!arguments.length) return y;
|
2826
|
-
y = v;
|
2827
|
-
return line;
|
2828
|
-
};
|
2829
|
-
|
2830
|
-
line.interpolate = function(v) {
|
2831
|
-
if (!arguments.length) return interpolate;
|
2832
|
-
interpolator = d3_svg_lineInterpolators[interpolate = v];
|
2833
|
-
return line;
|
2834
|
-
};
|
2835
|
-
|
2836
|
-
line.tension = function(v) {
|
2837
|
-
if (!arguments.length) return tension;
|
2838
|
-
tension = v;
|
2839
|
-
return line;
|
2840
|
-
};
|
2841
|
-
|
2842
|
-
return line;
|
2843
|
-
}
|
2844
|
-
|
2845
|
-
d3.svg.line = function() {
|
2846
|
-
return d3_svg_line(Object);
|
2847
|
-
};
|
2848
|
-
|
2849
|
-
// Converts the specified array of data into an array of points
|
2850
|
-
// (x-y tuples), by evaluating the specified `x` and `y` functions on each
|
2851
|
-
// data point. The `this` context of the evaluated functions is the specified
|
2852
|
-
// "self" object; each function is passed the current datum and index.
|
2853
|
-
function d3_svg_linePoints(self, d, x, y) {
|
2854
|
-
var points = [],
|
2855
|
-
i = -1,
|
2856
|
-
n = d.length,
|
2857
|
-
fx = typeof x === "function",
|
2858
|
-
fy = typeof y === "function",
|
2859
|
-
value;
|
2860
|
-
if (fx && fy) {
|
2861
|
-
while (++i < n) points.push([
|
2862
|
-
x.call(self, value = d[i], i),
|
2863
|
-
y.call(self, value, i)
|
2864
|
-
]);
|
2865
|
-
} else if (fx) {
|
2866
|
-
while (++i < n) points.push([x.call(self, d[i], i), y]);
|
2867
|
-
} else if (fy) {
|
2868
|
-
while (++i < n) points.push([x, y.call(self, d[i], i)]);
|
2869
|
-
} else {
|
2870
|
-
while (++i < n) points.push([x, y]);
|
2871
|
-
}
|
2872
|
-
return points;
|
2873
|
-
}
|
2874
|
-
|
2875
|
-
// The default `x` property, which references d[0].
|
2876
|
-
function d3_svg_lineX(d) {
|
2877
|
-
return d[0];
|
2878
|
-
}
|
2879
|
-
|
2880
|
-
// The default `y` property, which references d[1].
|
2881
|
-
function d3_svg_lineY(d) {
|
2882
|
-
return d[1];
|
2883
|
-
}
|
2884
|
-
|
2885
|
-
// The various interpolators supported by the `line` class.
|
2886
|
-
var d3_svg_lineInterpolators = {
|
2887
|
-
"linear": d3_svg_lineLinear,
|
2888
|
-
"step-before": d3_svg_lineStepBefore,
|
2889
|
-
"step-after": d3_svg_lineStepAfter,
|
2890
|
-
"basis": d3_svg_lineBasis,
|
2891
|
-
"basis-open": d3_svg_lineBasisOpen,
|
2892
|
-
"basis-closed": d3_svg_lineBasisClosed,
|
2893
|
-
"bundle": d3_svg_lineBundle,
|
2894
|
-
"cardinal": d3_svg_lineCardinal,
|
2895
|
-
"cardinal-open": d3_svg_lineCardinalOpen,
|
2896
|
-
"cardinal-closed": d3_svg_lineCardinalClosed,
|
2897
|
-
"monotone": d3_svg_lineMonotone
|
2898
|
-
};
|
2899
|
-
|
2900
|
-
// Linear interpolation; generates "L" commands.
|
2901
|
-
function d3_svg_lineLinear(points) {
|
2902
|
-
var i = 0,
|
2903
|
-
n = points.length,
|
2904
|
-
p = points[0],
|
2905
|
-
path = [p[0], ",", p[1]];
|
2906
|
-
while (++i < n) path.push("L", (p = points[i])[0], ",", p[1]);
|
2907
|
-
return path.join("");
|
2908
|
-
}
|
2909
|
-
|
2910
|
-
// Step interpolation; generates "H" and "V" commands.
|
2911
|
-
function d3_svg_lineStepBefore(points) {
|
2912
|
-
var i = 0,
|
2913
|
-
n = points.length,
|
2914
|
-
p = points[0],
|
2915
|
-
path = [p[0], ",", p[1]];
|
2916
|
-
while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
|
2917
|
-
return path.join("");
|
2918
|
-
}
|
2919
|
-
|
2920
|
-
// Step interpolation; generates "H" and "V" commands.
|
2921
|
-
function d3_svg_lineStepAfter(points) {
|
2922
|
-
var i = 0,
|
2923
|
-
n = points.length,
|
2924
|
-
p = points[0],
|
2925
|
-
path = [p[0], ",", p[1]];
|
2926
|
-
while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
|
2927
|
-
return path.join("");
|
2928
|
-
}
|
2929
|
-
|
2930
|
-
// Open cardinal spline interpolation; generates "C" commands.
|
2931
|
-
function d3_svg_lineCardinalOpen(points, tension) {
|
2932
|
-
return points.length < 4
|
2933
|
-
? d3_svg_lineLinear(points)
|
2934
|
-
: points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1),
|
2935
|
-
d3_svg_lineCardinalTangents(points, tension));
|
2936
|
-
}
|
2937
|
-
|
2938
|
-
// Closed cardinal spline interpolation; generates "C" commands.
|
2939
|
-
function d3_svg_lineCardinalClosed(points, tension) {
|
2940
|
-
return points.length < 3
|
2941
|
-
? d3_svg_lineLinear(points)
|
2942
|
-
: points[0] + d3_svg_lineHermite((points.push(points[0]), points),
|
2943
|
-
d3_svg_lineCardinalTangents([points[points.length - 2]]
|
2944
|
-
.concat(points, [points[1]]), tension));
|
2945
|
-
}
|
2946
|
-
|
2947
|
-
// Cardinal spline interpolation; generates "C" commands.
|
2948
|
-
function d3_svg_lineCardinal(points, tension, closed) {
|
2949
|
-
return points.length < 3
|
2950
|
-
? d3_svg_lineLinear(points)
|
2951
|
-
: points[0] + d3_svg_lineHermite(points,
|
2952
|
-
d3_svg_lineCardinalTangents(points, tension));
|
2953
|
-
}
|
2954
|
-
|
2955
|
-
// Hermite spline construction; generates "C" commands.
|
2956
|
-
function d3_svg_lineHermite(points, tangents) {
|
2957
|
-
if (tangents.length < 1
|
2958
|
-
|| (points.length != tangents.length
|
2959
|
-
&& points.length != tangents.length + 2)) {
|
2960
|
-
return d3_svg_lineLinear(points);
|
2961
|
-
}
|
2962
|
-
|
2963
|
-
var quad = points.length != tangents.length,
|
2964
|
-
path = "",
|
2965
|
-
p0 = points[0],
|
2966
|
-
p = points[1],
|
2967
|
-
t0 = tangents[0],
|
2968
|
-
t = t0,
|
2969
|
-
pi = 1;
|
2970
|
-
|
2971
|
-
if (quad) {
|
2972
|
-
path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3)
|
2973
|
-
+ "," + p[0] + "," + p[1];
|
2974
|
-
p0 = points[1];
|
2975
|
-
pi = 2;
|
2976
|
-
}
|
2977
|
-
|
2978
|
-
if (tangents.length > 1) {
|
2979
|
-
t = tangents[1];
|
2980
|
-
p = points[pi];
|
2981
|
-
pi++;
|
2982
|
-
path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1])
|
2983
|
-
+ "," + (p[0] - t[0]) + "," + (p[1] - t[1])
|
2984
|
-
+ "," + p[0] + "," + p[1];
|
2985
|
-
for (var i = 2; i < tangents.length; i++, pi++) {
|
2986
|
-
p = points[pi];
|
2987
|
-
t = tangents[i];
|
2988
|
-
path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1])
|
2989
|
-
+ "," + p[0] + "," + p[1];
|
2990
|
-
}
|
2991
|
-
}
|
2992
|
-
|
2993
|
-
if (quad) {
|
2994
|
-
var lp = points[pi];
|
2995
|
-
path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3)
|
2996
|
-
+ "," + lp[0] + "," + lp[1];
|
2997
|
-
}
|
2998
|
-
|
2999
|
-
return path;
|
3000
|
-
}
|
3001
|
-
|
3002
|
-
// Generates tangents for a cardinal spline.
|
3003
|
-
function d3_svg_lineCardinalTangents(points, tension) {
|
3004
|
-
var tangents = [],
|
3005
|
-
a = (1 - tension) / 2,
|
3006
|
-
p0,
|
3007
|
-
p1 = points[0],
|
3008
|
-
p2 = points[1],
|
3009
|
-
i = 1,
|
3010
|
-
n = points.length;
|
3011
|
-
while (++i < n) {
|
3012
|
-
p0 = p1;
|
3013
|
-
p1 = p2;
|
3014
|
-
p2 = points[i];
|
3015
|
-
tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
|
3016
|
-
}
|
3017
|
-
return tangents;
|
3018
|
-
}
|
3019
|
-
|
3020
|
-
// B-spline interpolation; generates "C" commands.
|
3021
|
-
function d3_svg_lineBasis(points) {
|
3022
|
-
if (points.length < 3) return d3_svg_lineLinear(points);
|
3023
|
-
var i = 1,
|
3024
|
-
n = points.length,
|
3025
|
-
pi = points[0],
|
3026
|
-
x0 = pi[0],
|
3027
|
-
y0 = pi[1],
|
3028
|
-
px = [x0, x0, x0, (pi = points[1])[0]],
|
3029
|
-
py = [y0, y0, y0, pi[1]],
|
3030
|
-
path = [x0, ",", y0];
|
3031
|
-
d3_svg_lineBasisBezier(path, px, py);
|
3032
|
-
while (++i < n) {
|
3033
|
-
pi = points[i];
|
3034
|
-
px.shift(); px.push(pi[0]);
|
3035
|
-
py.shift(); py.push(pi[1]);
|
3036
|
-
d3_svg_lineBasisBezier(path, px, py);
|
3037
|
-
}
|
3038
|
-
i = -1;
|
3039
|
-
while (++i < 2) {
|
3040
|
-
px.shift(); px.push(pi[0]);
|
3041
|
-
py.shift(); py.push(pi[1]);
|
3042
|
-
d3_svg_lineBasisBezier(path, px, py);
|
3043
|
-
}
|
3044
|
-
return path.join("");
|
3045
|
-
}
|
3046
|
-
|
3047
|
-
// Open B-spline interpolation; generates "C" commands.
|
3048
|
-
function d3_svg_lineBasisOpen(points) {
|
3049
|
-
if (points.length < 4) return d3_svg_lineLinear(points);
|
3050
|
-
var path = [],
|
3051
|
-
i = -1,
|
3052
|
-
n = points.length,
|
3053
|
-
pi,
|
3054
|
-
px = [0],
|
3055
|
-
py = [0];
|
3056
|
-
while (++i < 3) {
|
3057
|
-
pi = points[i];
|
3058
|
-
px.push(pi[0]);
|
3059
|
-
py.push(pi[1]);
|
3060
|
-
}
|
3061
|
-
path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px)
|
3062
|
-
+ "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
|
3063
|
-
--i; while (++i < n) {
|
3064
|
-
pi = points[i];
|
3065
|
-
px.shift(); px.push(pi[0]);
|
3066
|
-
py.shift(); py.push(pi[1]);
|
3067
|
-
d3_svg_lineBasisBezier(path, px, py);
|
3068
|
-
}
|
3069
|
-
return path.join("");
|
3070
|
-
}
|
3071
|
-
|
3072
|
-
// Closed B-spline interpolation; generates "C" commands.
|
3073
|
-
function d3_svg_lineBasisClosed(points) {
|
3074
|
-
var path,
|
3075
|
-
i = -1,
|
3076
|
-
n = points.length,
|
3077
|
-
m = n + 4,
|
3078
|
-
pi,
|
3079
|
-
px = [],
|
3080
|
-
py = [];
|
3081
|
-
while (++i < 4) {
|
3082
|
-
pi = points[i % n];
|
3083
|
-
px.push(pi[0]);
|
3084
|
-
py.push(pi[1]);
|
3085
|
-
}
|
3086
|
-
path = [
|
3087
|
-
d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",",
|
3088
|
-
d3_svg_lineDot4(d3_svg_lineBasisBezier3, py)
|
3089
|
-
];
|
3090
|
-
--i; while (++i < m) {
|
3091
|
-
pi = points[i % n];
|
3092
|
-
px.shift(); px.push(pi[0]);
|
3093
|
-
py.shift(); py.push(pi[1]);
|
3094
|
-
d3_svg_lineBasisBezier(path, px, py);
|
3095
|
-
}
|
3096
|
-
return path.join("");
|
3097
|
-
}
|
3098
|
-
|
3099
|
-
function d3_svg_lineBundle(points, tension) {
|
3100
|
-
var n = points.length - 1,
|
3101
|
-
x0 = points[0][0],
|
3102
|
-
y0 = points[0][1],
|
3103
|
-
dx = points[n][0] - x0,
|
3104
|
-
dy = points[n][1] - y0,
|
3105
|
-
i = -1,
|
3106
|
-
p,
|
3107
|
-
t;
|
3108
|
-
while (++i <= n) {
|
3109
|
-
p = points[i];
|
3110
|
-
t = i / n;
|
3111
|
-
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
|
3112
|
-
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
|
3113
|
-
}
|
3114
|
-
return d3_svg_lineBasis(points);
|
3115
|
-
}
|
3116
|
-
|
3117
|
-
// Returns the dot product of the given four-element vectors.
|
3118
|
-
function d3_svg_lineDot4(a, b) {
|
3119
|
-
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
3120
|
-
}
|
3121
|
-
|
3122
|
-
// Matrix to transform basis (b-spline) control points to bezier
|
3123
|
-
// control points. Derived from FvD 11.2.8.
|
3124
|
-
var d3_svg_lineBasisBezier1 = [0, 2/3, 1/3, 0],
|
3125
|
-
d3_svg_lineBasisBezier2 = [0, 1/3, 2/3, 0],
|
3126
|
-
d3_svg_lineBasisBezier3 = [0, 1/6, 2/3, 1/6];
|
3127
|
-
|
3128
|
-
// Pushes a "C" Bézier curve onto the specified path array, given the
|
3129
|
-
// two specified four-element arrays which define the control points.
|
3130
|
-
function d3_svg_lineBasisBezier(path, x, y) {
|
3131
|
-
path.push(
|
3132
|
-
"C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x),
|
3133
|
-
",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y),
|
3134
|
-
",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x),
|
3135
|
-
",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y),
|
3136
|
-
",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x),
|
3137
|
-
",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
|
3138
|
-
}
|
3139
|
-
|
3140
|
-
// Computes the slope from points p0 to p1.
|
3141
|
-
function d3_svg_lineSlope(p0, p1) {
|
3142
|
-
return (p1[1] - p0[1]) / (p1[0] - p0[0]);
|
3143
|
-
}
|
3144
|
-
|
3145
|
-
// Compute three-point differences for the given points.
|
3146
|
-
// http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Finite_difference
|
3147
|
-
function d3_svg_lineFiniteDifferences(points) {
|
3148
|
-
var i = 0,
|
3149
|
-
j = points.length - 1,
|
3150
|
-
m = [],
|
3151
|
-
p0 = points[0],
|
3152
|
-
p1 = points[1],
|
3153
|
-
d = m[0] = d3_svg_lineSlope(p0, p1);
|
3154
|
-
while (++i < j) {
|
3155
|
-
m[i] = d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]));
|
3156
|
-
}
|
3157
|
-
m[i] = d;
|
3158
|
-
return m;
|
3159
|
-
}
|
3160
|
-
|
3161
|
-
// Interpolates the given points using Fritsch-Carlson Monotone cubic Hermite
|
3162
|
-
// interpolation. Returns an array of tangent vectors. For details, see
|
3163
|
-
// http://en.wikipedia.org/wiki/Monotone_cubic_interpolation
|
3164
|
-
function d3_svg_lineMonotoneTangents(points) {
|
3165
|
-
var tangents = [],
|
3166
|
-
d,
|
3167
|
-
a,
|
3168
|
-
b,
|
3169
|
-
s,
|
3170
|
-
m = d3_svg_lineFiniteDifferences(points),
|
3171
|
-
i = -1,
|
3172
|
-
j = points.length - 1;
|
3173
|
-
|
3174
|
-
// The first two steps are done by computing finite-differences:
|
3175
|
-
// 1. Compute the slopes of the secant lines between successive points.
|
3176
|
-
// 2. Initialize the tangents at every point as the average of the secants.
|
3177
|
-
|
3178
|
-
// Then, for each segment…
|
3179
|
-
while (++i < j) {
|
3180
|
-
d = d3_svg_lineSlope(points[i], points[i + 1]);
|
3181
|
-
|
3182
|
-
// 3. If two successive yk = y{k + 1} are equal (i.e., d is zero), then set
|
3183
|
-
// mk = m{k + 1} = 0 as the spline connecting these points must be flat to
|
3184
|
-
// preserve monotonicity. Ignore step 4 and 5 for those k.
|
3185
|
-
|
3186
|
-
if (Math.abs(d) < 1e-6) {
|
3187
|
-
m[i] = m[i + 1] = 0;
|
3188
|
-
} else {
|
3189
|
-
// 4. Let ak = mk / dk and bk = m{k + 1} / dk.
|
3190
|
-
a = m[i] / d;
|
3191
|
-
b = m[i + 1] / d;
|
3192
|
-
|
3193
|
-
// 5. Prevent overshoot and ensure monotonicity by restricting the
|
3194
|
-
// magnitude of vector <ak, bk> to a circle of radius 3.
|
3195
|
-
s = a * a + b * b;
|
3196
|
-
if (s > 9) {
|
3197
|
-
s = d * 3 / Math.sqrt(s);
|
3198
|
-
m[i] = s * a;
|
3199
|
-
m[i + 1] = s * b;
|
3200
|
-
}
|
3201
|
-
}
|
3202
|
-
}
|
3203
|
-
|
3204
|
-
// Compute the normalized tangent vector from the slopes. Note that if x is
|
3205
|
-
// not monotonic, it's possible that the slope will be infinite, so we protect
|
3206
|
-
// against NaN by setting the coordinate to zero.
|
3207
|
-
i = -1; while (++i <= j) {
|
3208
|
-
s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0])
|
3209
|
-
/ (6 * (1 + m[i] * m[i]));
|
3210
|
-
tangents.push([s || 0, m[i] * s || 0]);
|
3211
|
-
}
|
3212
|
-
|
3213
|
-
return tangents;
|
3214
|
-
}
|
3215
|
-
|
3216
|
-
function d3_svg_lineMonotone(points) {
|
3217
|
-
return points.length < 3
|
3218
|
-
? d3_svg_lineLinear(points)
|
3219
|
-
: points[0] +
|
3220
|
-
d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
|
3221
|
-
}
|
3222
|
-
d3.svg.line.radial = function() {
|
3223
|
-
var line = d3_svg_line(d3_svg_lineRadial);
|
3224
|
-
line.radius = line.x, delete line.x;
|
3225
|
-
line.angle = line.y, delete line.y;
|
3226
|
-
return line;
|
3227
|
-
};
|
3228
|
-
|
3229
|
-
function d3_svg_lineRadial(points) {
|
3230
|
-
var point,
|
3231
|
-
i = -1,
|
3232
|
-
n = points.length,
|
3233
|
-
r,
|
3234
|
-
a;
|
3235
|
-
while (++i < n) {
|
3236
|
-
point = points[i];
|
3237
|
-
r = point[0];
|
3238
|
-
a = point[1] + d3_svg_arcOffset;
|
3239
|
-
point[0] = r * Math.cos(a);
|
3240
|
-
point[1] = r * Math.sin(a);
|
3241
|
-
}
|
3242
|
-
return points;
|
3243
|
-
}
|
3244
|
-
function d3_svg_area(projection) {
|
3245
|
-
var x0 = d3_svg_lineX,
|
3246
|
-
x1 = d3_svg_lineX,
|
3247
|
-
y0 = 0,
|
3248
|
-
y1 = d3_svg_lineY,
|
3249
|
-
interpolate,
|
3250
|
-
i0,
|
3251
|
-
i1,
|
3252
|
-
tension = .7;
|
3253
|
-
|
3254
|
-
function area(d) {
|
3255
|
-
if (d.length < 1) return null;
|
3256
|
-
var points0 = d3_svg_linePoints(this, d, x0, y0),
|
3257
|
-
points1 = d3_svg_linePoints(this, d, x0 === x1 ? d3_svg_areaX(points0) : x1, y0 === y1 ? d3_svg_areaY(points0) : y1);
|
3258
|
-
return "M" + i0(projection(points1), tension)
|
3259
|
-
+ "L" + i1(projection(points0.reverse()), tension)
|
3260
|
-
+ "Z";
|
3261
|
-
}
|
3262
|
-
|
3263
|
-
area.x = function(x) {
|
3264
|
-
if (!arguments.length) return x1;
|
3265
|
-
x0 = x1 = x;
|
3266
|
-
return area;
|
3267
|
-
};
|
3268
|
-
|
3269
|
-
area.x0 = function(x) {
|
3270
|
-
if (!arguments.length) return x0;
|
3271
|
-
x0 = x;
|
3272
|
-
return area;
|
3273
|
-
};
|
3274
|
-
|
3275
|
-
area.x1 = function(x) {
|
3276
|
-
if (!arguments.length) return x1;
|
3277
|
-
x1 = x;
|
3278
|
-
return area;
|
3279
|
-
};
|
3280
|
-
|
3281
|
-
area.y = function(y) {
|
3282
|
-
if (!arguments.length) return y1;
|
3283
|
-
y0 = y1 = y;
|
3284
|
-
return area;
|
3285
|
-
};
|
3286
|
-
|
3287
|
-
area.y0 = function(y) {
|
3288
|
-
if (!arguments.length) return y0;
|
3289
|
-
y0 = y;
|
3290
|
-
return area;
|
3291
|
-
};
|
3292
|
-
|
3293
|
-
area.y1 = function(y) {
|
3294
|
-
if (!arguments.length) return y1;
|
3295
|
-
y1 = y;
|
3296
|
-
return area;
|
3297
|
-
};
|
3298
|
-
|
3299
|
-
area.interpolate = function(x) {
|
3300
|
-
if (!arguments.length) return interpolate;
|
3301
|
-
i0 = d3_svg_lineInterpolators[interpolate = x];
|
3302
|
-
i1 = i0.reverse || i0;
|
3303
|
-
return area;
|
3304
|
-
};
|
3305
|
-
|
3306
|
-
area.tension = function(x) {
|
3307
|
-
if (!arguments.length) return tension;
|
3308
|
-
tension = x;
|
3309
|
-
return area;
|
3310
|
-
};
|
3311
|
-
|
3312
|
-
return area.interpolate("linear");
|
3313
|
-
}
|
3314
|
-
|
3315
|
-
d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
|
3316
|
-
d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
|
3317
|
-
|
3318
|
-
d3.svg.area = function() {
|
3319
|
-
return d3_svg_area(Object);
|
3320
|
-
};
|
3321
|
-
|
3322
|
-
function d3_svg_areaX(points) {
|
3323
|
-
return function(d, i) {
|
3324
|
-
return points[i][0];
|
3325
|
-
};
|
3326
|
-
}
|
3327
|
-
|
3328
|
-
function d3_svg_areaY(points) {
|
3329
|
-
return function(d, i) {
|
3330
|
-
return points[i][1];
|
3331
|
-
};
|
3332
|
-
}
|
3333
|
-
d3.svg.area.radial = function() {
|
3334
|
-
var area = d3_svg_area(d3_svg_lineRadial);
|
3335
|
-
area.radius = area.x, delete area.x;
|
3336
|
-
area.innerRadius = area.x0, delete area.x0;
|
3337
|
-
area.outerRadius = area.x1, delete area.x1;
|
3338
|
-
area.angle = area.y, delete area.y;
|
3339
|
-
area.startAngle = area.y0, delete area.y0;
|
3340
|
-
area.endAngle = area.y1, delete area.y1;
|
3341
|
-
return area;
|
3342
|
-
};
|
3343
|
-
d3.svg.chord = function() {
|
3344
|
-
var source = d3_svg_chordSource,
|
3345
|
-
target = d3_svg_chordTarget,
|
3346
|
-
radius = d3_svg_chordRadius,
|
3347
|
-
startAngle = d3_svg_arcStartAngle,
|
3348
|
-
endAngle = d3_svg_arcEndAngle;
|
3349
|
-
|
3350
|
-
// TODO Allow control point to be customized.
|
3351
|
-
|
3352
|
-
function chord(d, i) {
|
3353
|
-
var s = subgroup(this, source, d, i),
|
3354
|
-
t = subgroup(this, target, d, i);
|
3355
|
-
return "M" + s.p0
|
3356
|
-
+ arc(s.r, s.p1) + (equals(s, t)
|
3357
|
-
? curve(s.r, s.p1, s.r, s.p0)
|
3358
|
-
: curve(s.r, s.p1, t.r, t.p0)
|
3359
|
-
+ arc(t.r, t.p1)
|
3360
|
-
+ curve(t.r, t.p1, s.r, s.p0))
|
3361
|
-
+ "Z";
|
3362
|
-
}
|
3363
|
-
|
3364
|
-
function subgroup(self, f, d, i) {
|
3365
|
-
var subgroup = f.call(self, d, i),
|
3366
|
-
r = radius.call(self, subgroup, i),
|
3367
|
-
a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset,
|
3368
|
-
a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
|
3369
|
-
return {
|
3370
|
-
r: r,
|
3371
|
-
a0: a0,
|
3372
|
-
a1: a1,
|
3373
|
-
p0: [r * Math.cos(a0), r * Math.sin(a0)],
|
3374
|
-
p1: [r * Math.cos(a1), r * Math.sin(a1)]
|
3375
|
-
};
|
3376
|
-
}
|
3377
|
-
|
3378
|
-
function equals(a, b) {
|
3379
|
-
return a.a0 == b.a0 && a.a1 == b.a1;
|
3380
|
-
}
|
3381
|
-
|
3382
|
-
function arc(r, p) {
|
3383
|
-
return "A" + r + "," + r + " 0 0,1 " + p;
|
3384
|
-
}
|
3385
|
-
|
3386
|
-
function curve(r0, p0, r1, p1) {
|
3387
|
-
return "Q 0,0 " + p1;
|
3388
|
-
}
|
3389
|
-
|
3390
|
-
chord.radius = function(v) {
|
3391
|
-
if (!arguments.length) return radius;
|
3392
|
-
radius = d3.functor(v);
|
3393
|
-
return chord;
|
3394
|
-
};
|
3395
|
-
|
3396
|
-
chord.source = function(v) {
|
3397
|
-
if (!arguments.length) return source;
|
3398
|
-
source = d3.functor(v);
|
3399
|
-
return chord;
|
3400
|
-
};
|
3401
|
-
|
3402
|
-
chord.target = function(v) {
|
3403
|
-
if (!arguments.length) return target;
|
3404
|
-
target = d3.functor(v);
|
3405
|
-
return chord;
|
3406
|
-
};
|
3407
|
-
|
3408
|
-
chord.startAngle = function(v) {
|
3409
|
-
if (!arguments.length) return startAngle;
|
3410
|
-
startAngle = d3.functor(v);
|
3411
|
-
return chord;
|
3412
|
-
};
|
3413
|
-
|
3414
|
-
chord.endAngle = function(v) {
|
3415
|
-
if (!arguments.length) return endAngle;
|
3416
|
-
endAngle = d3.functor(v);
|
3417
|
-
return chord;
|
3418
|
-
};
|
3419
|
-
|
3420
|
-
return chord;
|
3421
|
-
};
|
3422
|
-
|
3423
|
-
function d3_svg_chordSource(d) {
|
3424
|
-
return d.source;
|
3425
|
-
}
|
3426
|
-
|
3427
|
-
function d3_svg_chordTarget(d) {
|
3428
|
-
return d.target;
|
3429
|
-
}
|
3430
|
-
|
3431
|
-
function d3_svg_chordRadius(d) {
|
3432
|
-
return d.radius;
|
3433
|
-
}
|
3434
|
-
|
3435
|
-
function d3_svg_chordStartAngle(d) {
|
3436
|
-
return d.startAngle;
|
3437
|
-
}
|
3438
|
-
|
3439
|
-
function d3_svg_chordEndAngle(d) {
|
3440
|
-
return d.endAngle;
|
3441
|
-
}
|
3442
|
-
d3.svg.diagonal = function() {
|
3443
|
-
var source = d3_svg_chordSource,
|
3444
|
-
target = d3_svg_chordTarget,
|
3445
|
-
projection = d3_svg_diagonalProjection;
|
3446
|
-
|
3447
|
-
function diagonal(d, i) {
|
3448
|
-
var p0 = source.call(this, d, i),
|
3449
|
-
p3 = target.call(this, d, i),
|
3450
|
-
m = (p0.y + p3.y) / 2,
|
3451
|
-
p = [p0, {x: p0.x, y: m}, {x: p3.x, y: m}, p3];
|
3452
|
-
p = p.map(projection);
|
3453
|
-
return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
|
3454
|
-
}
|
3455
|
-
|
3456
|
-
diagonal.source = function(x) {
|
3457
|
-
if (!arguments.length) return source;
|
3458
|
-
source = d3.functor(x);
|
3459
|
-
return diagonal;
|
3460
|
-
};
|
3461
|
-
|
3462
|
-
diagonal.target = function(x) {
|
3463
|
-
if (!arguments.length) return target;
|
3464
|
-
target = d3.functor(x);
|
3465
|
-
return diagonal;
|
3466
|
-
};
|
3467
|
-
|
3468
|
-
diagonal.projection = function(x) {
|
3469
|
-
if (!arguments.length) return projection;
|
3470
|
-
projection = x;
|
3471
|
-
return diagonal;
|
3472
|
-
};
|
3473
|
-
|
3474
|
-
return diagonal;
|
3475
|
-
};
|
3476
|
-
|
3477
|
-
function d3_svg_diagonalProjection(d) {
|
3478
|
-
return [d.x, d.y];
|
3479
|
-
}
|
3480
|
-
d3.svg.diagonal.radial = function() {
|
3481
|
-
var diagonal = d3.svg.diagonal(),
|
3482
|
-
projection = d3_svg_diagonalProjection,
|
3483
|
-
projection_ = diagonal.projection;
|
3484
|
-
|
3485
|
-
diagonal.projection = function(x) {
|
3486
|
-
return arguments.length
|
3487
|
-
? projection_(d3_svg_diagonalRadialProjection(projection = x))
|
3488
|
-
: projection;
|
3489
|
-
};
|
3490
|
-
|
3491
|
-
return diagonal;
|
3492
|
-
};
|
3493
|
-
|
3494
|
-
function d3_svg_diagonalRadialProjection(projection) {
|
3495
|
-
return function() {
|
3496
|
-
var d = projection.apply(this, arguments),
|
3497
|
-
r = d[0],
|
3498
|
-
a = d[1] + d3_svg_arcOffset;
|
3499
|
-
return [r * Math.cos(a), r * Math.sin(a)];
|
3500
|
-
};
|
3501
|
-
}
|
3502
|
-
d3.svg.mouse = function(container) {
|
3503
|
-
return d3_svg_mousePoint(container, d3.event);
|
3504
|
-
};
|
3505
|
-
|
3506
|
-
// https://bugs.webkit.org/show_bug.cgi?id=44083
|
3507
|
-
var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
|
3508
|
-
|
3509
|
-
function d3_svg_mousePoint(container, e) {
|
3510
|
-
var point = (container.ownerSVGElement || container).createSVGPoint();
|
3511
|
-
if ((d3_mouse_bug44083 < 0) && (window.scrollX || window.scrollY)) {
|
3512
|
-
var svg = d3.select(document.body)
|
3513
|
-
.append("svg:svg")
|
3514
|
-
.style("position", "absolute")
|
3515
|
-
.style("top", 0)
|
3516
|
-
.style("left", 0);
|
3517
|
-
var ctm = svg[0][0].getScreenCTM();
|
3518
|
-
d3_mouse_bug44083 = !(ctm.f || ctm.e);
|
3519
|
-
svg.remove();
|
3520
|
-
}
|
3521
|
-
if (d3_mouse_bug44083) {
|
3522
|
-
point.x = e.pageX;
|
3523
|
-
point.y = e.pageY;
|
3524
|
-
} else {
|
3525
|
-
point.x = e.clientX;
|
3526
|
-
point.y = e.clientY;
|
3527
|
-
}
|
3528
|
-
point = point.matrixTransform(container.getScreenCTM().inverse());
|
3529
|
-
return [point.x, point.y];
|
3530
|
-
};
|
3531
|
-
d3.svg.touches = function(container) {
|
3532
|
-
var touches = d3.event.touches;
|
3533
|
-
return touches ? d3_array(touches).map(function(touch) {
|
3534
|
-
var point = d3_svg_mousePoint(container, touch);
|
3535
|
-
point.identifier = touch.identifier;
|
3536
|
-
return point;
|
3537
|
-
}) : [];
|
3538
|
-
};
|
3539
|
-
d3.svg.symbol = function() {
|
3540
|
-
var type = d3_svg_symbolType,
|
3541
|
-
size = d3_svg_symbolSize;
|
3542
|
-
|
3543
|
-
function symbol(d, i) {
|
3544
|
-
return (d3_svg_symbols[type.call(this, d, i)]
|
3545
|
-
|| d3_svg_symbols.circle)
|
3546
|
-
(size.call(this, d, i));
|
3547
|
-
}
|
3548
|
-
|
3549
|
-
symbol.type = function(x) {
|
3550
|
-
if (!arguments.length) return type;
|
3551
|
-
type = d3.functor(x);
|
3552
|
-
return symbol;
|
3553
|
-
};
|
3554
|
-
|
3555
|
-
// size of symbol in square pixels
|
3556
|
-
symbol.size = function(x) {
|
3557
|
-
if (!arguments.length) return size;
|
3558
|
-
size = d3.functor(x);
|
3559
|
-
return symbol;
|
3560
|
-
};
|
3561
|
-
|
3562
|
-
return symbol;
|
3563
|
-
};
|
3564
|
-
|
3565
|
-
function d3_svg_symbolSize() {
|
3566
|
-
return 64;
|
3567
|
-
}
|
3568
|
-
|
3569
|
-
function d3_svg_symbolType() {
|
3570
|
-
return "circle";
|
3571
|
-
}
|
3572
|
-
|
3573
|
-
// TODO cross-diagonal?
|
3574
|
-
var d3_svg_symbols = {
|
3575
|
-
"circle": function(size) {
|
3576
|
-
var r = Math.sqrt(size / Math.PI);
|
3577
|
-
return "M0," + r
|
3578
|
-
+ "A" + r + "," + r + " 0 1,1 0," + (-r)
|
3579
|
-
+ "A" + r + "," + r + " 0 1,1 0," + r
|
3580
|
-
+ "Z";
|
3581
|
-
},
|
3582
|
-
"cross": function(size) {
|
3583
|
-
var r = Math.sqrt(size / 5) / 2;
|
3584
|
-
return "M" + -3 * r + "," + -r
|
3585
|
-
+ "H" + -r
|
3586
|
-
+ "V" + -3 * r
|
3587
|
-
+ "H" + r
|
3588
|
-
+ "V" + -r
|
3589
|
-
+ "H" + 3 * r
|
3590
|
-
+ "V" + r
|
3591
|
-
+ "H" + r
|
3592
|
-
+ "V" + 3 * r
|
3593
|
-
+ "H" + -r
|
3594
|
-
+ "V" + r
|
3595
|
-
+ "H" + -3 * r
|
3596
|
-
+ "Z";
|
3597
|
-
},
|
3598
|
-
"diamond": function(size) {
|
3599
|
-
var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)),
|
3600
|
-
rx = ry * d3_svg_symbolTan30;
|
3601
|
-
return "M0," + -ry
|
3602
|
-
+ "L" + rx + ",0"
|
3603
|
-
+ " 0," + ry
|
3604
|
-
+ " " + -rx + ",0"
|
3605
|
-
+ "Z";
|
3606
|
-
},
|
3607
|
-
"square": function(size) {
|
3608
|
-
var r = Math.sqrt(size) / 2;
|
3609
|
-
return "M" + -r + "," + -r
|
3610
|
-
+ "L" + r + "," + -r
|
3611
|
-
+ " " + r + "," + r
|
3612
|
-
+ " " + -r + "," + r
|
3613
|
-
+ "Z";
|
3614
|
-
},
|
3615
|
-
"triangle-down": function(size) {
|
3616
|
-
var rx = Math.sqrt(size / d3_svg_symbolSqrt3),
|
3617
|
-
ry = rx * d3_svg_symbolSqrt3 / 2;
|
3618
|
-
return "M0," + ry
|
3619
|
-
+ "L" + rx +"," + -ry
|
3620
|
-
+ " " + -rx + "," + -ry
|
3621
|
-
+ "Z";
|
3622
|
-
},
|
3623
|
-
"triangle-up": function(size) {
|
3624
|
-
var rx = Math.sqrt(size / d3_svg_symbolSqrt3),
|
3625
|
-
ry = rx * d3_svg_symbolSqrt3 / 2;
|
3626
|
-
return "M0," + -ry
|
3627
|
-
+ "L" + rx +"," + ry
|
3628
|
-
+ " " + -rx + "," + ry
|
3629
|
-
+ "Z";
|
3630
|
-
}
|
3631
|
-
};
|
3632
|
-
|
3633
|
-
d3.svg.symbolTypes = d3.keys(d3_svg_symbols);
|
3634
|
-
|
3635
|
-
var d3_svg_symbolSqrt3 = Math.sqrt(3),
|
3636
|
-
d3_svg_symbolTan30 = Math.tan(30 * Math.PI / 180);
|
3637
|
-
d3.svg.axis = function() {
|
3638
|
-
var scale = d3.scale.linear(),
|
3639
|
-
orient = "bottom",
|
3640
|
-
tickMajorSize = 6,
|
3641
|
-
tickMinorSize = 6,
|
3642
|
-
tickEndSize = 6,
|
3643
|
-
tickPadding = 3,
|
3644
|
-
tickArguments_ = [10],
|
3645
|
-
tickFormat_,
|
3646
|
-
tickSubdivide = 0;
|
3647
|
-
|
3648
|
-
function axis(selection) {
|
3649
|
-
selection.each(function(d, i, j) {
|
3650
|
-
var g = d3.select(this);
|
3651
|
-
|
3652
|
-
// If selection is a transition, create subtransitions.
|
3653
|
-
var transition = selection.delay ? function(o) {
|
3654
|
-
var id = d3_transitionInheritId;
|
3655
|
-
try {
|
3656
|
-
d3_transitionInheritId = selection.id;
|
3657
|
-
return o.transition()
|
3658
|
-
.delay(selection[j][i].delay)
|
3659
|
-
.duration(selection[j][i].duration)
|
3660
|
-
.ease(selection.ease());
|
3661
|
-
} finally {
|
3662
|
-
d3_transitionInheritId = id;
|
3663
|
-
}
|
3664
|
-
} : Object;
|
3665
|
-
|
3666
|
-
// Ticks.
|
3667
|
-
var ticks = scale.ticks.apply(scale, tickArguments_),
|
3668
|
-
tickFormat = tickFormat_ == null ? scale.tickFormat.apply(scale, tickArguments_) : tickFormat_;
|
3669
|
-
|
3670
|
-
// Minor ticks.
|
3671
|
-
var subticks = d3_svg_axisSubdivide(scale, ticks, tickSubdivide),
|
3672
|
-
subtick = g.selectAll(".minor").data(subticks, String),
|
3673
|
-
subtickEnter = subtick.enter().insert("svg:line", "g").attr("class", "tick minor").style("opacity", 1e-6),
|
3674
|
-
subtickExit = transition(subtick.exit()).style("opacity", 1e-6).remove(),
|
3675
|
-
subtickUpdate = transition(subtick).style("opacity", 1);
|
3676
|
-
|
3677
|
-
// Major ticks.
|
3678
|
-
var tick = g.selectAll("g").data(ticks, String),
|
3679
|
-
tickEnter = tick.enter().insert("svg:g", "path").style("opacity", 1e-6),
|
3680
|
-
tickExit = transition(tick.exit()).style("opacity", 1e-6).remove(),
|
3681
|
-
tickUpdate = transition(tick).style("opacity", 1),
|
3682
|
-
tickTransform;
|
3683
|
-
|
3684
|
-
// Domain.
|
3685
|
-
var range = d3_scaleExtent(scale.range()),
|
3686
|
-
path = g.selectAll(".domain").data([0]),
|
3687
|
-
pathEnter = path.enter().append("svg:path").attr("class", "domain"),
|
3688
|
-
pathUpdate = transition(path);
|
3689
|
-
|
3690
|
-
// Stash the new scale and grab the old scale.
|
3691
|
-
var scale0 = this.__chart__ || scale;
|
3692
|
-
this.__chart__ = scale.copy();
|
3693
|
-
|
3694
|
-
tickEnter.append("svg:line").attr("class", "tick");
|
3695
|
-
tickEnter.append("svg:text");
|
3696
|
-
tickUpdate.select("text").text(tickFormat);
|
3697
|
-
|
3698
|
-
switch (orient) {
|
3699
|
-
case "bottom": {
|
3700
|
-
tickTransform = d3_svg_axisX;
|
3701
|
-
subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
|
3702
|
-
tickUpdate.select("line").attr("x2", 0).attr("y2", tickMajorSize);
|
3703
|
-
tickUpdate.select("text").attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding).attr("dy", ".71em").attr("text-anchor", "middle");
|
3704
|
-
pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
|
3705
|
-
break;
|
3706
|
-
}
|
3707
|
-
case "top": {
|
3708
|
-
tickTransform = d3_svg_axisX;
|
3709
|
-
subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
|
3710
|
-
tickUpdate.select("line").attr("x2", 0).attr("y2", -tickMajorSize);
|
3711
|
-
tickUpdate.select("text").attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("dy", "0em").attr("text-anchor", "middle");
|
3712
|
-
pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
|
3713
|
-
break;
|
3714
|
-
}
|
3715
|
-
case "left": {
|
3716
|
-
tickTransform = d3_svg_axisY;
|
3717
|
-
subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
|
3718
|
-
tickUpdate.select("line").attr("x2", -tickMajorSize).attr("y2", 0);
|
3719
|
-
tickUpdate.select("text").attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0).attr("dy", ".32em").attr("text-anchor", "end");
|
3720
|
-
pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
|
3721
|
-
break;
|
3722
|
-
}
|
3723
|
-
case "right": {
|
3724
|
-
tickTransform = d3_svg_axisY;
|
3725
|
-
subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
|
3726
|
-
tickUpdate.select("line").attr("x2", tickMajorSize).attr("y2", 0);
|
3727
|
-
tickUpdate.select("text").attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0).attr("dy", ".32em").attr("text-anchor", "start");
|
3728
|
-
pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
|
3729
|
-
break;
|
3730
|
-
}
|
3731
|
-
}
|
3732
|
-
|
3733
|
-
tickEnter.call(tickTransform, scale0);
|
3734
|
-
tickUpdate.call(tickTransform, scale);
|
3735
|
-
tickExit.call(tickTransform, scale);
|
3736
|
-
|
3737
|
-
subtickEnter.call(tickTransform, scale0);
|
3738
|
-
subtickUpdate.call(tickTransform, scale);
|
3739
|
-
subtickExit.call(tickTransform, scale);
|
3740
|
-
});
|
3741
|
-
}
|
3742
|
-
|
3743
|
-
axis.scale = function(x) {
|
3744
|
-
if (!arguments.length) return scale;
|
3745
|
-
scale = x;
|
3746
|
-
return axis;
|
3747
|
-
};
|
3748
|
-
|
3749
|
-
axis.orient = function(x) {
|
3750
|
-
if (!arguments.length) return orient;
|
3751
|
-
orient = x;
|
3752
|
-
return axis;
|
3753
|
-
};
|
3754
|
-
|
3755
|
-
axis.ticks = function() {
|
3756
|
-
if (!arguments.length) return tickArguments_;
|
3757
|
-
tickArguments_ = arguments;
|
3758
|
-
return axis;
|
3759
|
-
};
|
3760
|
-
|
3761
|
-
axis.tickFormat = function(x) {
|
3762
|
-
if (!arguments.length) return tickFormat_;
|
3763
|
-
tickFormat_ = x;
|
3764
|
-
return axis;
|
3765
|
-
};
|
3766
|
-
|
3767
|
-
axis.tickSize = function(x, y, z) {
|
3768
|
-
if (!arguments.length) return tickMajorSize;
|
3769
|
-
var n = arguments.length - 1;
|
3770
|
-
tickMajorSize = +x;
|
3771
|
-
tickMinorSize = n > 1 ? +y : tickMajorSize;
|
3772
|
-
tickEndSize = n > 0 ? +arguments[n] : tickMajorSize;
|
3773
|
-
return axis;
|
3774
|
-
};
|
3775
|
-
|
3776
|
-
axis.tickPadding = function(x) {
|
3777
|
-
if (!arguments.length) return tickPadding;
|
3778
|
-
tickPadding = +x;
|
3779
|
-
return axis;
|
3780
|
-
};
|
3781
|
-
|
3782
|
-
axis.tickSubdivide = function(x) {
|
3783
|
-
if (!arguments.length) return tickSubdivide;
|
3784
|
-
tickSubdivide = +x;
|
3785
|
-
return axis;
|
3786
|
-
};
|
3787
|
-
|
3788
|
-
return axis;
|
3789
|
-
};
|
3790
|
-
|
3791
|
-
function d3_svg_axisX(selection, x) {
|
3792
|
-
selection.attr("transform", function(d) { return "translate(" + x(d) + ",0)"; });
|
3793
|
-
}
|
3794
|
-
|
3795
|
-
function d3_svg_axisY(selection, y) {
|
3796
|
-
selection.attr("transform", function(d) { return "translate(0," + y(d) + ")"; });
|
3797
|
-
}
|
3798
|
-
|
3799
|
-
function d3_svg_axisSubdivide(scale, ticks, m) {
|
3800
|
-
subticks = [];
|
3801
|
-
if (m && ticks.length > 1) {
|
3802
|
-
var extent = d3_scaleExtent(scale.domain()),
|
3803
|
-
subticks,
|
3804
|
-
i = -1,
|
3805
|
-
n = ticks.length,
|
3806
|
-
d = (ticks[1] - ticks[0]) / ++m,
|
3807
|
-
j,
|
3808
|
-
v;
|
3809
|
-
while (++i < n) {
|
3810
|
-
for (j = m; --j > 0;) {
|
3811
|
-
if ((v = +ticks[i] - j * d) >= extent[0]) {
|
3812
|
-
subticks.push(v);
|
3813
|
-
}
|
3814
|
-
}
|
3815
|
-
}
|
3816
|
-
for (--i, j = 0; ++j < m && (v = +ticks[i] + j * d) < extent[1];) {
|
3817
|
-
subticks.push(v);
|
3818
|
-
}
|
3819
|
-
}
|
3820
|
-
return subticks;
|
3821
|
-
}
|
3822
|
-
d3.behavior = {};
|
3823
|
-
d3.behavior.drag = function() {
|
3824
|
-
var event = d3.dispatch("drag", "dragstart", "dragend");
|
3825
|
-
|
3826
|
-
function drag() {
|
3827
|
-
this
|
3828
|
-
.on("mousedown.drag", mousedown)
|
3829
|
-
.on("touchstart.drag", mousedown);
|
3830
|
-
|
3831
|
-
d3.select(window)
|
3832
|
-
.on("mousemove.drag", d3_behavior_dragMove)
|
3833
|
-
.on("touchmove.drag", d3_behavior_dragMove)
|
3834
|
-
.on("mouseup.drag", d3_behavior_dragUp, true)
|
3835
|
-
.on("touchend.drag", d3_behavior_dragUp, true)
|
3836
|
-
.on("click.drag", d3_behavior_dragClick, true);
|
3837
|
-
}
|
3838
|
-
|
3839
|
-
// snapshot the local context for subsequent dispatch
|
3840
|
-
function start() {
|
3841
|
-
d3_behavior_dragEvent = event;
|
3842
|
-
d3_behavior_dragEventTarget = d3.event.target;
|
3843
|
-
d3_behavior_dragOffset = d3_behavior_dragPoint((d3_behavior_dragTarget = this).parentNode);
|
3844
|
-
d3_behavior_dragMoved = 0;
|
3845
|
-
d3_behavior_dragArguments = arguments;
|
3846
|
-
}
|
3847
|
-
|
3848
|
-
function mousedown() {
|
3849
|
-
start.apply(this, arguments);
|
3850
|
-
d3_behavior_dragDispatch("dragstart");
|
3851
|
-
}
|
3852
|
-
|
3853
|
-
drag.on = function(type, listener) {
|
3854
|
-
event[type].add(listener);
|
3855
|
-
return drag;
|
3856
|
-
};
|
3857
|
-
|
3858
|
-
return drag;
|
3859
|
-
};
|
3860
|
-
|
3861
|
-
var d3_behavior_dragEvent,
|
3862
|
-
d3_behavior_dragEventTarget,
|
3863
|
-
d3_behavior_dragTarget,
|
3864
|
-
d3_behavior_dragArguments,
|
3865
|
-
d3_behavior_dragOffset,
|
3866
|
-
d3_behavior_dragMoved,
|
3867
|
-
d3_behavior_dragStopClick;
|
3868
|
-
|
3869
|
-
function d3_behavior_dragDispatch(type) {
|
3870
|
-
var o = d3.event, p = d3_behavior_dragTarget.parentNode, dx = 0, dy = 0;
|
3871
|
-
|
3872
|
-
if (p) {
|
3873
|
-
p = d3_behavior_dragPoint(p);
|
3874
|
-
dx = p[0] - d3_behavior_dragOffset[0];
|
3875
|
-
dy = p[1] - d3_behavior_dragOffset[1];
|
3876
|
-
d3_behavior_dragOffset = p;
|
3877
|
-
d3_behavior_dragMoved |= dx | dy;
|
3878
|
-
}
|
3879
|
-
|
3880
|
-
try {
|
3881
|
-
d3.event = {dx: dx, dy: dy};
|
3882
|
-
d3_behavior_dragEvent[type].dispatch.apply(d3_behavior_dragTarget, d3_behavior_dragArguments);
|
3883
|
-
} finally {
|
3884
|
-
d3.event = o;
|
3885
|
-
}
|
3886
|
-
|
3887
|
-
o.preventDefault();
|
3888
|
-
}
|
3889
|
-
|
3890
|
-
function d3_behavior_dragPoint(container) {
|
3891
|
-
return d3.event.touches
|
3892
|
-
? d3.svg.touches(container)[0]
|
3893
|
-
: d3.svg.mouse(container);
|
3894
|
-
}
|
3895
|
-
|
3896
|
-
function d3_behavior_dragMove() {
|
3897
|
-
if (!d3_behavior_dragTarget) return;
|
3898
|
-
var parent = d3_behavior_dragTarget.parentNode;
|
3899
|
-
|
3900
|
-
// O NOES! The drag element was removed from the DOM.
|
3901
|
-
if (!parent) return d3_behavior_dragUp();
|
3902
|
-
|
3903
|
-
d3_behavior_dragDispatch("drag");
|
3904
|
-
d3_behavior_dragCancel();
|
3905
|
-
}
|
3906
|
-
|
3907
|
-
function d3_behavior_dragUp() {
|
3908
|
-
if (!d3_behavior_dragTarget) return;
|
3909
|
-
d3_behavior_dragDispatch("dragend");
|
3910
|
-
d3_behavior_dragTarget = null;
|
3911
|
-
|
3912
|
-
// If the node was moved, prevent the mouseup from propagating.
|
3913
|
-
// Also prevent the subsequent click from propagating (e.g., for anchors).
|
3914
|
-
if (d3_behavior_dragMoved && d3_behavior_dragEventTarget === d3.event.target) {
|
3915
|
-
d3_behavior_dragStopClick = true;
|
3916
|
-
d3_behavior_dragCancel();
|
3917
|
-
}
|
3918
|
-
}
|
3919
|
-
|
3920
|
-
function d3_behavior_dragClick() {
|
3921
|
-
if (d3_behavior_dragStopClick && d3_behavior_dragEventTarget === d3.event.target) {
|
3922
|
-
d3_behavior_dragCancel();
|
3923
|
-
d3_behavior_dragStopClick = false;
|
3924
|
-
d3_behavior_dragEventTarget = null;
|
3925
|
-
}
|
3926
|
-
}
|
3927
|
-
|
3928
|
-
function d3_behavior_dragCancel() {
|
3929
|
-
d3.event.stopPropagation();
|
3930
|
-
d3.event.preventDefault();
|
3931
|
-
}
|
3932
|
-
// TODO unbind zoom behavior?
|
3933
|
-
// TODO unbind listener?
|
3934
|
-
d3.behavior.zoom = function() {
|
3935
|
-
var xyz = [0, 0, 0],
|
3936
|
-
event = d3.dispatch("zoom");
|
3937
|
-
|
3938
|
-
function zoom() {
|
3939
|
-
this
|
3940
|
-
.on("mousedown.zoom", mousedown)
|
3941
|
-
.on("mousewheel.zoom", mousewheel)
|
3942
|
-
.on("DOMMouseScroll.zoom", mousewheel)
|
3943
|
-
.on("dblclick.zoom", dblclick)
|
3944
|
-
.on("touchstart.zoom", touchstart);
|
3945
|
-
|
3946
|
-
d3.select(window)
|
3947
|
-
.on("mousemove.zoom", d3_behavior_zoomMousemove)
|
3948
|
-
.on("mouseup.zoom", d3_behavior_zoomMouseup)
|
3949
|
-
.on("touchmove.zoom", d3_behavior_zoomTouchmove)
|
3950
|
-
.on("touchend.zoom", d3_behavior_zoomTouchup)
|
3951
|
-
.on("click.zoom", d3_behavior_zoomClick, true);
|
3952
|
-
}
|
3953
|
-
|
3954
|
-
// snapshot the local context for subsequent dispatch
|
3955
|
-
function start() {
|
3956
|
-
d3_behavior_zoomXyz = xyz;
|
3957
|
-
d3_behavior_zoomDispatch = event.zoom.dispatch;
|
3958
|
-
d3_behavior_zoomEventTarget = d3.event.target;
|
3959
|
-
d3_behavior_zoomTarget = this;
|
3960
|
-
d3_behavior_zoomArguments = arguments;
|
3961
|
-
}
|
3962
|
-
|
3963
|
-
function mousedown() {
|
3964
|
-
start.apply(this, arguments);
|
3965
|
-
d3_behavior_zoomPanning = d3_behavior_zoomLocation(d3.svg.mouse(d3_behavior_zoomTarget));
|
3966
|
-
d3_behavior_zoomMoved = false;
|
3967
|
-
d3.event.preventDefault();
|
3968
|
-
window.focus();
|
3969
|
-
}
|
3970
|
-
|
3971
|
-
// store starting mouse location
|
3972
|
-
function mousewheel() {
|
3973
|
-
start.apply(this, arguments);
|
3974
|
-
if (!d3_behavior_zoomZooming) d3_behavior_zoomZooming = d3_behavior_zoomLocation(d3.svg.mouse(d3_behavior_zoomTarget));
|
3975
|
-
d3_behavior_zoomTo(d3_behavior_zoomDelta() + xyz[2], d3.svg.mouse(d3_behavior_zoomTarget), d3_behavior_zoomZooming);
|
3976
|
-
}
|
3977
|
-
|
3978
|
-
function dblclick() {
|
3979
|
-
start.apply(this, arguments);
|
3980
|
-
var mouse = d3.svg.mouse(d3_behavior_zoomTarget);
|
3981
|
-
d3_behavior_zoomTo(d3.event.shiftKey ? Math.ceil(xyz[2] - 1) : Math.floor(xyz[2] + 1), mouse, d3_behavior_zoomLocation(mouse));
|
3982
|
-
}
|
3983
|
-
|
3984
|
-
// doubletap detection
|
3985
|
-
function touchstart() {
|
3986
|
-
start.apply(this, arguments);
|
3987
|
-
var touches = d3_behavior_zoomTouchup(),
|
3988
|
-
touch,
|
3989
|
-
now = Date.now();
|
3990
|
-
if ((touches.length === 1) && (now - d3_behavior_zoomLast < 300)) {
|
3991
|
-
d3_behavior_zoomTo(1 + Math.floor(xyz[2]), touch = touches[0], d3_behavior_zoomLocations[touch.identifier]);
|
3992
|
-
}
|
3993
|
-
d3_behavior_zoomLast = now;
|
3994
|
-
}
|
3995
|
-
|
3996
|
-
zoom.on = function(type, listener) {
|
3997
|
-
event[type].add(listener);
|
3998
|
-
return zoom;
|
3999
|
-
};
|
4000
|
-
|
4001
|
-
return zoom;
|
4002
|
-
};
|
4003
|
-
|
4004
|
-
var d3_behavior_zoomDiv,
|
4005
|
-
d3_behavior_zoomPanning,
|
4006
|
-
d3_behavior_zoomZooming,
|
4007
|
-
d3_behavior_zoomLocations = {}, // identifier -> location
|
4008
|
-
d3_behavior_zoomLast = 0,
|
4009
|
-
d3_behavior_zoomXyz,
|
4010
|
-
d3_behavior_zoomDispatch,
|
4011
|
-
d3_behavior_zoomEventTarget,
|
4012
|
-
d3_behavior_zoomTarget,
|
4013
|
-
d3_behavior_zoomArguments,
|
4014
|
-
d3_behavior_zoomMoved,
|
4015
|
-
d3_behavior_zoomStopClick;
|
4016
|
-
|
4017
|
-
function d3_behavior_zoomLocation(point) {
|
4018
|
-
return [
|
4019
|
-
point[0] - d3_behavior_zoomXyz[0],
|
4020
|
-
point[1] - d3_behavior_zoomXyz[1],
|
4021
|
-
d3_behavior_zoomXyz[2]
|
4022
|
-
];
|
4023
|
-
}
|
4024
|
-
|
4025
|
-
// detect the pixels that would be scrolled by this wheel event
|
4026
|
-
function d3_behavior_zoomDelta() {
|
4027
|
-
|
4028
|
-
// mousewheel events are totally broken!
|
4029
|
-
// https://bugs.webkit.org/show_bug.cgi?id=40441
|
4030
|
-
// not only that, but Chrome and Safari differ in re. to acceleration!
|
4031
|
-
if (!d3_behavior_zoomDiv) {
|
4032
|
-
d3_behavior_zoomDiv = d3.select("body").append("div")
|
4033
|
-
.style("visibility", "hidden")
|
4034
|
-
.style("top", 0)
|
4035
|
-
.style("height", 0)
|
4036
|
-
.style("width", 0)
|
4037
|
-
.style("overflow-y", "scroll")
|
4038
|
-
.append("div")
|
4039
|
-
.style("height", "2000px")
|
4040
|
-
.node().parentNode;
|
4041
|
-
}
|
4042
|
-
|
4043
|
-
var e = d3.event, delta;
|
4044
|
-
try {
|
4045
|
-
d3_behavior_zoomDiv.scrollTop = 1000;
|
4046
|
-
d3_behavior_zoomDiv.dispatchEvent(e);
|
4047
|
-
delta = 1000 - d3_behavior_zoomDiv.scrollTop;
|
4048
|
-
} catch (error) {
|
4049
|
-
delta = e.wheelDelta || (-e.detail * 5);
|
4050
|
-
}
|
4051
|
-
|
4052
|
-
return delta * .005;
|
4053
|
-
}
|
4054
|
-
|
4055
|
-
// Note: Since we don't rotate, it's possible for the touches to become
|
4056
|
-
// slightly detached from their original positions. Thus, we recompute the
|
4057
|
-
// touch points on touchend as well as touchstart!
|
4058
|
-
function d3_behavior_zoomTouchup() {
|
4059
|
-
var touches = d3.svg.touches(d3_behavior_zoomTarget),
|
4060
|
-
i = -1,
|
4061
|
-
n = touches.length,
|
4062
|
-
touch;
|
4063
|
-
while (++i < n) d3_behavior_zoomLocations[(touch = touches[i]).identifier] = d3_behavior_zoomLocation(touch);
|
4064
|
-
return touches;
|
4065
|
-
}
|
4066
|
-
|
4067
|
-
function d3_behavior_zoomTouchmove() {
|
4068
|
-
var touches = d3.svg.touches(d3_behavior_zoomTarget);
|
4069
|
-
switch (touches.length) {
|
4070
|
-
|
4071
|
-
// single-touch pan
|
4072
|
-
case 1: {
|
4073
|
-
var touch = touches[0];
|
4074
|
-
d3_behavior_zoomTo(d3_behavior_zoomXyz[2], touch, d3_behavior_zoomLocations[touch.identifier]);
|
4075
|
-
break;
|
4076
|
-
}
|
4077
|
-
|
4078
|
-
// double-touch pan + zoom
|
4079
|
-
case 2: {
|
4080
|
-
var p0 = touches[0],
|
4081
|
-
p1 = touches[1],
|
4082
|
-
p2 = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2],
|
4083
|
-
l0 = d3_behavior_zoomLocations[p0.identifier],
|
4084
|
-
l1 = d3_behavior_zoomLocations[p1.identifier],
|
4085
|
-
l2 = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2, l0[2]];
|
4086
|
-
d3_behavior_zoomTo(Math.log(d3.event.scale) / Math.LN2 + l0[2], p2, l2);
|
4087
|
-
break;
|
4088
|
-
}
|
4089
|
-
}
|
4090
|
-
}
|
4091
|
-
|
4092
|
-
function d3_behavior_zoomMousemove() {
|
4093
|
-
d3_behavior_zoomZooming = null;
|
4094
|
-
if (d3_behavior_zoomPanning) {
|
4095
|
-
d3_behavior_zoomMoved = true;
|
4096
|
-
d3_behavior_zoomTo(d3_behavior_zoomXyz[2], d3.svg.mouse(d3_behavior_zoomTarget), d3_behavior_zoomPanning);
|
4097
|
-
}
|
4098
|
-
}
|
4099
|
-
|
4100
|
-
function d3_behavior_zoomMouseup() {
|
4101
|
-
if (d3_behavior_zoomPanning) {
|
4102
|
-
if (d3_behavior_zoomMoved && d3_behavior_zoomEventTarget === d3.event.target) {
|
4103
|
-
d3_behavior_zoomStopClick = true;
|
4104
|
-
}
|
4105
|
-
d3_behavior_zoomMousemove();
|
4106
|
-
d3_behavior_zoomPanning = null;
|
4107
|
-
}
|
4108
|
-
}
|
4109
|
-
|
4110
|
-
function d3_behavior_zoomClick() {
|
4111
|
-
if (d3_behavior_zoomStopClick && d3_behavior_zoomEventTarget === d3.event.target) {
|
4112
|
-
d3.event.stopPropagation();
|
4113
|
-
d3.event.preventDefault();
|
4114
|
-
d3_behavior_zoomStopClick = false;
|
4115
|
-
d3_behavior_zoomEventTarget = null;
|
4116
|
-
}
|
4117
|
-
}
|
4118
|
-
|
4119
|
-
function d3_behavior_zoomTo(z, x0, x1) {
|
4120
|
-
var K = Math.pow(2, (d3_behavior_zoomXyz[2] = z) - x1[2]),
|
4121
|
-
x = d3_behavior_zoomXyz[0] = x0[0] - K * x1[0],
|
4122
|
-
y = d3_behavior_zoomXyz[1] = x0[1] - K * x1[1],
|
4123
|
-
o = d3.event, // Events can be reentrant (e.g., focus).
|
4124
|
-
k = Math.pow(2, z);
|
4125
|
-
|
4126
|
-
d3.event = {
|
4127
|
-
scale: k,
|
4128
|
-
translate: [x, y],
|
4129
|
-
transform: function(sx, sy) {
|
4130
|
-
if (sx) transform(sx, x);
|
4131
|
-
if (sy) transform(sy, y);
|
4132
|
-
}
|
4133
|
-
};
|
4134
|
-
|
4135
|
-
function transform(scale, o) {
|
4136
|
-
var domain = scale.__domain || (scale.__domain = scale.domain()),
|
4137
|
-
range = scale.range().map(function(v) { return (v - o) / k; });
|
4138
|
-
scale.domain(domain).domain(range.map(scale.invert));
|
4139
|
-
}
|
4140
|
-
|
4141
|
-
try {
|
4142
|
-
d3_behavior_zoomDispatch.apply(d3_behavior_zoomTarget, d3_behavior_zoomArguments);
|
4143
|
-
} finally {
|
4144
|
-
d3.event = o;
|
4145
|
-
}
|
4146
|
-
|
4147
|
-
o.preventDefault();
|
4148
|
-
}
|
4149
|
-
})();
|