d3_rails 2.9.7 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store CHANGED
Binary file
data/lib/.DS_Store CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module D3Rails
2
- VERSION = "2.9.7"
2
+ VERSION = "2.10.0"
3
3
  end
data/vendor/.DS_Store CHANGED
Binary file
@@ -11,7 +11,7 @@
11
11
  };
12
12
  }
13
13
  d3 = {
14
- version: "2.9.7"
14
+ version: "2.10.0"
15
15
  };
16
16
  function d3_class(ctor, properties) {
17
17
  try {
@@ -183,9 +183,10 @@
183
183
  return [ a, c ];
184
184
  };
185
185
  d3.random = {
186
- normal: function(mean, deviation) {
187
- if (arguments.length < 2) deviation = 1;
188
- if (arguments.length < 1) mean = 0;
186
+ normal: function(µ, σ) {
187
+ var n = arguments.length;
188
+ if (n < 2) σ = 1;
189
+ if (n < 1) µ = 0;
189
190
  return function() {
190
191
  var x, y, r;
191
192
  do {
@@ -193,7 +194,22 @@
193
194
  y = Math.random() * 2 - 1;
194
195
  r = x * x + y * y;
195
196
  } while (!r || r > 1);
196
- return mean + deviation * x * Math.sqrt(-2 * Math.log(r) / r);
197
+ return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
198
+ };
199
+ },
200
+ logNormal: function(µ, σ) {
201
+ var n = arguments.length;
202
+ if (n < 2) σ = 1;
203
+ if (n < 1) µ = 0;
204
+ var random = d3.random.normal();
205
+ return function() {
206
+ return Math.exp(µ + σ * random());
207
+ };
208
+ },
209
+ irwinHall: function(m) {
210
+ return function() {
211
+ for (var s = 0, j = 0; j < m; j++) s += Math.random();
212
+ return s / m;
197
213
  };
198
214
  }
199
215
  };
@@ -373,7 +389,7 @@
373
389
  return d == null;
374
390
  }
375
391
  function d3_collapse(s) {
376
- return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ");
392
+ return s.trim().replace(/\s+/g, " ");
377
393
  }
378
394
  d3.range = function(start, stop, step) {
379
395
  if (arguments.length < 3) {
@@ -541,7 +557,7 @@
541
557
  type = d3_format_types.get(type) || d3_format_typeDefault;
542
558
  return function(value) {
543
559
  if (integer && value % 1) return "";
544
- var negative = value < 0 && (value = -value) ? "" : sign;
560
+ var negative = value < 0 && (value = -value) ? "-" : sign;
545
561
  if (scale < 0) {
546
562
  var prefix = d3.formatPrefix(value, precision);
547
563
  value = prefix.scale(value);
@@ -860,7 +876,6 @@
860
876
  };
861
877
  };
862
878
  d3.interpolateTransform = function(a, b) {
863
- if (n = d3_interpolateTransformSimilar(a, b)) return n;
864
879
  var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
865
880
  if (ta[0] != tb[0] || ta[1] != tb[1]) {
866
881
  s.push("translate(", null, ",", null, ")");
@@ -912,65 +927,6 @@
912
927
  return s.join("");
913
928
  };
914
929
  };
915
- var d3_interpolateTransformTypes = [ "", "", "translate", "scale", "rotate", "skewX", "skewY" ];
916
- var d3_interpolateTransformSimilar = function(a, b) {
917
- var ga = document.createElementNS(d3.ns.prefix.svg, "g"), gb = document.createElementNS(d3.ns.prefix.svg, "g");
918
- return (d3_interpolateTransformSimilar = function(a, b) {
919
- ga.setAttribute("transform", a);
920
- gb.setAttribute("transform", b);
921
- a = ga.transform.baseVal;
922
- b = gb.transform.baseVal;
923
- var sa = [], sb = [], i = -1, n = a.numberOfItems, m = b.numberOfItems, ta, tb, type;
924
- if (m !== n) {
925
- if (!m) b = d3_interpolateTransformIdentity(a); else if (!n) a = d3_interpolateTransformIdentity(b), n = m; else return;
926
- } else if (!m) return;
927
- while (++i < n) {
928
- ta = a.getItem(i);
929
- tb = b.getItem(i);
930
- type = ta.type;
931
- if (type !== tb.type || !type) return;
932
- switch (type) {
933
- case 1:
934
- {
935
- sa.push(new d3_transform(ta.matrix));
936
- sb.push(new d3_transform(tb.matrix));
937
- continue;
938
- }
939
- case 2:
940
- {
941
- ra = ta.matrix.e + "," + ta.matrix.f;
942
- rb = tb.matrix.e + "," + tb.matrix.f;
943
- break;
944
- }
945
- case 3:
946
- {
947
- ra = ta.matrix.a + "," + ta.matrix.d;
948
- rb = tb.matrix.a + "," + tb.matrix.d;
949
- break;
950
- }
951
- default:
952
- {
953
- ra = ta.angle;
954
- rb = tb.angle;
955
- }
956
- }
957
- sa.push(type = d3_interpolateTransformTypes[type], "(", ra, ")");
958
- sb.push(type, "(", rb, ")");
959
- }
960
- return d3.interpolateString(sa.join(""), sb.join(""));
961
- })(a, b);
962
- };
963
- function d3_interpolateTransformIdentity(a) {
964
- return {
965
- getItem: function(i) {
966
- return {
967
- type: a.getItem(i).type,
968
- angle: 0,
969
- matrix: d3_transformIdentity
970
- };
971
- }
972
- };
973
- }
974
930
  d3.interpolateRgb = function(a, b) {
975
931
  a = d3.rgb(a);
976
932
  b = d3.rgb(b);
@@ -985,7 +941,24 @@
985
941
  var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
986
942
  if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
987
943
  return function(t) {
988
- return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t).toString();
944
+ return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
945
+ };
946
+ };
947
+ d3.interpolateLab = function(a, b) {
948
+ a = d3.lab(a);
949
+ b = d3.lab(b);
950
+ var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
951
+ return function(t) {
952
+ return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
953
+ };
954
+ };
955
+ d3.interpolateHcl = function(a, b) {
956
+ a = d3.hcl(a);
957
+ b = d3.hcl(b);
958
+ var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
959
+ if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
960
+ return function(t) {
961
+ return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
989
962
  };
990
963
  };
991
964
  d3.interpolateArray = function(a, b) {
@@ -1018,8 +991,8 @@
1018
991
  };
1019
992
  };
1020
993
  var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
1021
- function d3_interpolateByName(n) {
1022
- return n == "transform" ? d3.interpolateTransform : d3.interpolate;
994
+ function d3_interpolateByName(name) {
995
+ return name == "transform" ? d3.interpolateTransform : d3.interpolate;
1023
996
  }
1024
997
  d3.interpolators = [ d3.interpolateObject, function(a, b) {
1025
998
  return b instanceof Array && d3.interpolateArray(a, b);
@@ -1122,6 +1095,16 @@
1122
1095
  }
1123
1096
  return d3_hsl(h, s, l);
1124
1097
  }
1098
+ function d3_rgb_lab(r, g, b) {
1099
+ r = d3_rgb_xyz(r);
1100
+ g = d3_rgb_xyz(g);
1101
+ b = d3_rgb_xyz(b);
1102
+ var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
1103
+ return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1104
+ }
1105
+ function d3_rgb_xyz(r) {
1106
+ return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1107
+ }
1125
1108
  function d3_rgb_parseNumber(c) {
1126
1109
  var f = parseFloat(c);
1127
1110
  return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
@@ -1323,6 +1306,76 @@
1323
1306
  }
1324
1307
  return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1325
1308
  }
1309
+ d3.hcl = function(h, c, l) {
1310
+ return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
1311
+ };
1312
+ function d3_hcl(h, c, l) {
1313
+ return new d3_Hcl(h, c, l);
1314
+ }
1315
+ function d3_Hcl(h, c, l) {
1316
+ this.h = h;
1317
+ this.c = c;
1318
+ this.l = l;
1319
+ }
1320
+ d3_Hcl.prototype.brighter = function(k) {
1321
+ return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1322
+ };
1323
+ d3_Hcl.prototype.darker = function(k) {
1324
+ return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1325
+ };
1326
+ d3_Hcl.prototype.rgb = function() {
1327
+ return d3_hcl_lab(this.h, this.c, this.l).rgb();
1328
+ };
1329
+ d3_Hcl.prototype.toString = function() {
1330
+ return this.rgb() + "";
1331
+ };
1332
+ function d3_hcl_lab(h, c, l) {
1333
+ return d3_lab(l, Math.cos(h *= Math.PI / 180) * c, Math.sin(h) * c);
1334
+ }
1335
+ d3.lab = function(l, a, b) {
1336
+ return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
1337
+ };
1338
+ function d3_lab(l, a, b) {
1339
+ return new d3_Lab(l, a, b);
1340
+ }
1341
+ function d3_Lab(l, a, b) {
1342
+ this.l = l;
1343
+ this.a = a;
1344
+ this.b = b;
1345
+ }
1346
+ var d3_lab_K = 18;
1347
+ var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1348
+ d3_Lab.prototype.brighter = function(k) {
1349
+ return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1350
+ };
1351
+ d3_Lab.prototype.darker = function(k) {
1352
+ return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1353
+ };
1354
+ d3_Lab.prototype.rgb = function() {
1355
+ return d3_lab_rgb(this.l, this.a, this.b);
1356
+ };
1357
+ d3_Lab.prototype.toString = function() {
1358
+ return this.rgb() + "";
1359
+ };
1360
+ function d3_lab_rgb(l, a, b) {
1361
+ var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1362
+ x = d3_lab_xyz(x) * d3_lab_X;
1363
+ y = d3_lab_xyz(y) * d3_lab_Y;
1364
+ z = d3_lab_xyz(z) * d3_lab_Z;
1365
+ return d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
1366
+ }
1367
+ function d3_lab_hcl(l, a, b) {
1368
+ return d3_hcl(Math.atan2(b, a) / Math.PI * 180, Math.sqrt(a * a + b * b), l);
1369
+ }
1370
+ function d3_lab_xyz(x) {
1371
+ return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1372
+ }
1373
+ function d3_xyz_lab(x) {
1374
+ return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1375
+ }
1376
+ function d3_xyz_rgb(r) {
1377
+ return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1378
+ }
1326
1379
  function d3_selection(groups) {
1327
1380
  d3_arraySubclass(groups, d3_selectionPrototype);
1328
1381
  return groups;
@@ -1389,11 +1442,19 @@
1389
1442
  };
1390
1443
  }
1391
1444
  d3_selectionPrototype.attr = function(name, value) {
1392
- name = d3.ns.qualify(name);
1393
1445
  if (arguments.length < 2) {
1394
- var node = this.node();
1395
- return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
1446
+ if (typeof name === "string") {
1447
+ var node = this.node();
1448
+ name = d3.ns.qualify(name);
1449
+ return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
1450
+ }
1451
+ for (value in name) this.each(d3_selection_attr(value, name[value]));
1452
+ return this;
1396
1453
  }
1454
+ return this.each(d3_selection_attr(name, value));
1455
+ };
1456
+ function d3_selection_attr(name, value) {
1457
+ name = d3.ns.qualify(name);
1397
1458
  function attrNull() {
1398
1459
  this.removeAttribute(name);
1399
1460
  }
@@ -1414,52 +1475,73 @@
1414
1475
  var x = value.apply(this, arguments);
1415
1476
  if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
1416
1477
  }
1417
- return this.each(value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant);
1418
- };
1478
+ return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
1479
+ }
1419
1480
  d3_selectionPrototype.classed = function(name, value) {
1420
- var names = d3_collapse(name).split(" "), n = names.length, i = -1;
1421
- if (arguments.length > 1) {
1422
- while (++i < n) d3_selection_classed.call(this, names[i], value);
1481
+ if (arguments.length < 2) {
1482
+ if (typeof name === "string") {
1483
+ var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
1484
+ if (value = node.classList) {
1485
+ while (++i < n) if (!value.contains(name[i])) return false;
1486
+ } else {
1487
+ value = node.className;
1488
+ if (value.baseVal != null) value = value.baseVal;
1489
+ while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
1490
+ }
1491
+ return true;
1492
+ }
1493
+ for (value in name) this.each(d3_selection_classed(value, name[value]));
1423
1494
  return this;
1424
- } else {
1425
- while (++i < n) if (!d3_selection_classed.call(this, names[i])) return false;
1426
- return true;
1427
1495
  }
1496
+ return this.each(d3_selection_classed(name, value));
1428
1497
  };
1498
+ function d3_selection_classedRe(name) {
1499
+ return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
1500
+ }
1429
1501
  function d3_selection_classed(name, value) {
1430
- var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");
1431
- if (arguments.length < 2) {
1432
- var node = this.node();
1433
- if (c = node.classList) return c.contains(name);
1434
- var c = node.className;
1435
- re.lastIndex = 0;
1436
- return re.test(c.baseVal != null ? c.baseVal : c);
1437
- }
1438
- function classedAdd() {
1439
- if (c = this.classList) return c.add(name);
1440
- var c = this.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
1441
- re.lastIndex = 0;
1442
- if (!re.test(cv)) {
1443
- cv = d3_collapse(cv + " " + name);
1444
- if (cb) c.baseVal = cv; else this.className = cv;
1445
- }
1446
- }
1447
- function classedRemove() {
1448
- if (c = this.classList) return c.remove(name);
1449
- var c = this.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
1450
- if (cv) {
1451
- cv = d3_collapse(cv.replace(re, " "));
1452
- if (cb) c.baseVal = cv; else this.className = cv;
1453
- }
1502
+ name = name.trim().split(/\s+/).map(d3_selection_classedName);
1503
+ var n = name.length;
1504
+ function classedConstant() {
1505
+ var i = -1;
1506
+ while (++i < n) name[i](this, value);
1454
1507
  }
1455
1508
  function classedFunction() {
1456
- (value.apply(this, arguments) ? classedAdd : classedRemove).call(this);
1457
- }
1458
- return this.each(typeof value === "function" ? classedFunction : value ? classedAdd : classedRemove);
1509
+ var i = -1, x = value.apply(this, arguments);
1510
+ while (++i < n) name[i](this, x);
1511
+ }
1512
+ return typeof value === "function" ? classedFunction : classedConstant;
1513
+ }
1514
+ function d3_selection_classedName(name) {
1515
+ var re = d3_selection_classedRe(name);
1516
+ return function(node, value) {
1517
+ if (c = node.classList) return value ? c.add(name) : c.remove(name);
1518
+ var c = node.className, cb = c.baseVal != null, cv = cb ? c.baseVal : c;
1519
+ if (value) {
1520
+ re.lastIndex = 0;
1521
+ if (!re.test(cv)) {
1522
+ cv = d3_collapse(cv + " " + name);
1523
+ if (cb) c.baseVal = cv; else node.className = cv;
1524
+ }
1525
+ } else if (cv) {
1526
+ cv = d3_collapse(cv.replace(re, " "));
1527
+ if (cb) c.baseVal = cv; else node.className = cv;
1528
+ }
1529
+ };
1459
1530
  }
1460
1531
  d3_selectionPrototype.style = function(name, value, priority) {
1461
- if (arguments.length < 3) priority = "";
1462
- if (arguments.length < 2) return window.getComputedStyle(this.node(), null).getPropertyValue(name);
1532
+ var n = arguments.length;
1533
+ if (n < 3) {
1534
+ if (typeof name !== "string") {
1535
+ if (n < 2) value = "";
1536
+ for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
1537
+ return this;
1538
+ }
1539
+ if (n < 2) return window.getComputedStyle(this.node(), null).getPropertyValue(name);
1540
+ priority = "";
1541
+ }
1542
+ return this.each(d3_selection_style(name, value, priority));
1543
+ };
1544
+ function d3_selection_style(name, value, priority) {
1463
1545
  function styleNull() {
1464
1546
  this.style.removeProperty(name);
1465
1547
  }
@@ -1470,10 +1552,17 @@
1470
1552
  var x = value.apply(this, arguments);
1471
1553
  if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
1472
1554
  }
1473
- return this.each(value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant);
1474
- };
1555
+ return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
1556
+ }
1475
1557
  d3_selectionPrototype.property = function(name, value) {
1476
- if (arguments.length < 2) return this.node()[name];
1558
+ if (arguments.length < 2) {
1559
+ if (typeof name === "string") return this.node()[name];
1560
+ for (value in name) this.each(d3_selection_property(value, name[value]));
1561
+ return this;
1562
+ }
1563
+ return this.each(d3_selection_property(name, value));
1564
+ };
1565
+ function d3_selection_property(name, value) {
1477
1566
  function propertyNull() {
1478
1567
  delete this[name];
1479
1568
  }
@@ -1484,8 +1573,8 @@
1484
1573
  var x = value.apply(this, arguments);
1485
1574
  if (x == null) delete this[name]; else this[name] = x;
1486
1575
  }
1487
- return this.each(value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant);
1488
- };
1576
+ return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
1577
+ }
1489
1578
  d3_selectionPrototype.text = function(value) {
1490
1579
  return arguments.length < 1 ? this.node().textContent : this.each(typeof value === "function" ? function() {
1491
1580
  var v = value.apply(this, arguments);
@@ -1669,21 +1758,34 @@
1669
1758
  };
1670
1759
  }
1671
1760
  d3_selectionPrototype.on = function(type, listener, capture) {
1672
- if (arguments.length < 3) capture = false;
1761
+ var n = arguments.length;
1762
+ if (n < 3) {
1763
+ if (typeof type !== "string") {
1764
+ if (n < 2) listener = false;
1765
+ for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1766
+ return this;
1767
+ }
1768
+ if (n < 2) return (n = this.node()["__on" + type]) && n._;
1769
+ capture = false;
1770
+ }
1771
+ return this.each(d3_selection_on(type, listener, capture));
1772
+ };
1773
+ function d3_selection_on(type, listener, capture) {
1673
1774
  var name = "__on" + type, i = type.indexOf(".");
1674
1775
  if (i > 0) type = type.substring(0, i);
1675
- if (arguments.length < 2) return (i = this.node()[name]) && i._;
1676
- return this.each(function() {
1677
- var node = this, args = arguments, o = node[name];
1678
- if (o) {
1679
- node.removeEventListener(type, o, o.$);
1680
- delete node[name];
1681
- }
1682
- if (listener) {
1683
- node.addEventListener(type, node[name] = l, l.$ = capture);
1684
- l._ = listener;
1685
- }
1686
- function l(e) {
1776
+ function onRemove() {
1777
+ var wrapper = this[name];
1778
+ if (wrapper) {
1779
+ this.removeEventListener(type, wrapper, wrapper.$);
1780
+ delete this[name];
1781
+ }
1782
+ }
1783
+ function onAdd() {
1784
+ var node = this, args = arguments;
1785
+ onRemove.call(this);
1786
+ this.addEventListener(type, this[name] = wrapper, wrapper.$ = capture);
1787
+ wrapper._ = listener;
1788
+ function wrapper(e) {
1687
1789
  var o = d3.event;
1688
1790
  d3.event = e;
1689
1791
  args[0] = node.__data__;
@@ -1693,8 +1795,9 @@
1693
1795
  d3.event = o;
1694
1796
  }
1695
1797
  }
1696
- });
1697
- };
1798
+ }
1799
+ return listener ? onAdd : onRemove;
1800
+ }
1698
1801
  d3_selectionPrototype.each = function(callback) {
1699
1802
  return d3_selection_each(this, function(node, i, j) {
1700
1803
  callback.call(node, node.__data__, i, j);
@@ -1836,21 +1939,6 @@
1836
1939
  }, 0, time);
1837
1940
  return groups;
1838
1941
  }
1839
- var d3_transitionRemove = {};
1840
- function d3_transitionNull(d, i, a) {
1841
- return a != "" && d3_transitionRemove;
1842
- }
1843
- function d3_transitionTween(name, b) {
1844
- var interpolate = d3_interpolateByName(name);
1845
- function transitionFunction(d, i, a) {
1846
- var v = b.call(this, d, i);
1847
- return v == null ? a != "" && d3_transitionRemove : a != v && interpolate(a, v);
1848
- }
1849
- function transitionString(d, i, a) {
1850
- return a != b && interpolate(a, b);
1851
- }
1852
- return typeof b === "function" ? transitionFunction : b == null ? d3_transitionNull : (b += "", transitionString);
1853
- }
1854
1942
  var d3_transitionPrototype = [], d3_transitionNextId = 0, d3_transitionId = 0, d3_transitionDefaultDelay = 0, d3_transitionDefaultDuration = 250, d3_transitionDefaultEase = d3.ease("cubic-in-out"), d3_transitionDelay = d3_transitionDefaultDelay, d3_transitionDuration = d3_transitionDefaultDuration, d3_transitionEase = d3_transitionDefaultEase;
1855
1943
  d3_transitionPrototype.call = d3_selectionPrototype.call;
1856
1944
  d3.transition = function(selection) {
@@ -1911,33 +1999,45 @@
1911
1999
  return d3_transition(subgroups, this.id, this.time).ease(this.ease());
1912
2000
  };
1913
2001
  d3_transitionPrototype.attr = function(name, value) {
1914
- return this.attrTween(name, d3_transitionTween(name, value));
2002
+ if (arguments.length < 2) {
2003
+ for (value in name) this.attrTween(value, d3_tweenByName(name[value], value));
2004
+ return this;
2005
+ }
2006
+ return this.attrTween(name, d3_tweenByName(value, name));
1915
2007
  };
1916
2008
  d3_transitionPrototype.attrTween = function(nameNS, tween) {
1917
2009
  var name = d3.ns.qualify(nameNS);
1918
2010
  function attrTween(d, i) {
1919
2011
  var f = tween.call(this, d, i, this.getAttribute(name));
1920
- return f === d3_transitionRemove ? (this.removeAttribute(name), null) : f && function(t) {
2012
+ return f === d3_tweenRemove ? (this.removeAttribute(name), null) : f && function(t) {
1921
2013
  this.setAttribute(name, f(t));
1922
2014
  };
1923
2015
  }
1924
2016
  function attrTweenNS(d, i) {
1925
2017
  var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
1926
- return f === d3_transitionRemove ? (this.removeAttributeNS(name.space, name.local), null) : f && function(t) {
2018
+ return f === d3_tweenRemove ? (this.removeAttributeNS(name.space, name.local), null) : f && function(t) {
1927
2019
  this.setAttributeNS(name.space, name.local, f(t));
1928
2020
  };
1929
2021
  }
1930
2022
  return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
1931
2023
  };
1932
2024
  d3_transitionPrototype.style = function(name, value, priority) {
1933
- if (arguments.length < 3) priority = "";
1934
- return this.styleTween(name, d3_transitionTween(name, value), priority);
2025
+ var n = arguments.length;
2026
+ if (n < 3) {
2027
+ if (typeof name !== "string") {
2028
+ if (n < 2) value = "";
2029
+ for (priority in name) this.styleTween(priority, d3_tweenByName(name[priority], priority), value);
2030
+ return this;
2031
+ }
2032
+ priority = "";
2033
+ }
2034
+ return this.styleTween(name, d3_tweenByName(value, name), priority);
1935
2035
  };
1936
2036
  d3_transitionPrototype.styleTween = function(name, tween, priority) {
1937
2037
  if (arguments.length < 3) priority = "";
1938
2038
  return this.tween("style." + name, function(d, i) {
1939
2039
  var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
1940
- return f === d3_transitionRemove ? (this.style.removeProperty(name), null) : f && function(t) {
2040
+ return f === d3_tweenRemove ? (this.style.removeProperty(name), null) : f && function(t) {
1941
2041
  this.style.setProperty(name, f(t), priority);
1942
2042
  };
1943
2043
  });
@@ -1985,6 +2085,23 @@
1985
2085
  d3_transitionPrototype.transition = function() {
1986
2086
  return this.select(d3_this);
1987
2087
  };
2088
+ d3.tween = function(b, interpolate) {
2089
+ function tweenFunction(d, i, a) {
2090
+ var v = b.call(this, d, i);
2091
+ return v == null ? a != "" && d3_tweenRemove : a != v && interpolate(a, v);
2092
+ }
2093
+ function tweenString(d, i, a) {
2094
+ return a != b && interpolate(a, b);
2095
+ }
2096
+ return typeof b === "function" ? tweenFunction : b == null ? d3_tweenNull : (b += "", tweenString);
2097
+ };
2098
+ var d3_tweenRemove = {};
2099
+ function d3_tweenNull(d, i, a) {
2100
+ return a != "" && d3_tweenRemove;
2101
+ }
2102
+ function d3_tweenByName(b, name) {
2103
+ return d3.tween(b, d3_interpolateByName(name));
2104
+ }
1988
2105
  var d3_timer_queue = null, d3_timer_interval, d3_timer_timeout;
1989
2106
  d3.timer = function(callback, delay, then) {
1990
2107
  var found = false, t0, t1 = d3_timer_queue;
@@ -2104,15 +2221,10 @@
2104
2221
  function d3_scale_nice(domain, nice) {
2105
2222
  var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
2106
2223
  if (x1 < x0) {
2107
- dx = i0;
2108
- i0 = i1;
2109
- i1 = dx;
2110
- dx = x0;
2111
- x0 = x1;
2112
- x1 = dx;
2113
- }
2114
- if (dx = x1 - x0) {
2115
- nice = nice(dx);
2224
+ dx = i0, i0 = i1, i1 = dx;
2225
+ dx = x0, x0 = x1, x1 = dx;
2226
+ }
2227
+ if (nice = nice(x1 - x0)) {
2116
2228
  domain[i0] = nice.floor(x0);
2117
2229
  domain[i1] = nice.ceil(x1);
2118
2230
  }
@@ -2181,7 +2293,7 @@
2181
2293
  }
2182
2294
  function d3_scale_linearNice(dx) {
2183
2295
  dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
2184
- return {
2296
+ return dx && {
2185
2297
  floor: function(x) {
2186
2298
  return Math.floor(x / dx) * dx;
2187
2299
  },
@@ -2338,7 +2450,7 @@
2338
2450
  d3.scale.ordinal = function() {
2339
2451
  return d3_scale_ordinal([], {
2340
2452
  t: "range",
2341
- x: []
2453
+ a: [ [] ]
2342
2454
  });
2343
2455
  };
2344
2456
  function d3_scale_ordinal(domain, ranger) {
@@ -2357,7 +2469,7 @@
2357
2469
  index = new d3_Map;
2358
2470
  var i = -1, n = x.length, xi;
2359
2471
  while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
2360
- return scale[ranger.t](ranger.x, ranger.p);
2472
+ return scale[ranger.t].apply(scale, ranger.a);
2361
2473
  };
2362
2474
  scale.range = function(x) {
2363
2475
  if (!arguments.length) return range;
@@ -2365,7 +2477,7 @@
2365
2477
  rangeBand = 0;
2366
2478
  ranger = {
2367
2479
  t: "range",
2368
- x: x
2480
+ a: arguments
2369
2481
  };
2370
2482
  return scale;
2371
2483
  };
@@ -2376,34 +2488,33 @@
2376
2488
  rangeBand = 0;
2377
2489
  ranger = {
2378
2490
  t: "rangePoints",
2379
- x: x,
2380
- p: padding
2491
+ a: arguments
2381
2492
  };
2382
2493
  return scale;
2383
2494
  };
2384
- scale.rangeBands = function(x, padding) {
2495
+ scale.rangeBands = function(x, padding, outerPadding) {
2385
2496
  if (arguments.length < 2) padding = 0;
2386
- var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length + padding);
2387
- range = steps(start + step * padding, step);
2497
+ if (arguments.length < 3) outerPadding = padding;
2498
+ var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
2499
+ range = steps(start + step * outerPadding, step);
2388
2500
  if (reverse) range.reverse();
2389
2501
  rangeBand = step * (1 - padding);
2390
2502
  ranger = {
2391
2503
  t: "rangeBands",
2392
- x: x,
2393
- p: padding
2504
+ a: arguments
2394
2505
  };
2395
2506
  return scale;
2396
2507
  };
2397
- scale.rangeRoundBands = function(x, padding) {
2508
+ scale.rangeRoundBands = function(x, padding, outerPadding) {
2398
2509
  if (arguments.length < 2) padding = 0;
2399
- var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length + padding)), error = stop - start - (domain.length - padding) * step;
2510
+ if (arguments.length < 3) outerPadding = padding;
2511
+ var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
2400
2512
  range = steps(start + Math.round(error / 2), step);
2401
2513
  if (reverse) range.reverse();
2402
2514
  rangeBand = Math.round(step * (1 - padding));
2403
2515
  ranger = {
2404
2516
  t: "rangeRoundBands",
2405
- x: x,
2406
- p: padding
2517
+ a: arguments
2407
2518
  };
2408
2519
  return scale;
2409
2520
  };
@@ -2411,7 +2522,7 @@
2411
2522
  return rangeBand;
2412
2523
  };
2413
2524
  scale.rangeExtent = function() {
2414
- return d3_scaleExtent(ranger.x);
2525
+ return d3_scaleExtent(ranger.a[0]);
2415
2526
  };
2416
2527
  scale.copy = function() {
2417
2528
  return d3_scale_ordinal(domain, ranger);
@@ -2498,6 +2609,28 @@
2498
2609
  };
2499
2610
  return rescale();
2500
2611
  }
2612
+ d3.scale.threshold = function() {
2613
+ return d3_scale_threshold([ .5 ], [ 0, 1 ]);
2614
+ };
2615
+ function d3_scale_threshold(domain, range) {
2616
+ function scale(x) {
2617
+ return range[d3.bisect(domain, x)];
2618
+ }
2619
+ scale.domain = function(_) {
2620
+ if (!arguments.length) return domain;
2621
+ domain = _;
2622
+ return scale;
2623
+ };
2624
+ scale.range = function(_) {
2625
+ if (!arguments.length) return range;
2626
+ range = _;
2627
+ return scale;
2628
+ };
2629
+ scale.copy = function() {
2630
+ return d3_scale_threshold(domain, range);
2631
+ };
2632
+ return scale;
2633
+ }
2501
2634
  d3.scale.identity = function() {
2502
2635
  return d3_scale_identity([ 0, 1 ]);
2503
2636
  };
@@ -2569,11 +2702,11 @@
2569
2702
  return d.endAngle;
2570
2703
  }
2571
2704
  function d3_svg_line(projection) {
2572
- var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineInterpolatorDefault, interpolator = d3_svg_lineLinear, tension = .7;
2705
+ var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
2573
2706
  function line(data) {
2574
2707
  var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
2575
2708
  function segment() {
2576
- segments.push("M", interpolator(projection(points), tension));
2709
+ segments.push("M", interpolate(projection(points), tension));
2577
2710
  }
2578
2711
  while (++i < n) {
2579
2712
  if (defined.call(this, d = data[i], i)) {
@@ -2602,9 +2735,8 @@
2602
2735
  return line;
2603
2736
  };
2604
2737
  line.interpolate = function(_) {
2605
- if (!arguments.length) return interpolate;
2606
- if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
2607
- interpolator = d3_svg_lineInterpolators.get(interpolate = _);
2738
+ if (!arguments.length) return interpolateKey;
2739
+ if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
2608
2740
  return line;
2609
2741
  };
2610
2742
  line.tension = function(_) {
@@ -2623,7 +2755,6 @@
2623
2755
  function d3_svg_lineY(d) {
2624
2756
  return d[1];
2625
2757
  }
2626
- var d3_svg_lineInterpolatorDefault = "linear";
2627
2758
  var d3_svg_lineInterpolators = d3.map({
2628
2759
  linear: d3_svg_lineLinear,
2629
2760
  "linear-closed": d3_svg_lineLinearClosed,
@@ -2638,6 +2769,10 @@
2638
2769
  "cardinal-closed": d3_svg_lineCardinalClosed,
2639
2770
  monotone: d3_svg_lineMonotone
2640
2771
  });
2772
+ d3_svg_lineInterpolators.forEach(function(key, value) {
2773
+ value.key = key;
2774
+ value.closed = /-closed$/.test(key);
2775
+ });
2641
2776
  function d3_svg_lineLinear(points) {
2642
2777
  return points.join("L");
2643
2778
  }
@@ -2787,7 +2922,7 @@
2787
2922
  function d3_svg_lineFiniteDifferences(points) {
2788
2923
  var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
2789
2924
  while (++i < j) {
2790
- m[i] = d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]));
2925
+ m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
2791
2926
  }
2792
2927
  m[i] = d;
2793
2928
  return m;
@@ -2837,7 +2972,7 @@
2837
2972
  return points;
2838
2973
  }
2839
2974
  function d3_svg_area(projection) {
2840
- var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineInterpolatorDefault, i0 = d3_svg_lineLinear, i1 = d3_svg_lineLinear, L = "L", tension = .7;
2975
+ var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
2841
2976
  function area(data) {
2842
2977
  var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
2843
2978
  return x;
@@ -2845,7 +2980,7 @@
2845
2980
  return y;
2846
2981
  } : d3_functor(y1), x, y;
2847
2982
  function segment() {
2848
- segments.push("M", i0(projection(points1), tension), L, i1(projection(points0.reverse()), tension), "Z");
2983
+ segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
2849
2984
  }
2850
2985
  while (++i < n) {
2851
2986
  if (defined.call(this, d = data[i], i)) {
@@ -2896,11 +3031,10 @@
2896
3031
  return area;
2897
3032
  };
2898
3033
  area.interpolate = function(_) {
2899
- if (!arguments.length) return interpolate;
2900
- if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
2901
- i0 = d3_svg_lineInterpolators.get(interpolate = _);
2902
- i1 = i0.reverse || i0;
2903
- L = /-closed$/.test(_) ? "M" : "L";
3034
+ if (!arguments.length) return interpolateKey;
3035
+ if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
3036
+ interpolateReverse = interpolate.reverse || interpolate;
3037
+ L = interpolate.closed ? "M" : "L";
2904
3038
  return area;
2905
3039
  };
2906
3040
  area.tension = function(_) {
@@ -2913,7 +3047,7 @@
2913
3047
  d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
2914
3048
  d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
2915
3049
  d3.svg.area = function() {
2916
- return d3_svg_area(Object);
3050
+ return d3_svg_area(d3_identity);
2917
3051
  };
2918
3052
  d3.svg.area.radial = function() {
2919
3053
  var area = d3_svg_area(d3_svg_lineRadial);
@@ -4474,14 +4608,28 @@
4474
4608
  }
4475
4609
  var d3_layout_hierarchyInline = false;
4476
4610
  d3.layout.pack = function() {
4477
- var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), size = [ 1, 1 ];
4611
+ var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
4478
4612
  function pack(d, i) {
4479
4613
  var nodes = hierarchy.call(this, d, i), root = nodes[0];
4480
4614
  root.x = 0;
4481
4615
  root.y = 0;
4482
- d3_layout_packTree(root);
4483
- var w = size[0], h = size[1], k = 1 / Math.max(2 * root.r / w, 2 * root.r / h);
4484
- d3_layout_packTransform(root, w / 2, h / 2, k);
4616
+ d3_layout_treeVisitAfter(root, function(d) {
4617
+ d.r = Math.sqrt(d.value);
4618
+ });
4619
+ d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
4620
+ var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
4621
+ if (padding > 0) {
4622
+ var dr = padding * k / 2;
4623
+ d3_layout_treeVisitAfter(root, function(d) {
4624
+ d.r += dr;
4625
+ });
4626
+ d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
4627
+ d3_layout_treeVisitAfter(root, function(d) {
4628
+ d.r -= dr;
4629
+ });
4630
+ k = Math.max(2 * root.r / w, 2 * root.r / h);
4631
+ }
4632
+ d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
4485
4633
  return nodes;
4486
4634
  }
4487
4635
  pack.size = function(x) {
@@ -4489,6 +4637,11 @@
4489
4637
  size = x;
4490
4638
  return pack;
4491
4639
  };
4640
+ pack.padding = function(_) {
4641
+ if (!arguments.length) return padding;
4642
+ padding = +_;
4643
+ return pack;
4644
+ };
4492
4645
  return d3_layout_hierarchyRebind(pack, hierarchy);
4493
4646
  };
4494
4647
  function d3_layout_packSort(a, b) {
@@ -4509,8 +4662,9 @@
4509
4662
  var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
4510
4663
  return dr * dr - dx * dx - dy * dy > .001;
4511
4664
  }
4512
- function d3_layout_packCircle(nodes) {
4513
- var xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, n = nodes.length, a, b, c, j, k;
4665
+ function d3_layout_packSiblings(node) {
4666
+ if (!(nodes = node.children) || !(n = nodes.length)) return;
4667
+ var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
4514
4668
  function bound(node) {
4515
4669
  xMin = Math.min(node.x - node.r, xMin);
4516
4670
  xMax = Math.max(node.x + node.r, xMax);
@@ -4535,7 +4689,7 @@
4535
4689
  a._pack_prev = c;
4536
4690
  d3_layout_packInsert(c, b);
4537
4691
  b = a._pack_next;
4538
- for (var i = 3; i < n; i++) {
4692
+ for (i = 3; i < n; i++) {
4539
4693
  d3_layout_packPlace(a, b, c = nodes[i]);
4540
4694
  var isect = 0, s1 = 1, s2 = 1;
4541
4695
  for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
@@ -4563,14 +4717,14 @@
4563
4717
  }
4564
4718
  }
4565
4719
  var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
4566
- for (var i = 0; i < n; i++) {
4567
- var node = nodes[i];
4568
- node.x -= cx;
4569
- node.y -= cy;
4570
- cr = Math.max(cr, node.r + Math.sqrt(node.x * node.x + node.y * node.y));
4720
+ for (i = 0; i < n; i++) {
4721
+ c = nodes[i];
4722
+ c.x -= cx;
4723
+ c.y -= cy;
4724
+ cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
4571
4725
  }
4726
+ node.r = cr;
4572
4727
  nodes.forEach(d3_layout_packUnlink);
4573
- return cr;
4574
4728
  }
4575
4729
  function d3_layout_packLink(node) {
4576
4730
  node._pack_next = node._pack_prev = node;
@@ -4579,15 +4733,6 @@
4579
4733
  delete node._pack_next;
4580
4734
  delete node._pack_prev;
4581
4735
  }
4582
- function d3_layout_packTree(node) {
4583
- var children = node.children;
4584
- if (children && children.length) {
4585
- children.forEach(d3_layout_packTree);
4586
- node.r = d3_layout_packCircle(children);
4587
- } else {
4588
- node.r = Math.sqrt(node.value);
4589
- }
4590
- }
4591
4736
  function d3_layout_packTransform(node, x, y, k) {
4592
4737
  var children = node.children;
4593
4738
  node.x = x += k * node.x;
@@ -5001,80 +5146,86 @@
5001
5146
  dy: dy
5002
5147
  };
5003
5148
  }
5004
- d3.csv = function(url, callback) {
5005
- d3.text(url, "text/csv", function(text) {
5006
- callback(text && d3.csv.parse(text));
5007
- });
5008
- };
5009
- d3.csv.parse = function(text) {
5010
- var header;
5011
- return d3.csv.parseRows(text, function(row, i) {
5012
- if (i) {
5013
- var o = {}, j = -1, m = header.length;
5014
- while (++j < m) o[header[j]] = row[j];
5015
- return o;
5016
- } else {
5017
- header = row;
5018
- return null;
5019
- }
5020
- });
5021
- };
5022
- d3.csv.parseRows = function(text, f) {
5023
- var EOL = {}, EOF = {}, rows = [], re = /\r\n|[,\r\n]/g, n = 0, t, eol;
5024
- re.lastIndex = 0;
5025
- function token() {
5026
- if (re.lastIndex >= text.length) return EOF;
5027
- if (eol) {
5028
- eol = false;
5029
- return EOL;
5030
- }
5031
- var j = re.lastIndex;
5032
- if (text.charCodeAt(j) === 34) {
5033
- var i = j;
5034
- while (i++ < text.length) {
5035
- if (text.charCodeAt(i) === 34) {
5036
- if (text.charCodeAt(i + 1) !== 34) break;
5037
- i++;
5149
+ function d3_dsv(delimiter, mimeType) {
5150
+ var reParse = new RegExp("\r\n|[" + delimiter + "\r\n]", "g"), reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
5151
+ function dsv(url, callback) {
5152
+ d3.text(url, mimeType, function(text) {
5153
+ callback(text && dsv.parse(text));
5154
+ });
5155
+ }
5156
+ dsv.parse = function(text) {
5157
+ var header;
5158
+ return dsv.parseRows(text, function(row, i) {
5159
+ if (i) {
5160
+ var o = {}, j = -1, m = header.length;
5161
+ while (++j < m) o[header[j]] = row[j];
5162
+ return o;
5163
+ } else {
5164
+ header = row;
5165
+ return null;
5166
+ }
5167
+ });
5168
+ };
5169
+ dsv.parseRows = function(text, f) {
5170
+ var EOL = {}, EOF = {}, rows = [], n = 0, t, eol;
5171
+ reParse.lastIndex = 0;
5172
+ function token() {
5173
+ if (reParse.lastIndex >= text.length) return EOF;
5174
+ if (eol) {
5175
+ eol = false;
5176
+ return EOL;
5177
+ }
5178
+ var j = reParse.lastIndex;
5179
+ if (text.charCodeAt(j) === 34) {
5180
+ var i = j;
5181
+ while (i++ < text.length) {
5182
+ if (text.charCodeAt(i) === 34) {
5183
+ if (text.charCodeAt(i + 1) !== 34) break;
5184
+ i++;
5185
+ }
5186
+ }
5187
+ reParse.lastIndex = i + 2;
5188
+ var c = text.charCodeAt(i + 1);
5189
+ if (c === 13) {
5190
+ eol = true;
5191
+ if (text.charCodeAt(i + 2) === 10) reParse.lastIndex++;
5192
+ } else if (c === 10) {
5193
+ eol = true;
5038
5194
  }
5195
+ return text.substring(j + 1, i).replace(/""/g, '"');
5039
5196
  }
5040
- re.lastIndex = i + 2;
5041
- var c = text.charCodeAt(i + 1);
5042
- if (c === 13) {
5043
- eol = true;
5044
- if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
5045
- } else if (c === 10) {
5046
- eol = true;
5197
+ var m = reParse.exec(text);
5198
+ if (m) {
5199
+ eol = m[0].charCodeAt(0) !== delimiterCode;
5200
+ return text.substring(j, m.index);
5047
5201
  }
5048
- return text.substring(j + 1, i).replace(/""/g, '"');
5049
- }
5050
- var m = re.exec(text);
5051
- if (m) {
5052
- eol = m[0].charCodeAt(0) !== 44;
5053
- return text.substring(j, m.index);
5202
+ reParse.lastIndex = text.length;
5203
+ return text.substring(j);
5204
+ }
5205
+ while ((t = token()) !== EOF) {
5206
+ var a = [];
5207
+ while (t !== EOL && t !== EOF) {
5208
+ a.push(t);
5209
+ t = token();
5210
+ }
5211
+ if (f && !(a = f(a, n++))) continue;
5212
+ rows.push(a);
5054
5213
  }
5055
- re.lastIndex = text.length;
5056
- return text.substring(j);
5214
+ return rows;
5215
+ };
5216
+ dsv.format = function(rows) {
5217
+ return rows.map(formatRow).join("\n");
5218
+ };
5219
+ function formatRow(row) {
5220
+ return row.map(formatValue).join(delimiter);
5057
5221
  }
5058
- while ((t = token()) !== EOF) {
5059
- var a = [];
5060
- while (t !== EOL && t !== EOF) {
5061
- a.push(t);
5062
- t = token();
5063
- }
5064
- if (f && !(a = f(a, n++))) continue;
5065
- rows.push(a);
5222
+ function formatValue(text) {
5223
+ return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
5066
5224
  }
5067
- return rows;
5068
- };
5069
- d3.csv.format = function(rows) {
5070
- return rows.map(d3_csv_formatRow).join("\n");
5071
- };
5072
- function d3_csv_formatRow(row) {
5073
- return row.map(d3_csv_formatValue).join(",");
5074
- }
5075
- function d3_csv_formatValue(text) {
5076
- return /[",\n]/.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
5225
+ return dsv;
5077
5226
  }
5227
+ d3.csv = d3_dsv(",", "text/csv");
5228
+ d3.tsv = d3_dsv("\t", "text/tab-separated-values");
5078
5229
  d3.geo = {};
5079
5230
  var d3_geo_radians = Math.PI / 180;
5080
5231
  d3.geo.azimuthal = function() {
@@ -6273,7 +6424,7 @@
6273
6424
  };
6274
6425
  }
6275
6426
  d3.time = {};
6276
- var d3_time = Date;
6427
+ var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
6277
6428
  function d3_time_utc() {
6278
6429
  this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
6279
6430
  }
@@ -6340,6 +6491,11 @@
6340
6491
  }
6341
6492
  };
6342
6493
  var d3_time_prototype = Date.prototype;
6494
+ var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y", d3_time_formatDate = "%m/%d/%y", d3_time_formatTime = "%H:%M:%S";
6495
+ var d3_time_days = d3_time_daySymbols, d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate), d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
6496
+ function d3_time_formatAbbreviate(name) {
6497
+ return name.substring(0, 3);
6498
+ }
6343
6499
  d3.time.format = function(template) {
6344
6500
  var n = template.length;
6345
6501
  function format(date) {
@@ -6389,21 +6545,30 @@
6389
6545
  }
6390
6546
  return j;
6391
6547
  }
6548
+ function d3_time_formatRe(names) {
6549
+ return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
6550
+ }
6551
+ function d3_time_formatLookup(names) {
6552
+ var map = new d3_Map, i = -1, n = names.length;
6553
+ while (++i < n) map.set(names[i].toLowerCase(), i);
6554
+ return map;
6555
+ }
6392
6556
  var d3_time_zfill2 = d3.format("02d"), d3_time_zfill3 = d3.format("03d"), d3_time_zfill4 = d3.format("04d"), d3_time_sfill2 = d3.format("2d");
6557
+ var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
6393
6558
  var d3_time_formats = {
6394
6559
  a: function(d) {
6395
- return d3_time_weekdays[d.getDay()].substring(0, 3);
6560
+ return d3_time_dayAbbreviations[d.getDay()];
6396
6561
  },
6397
6562
  A: function(d) {
6398
- return d3_time_weekdays[d.getDay()];
6563
+ return d3_time_days[d.getDay()];
6399
6564
  },
6400
6565
  b: function(d) {
6401
- return d3_time_months[d.getMonth()].substring(0, 3);
6566
+ return d3_time_monthAbbreviations[d.getMonth()];
6402
6567
  },
6403
6568
  B: function(d) {
6404
6569
  return d3_time_months[d.getMonth()];
6405
6570
  },
6406
- c: d3.time.format("%a %b %e %H:%M:%S %Y"),
6571
+ c: d3.time.format(d3_time_formatDateTime),
6407
6572
  d: function(d) {
6408
6573
  return d3_time_zfill2(d.getDate());
6409
6574
  },
@@ -6443,8 +6608,8 @@
6443
6608
  W: function(d) {
6444
6609
  return d3_time_zfill2(d3.time.mondayOfYear(d));
6445
6610
  },
6446
- x: d3.time.format("%m/%d/%y"),
6447
- X: d3.time.format("%H:%M:%S"),
6611
+ x: d3.time.format(d3_time_formatDate),
6612
+ X: d3.time.format(d3_time_formatTime),
6448
6613
  y: function(d) {
6449
6614
  return d3_time_zfill2(d.getFullYear() % 100);
6450
6615
  },
@@ -6477,53 +6642,25 @@
6477
6642
  Y: d3_time_parseFullYear
6478
6643
  };
6479
6644
  function d3_time_parseWeekdayAbbrev(date, string, i) {
6480
- return d3_time_weekdayAbbrevRe.test(string.substring(i, i += 3)) ? i : -1;
6645
+ d3_time_dayAbbrevRe.lastIndex = 0;
6646
+ var n = d3_time_dayAbbrevRe.exec(string.substring(i));
6647
+ return n ? i += n[0].length : -1;
6481
6648
  }
6482
6649
  function d3_time_parseWeekday(date, string, i) {
6483
- d3_time_weekdayRe.lastIndex = 0;
6484
- var n = d3_time_weekdayRe.exec(string.substring(i, i + 10));
6650
+ d3_time_dayRe.lastIndex = 0;
6651
+ var n = d3_time_dayRe.exec(string.substring(i));
6485
6652
  return n ? i += n[0].length : -1;
6486
6653
  }
6487
- var d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i, d3_time_weekdayRe = /^(?:Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)/i, d3_time_weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
6488
6654
  function d3_time_parseMonthAbbrev(date, string, i) {
6489
- var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
6490
- return n == null ? -1 : (date.m = n, i);
6491
- }
6492
- var d3_time_monthAbbrevLookup = d3.map({
6493
- jan: 0,
6494
- feb: 1,
6495
- mar: 2,
6496
- apr: 3,
6497
- may: 4,
6498
- jun: 5,
6499
- jul: 6,
6500
- aug: 7,
6501
- sep: 8,
6502
- oct: 9,
6503
- nov: 10,
6504
- dec: 11
6505
- });
6655
+ d3_time_monthAbbrevRe.lastIndex = 0;
6656
+ var n = d3_time_monthAbbrevRe.exec(string.substring(i));
6657
+ return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
6658
+ }
6506
6659
  function d3_time_parseMonth(date, string, i) {
6507
6660
  d3_time_monthRe.lastIndex = 0;
6508
- var n = d3_time_monthRe.exec(string.substring(i, i + 12));
6661
+ var n = d3_time_monthRe.exec(string.substring(i));
6509
6662
  return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
6510
6663
  }
6511
- var d3_time_monthRe = /^(?:January|February|March|April|May|June|July|August|September|October|November|December)/ig;
6512
- var d3_time_monthLookup = d3.map({
6513
- january: 0,
6514
- february: 1,
6515
- march: 2,
6516
- april: 3,
6517
- may: 4,
6518
- june: 5,
6519
- july: 6,
6520
- august: 7,
6521
- september: 8,
6522
- october: 9,
6523
- november: 10,
6524
- december: 11
6525
- });
6526
- var d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
6527
6664
  function d3_time_parseLocaleFull(date, string, i) {
6528
6665
  return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
6529
6666
  }
@@ -6576,7 +6713,7 @@
6576
6713
  var n = d3_time_numberRe.exec(string.substring(i, i + 3));
6577
6714
  return n ? (date.L = +n[0], i += n[0].length) : -1;
6578
6715
  }
6579
- var d3_time_numberRe = /\s*\d+/;
6716
+ var d3_time_numberRe = /^\s*\d+/;
6580
6717
  function d3_time_parseAmPm(date, string, i) {
6581
6718
  var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
6582
6719
  return n == null ? -1 : (date.p = n, i);
@@ -6726,7 +6863,7 @@
6726
6863
  var year = d3.time.year(date);
6727
6864
  return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
6728
6865
  };
6729
- d3_time_weekdays.forEach(function(day, i) {
6866
+ d3_time_daySymbols.forEach(function(day, i) {
6730
6867
  day = day.toLowerCase();
6731
6868
  i = 7 - i;
6732
6869
  var interval = d3.time[day] = d3_time_interval(function(date) {
@@ -6784,8 +6921,9 @@
6784
6921
  return scale;
6785
6922
  };
6786
6923
  scale.nice = function(m) {
6787
- var extent = d3_time_scaleExtent(scale.domain());
6788
- return scale.domain([ m.floor(extent[0]), m.ceil(extent[1]) ]);
6924
+ return scale.domain(d3_scale_nice(scale.domain(), function() {
6925
+ return m;
6926
+ }));
6789
6927
  };
6790
6928
  scale.ticks = function(m, k) {
6791
6929
  var extent = d3_time_scaleExtent(scale.domain());