|
746 | 746 | }); |
747 | 747 | }; |
748 | 748 | d3_selectionPrototype.remove = function() { |
749 | | - return this.each(function() { |
750 | | - var parent = this.parentNode; |
751 | | - if (parent) parent.removeChild(this); |
752 | | - }); |
| 749 | + return this.each(d3_selectionRemove); |
753 | 750 | }; |
| 751 | + function d3_selectionRemove() { |
| 752 | + var parent = this.parentNode; |
| 753 | + if (parent) parent.removeChild(this); |
| 754 | + } |
754 | 755 | d3_selectionPrototype.data = function(value, key) { |
755 | 756 | var i = -1, n = this.length, group, node; |
756 | 757 | if (!arguments.length) { |
|
959 | 960 | return node; |
960 | 961 | }; |
961 | 962 | } |
962 | | - d3_selectionPrototype.transition = function() { |
963 | | - var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = d3_transitionInherit || { |
| 963 | + d3_selectionPrototype.transition = function(name) { |
| 964 | + var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || { |
964 | 965 | time: Date.now(), |
965 | 966 | ease: d3_ease_cubicInOut, |
966 | 967 | delay: 0, |
|
969 | 970 | for (var j = -1, m = this.length; ++j < m; ) { |
970 | 971 | subgroups.push(subgroup = []); |
971 | 972 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
972 | | - if (node = group[i]) d3_transitionNode(node, i, id, transition); |
| 973 | + if (node = group[i]) d3_transitionNode(node, i, ns, id, transition); |
973 | 974 | subgroup.push(node); |
974 | 975 | } |
975 | 976 | } |
976 | | - return d3_transition(subgroups, id); |
| 977 | + return d3_transition(subgroups, ns, id); |
977 | 978 | }; |
978 | | - d3_selectionPrototype.interrupt = function() { |
979 | | - return this.each(d3_selection_interrupt); |
| 979 | + d3_selectionPrototype.interrupt = function(name) { |
| 980 | + var ns = d3_transitionNamespace(name); |
| 981 | + return this.each(function() { |
| 982 | + var lock = this[ns]; |
| 983 | + if (lock) ++lock.active; |
| 984 | + }); |
980 | 985 | }; |
981 | | - function d3_selection_interrupt() { |
982 | | - var lock = this.__transition__; |
983 | | - if (lock) ++lock.active; |
984 | | - } |
985 | 986 | d3.select = function(node) { |
986 | 987 | var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ]; |
987 | 988 | group.parentNode = d3_documentElement; |
|
8352 | 8353 | }); |
8353 | 8354 | d3.svg.symbolTypes = d3_svg_symbols.keys(); |
8354 | 8355 | var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians); |
8355 | | - function d3_transition(groups, id) { |
| 8356 | + function d3_transition(groups, namespace, id) { |
8356 | 8357 | d3_subclass(groups, d3_transitionPrototype); |
| 8358 | + groups.namespace = namespace; |
8357 | 8359 | groups.id = id; |
8358 | 8360 | return groups; |
8359 | 8361 | } |
|
8367 | 8369 | }; |
8368 | 8370 | d3.transition.prototype = d3_transitionPrototype; |
8369 | 8371 | d3_transitionPrototype.select = function(selector) { |
8370 | | - var id = this.id, subgroups = [], subgroup, subnode, node; |
| 8372 | + var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node; |
8371 | 8373 | selector = d3_selection_selector(selector); |
8372 | 8374 | for (var j = -1, m = this.length; ++j < m; ) { |
8373 | 8375 | subgroups.push(subgroup = []); |
8374 | 8376 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
8375 | 8377 | if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) { |
8376 | 8378 | if ("__data__" in node) subnode.__data__ = node.__data__; |
8377 | | - d3_transitionNode(subnode, i, id, node.__transition__[id]); |
| 8379 | + d3_transitionNode(subnode, i, ns, id, node[ns][id]); |
8378 | 8380 | subgroup.push(subnode); |
8379 | 8381 | } else { |
8380 | 8382 | subgroup.push(null); |
8381 | 8383 | } |
8382 | 8384 | } |
8383 | 8385 | } |
8384 | | - return d3_transition(subgroups, id); |
| 8386 | + return d3_transition(subgroups, ns, id); |
8385 | 8387 | }; |
8386 | 8388 | d3_transitionPrototype.selectAll = function(selector) { |
8387 | | - var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition; |
| 8389 | + var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition; |
8388 | 8390 | selector = d3_selection_selectorAll(selector); |
8389 | 8391 | for (var j = -1, m = this.length; ++j < m; ) { |
8390 | 8392 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
8391 | 8393 | if (node = group[i]) { |
8392 | | - transition = node.__transition__[id]; |
| 8394 | + transition = node[ns][id]; |
8393 | 8395 | subnodes = selector.call(node, node.__data__, i, j); |
8394 | 8396 | subgroups.push(subgroup = []); |
8395 | 8397 | for (var k = -1, o = subnodes.length; ++k < o; ) { |
8396 | | - if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition); |
| 8398 | + if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition); |
8397 | 8399 | subgroup.push(subnode); |
8398 | 8400 | } |
8399 | 8401 | } |
8400 | 8402 | } |
8401 | 8403 | } |
8402 | | - return d3_transition(subgroups, id); |
| 8404 | + return d3_transition(subgroups, ns, id); |
8403 | 8405 | }; |
8404 | 8406 | d3_transitionPrototype.filter = function(filter) { |
8405 | 8407 | var subgroups = [], subgroup, group, node; |
|
8412 | 8414 | } |
8413 | 8415 | } |
8414 | 8416 | } |
8415 | | - return d3_transition(subgroups, this.id); |
| 8417 | + return d3_transition(subgroups, this.namespace, this.id); |
8416 | 8418 | }; |
8417 | 8419 | d3_transitionPrototype.tween = function(name, tween) { |
8418 | | - var id = this.id; |
8419 | | - if (arguments.length < 2) return this.node().__transition__[id].tween.get(name); |
| 8420 | + var id = this.id, ns = this.namespace; |
| 8421 | + if (arguments.length < 2) return this.node()[ns][id].tween.get(name); |
8420 | 8422 | return d3_selection_each(this, tween == null ? function(node) { |
8421 | | - node.__transition__[id].tween.remove(name); |
| 8423 | + node[ns][id].tween.remove(name); |
8422 | 8424 | } : function(node) { |
8423 | | - node.__transition__[id].tween.set(name, tween); |
| 8425 | + node[ns][id].tween.set(name, tween); |
8424 | 8426 | }); |
8425 | 8427 | }; |
8426 | 8428 | function d3_transition_tween(groups, name, value, tween) { |
8427 | | - var id = groups.id; |
| 8429 | + var id = groups.id, ns = groups.namespace; |
8428 | 8430 | return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) { |
8429 | | - node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j))); |
| 8431 | + node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j))); |
8430 | 8432 | } : (value = tween(value), function(node) { |
8431 | | - node.__transition__[id].tween.set(name, value); |
| 8433 | + node[ns][id].tween.set(name, value); |
8432 | 8434 | })); |
8433 | 8435 | } |
8434 | 8436 | d3_transitionPrototype.attr = function(nameNS, value) { |
|
8520 | 8522 | }; |
8521 | 8523 | } |
8522 | 8524 | d3_transitionPrototype.remove = function() { |
| 8525 | + var ns = this.namespace; |
8523 | 8526 | return this.each("end.transition", function() { |
8524 | 8527 | var p; |
8525 | | - if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this); |
| 8528 | + if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this); |
8526 | 8529 | }); |
8527 | 8530 | }; |
8528 | 8531 | d3_transitionPrototype.ease = function(value) { |
8529 | | - var id = this.id; |
8530 | | - if (arguments.length < 1) return this.node().__transition__[id].ease; |
| 8532 | + var id = this.id, ns = this.namespace; |
| 8533 | + if (arguments.length < 1) return this.node()[ns][id].ease; |
8531 | 8534 | if (typeof value !== "function") value = d3.ease.apply(d3, arguments); |
8532 | 8535 | return d3_selection_each(this, function(node) { |
8533 | | - node.__transition__[id].ease = value; |
| 8536 | + node[ns][id].ease = value; |
8534 | 8537 | }); |
8535 | 8538 | }; |
8536 | 8539 | d3_transitionPrototype.delay = function(value) { |
8537 | | - var id = this.id; |
8538 | | - if (arguments.length < 1) return this.node().__transition__[id].delay; |
| 8540 | + var id = this.id, ns = this.namespace; |
| 8541 | + if (arguments.length < 1) return this.node()[ns][id].delay; |
8539 | 8542 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) { |
8540 | | - node.__transition__[id].delay = +value.call(node, node.__data__, i, j); |
| 8543 | + node[ns][id].delay = +value.call(node, node.__data__, i, j); |
8541 | 8544 | } : (value = +value, function(node) { |
8542 | | - node.__transition__[id].delay = value; |
| 8545 | + node[ns][id].delay = value; |
8543 | 8546 | })); |
8544 | 8547 | }; |
8545 | 8548 | d3_transitionPrototype.duration = function(value) { |
8546 | | - var id = this.id; |
8547 | | - if (arguments.length < 1) return this.node().__transition__[id].duration; |
| 8549 | + var id = this.id, ns = this.namespace; |
| 8550 | + if (arguments.length < 1) return this.node()[ns][id].duration; |
8548 | 8551 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) { |
8549 | | - node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j)); |
| 8552 | + node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j)); |
8550 | 8553 | } : (value = Math.max(1, value), function(node) { |
8551 | | - node.__transition__[id].duration = value; |
| 8554 | + node[ns][id].duration = value; |
8552 | 8555 | })); |
8553 | 8556 | }; |
8554 | 8557 | d3_transitionPrototype.each = function(type, listener) { |
8555 | | - var id = this.id; |
| 8558 | + var id = this.id, ns = this.namespace; |
8556 | 8559 | if (arguments.length < 2) { |
8557 | 8560 | var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId; |
8558 | 8561 | d3_transitionInheritId = id; |
8559 | 8562 | d3_selection_each(this, function(node, i, j) { |
8560 | | - d3_transitionInherit = node.__transition__[id]; |
| 8563 | + d3_transitionInherit = node[ns][id]; |
8561 | 8564 | type.call(node, node.__data__, i, j); |
8562 | 8565 | }); |
8563 | 8566 | d3_transitionInherit = inherit; |
8564 | 8567 | d3_transitionInheritId = inheritId; |
8565 | 8568 | } else { |
8566 | 8569 | d3_selection_each(this, function(node) { |
8567 | | - var transition = node.__transition__[id]; |
| 8570 | + var transition = node[ns][id]; |
8568 | 8571 | (transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener); |
8569 | 8572 | }); |
8570 | 8573 | } |
8571 | 8574 | return this; |
8572 | 8575 | }; |
8573 | 8576 | d3_transitionPrototype.transition = function() { |
8574 | | - var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition; |
| 8577 | + var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition; |
8575 | 8578 | for (var j = 0, m = this.length; j < m; j++) { |
8576 | 8579 | subgroups.push(subgroup = []); |
8577 | 8580 | for (var group = this[j], i = 0, n = group.length; i < n; i++) { |
8578 | 8581 | if (node = group[i]) { |
8579 | | - transition = Object.create(node.__transition__[id0]); |
| 8582 | + transition = Object.create(node[ns][id0]); |
8580 | 8583 | transition.delay += transition.duration; |
8581 | | - d3_transitionNode(node, i, id1, transition); |
| 8584 | + d3_transitionNode(node, i, ns, id1, transition); |
8582 | 8585 | } |
8583 | 8586 | subgroup.push(node); |
8584 | 8587 | } |
8585 | 8588 | } |
8586 | | - return d3_transition(subgroups, id1); |
| 8589 | + return d3_transition(subgroups, ns, id1); |
8587 | 8590 | }; |
8588 | | - function d3_transitionNode(node, i, id, inherit) { |
8589 | | - var lock = node.__transition__ || (node.__transition__ = { |
| 8591 | + function d3_transitionNamespace(name) { |
| 8592 | + return name == null ? "__transition__" : "__transition_" + name + "__"; |
| 8593 | + } |
| 8594 | + function d3_transitionNode(node, i, namespace, id, inherit) { |
| 8595 | + var lock = node[namespace] || (node[namespace] = { |
8590 | 8596 | active: 0, |
8591 | 8597 | count: 0 |
8592 | 8598 | }), transition = lock[id]; |
|
8631 | 8637 | } |
8632 | 8638 | } |
8633 | 8639 | function stop() { |
8634 | | - if (--lock.count) delete lock[id]; else delete node.__transition__; |
| 8640 | + if (--lock.count) delete lock[id]; else delete node[namespace]; |
8635 | 8641 | return 1; |
8636 | 8642 | } |
8637 | 8643 | }, 0, time); |
|
0 commit comments