File size: 4,036 Bytes
e7b2eb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import "../arrays/map";
import "../core/subclass";
import "../core/true";
import "../event/dispatch";
import "../event/timer";
import "../selection/selection";
import "../selection/transition";
import "../selection/interrupt";

function d3_transition(groups, ns, id) {
  d3_subclass(groups, d3_transitionPrototype);

  // Note: read-only!
  groups.namespace = ns;
  groups.id = id;

  return groups;
}

var d3_transitionPrototype = [],
    d3_transitionId = 0,
    d3_transitionInheritId,
    d3_transitionInherit;

d3_transitionPrototype.call = d3_selectionPrototype.call;
d3_transitionPrototype.empty = d3_selectionPrototype.empty;
d3_transitionPrototype.node = d3_selectionPrototype.node;
d3_transitionPrototype.size = d3_selectionPrototype.size;

d3.transition = function(selection, name) {
  return selection && selection.transition
      ? (d3_transitionInheritId ? selection.transition(name) : selection)
      : d3.selection().transition(selection);
};

d3.transition.prototype = d3_transitionPrototype;

import "select";
import "selectAll";
import "filter";
import "attr";
import "style";
import "text";
import "remove";
import "ease";
import "delay";
import "duration";
import "each";
import "subtransition";
import "tween";

function d3_transitionNamespace(name) {
  return name == null ? "__transition__" : "__transition_" + name + "__";
}

function d3_transitionNode(node, i, ns, id, inherit) {
  var lock = node[ns] || (node[ns] = {active: 0, count: 0}),
      transition = lock[id],
      time,
      timer,
      duration,
      ease,
      tweens;

  function schedule(elapsed) {
    var delay = transition.delay;
    timer.t = delay + time;
    if (delay <= elapsed) return start(elapsed - delay);
    timer.c = start;
  }

  function start(elapsed) {

    // Interrupt the active transition, if any.
    var activeId = lock.active,
        active = lock[activeId];
    if (active) {
      active.timer.c = null;
      active.timer.t = NaN;
      --lock.count;
      delete lock[activeId];
      active.event && active.event.interrupt.call(node, node.__data__, active.index);
    }

    // Cancel any pre-empted transitions. No interrupt event is dispatched
    // because the cancelled transitions never started.
    for (var cancelId in lock) {
      if (+cancelId < id) {
        var cancel = lock[cancelId];
        cancel.timer.c = null;
        cancel.timer.t = NaN;
        --lock.count;
        delete lock[cancelId];
      }
    }

    // Defer tween invocation to end of current frame; see mbostock/d3#1576.
    // Note that this transition may be canceled before then!
    // This must be scheduled before the start event; see d3/d3-transition#16!
    timer.c = tick;
    d3_timer(function() {
      if (timer.c && tick(elapsed || 1)) {
        timer.c = null;
        timer.t = NaN;
      }
      return 1;
    }, 0, time);

    // Start the transition.
    lock.active = id;
    transition.event && transition.event.start.call(node, node.__data__, i);

    // Initialize the tweens.
    tweens = [];
    transition.tween.forEach(function(key, value) {
      if (value = value.call(node, node.__data__, i)) {
        tweens.push(value);
      }
    });

    // Defer capture to allow tween initialization to set ease & duration.
    ease = transition.ease;
    duration = transition.duration;
  }

  function tick(elapsed) {
    var t = elapsed / duration,
        e = ease(t),
        n = tweens.length;

    while (n > 0) {
      tweens[--n].call(node, e);
    }

    if (t >= 1) {
      transition.event && transition.event.end.call(node, node.__data__, i);
      if (--lock.count) delete lock[id];
      else delete node[ns];
      return 1;
    }
  }

  if (!transition) {
    time = inherit.time;
    timer = d3_timer(schedule, 0, time);

    transition = lock[id] = {
      tween: new d3_Map,
      time: time,
      timer: timer,
      delay: inherit.delay,
      duration: inherit.duration,
      ease: inherit.ease,
      index: i
    };

    inherit = null; // allow gc

    ++lock.count;
  }
}