|
1 | | -(function(){d3 = {version: "0.30.8"}; // semver |
| 1 | +(function(){d3 = {version: "1.0.0"}; // semver |
2 | 2 | if (!Date.now) Date.now = function() { |
3 | 3 | return +new Date(); |
4 | 4 | }; |
@@ -923,20 +923,29 @@ function d3_hsl_rgb(h, s, l) { |
923 | 923 |
|
924 | 924 | return d3_rgb(vv(h + 120), vv(h), vv(h - 120)); |
925 | 925 | } |
| 926 | +var d3_select = function(s, n) { return n.querySelector(s); }, |
| 927 | + d3_selectAll = function(s, n) { return d3_array(n.querySelectorAll(s)); }; |
| 928 | + |
| 929 | +// Use Sizzle, if available. |
| 930 | +if (typeof Sizzle == "function") { |
| 931 | + d3_select = function(s, n) { return Sizzle(s, n)[0]; }; |
| 932 | + d3_selectAll = Sizzle; |
| 933 | +} |
| 934 | + |
926 | 935 | var d3_root = d3_selection([[document]]); |
927 | 936 | d3_root[0].parentNode = document.documentElement; |
928 | 937 |
|
929 | 938 | // TODO fast singleton implementation! |
930 | | -d3.select = function(query) { |
931 | | - return typeof query == "string" |
932 | | - ? d3_root.select(query) |
933 | | - : d3_selection([[query]]); // assume node |
| 939 | +d3.select = function(selector) { |
| 940 | + return typeof selector == "string" |
| 941 | + ? d3_root.select(selector) |
| 942 | + : d3_selection([[selector]]); // assume node |
934 | 943 | }; |
935 | 944 |
|
936 | | -d3.selectAll = function(query) { |
937 | | - return typeof query == "string" |
938 | | - ? d3_root.selectAll(query) |
939 | | - : d3_selection([d3_array(query)]); // assume node[] |
| 945 | +d3.selectAll = function(selector) { |
| 946 | + return typeof selector == "string" |
| 947 | + ? d3_root.selectAll(selector) |
| 948 | + : d3_selection([d3_array(selector)]); // assume node[] |
940 | 949 | }; |
941 | 950 |
|
942 | 951 | function d3_selection(groups) { |
@@ -983,16 +992,16 @@ function d3_selection(groups) { |
983 | 992 | } |
984 | 993 |
|
985 | 994 | // TODO select(function)? |
986 | | - groups.select = function(query) { |
| 995 | + groups.select = function(selector) { |
987 | 996 | return select(function(node) { |
988 | | - return node.querySelector(query); |
| 997 | + return d3_select(selector, node); |
989 | 998 | }); |
990 | 999 | }; |
991 | 1000 |
|
992 | 1001 | // TODO selectAll(function)? |
993 | | - groups.selectAll = function(query) { |
| 1002 | + groups.selectAll = function(selector) { |
994 | 1003 | return selectAll(function(node) { |
995 | | - return d3_array(node.querySelectorAll(query)); |
| 1004 | + return d3_selectAll(selector, node); |
996 | 1005 | }); |
997 | 1006 | }; |
998 | 1007 |
|
@@ -1035,18 +1044,7 @@ function d3_selection(groups) { |
1035 | 1044 | nodeData; |
1036 | 1045 |
|
1037 | 1046 | function enterNode(data) { |
1038 | | - return { |
1039 | | - __data__: data, |
1040 | | - appendChild: function(a) { |
1041 | | - return group.parentNode.appendChild(a); |
1042 | | - }, |
1043 | | - insertBefore: function(a, b) { |
1044 | | - return group.parentNode.insertBefore(a, b); |
1045 | | - }, |
1046 | | - querySelector: function(a) { |
1047 | | - return group.parentNode.querySelector(a); |
1048 | | - } |
1049 | | - }; |
| 1047 | + return {__data__: data}; |
1050 | 1048 | } |
1051 | 1049 |
|
1052 | 1050 | if (join) { |
@@ -1137,7 +1135,7 @@ function d3_selection(groups) { |
1137 | 1135 |
|
1138 | 1136 | var selection = d3_selection(update); |
1139 | 1137 | selection.enter = function() { |
1140 | | - return d3_selection(enter); |
| 1138 | + return d3_selectionEnter(enter); |
1141 | 1139 | }; |
1142 | 1140 | selection.exit = function() { |
1143 | 1141 | return d3_selection(exit); |
@@ -1409,19 +1407,19 @@ function d3_selection(groups) { |
1409 | 1407 | function insert(node) { |
1410 | 1408 | return node.insertBefore( |
1411 | 1409 | document.createElement(name), |
1412 | | - node.querySelector(before)); |
| 1410 | + d3_select(before, node)); |
1413 | 1411 | } |
1414 | 1412 |
|
1415 | 1413 | function insertNS(node) { |
1416 | 1414 | return node.insertBefore( |
1417 | 1415 | document.createElementNS(name.space, name.local), |
1418 | | - node.querySelector(before)); |
| 1416 | + d3_select(before, node)); |
1419 | 1417 | } |
1420 | 1418 |
|
1421 | 1419 | return select(name.local ? insertNS : insert); |
1422 | 1420 | }; |
1423 | 1421 |
|
1424 | | - // TODO remove(query)? |
| 1422 | + // TODO remove(selector)? |
1425 | 1423 | // TODO remove(node)? |
1426 | 1424 | // TODO remove(function)? |
1427 | 1425 | groups.remove = function() { |
@@ -1486,6 +1484,71 @@ function d3_selection(groups) { |
1486 | 1484 | return groups; |
1487 | 1485 | } |
1488 | 1486 |
|
| 1487 | +function d3_selectionEnter(groups) { |
| 1488 | + |
| 1489 | + function select(select) { |
| 1490 | + var subgroups = [], |
| 1491 | + subgroup, |
| 1492 | + subnode, |
| 1493 | + group, |
| 1494 | + node; |
| 1495 | + for (var j = 0, m = groups.length; j < m; j++) { |
| 1496 | + group = groups[j]; |
| 1497 | + subgroups.push(subgroup = []); |
| 1498 | + subgroup.parentNode = group.parentNode; |
| 1499 | + subgroup.parentData = group.parentData; |
| 1500 | + for (var i = 0, n = group.length; i < n; i++) { |
| 1501 | + if (node = group[i]) { |
| 1502 | + subgroup.push(subnode = select(group.parentNode)); |
| 1503 | + subnode.__data__ = node.__data__; |
| 1504 | + } else { |
| 1505 | + subgroup.push(null); |
| 1506 | + } |
| 1507 | + } |
| 1508 | + } |
| 1509 | + return d3_selection(subgroups); |
| 1510 | + } |
| 1511 | + |
| 1512 | + // TODO append(node)? |
| 1513 | + // TODO append(function)? |
| 1514 | + groups.append = function(name) { |
| 1515 | + name = d3.ns.qualify(name); |
| 1516 | + |
| 1517 | + function append(node) { |
| 1518 | + return node.appendChild(document.createElement(name)); |
| 1519 | + } |
| 1520 | + |
| 1521 | + function appendNS(node) { |
| 1522 | + return node.appendChild(document.createElementNS(name.space, name.local)); |
| 1523 | + } |
| 1524 | + |
| 1525 | + return select(name.local ? appendNS : append); |
| 1526 | + }; |
| 1527 | + |
| 1528 | + // TODO insert(node, function)? |
| 1529 | + // TODO insert(function, string)? |
| 1530 | + // TODO insert(function, function)? |
| 1531 | + groups.insert = function(name, before) { |
| 1532 | + name = d3.ns.qualify(name); |
| 1533 | + |
| 1534 | + function insert(node) { |
| 1535 | + return node.insertBefore( |
| 1536 | + document.createElement(name), |
| 1537 | + d3_select(before, node)); |
| 1538 | + } |
| 1539 | + |
| 1540 | + function insertNS(node) { |
| 1541 | + return node.insertBefore( |
| 1542 | + document.createElementNS(name.space, name.local), |
| 1543 | + d3_select(before, node)); |
| 1544 | + } |
| 1545 | + |
| 1546 | + return select(name.local ? insertNS : insert); |
| 1547 | + }; |
| 1548 | + |
| 1549 | + return groups; |
| 1550 | +} |
| 1551 | + |
1489 | 1552 | function d3_selection_comparator(comparator) { |
1490 | 1553 | if (!arguments.length) comparator = d3.ascending; |
1491 | 1554 | return function(a, b) { |
|
0 commit comments