d3_rails 2.10.3 → 3.0.0

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