|
136 | 136 | return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t)); |
137 | 137 | }; |
138 | 138 | } |
139 | | - function d3_ease_identity(t) { |
140 | | - return t; |
| 139 | + function d3_ease_quad(t) { |
| 140 | + return t * t; |
| 141 | + } |
| 142 | + function d3_ease_cubic(t) { |
| 143 | + return t * t * t; |
| 144 | + } |
| 145 | + function d3_ease_cubicInOut(t) { |
| 146 | + if (t <= 0) return 0; |
| 147 | + if (t >= 1) return 1; |
| 148 | + var t2 = t * t, t3 = t2 * t; |
| 149 | + return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75); |
141 | 150 | } |
142 | 151 | function d3_ease_poly(e) { |
143 | 152 | return function(t) { |
|
537 | 546 | } |
538 | 547 | function d3_transition(groups, id, time) { |
539 | 548 | d3_arraySubclass(groups, d3_transitionPrototype); |
540 | | - var tweens = new d3_Map, event = d3.dispatch("start", "end"), ease = d3_transitionEase; |
| 549 | + var event = d3.dispatch("start", "end"), ease = d3_transitionEase; |
541 | 550 | groups.id = id; |
542 | 551 | groups.time = time; |
543 | | - groups.tween = function(name, tween) { |
544 | | - if (arguments.length < 2) return tweens.get(name); |
545 | | - if (tween == null) tweens.remove(name); else tweens.set(name, tween); |
546 | | - return groups; |
547 | | - }; |
548 | 552 | groups.ease = function(value) { |
549 | 553 | if (!arguments.length) return ease; |
550 | 554 | ease = typeof value === "function" ? value : d3.ease.apply(d3, arguments); |
|
560 | 564 | function start(elapsed) { |
561 | 565 | if (lock.active > id) return stop(); |
562 | 566 | lock.active = id; |
563 | | - tweens.forEach(function(key, value) { |
| 567 | + transition.tween.forEach(function(key, value) { |
564 | 568 | if (value = value.call(node, d, i)) { |
565 | 569 | tweened.push(value); |
566 | 570 | } |
|
584 | 588 | } |
585 | 589 | } |
586 | 590 | function stop() { |
587 | | - if (!--lock.count) delete node.__transition__; |
| 591 | + if (--lock.count) delete lock[id]; else delete node.__transition__; |
588 | 592 | return 1; |
589 | 593 | } |
590 | | - var tweened = [], delay = node.delay, duration = node.duration, lock = (node = node.node).__transition__ || (node.__transition__ = { |
591 | | - active: 0, |
592 | | - count: 0 |
593 | | - }), d = node.__data__; |
594 | | - ++lock.count; |
| 594 | + var d = node.__data__, lock = node.__transition__, transition = lock[id], delay = transition.delay, duration = transition.duration, tweened = []; |
595 | 595 | delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time); |
596 | 596 | }); |
597 | 597 | }, 0, time); |
598 | 598 | return groups; |
599 | 599 | } |
| 600 | + function d3_transitionNode(node, id, delay, duration) { |
| 601 | + var lock = node.__transition__ || (node.__transition__ = { |
| 602 | + active: 0, |
| 603 | + count: 0 |
| 604 | + }); |
| 605 | + lock[id] || (lock[id] = { |
| 606 | + delay: delay, |
| 607 | + duration: duration, |
| 608 | + tween: new d3_Map |
| 609 | + }); |
| 610 | + ++lock.count; |
| 611 | + } |
600 | 612 | function d3_transition_each(callback) { |
601 | 613 | var id = d3_transitionId, ease = d3_transitionEase, delay = d3_transitionDelay, duration = d3_transitionDuration; |
602 | 614 | d3_transitionId = this.id; |
603 | 615 | d3_transitionEase = this.ease(); |
604 | 616 | d3_selection_each(this, function(node, i, j) { |
605 | | - d3_transitionDelay = node.delay; |
606 | | - d3_transitionDuration = node.duration; |
607 | | - callback.call(node = node.node, node.__data__, i, j); |
| 617 | + var transition = node.__transition__[d3_transitionId]; |
| 618 | + d3_transitionDelay = transition.delay; |
| 619 | + d3_transitionDuration = transition.duration; |
| 620 | + callback.call(node, node.__data__, i, j); |
608 | 621 | }); |
609 | 622 | d3_transitionId = id; |
610 | 623 | d3_transitionEase = ease; |
|
641 | 654 | var t0 = null, t1 = d3_timer_queue, then = Infinity; |
642 | 655 | while (t1) { |
643 | 656 | if (t1.flush) { |
| 657 | + delete d3_timer_byId[t1.callback.id]; |
644 | 658 | t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next; |
645 | 659 | } else { |
646 | 660 | then = Math.min(then, t1.then + t1.delay); |
|
2593 | 2607 | }; |
2594 | 2608 | } |
2595 | 2609 | d3 = { |
2596 | | - version: "2.10.2" |
| 2610 | + version: "3.0.0pre" |
2597 | 2611 | }; |
2598 | 2612 | var d3_array = d3_arraySlice; |
2599 | 2613 | try { |
|
3128 | 3142 | } |
3129 | 3143 | return d3_formatPrefixes[8 + i / 3]; |
3130 | 3144 | }; |
3131 | | - var d3_ease_quad = d3_ease_poly(2), d3_ease_cubic = d3_ease_poly(3), d3_ease_default = function() { |
3132 | | - return d3_ease_identity; |
| 3145 | + var d3_ease_default = function() { |
| 3146 | + return d3_identity; |
3133 | 3147 | }; |
3134 | 3148 | var d3_ease = d3.map({ |
3135 | 3149 | linear: d3_ease_default, |
|
3156 | 3170 | } |
3157 | 3171 | }); |
3158 | 3172 | var d3_ease_mode = d3.map({ |
3159 | | - "in": d3_ease_identity, |
| 3173 | + "in": d3_identity, |
3160 | 3174 | out: d3_ease_reverse, |
3161 | 3175 | "in-out": d3_ease_reflect, |
3162 | 3176 | "out-in": function(f) { |
|
3166 | 3180 | d3.ease = function(name) { |
3167 | 3181 | var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in"; |
3168 | 3182 | t = d3_ease.get(t) || d3_ease_default; |
3169 | | - m = d3_ease_mode.get(m) || d3_ease_identity; |
| 3183 | + m = d3_ease_mode.get(m) || d3_identity; |
3170 | 3184 | return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1)))); |
3171 | 3185 | }; |
3172 | 3186 | d3.event = null; |
|
3917 | 3931 | return null; |
3918 | 3932 | }; |
3919 | 3933 | d3_selectionPrototype.transition = function() { |
3920 | | - var subgroups = [], subgroup, node; |
| 3934 | + var id = d3_transitionId || ++d3_transitionNextId, subgroups = [], subgroup, node, transition; |
3921 | 3935 | for (var j = -1, m = this.length; ++j < m; ) { |
3922 | 3936 | subgroups.push(subgroup = []); |
3923 | 3937 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
3924 | | - subgroup.push((node = group[i]) ? { |
3925 | | - node: node, |
3926 | | - delay: d3_transitionDelay, |
3927 | | - duration: d3_transitionDuration |
3928 | | - } : null); |
| 3938 | + if (node = group[i]) d3_transitionNode(node, id, d3_transitionDelay, d3_transitionDuration); |
| 3939 | + subgroup.push(node); |
3929 | 3940 | } |
3930 | 3941 | } |
3931 | | - return d3_transition(subgroups, d3_transitionId || ++d3_transitionNextId, Date.now()); |
| 3942 | + return d3_transition(subgroups, id, Date.now()); |
3932 | 3943 | }; |
3933 | 3944 | var d3_selectionRoot = d3_selection([ [ document ] ]); |
3934 | 3945 | d3_selectionRoot[0].parentNode = d3_selectRoot; |
|
3962 | 3973 | } |
3963 | 3974 | return d3_selection(subgroups); |
3964 | 3975 | }; |
3965 | | - 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; |
| 3976 | + var d3_transitionPrototype = [], d3_transitionNextId = 0, d3_transitionId = 0, d3_transitionDefaultDelay = 0, d3_transitionDefaultDuration = 250, d3_transitionDelay = d3_transitionDefaultDelay, d3_transitionDuration = d3_transitionDefaultDuration, d3_transitionEase = d3_ease_cubicInOut; |
3966 | 3977 | d3_transitionPrototype.call = d3_selectionPrototype.call; |
| 3978 | + d3_transitionPrototype.empty = d3_selectionPrototype.empty; |
| 3979 | + d3_transitionPrototype.node = d3_selectionPrototype.node; |
3967 | 3980 | d3.transition = function(selection) { |
3968 | 3981 | return arguments.length ? d3_transitionId ? selection.transition() : selection : d3_selectionRoot.transition(); |
3969 | 3982 | }; |
3970 | 3983 | d3.transition.prototype = d3_transitionPrototype; |
3971 | 3984 | d3_transitionPrototype.select = function(selector) { |
3972 | | - var subgroups = [], subgroup, subnode, node; |
| 3985 | + var id = this.id, subgroups = [], subgroup, subnode, node, transition; |
3973 | 3986 | if (typeof selector !== "function") selector = d3_selection_selector(selector); |
3974 | 3987 | for (var j = -1, m = this.length; ++j < m; ) { |
3975 | 3988 | subgroups.push(subgroup = []); |
3976 | 3989 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
3977 | | - if ((node = group[i]) && (subnode = selector.call(node.node, node.node.__data__, i))) { |
3978 | | - if ("__data__" in node.node) subnode.__data__ = node.node.__data__; |
3979 | | - subgroup.push({ |
3980 | | - node: subnode, |
3981 | | - delay: node.delay, |
3982 | | - duration: node.duration |
3983 | | - }); |
| 3990 | + if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i))) { |
| 3991 | + if ("__data__" in node) subnode.__data__ = node.__data__; |
| 3992 | + transition = node.__transition__[id]; |
| 3993 | + d3_transitionNode(subnode, id, transition.delay, transition.duration); |
| 3994 | + subgroup.push(subnode); |
3984 | 3995 | } else { |
3985 | 3996 | subgroup.push(null); |
3986 | 3997 | } |
3987 | 3998 | } |
3988 | 3999 | } |
3989 | | - return d3_transition(subgroups, this.id, this.time).ease(this.ease()); |
| 4000 | + return d3_transition(subgroups, id, this.time).ease(this.ease()); |
3990 | 4001 | }; |
3991 | 4002 | d3_transitionPrototype.selectAll = function(selector) { |
3992 | | - var subgroups = [], subgroup, subnodes, node; |
| 4003 | + var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition; |
3993 | 4004 | if (typeof selector !== "function") selector = d3_selection_selectorAll(selector); |
3994 | 4005 | for (var j = -1, m = this.length; ++j < m; ) { |
3995 | 4006 | for (var group = this[j], i = -1, n = group.length; ++i < n; ) { |
3996 | 4007 | if (node = group[i]) { |
3997 | | - subnodes = selector.call(node.node, node.node.__data__, i); |
| 4008 | + transition = node.__transition__[id]; |
| 4009 | + subnodes = selector.call(node, node.__data__, i); |
3998 | 4010 | subgroups.push(subgroup = []); |
3999 | 4011 | for (var k = -1, o = subnodes.length; ++k < o; ) { |
4000 | | - subgroup.push({ |
4001 | | - node: subnodes[k], |
4002 | | - delay: node.delay, |
4003 | | - duration: node.duration |
4004 | | - }); |
| 4012 | + d3_transitionNode(subnode = subnodes[k], id, transition.delay, transition.duration); |
| 4013 | + subgroup.push(subnode); |
4005 | 4014 | } |
4006 | 4015 | } |
4007 | 4016 | } |
4008 | 4017 | } |
4009 | | - return d3_transition(subgroups, this.id, this.time).ease(this.ease()); |
| 4018 | + return d3_transition(subgroups, id, this.time).ease(this.ease()); |
4010 | 4019 | }; |
4011 | 4020 | d3_transitionPrototype.filter = function(filter) { |
4012 | 4021 | var subgroups = [], subgroup, group, node; |
4013 | 4022 | if (typeof filter !== "function") filter = d3_selection_filter(filter); |
4014 | 4023 | for (var j = 0, m = this.length; j < m; j++) { |
4015 | 4024 | subgroups.push(subgroup = []); |
4016 | 4025 | for (var group = this[j], i = 0, n = group.length; i < n; i++) { |
4017 | | - if ((node = group[i]) && filter.call(node.node, node.node.__data__, i)) { |
| 4026 | + if ((node = group[i]) && filter.call(node, node.__data__, i)) { |
4018 | 4027 | subgroup.push(node); |
4019 | 4028 | } |
4020 | 4029 | } |
|
4077 | 4086 | }); |
4078 | 4087 | }; |
4079 | 4088 | d3_transitionPrototype.delay = function(value) { |
| 4089 | + var id = this.id; |
4080 | 4090 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) { |
4081 | | - node.delay = value.call(node = node.node, node.__data__, i, j) | 0; |
4082 | | - } : (value = value | 0, function(node) { |
4083 | | - node.delay = value; |
| 4091 | + node.__transition__[id].delay = value.call(node, node.__data__, i, j) | 0; |
| 4092 | + } : (value |= 0, function(node) { |
| 4093 | + node.__transition__[id].delay = value; |
4084 | 4094 | })); |
4085 | 4095 | }; |
4086 | 4096 | d3_transitionPrototype.duration = function(value) { |
| 4097 | + var id = this.id; |
4087 | 4098 | return d3_selection_each(this, typeof value === "function" ? function(node, i, j) { |
4088 | | - node.duration = Math.max(1, value.call(node = node.node, node.__data__, i, j) | 0); |
| 4099 | + node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j) | 0); |
4089 | 4100 | } : (value = Math.max(1, value | 0), function(node) { |
4090 | | - node.duration = value; |
| 4101 | + node.__transition__[id].duration = value; |
4091 | 4102 | })); |
4092 | 4103 | }; |
4093 | 4104 | d3_transitionPrototype.transition = function() { |
4094 | | - return this.select(d3_this); |
| 4105 | + var id0 = this.id, id1 = ++d3_transitionNextId, subgroups = [], subgroup, group, node, transition; |
| 4106 | + for (var j = 0, m = this.length; j < m; j++) { |
| 4107 | + subgroups.push(subgroup = []); |
| 4108 | + for (var group = this[j], i = 0, n = group.length; i < n; i++) { |
| 4109 | + if (node = group[i]) { |
| 4110 | + transition = node.__transition__[id0]; |
| 4111 | + d3_transitionNode(node, id1, transition.delay + transition.duration, transition.duration); |
| 4112 | + } |
| 4113 | + subgroup.push(node); |
| 4114 | + } |
| 4115 | + } |
| 4116 | + return d3_transition(subgroups, id1, this.time).ease(this.ease()); |
| 4117 | + }; |
| 4118 | + d3_transitionPrototype.tween = function(name, tween) { |
| 4119 | + var id = this.id; |
| 4120 | + if (arguments.length < 2) return this.node().__transition__[id].tween.get(name); |
| 4121 | + return d3_selection_each(this, tween == null ? function(node) { |
| 4122 | + node.__transition__[id].tween.remove(name); |
| 4123 | + } : function(node) { |
| 4124 | + node.__transition__[id].tween.set(name, tween); |
| 4125 | + }); |
4095 | 4126 | }; |
4096 | 4127 | d3.tween = function(b, interpolate) { |
4097 | 4128 | function tweenFunction(d, i, a) { |
|
4104 | 4135 | return typeof b === "function" ? tweenFunction : b == null ? d3_tweenNull : (b += "", tweenString); |
4105 | 4136 | }; |
4106 | 4137 | var d3_tweenRemove = {}; |
4107 | | - var d3_timer_queue = null, d3_timer_interval, d3_timer_timeout; |
| 4138 | + var d3_timer_id = 0, d3_timer_byId = {}, d3_timer_queue = null, d3_timer_interval, d3_timer_timeout; |
4108 | 4139 | d3.timer = function(callback, delay, then) { |
4109 | | - var found = false, t0, t1 = d3_timer_queue; |
4110 | 4140 | if (arguments.length < 3) { |
4111 | 4141 | if (arguments.length < 2) delay = 0; else if (!isFinite(delay)) return; |
4112 | 4142 | then = Date.now(); |
4113 | 4143 | } |
4114 | | - while (t1) { |
4115 | | - if (t1.callback === callback) { |
4116 | | - t1.then = then; |
4117 | | - t1.delay = delay; |
4118 | | - found = true; |
4119 | | - break; |
4120 | | - } |
4121 | | - t0 = t1; |
4122 | | - t1 = t1.next; |
4123 | | - } |
4124 | | - if (!found) d3_timer_queue = { |
| 4144 | + var timer = d3_timer_byId[callback.id]; |
| 4145 | + if (timer && timer.callback === callback) { |
| 4146 | + timer.then = then; |
| 4147 | + timer.delay = delay; |
| 4148 | + } else d3_timer_byId[callback.id = ++d3_timer_id] = d3_timer_queue = { |
4125 | 4149 | callback: callback, |
4126 | 4150 | then: then, |
4127 | 4151 | delay: delay, |
|
4444 | 4468 | textEnter.attr("y", Math.max(tickMajorSize, 0) + tickPadding); |
4445 | 4469 | lineUpdate.attr("x2", 0).attr("y2", tickMajorSize); |
4446 | 4470 | textUpdate.attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding); |
4447 | | - text.attr("dy", ".71em").attr("text-anchor", "middle"); |
| 4471 | + text.attr("dy", ".71em").style("text-anchor", "middle"); |
4448 | 4472 | pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize); |
4449 | 4473 | break; |
4450 | 4474 | } |
|
4457 | 4481 | textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding)); |
4458 | 4482 | lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize); |
4459 | 4483 | textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding)); |
4460 | | - text.attr("dy", "0em").attr("text-anchor", "middle"); |
| 4484 | + text.attr("dy", "0em").style("text-anchor", "middle"); |
4461 | 4485 | pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize); |
4462 | 4486 | break; |
4463 | 4487 | } |
|
4470 | 4494 | textEnter.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)); |
4471 | 4495 | lineUpdate.attr("x2", -tickMajorSize).attr("y2", 0); |
4472 | 4496 | textUpdate.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0); |
4473 | | - text.attr("dy", ".32em").attr("text-anchor", "end"); |
| 4497 | + text.attr("dy", ".32em").style("text-anchor", "end"); |
4474 | 4498 | pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize); |
4475 | 4499 | break; |
4476 | 4500 | } |
|
4483 | 4507 | textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding); |
4484 | 4508 | lineUpdate.attr("x2", tickMajorSize).attr("y2", 0); |
4485 | 4509 | textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0); |
4486 | | - text.attr("dy", ".32em").attr("text-anchor", "start"); |
| 4510 | + text.attr("dy", ".32em").style("text-anchor", "start"); |
4487 | 4511 | pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize); |
4488 | 4512 | break; |
4489 | 4513 | } |
|
0 commit comments