pax_global_header 0000666 0000000 0000000 00000000064 13106367270 0014517 g ustar 00root root 0000000 0000000 52 comment=328cc9a5705ceecadfcf7da558bbf0f6b9e23d9d d3-transition-1.1.0/ 0000775 0000000 0000000 00000000000 13106367270 0014214 5 ustar 00root root 0000000 0000000 d3-transition-1.1.0/.eslintrc 0000664 0000000 0000000 00000000147 13106367270 0016042 0 ustar 00root root 0000000 0000000 parserOptions: sourceType: module extends: "eslint:recommended" rules: no-cond-assign: 0 d3-transition-1.1.0/.gitignore 0000664 0000000 0000000 00000000100 13106367270 0016173 0 ustar 00root root 0000000 0000000 *.sublime-workspace .DS_Store build/ node_modules npm-debug.log d3-transition-1.1.0/.npmignore 0000664 0000000 0000000 00000000036 13106367270 0016212 0 ustar 00root root 0000000 0000000 *.sublime-* build/*.zip test/ d3-transition-1.1.0/LICENSE 0000664 0000000 0000000 00000005632 13106367270 0015227 0 ustar 00root root 0000000 0000000 Copyright (c) 2010-2015, Michael Bostock All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name Michael Bostock may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TERMS OF USE - EASING EQUATIONS Open source under the BSD License. Copyright 2001 Robert Penner All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. d3-transition-1.1.0/README.md 0000664 0000000 0000000 00000106611 13106367270 0015500 0 ustar 00root root 0000000 0000000 # d3-transition A transition is a [selection](https://github.com/d3/d3-selection)-like interface for animating changes to the DOM. Instead of applying changes instantaneously, transitions smoothly interpolate the DOM from its current state to the desired target state over a given duration. To apply a transition, select elements, call [*selection*.transition](#selection_transition), and then make the desired changes. For example: ```js d3.select("body") .transition() .style("background-color", "red"); ``` Transitions support most selection methods (such as [*transition*.attr](#transition_attr) and [*transition*.style](#transition_style) in place of [*selection*.attr](https://github.com/d3/d3-selection#selection_attr) and [*selection*.style](https://github.com/d3/d3-selection#selection_style)), but not all methods are supported; for example, you must [append](https://github.com/d3/d3-selection#selection_append) elements or [bind data](https://github.com/d3/d3-selection#joining-data) before a transition starts. A [*transition*.remove](#transition_remove) operator is provided for convenient removal of elements when the transition ends. To compute intermediate state, transitions leverage a variety of [built-in interpolators](https://github.com/d3/d3-interpolate). [Colors](https://github.com/d3/d3-interpolate#interpolateRgb), [numbers](https://github.com/d3/d3-interpolate#interpolateNumber), and [transforms](https://github.com/d3/d3-interpolate#interpolateTransform) are automatically detected. [Strings](https://github.com/d3/d3-interpolate#interpolateString) with embedded numbers are also detected, as is common with many styles (such as padding or font sizes) and paths. To specify a custom interpolator, use [*transition*.attrTween](#transition_attrTween), [*transition*.styleTween](#transition_styleTween) or [*transition*.tween](#transition_tween). ## Installing If you use NPM, `npm install d3-transition`. Otherwise, download the [latest release](https://github.com/d3/d3-transition/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-transition.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: ```html ``` [Try d3-transition in your browser.](https://tonicdev.com/npm/d3-transition) ## API Reference * [Selecting Elements](#selecting-elements) * [Modifying Elements](#modifying-elements) * [Timing](#timing) * [Control Flow](#control-flow) * [The Life of a Transition](#the-life-of-a-transition) ### Selecting Elements Transitions are derived from [selections](https://github.com/d3/d3-selection) via [*selection*.transition](#selection_transition). You can also create a transition on the document root element using [d3.transition](#transition). # selection.transition([name]) [<>](https://github.com/d3/d3-transition/blob/master/src/selection/transition.js "Source") Returns a new transition on the given *selection* with the specified *name*. If a *name* is not specified, null is used. The new transition is only exclusive with other transitions of the same name. If the *name* is a [transition](#transition) instance, the returned transition has the same id and name as the specified transition. If a transition with the same id already exists on a selected element, the existing transition is returned for that element. Otherwise, the timing of the returned transition is inherited from the existing transition of the same id on the nearest ancestor of each selected element. Thus, this method can be used to synchronize a transition across multiple selections, or to re-select a transition for specific elements and modify its configuration. For example: ```js var t = d3.transition() .duration(750) .ease(d3.easeLinear); d3.selectAll(".apple").transition(t) .style("fill", "red"); d3.selectAll(".orange").transition(t) .style("fill", "orange"); ``` If the specified *transition* is not found on a selected node or its ancestors (such as if the transition [already ended](#the-life-of-a-transition)), the default timing parameters are used; however, in a future release, this will likely be changed to throw an error. See [#59](https://github.com/d3/d3-transition/issues/59). # selection.interrupt([name]) [<>](https://github.com/d3/d3-transition/blob/master/src/selection/interrupt.js "Source") Interrupts the active transition of the specified *name* on the selected elements, and cancels any pending transitions with the specified *name*, if any. If a name is not specified, null is used. Interrupting a transition on an element has no effect on any transitions on any descendant elements. For example, an [axis transition](https://github.com/d3/d3-axis) consists of multiple independent, synchronized transitions on the descendants of the axis [G element](https://www.w3.org/TR/SVG/struct.html#Groups) (the tick lines, the tick labels, the domain path, *etc.*). To interrupt the axis transition, you must therefore interrupt the descendants: ```js selection.selectAll("*").interrupt(); ``` The [universal selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors), `*`, selects all descendant elements. If you also want to interrupt the G element itself: ```js selection.interrupt().selectAll("*").interrupt(); ``` # d3.interrupt(node[, name]) [<>](https://github.com/d3/d3-transition/blob/master/src/interrupt.js "Source") Interrupts the active transition of the specified *name* on the specified *node*, and cancels any pending transitions with the specified *name*, if any. If a name is not specified, null is used. See also [*selection*.interrupt](#selection_interrupt). # d3.transition([name]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/index.js#L29 "Source") Returns a new transition on the root element, `document.documentElement`, with the specified *name*. If a *name* is not specified, null is used. The new transition is only exclusive with other transitions of the same name. The *name* may also be a [transition](#transition) instance; see [*selection*.transition](#selection_transition). This method is equivalent to: ```js d3.selection() .transition(name) ``` This function can also be used to test for transitions (`instanceof d3.transition`) or to extend the transition prototype. # transition.select(selector) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/select.js "Source") For each selected element, selects the first descendant element that matches the specified *selector* string, if any, and returns a transition on the resulting selection. The *selector* may be specified either as a selector string or a function. If a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element. This method is equivalent to deriving the selection for this transition via [*transition*.selection](#transition_selection), creating a subselection via [*selection*.select](https://github.com/d3/d3-selection#selection_select), and then creating a new transition via [*selection*.transition](#selection_transition): ```js transition .selection() .select(selector) .transition(transition) ``` # transition.selectAll(selector) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/selectAll.js "Source") For each selected element, selects all descendant elements that match the specified *selector* string, if any, and returns a transition on the resulting selection. The *selector* may be specified either as a selector string or a function. If a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element. This method is equivalent to deriving the selection for this transition via [*transition*.selection](#transition_selection), creating a subselection via [*selection*.selectAll](https://github.com/d3/d3-selection#selection_selectAll), and then creating a new transition via [*selection*.transition](#selection_transition): ```js transition .selection() .selectAll(selector) .transition(transition) ``` # transition.filter(filter) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/filter.js "Source") For each selected element, selects only the elements that match the specified *filter*, and returns a transition on the resulting selection. The *filter* may be specified either as a selector string or a function. If a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element. This method is equivalent to deriving the selection for this transition via [*transition*.selection](#transition_selection), creating a subselection via [*selection*.filter](https://github.com/d3/d3-selection#selection_filter), and then creating a new transition via [*selection*.transition](#selection_transition): ```js transition .selection() .filter(filter) .transition(transition) ``` # transition.merge(other) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/merge.js "Source") Returns a new transition merging this transition with the specified *other* transition, which must have the same id as this transition. The returned transition has the same number of groups, the same parents, the same name and the same id as this transition. Any missing (null) elements in this transition are filled with the corresponding element, if present (not null), from the *other* transition. This method is equivalent to deriving the selection for this transition via [*transition*.selection](#transition_selection), merging with the selection likewise derived from the *other* transition via [*selection*.merge](https://github.com/d3/d3-selection#selection_merge), and then creating a new transition via [*selection*.transition](#selection_transition): ```js transition .selection() .merge(other.selection()) .transition(transition) ``` # transition.transition() [<>](https://github.com/d3/d3-transition/blob/master/src/transition/transition.js "Source") Returns a new transition on the same selected elements as this transition, scheduled to start when this transition ends. The new transition inherits a reference time equal to this transition’s time plus its [delay](#transition_delay) and [duration](#transition_duration). The new transition also inherits this transition’s name, duration, and [easing](#transition_ease). This method can be used to schedule a sequence of chained transitions. For example: ```js d3.selectAll(".apple") .transition() // First fade to green. .style("fill", "green") .transition() // Then red. .style("fill", "red") .transition() // Wait one second. Then brown, and remove. .delay(1000) .style("fill", "brown") .remove(); ``` The delay for each transition is relative to its previous transition. Thus, in the above example, apples will stay red for one second before the last transition to brown starts. # transition.selection() [<>](https://github.com/d3/d3-transition/blob/master/src/transition/selection.js "Source") Returns the [selection](https://github.com/d3/d3-selection#selection) corresponding to this transition. # d3.active(node[, name]) [<>](https://github.com/d3/d3-transition/blob/master/src/active.js "Source") Returns the active transition on the specified *node* with the specified *name*, if any. If no *name* is specified, null is used. Returns null if there is no such active transition on the specified node. This method is useful for creating chained transitions. For example, to initiate disco mode: ```js d3.selectAll("circle").transition() .delay(function(d, i) { return i * 50; }) .on("start", function repeat() { d3.active(this) .style("fill", "red") .transition() .style("fill", "green") .transition() .style("fill", "blue") .transition() .on("start", repeat); }); ``` See [chained transitions](http://bl.ocks.org/mbostock/70d5541b547cc222aa02) for an example. ### Modifying Elements After selecting elements and creating a transition with [*selection*.transition](#selection_transition), use the transition’s transformation methods to affect document content. # transition.attr(name, value) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/attr.js "Source") For each selected element, assigns the [attribute tween](#transition_attrTween) for the attribute with the specified *name* to the specified target *value*. The starting value of the tween is the attribute’s value when the transition starts. The target *value* may be specified either as a constant or a function. If a function, it is immediately evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. If the target value is null, the attribute is removed when the transition starts. Otherwise, an interpolator is chosen based on the type of the target value, using the following algorithm: 1. If *value* is a number, use [interpolateNumber](https://github.com/d3/d3-interpolate#interpolateNumber). 2. If *value* is a [color](https://github.com/d3/d3-color#color) or a string coercible to a color, use [interpolateRgb](https://github.com/d3/d3-interpolate#interpolateRgb). 3. Use [interpolateString](https://github.com/d3/d3-interpolate#interpolateString). To apply a different interpolator, use [*transition*.attrTween](#transition_attrTween). # transition.attrTween(name[, factory]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/attrTween.js "Source") If *factory* is specified and not null, assigns the attribute [tween](#transition_tween) for the attribute with the specified *name* to the specified interpolator *factory*. An interpolator factory is a function that returns an [interpolator](https://github.com/d3/d3-interpolate); when the transition starts, the *factory* is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The returned interpolator will then be invoked for each frame of the transition, in order, being passed the [eased](#transition_ease) time *t*, typically in the range [0, 1]. Lastly, the return value of the interpolator will be used to set the attribute value. The interpolator must return a string. (To remove an attribute at the start of a transition, use [*transition*.attr](#transition_attr); to remove an attribute at the end of a transition, use [*transition*.on](#transition_on) to listen for the *end* event.) If the specified *factory* is null, removes the previously-assigned attribute tween of the specified *name*, if any. If *factory* is not specified, returns the current interpolator factory for attribute with the specified *name*, or undefined if no such tween exists. For example, to interpolate the fill attribute from red to blue: ```js transition.attrTween("fill", function() { return d3.interpolateRgb("red", "blue"); }); ``` Or to interpolate from the current fill to blue, like [*transition*.attr](#transition_attr): ```js transition.attrTween("fill", function() { return d3.interpolateRgb(this.getAttribute("fill"), "blue"); }); ``` Or to apply a custom rainbow interpolator: ```js transition.attrTween("fill", function() { return function(t) { return "hsl(" + t * 360 + ",100%,50%)"; }; }); ``` This method is useful to specify a custom interpolator, such as one that understands [SVG paths](http://bl.ocks.org/mbostock/3916621). A useful technique is *data interpolation*, where [d3.interpolateObject](https://github.com/d3/d3-interpolate#interpolateObject) is used to interpolate two data values, and the resulting value is then used (say, with a [shape](https://github.com/d3/d3-shape)) to compute the new attribute value. # transition.style(name, value[, priority]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/style.js "Source") For each selected element, assigns the [style tween](#transition_styleTween) for the style with the specified *name* to the specified target *value* with the specified *priority*. The starting value of the tween is the style’s inline value if present, and otherwise its computed value, when the transition starts. The target *value* may be specified either as a constant or a function. If a function, it is immediately evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. If the target value is null, the style is removed when the transition starts. Otherwise, an interpolator is chosen based on the type of the target value, using the following algorithm: 1. If *value* is a number, use [interpolateNumber](https://github.com/d3/d3-interpolate#interpolateNumber). 2. If *value* is a [color](https://github.com/d3/d3-color#color) or a string coercible to a color, use [interpolateRgb](https://github.com/d3/d3-interpolate#interpolateRgb). 3. Use [interpolateString](https://github.com/d3/d3-interpolate#interpolateString). To apply a different interpolator, use [*transition*.styleTween](#transition_styleTween). # transition.styleTween(name[, factory[, priority]])) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/styleTween.js "Source") If *factory* is specified and not null, assigns the style [tween](#transition_tween) for the style with the specified *name* to the specified interpolator *factory*. An interpolator factory is a function that returns an [interpolator](https://github.com/d3/d3-interpolate); when the transition starts, the *factory* is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The returned interpolator will then be invoked for each frame of the transition, in order, being passed the [eased](#transition_ease) time *t*, typically in the range [0, 1]. Lastly, the return value of the interpolator will be used to set the style value with the specified *priority*. The interpolator must return a string. (To remove an style at the start of a transition, use [*transition*.style](#transition_style); to remove an style at the end of a transition, use [*transition*.on](#transition_on) to listen for the *end* event.) If the specified *factory* is null, removes the previously-assigned style tween of the specified *name*, if any. If *factory* is not specified, returns the current interpolator factory for style with the specified *name*, or undefined if no such tween exists. For example, to interpolate the fill style from red to blue: ```js transition.styleTween("fill", function() { return d3.interpolateRgb("red", "blue"); }); ``` Or to interpolate from the current fill to blue, like [*transition*.style](#transition_style): ```js transition.styleTween("fill", function() { return d3.interpolateRgb(this.style.fill, "blue"); }); ``` Or to apply a custom rainbow interpolator: ```js transition.styleTween("fill", function() { return function(t) { return "hsl(" + t * 360 + ",100%,50%)"; }; }); ``` This method is useful to specify a custom interpolator, such as with *data interpolation*, where [d3.interpolateObject](https://github.com/d3/d3-interpolate#interpolateObject) is used to interpolate two data values, and the resulting value is then used to compute the new style value. # transition.text(value) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/text.js "Source") For each selected element, sets the [text content](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent) to the specified target *value* when the transition starts. The *value* may be specified either as a constant or a function. If a function, it is immediately evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s text content. A null value will clear the content. To interpolate text rather than to set it on start, use [*transition*.tween](#transition_tween) ([for example](http://bl.ocks.org/mbostock/7004f92cac972edef365)) or append a replacement element and cross-fade opacity ([for example](http://bl.ocks.org/mbostock/f7dcecb19c4af317e464)). Text is not interpolated by default because it is usually undesirable. # transition.remove() [<>](https://github.com/d3/d3-transition/blob/master/src/transition/remove.js "Source") For each selected element, [removes](https://github.com/d3/d3-selection#selection_remove) the element when the transition ends, as long as the element has no other active or pending transitions. If the element has other active or pending transitions, does nothing. # transition.tween(name[, value]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/tween.js "Source") For each selected element, assigns the tween with the specified *name* with the specified *value* function. The *value* must be specified as a function that returns a function. When the transition starts, the *value* function is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The returned function is then invoked for each frame of the transition, in order, being passed the [eased](#transition_ease) time *t*, typically in the range [0, 1]. If the specified *value* is null, removes the previously-assigned tween of the specified *name*, if any. For example, to interpolate the fill attribute to blue, like [*transition*.attr](#transition_attr): ```js transition.tween("attr.fill", function() { var node = this, i = d3.interpolateRgb(node.getAttribute("fill"), "blue"); return function(t) { node.setAttribute("fill", i(t)); }; }); ``` This method is useful to specify a custom interpolator, or to perform side-effects, say to animate the [scroll offset](http://bl.ocks.org/mbostock/1649463). ### Timing The [easing](#transition_ease), [delay](#transition_delay) and [duration](#transition_duration) of a transition is configurable. For example, a per-element delay can be used to [stagger the reordering](http://bl.ocks.org/mbostock/3885705) of elements, improving perception. See [Animated Transitions in Statistical Data Graphics](http://vis.berkeley.edu/papers/animated_transitions/) for recommendations. # transition.delay([value]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/delay.js "Source") For each selected element, sets the transition delay to the specified *value* in milliseconds. The *value* may be specified either as a constant or a function. If a function, it is immediately evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s transition delay. If a delay is not specified, it defaults to zero. If a *value* is not specified, returns the current value of the delay for the first (non-null) element in the transition. This is generally useful only if you know that the transition contains exactly one element. Setting the delay to a multiple of the index `i` is a convenient way to stagger transitions across a set of elements. For example: ```js transition.delay(function(d, i) { return i * 10; }); ``` Of course, you can also compute the delay as a function of the data, or [sort the selection](https://github.com/d3/d3-selection#selection_sort) before computed an index-based delay. # transition.duration([value]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/duration.js "Source") For each selected element, sets the transition duration to the specified *value* in milliseconds. The *value* may be specified either as a constant or a function. If a function, it is immediately evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s transition duration. If a duration is not specified, it defaults to 250ms. If a *value* is not specified, returns the current value of the duration for the first (non-null) element in the transition. This is generally useful only if you know that the transition contains exactly one element. # transition.ease([value]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/ease.js "Source") Specifies the transition [easing function](https://github.com/d3/d3-ease) for all selected elements. The *value* must be specified as a function. The easing function is invoked for each frame of the animation, being passed the normalized time *t* in the range [0, 1]; it must then return the eased time *tʹ* which is typically also in the range [0, 1]. A good easing function should return 0 if *t* = 0 and 1 if *t* = 1. If an easing function is not specified, it defaults to [d3.easeCubic](https://github.com/d3/d3-ease#easeCubic). If a *value* is not specified, returns the current easing function for the first (non-null) element in the transition. This is generally useful only if you know that the transition contains exactly one element. ### Control Flow For advanced usage, transitions provide methods for custom control flow. # transition.on(typenames[, listener]) [<>](https://github.com/d3/d3-transition/blob/master/src/transition/on.js "Source") Adds or removes a *listener* to each selected element for the specified event *typenames*. The *typenames* is one of the following string event types: * `start` - when the transition starts. * `end` - when the transition ends. * `interrupt` - when the transition is interrupted. See [The Life of a Transition](#the-life-of-a-transition) for more. Note that these are *not* native DOM events as implemented by [*selection*.on](https://github.com/d3/d3-selection#selection_on) and [*selection*.dispatch](https://github.com/d3/d3-selection#selection_dispatch), but transition events! The type may be optionally followed by a period (`.`) and a name; the optional name allows multiple callbacks to be registered to receive events of the same type, such as `start.foo` and `start.bar`. To specify multiple typenames, separate typenames with spaces, such as `interrupt end` or `start.foo start.bar`. When a specified transition event is dispatched on a selected node, the specified *listener* will be invoked for the transitioning element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. Listeners always see the latest datum for their element, but the index is a property of the selection and is fixed when the listener is assigned; to update the index, re-assign the listener. If an event listener was previously registered for the same *typename* on a selected element, the old listener is removed before the new listener is added. To remove a listener, pass null as the *listener*. To remove all listeners for a given name, pass null as the *listener* and `.foo` as the *typename*, where `foo` is the name; to remove all listeners with no name, specify `.` as the *typename*. If a *listener* is not specified, returns the currently-assigned listener for the specified event *typename* on the first (non-null) selected element, if any. If multiple typenames are specified, the first matching listener is returned. # transition.each(function) [<>](https://github.com/d3/d3-selection/blob/master/src/selection/each.js "Source") Invokes the specified *function* for each selected element, passing in the current datum `d` and index `i`, with the `this` context of the current DOM element. This method can be used to invoke arbitrary code for each selected element, and is useful for creating a context to access parent and child data simultaneously. Equivalent to [*selection*.each](https://github.com/d3/d3-selection#selection_each). # transition.call(function[, arguments…]) [<>](https://github.com/d3/d3-selection/blob/master/src/selection/call.js "Source") Invokes the specified *function* exactly once, passing in this transition along with any optional *arguments*. Returns this transition. This is equivalent to invoking the function by hand but facilitates method chaining. For example, to set several attributes in a reusable function: ```js function color(transition, fill, stroke) { transition .style("fill", fill) .style("stroke", stroke); } ``` Now say: ```js d3.selectAll("div").transition().call(color, "red", "blue"); ``` This is equivalent to: ```js color(d3.selectAll("div").transition(), "red", "blue"); ``` Equivalent to [*selection*.call](https://github.com/d3/d3-selection#selection_call). # transition.empty() [<>](https://github.com/d3/d3-selection/blob/master/src/selection/empty.js "Source") Returns true if this transition contains no (non-null) elements. Equivalent to [*selection*.empty](https://github.com/d3/d3-selection#selection_empty). # transition.nodes() [<>](https://github.com/d3/d3-selection/blob/master/src/selection/nodes.js "Source") Returns an array of all (non-null) elements in this transition. Equivalent to [*selection*.nodes](https://github.com/d3/d3-selection#selection_nodes). # transition.node() [<>](https://github.com/d3/d3-selection/blob/master/src/selection/node.js "Source") Returns the first (non-null) element in this transition. If the transition is empty, returns null. Equivalent to [*selection*.node](https://github.com/d3/d3-selection#selection_node). # transition.size() [<>](https://github.com/d3/d3-selection/blob/master/src/selection/size.js "Source") Returns the total number of elements in this transition. Equivalent to [*selection*.size](https://github.com/d3/d3-selection#selection_size). ### The Life of a Transition Immediately after creating a transition, such as by [*selection*.transition](#selection_transition) or [*transition*.transition](#transition_transition), you may configure the transition using methods such as [*transition*.delay](#transition_delay), [*transition*.duration](#transition_duration), [*transition*.attr](#transition_attr) and [*transition*.style](#transition_style). Methods that specify target values (such as *transition*.attr) are evaluated synchronously; however, methods that require the starting value for interpolation, such as [*transition*.attrTween](#transition_attrTween) and [*transition*.styleTween](#transition_styleTween), must be deferred until the transition starts. Shortly after creation, either at the end of the current frame or during the next frame, the transition is scheduled. At this point, the delay and `start` event listeners may no longer be changed. When the transition subsequently starts, it interrupts the active transition of the same name on the same element, if any, dispatching an `interrupt` event to registered listeners. (Note that interrupts happen on start, not creation, and thus even a zero-delay transition will not immediately interrupt the active transition: the old transition is given a final frame. Use [*selection*.interrupt](#selection_interrupt) to interrupt immediately.) The starting transition also cancels any pending transitions of the same name on the same element that were created before the starting transition. The transition then dispatches a `start` event to registered listeners. This is the last moment at which the transition may be modified: after starting, the transition’s timing, tweens, and listeners may no longer be changed. The transition initializes its tweens immediately after starting. During the frame the transition starts, but *after* all transitions starting this frame have been started, the transition invokes its tweens for the first time. Batching tween initialization, which typically involves reading from the DOM, improves performance by avoiding interleaved DOM reads and writes. For each frame that a transition is active, it invokes its tweens with an [eased](#transition_ease) *t*-value ranging from 0 to 1. Within each frame, the transition invokes its tweens in the order they were registered. When a transition ends, it invokes its tweens a final time with a (non-eased) *t*-value of 1. It then dispatches an `end` event to registered listeners. This is the last moment at which the transition may be inspected: after ending, the transition is deleted from the element, and its configuration is destroyed. (A transition’s configuration is also destroyed on interrupt or cancel.) d3-transition-1.1.0/d3-transition.sublime-project 0000664 0000000 0000000 00000000271 13106367270 0021740 0 ustar 00root root 0000000 0000000 { "folders": [ { "path": ".", "file_exclude_patterns": [ "*.sublime-workspace" ], "folder_exclude_patterns": [ "build" ] } ] } d3-transition-1.1.0/index.js 0000664 0000000 0000000 00000000304 13106367270 0015656 0 ustar 00root root 0000000 0000000 import "./src/selection/index"; export {default as transition} from "./src/transition/index"; export {default as active} from "./src/active"; export {default as interrupt} from "./src/interrupt"; d3-transition-1.1.0/package.json 0000664 0000000 0000000 00000003362 13106367270 0016506 0 ustar 00root root 0000000 0000000 { "name": "d3-transition", "version": "1.1.0", "description": "Animated transitions for D3 selections.", "keywords": [ "d3", "d3-module", "dom", "transition", "animation" ], "homepage": "https://d3js.org/d3-transition/", "license": "BSD-3-Clause", "author": { "name": "Mike Bostock", "url": "http://bost.ocks.org/mike" }, "main": "build/d3-transition.js", "module": "index", "jsnext:main": "index", "repository": { "type": "git", "url": "https://github.com/d3/d3-transition.git" }, "scripts": { "pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -g d3-color:d3,d3-interpolate:d3,d3-ease:d3,d3-dispatch:d3,d3-selection:d3,d3-timer:d3 -n d3 -o build/d3-transition.js -- index.js", "test": "tape 'test/**/*-test.js' && eslint index.js src test", "prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-transition.js -c -m -o build/d3-transition.min.js", "postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../d3-transition/build/d3-transition.js d3-transition.v1.js && cp ../d3-transition/build/d3-transition.min.js d3-transition.v1.min.js && git add d3-transition.v1.js d3-transition.v1.min.js && git commit -m \"d3-transition ${npm_package_version}\" && git push && cd - && zip -j build/d3-transition.zip -- LICENSE README.md build/d3-transition.js build/d3-transition.min.js" }, "dependencies": { "d3-color": "1", "d3-dispatch": "1", "d3-ease": "1", "d3-interpolate": "1", "d3-selection": "^1.1.0", "d3-timer": "1" }, "devDependencies": { "eslint": "3", "package-preamble": "0.1", "rollup": "0.41", "jsdom": "10", "tape": "4", "uglify-js": "^2.8.11" } } d3-transition-1.1.0/src/ 0000775 0000000 0000000 00000000000 13106367270 0015003 5 ustar 00root root 0000000 0000000 d3-transition-1.1.0/src/active.js 0000664 0000000 0000000 00000000744 13106367270 0016621 0 ustar 00root root 0000000 0000000 import {Transition} from "./transition/index"; import {SCHEDULED} from "./transition/schedule"; var root = [null]; export default function(node, name) { var schedules = node.__transition, schedule, i; if (schedules) { name = name == null ? null : name + ""; for (i in schedules) { if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) { return new Transition([[node]], root, name, +i); } } } return null; } d3-transition-1.1.0/src/interrupt.js 0000664 0000000 0000000 00000001231 13106367270 0017372 0 ustar 00root root 0000000 0000000 import {STARTING, ENDING, ENDED} from "./transition/schedule"; export default function(node, name) { var schedules = node.__transition, schedule, active, empty = true, i; if (!schedules) return; name = name == null ? null : name + ""; for (i in schedules) { if ((schedule = schedules[i]).name !== name) { empty = false; continue; } active = schedule.state > STARTING && schedule.state < ENDING; schedule.state = ENDED; schedule.timer.stop(); if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group); delete schedules[i]; } if (empty) delete node.__transition; } d3-transition-1.1.0/src/selection/ 0000775 0000000 0000000 00000000000 13106367270 0016770 5 ustar 00root root 0000000 0000000 d3-transition-1.1.0/src/selection/index.js 0000664 0000000 0000000 00000000365 13106367270 0020441 0 ustar 00root root 0000000 0000000 import {selection} from "d3-selection"; import selection_interrupt from "./interrupt"; import selection_transition from "./transition"; selection.prototype.interrupt = selection_interrupt; selection.prototype.transition = selection_transition; d3-transition-1.1.0/src/selection/interrupt.js 0000664 0000000 0000000 00000000212 13106367270 0021355 0 ustar 00root root 0000000 0000000 import interrupt from "../interrupt"; export default function(name) { return this.each(function() { interrupt(this, name); }); } d3-transition-1.1.0/src/selection/transition.js 0000664 0000000 0000000 00000002102 13106367270 0021513 0 ustar 00root root 0000000 0000000 import {Transition, newId} from "../transition/index"; import schedule from "../transition/schedule"; import {easeCubicInOut} from "d3-ease"; import {now} from "d3-timer"; var defaultTiming = { time: null, // Set on use. delay: 0, duration: 250, ease: easeCubicInOut }; function inherit(node, id) { var timing; while (!(timing = node.__transition) || !(timing = timing[id])) { if (!(node = node.parentNode)) { return defaultTiming.time = now(), defaultTiming; } } return timing; } export default function(name) { var id, timing; if (name instanceof Transition) { id = name._id, name = name._name; } else { id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + ""; } for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { if (node = group[i]) { schedule(node, name, id, i, group, timing || inherit(node, id)); } } } return new Transition(groups, this._parents, name, id); } d3-transition-1.1.0/src/transition/ 0000775 0000000 0000000 00000000000 13106367270 0017175 5 ustar 00root root 0000000 0000000 d3-transition-1.1.0/src/transition/attr.js 0000664 0000000 0000000 00000004656 13106367270 0020520 0 ustar 00root root 0000000 0000000 import {interpolateTransformSvg as interpolateTransform} from "d3-interpolate"; import {namespace} from "d3-selection"; import {tweenValue} from "./tween"; import interpolate from "./interpolate"; function attrRemove(name) { return function() { this.removeAttribute(name); }; } function attrRemoveNS(fullname) { return function() { this.removeAttributeNS(fullname.space, fullname.local); }; } function attrConstant(name, interpolate, value1) { var value00, interpolate0; return function() { var value0 = this.getAttribute(name); return value0 === value1 ? null : value0 === value00 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value1); }; } function attrConstantNS(fullname, interpolate, value1) { var value00, interpolate0; return function() { var value0 = this.getAttributeNS(fullname.space, fullname.local); return value0 === value1 ? null : value0 === value00 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value1); }; } function attrFunction(name, interpolate, value) { var value00, value10, interpolate0; return function() { var value0, value1 = value(this); if (value1 == null) return void this.removeAttribute(name); value0 = this.getAttribute(name); return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value10 = value1); }; } function attrFunctionNS(fullname, interpolate, value) { var value00, value10, interpolate0; return function() { var value0, value1 = value(this); if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local); value0 = this.getAttributeNS(fullname.space, fullname.local); return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value10 = value1); }; } export default function(name, value) { var fullname = namespace(name), i = fullname === "transform" ? interpolateTransform : interpolate; return this.attrTween(name, typeof value === "function" ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value)) : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname) : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value + "")); } d3-transition-1.1.0/src/transition/attrTween.js 0000664 0000000 0000000 00000001610 13106367270 0021506 0 ustar 00root root 0000000 0000000 import {namespace} from "d3-selection"; function attrTweenNS(fullname, value) { function tween() { var node = this, i = value.apply(node, arguments); return i && function(t) { node.setAttributeNS(fullname.space, fullname.local, i(t)); }; } tween._value = value; return tween; } function attrTween(name, value) { function tween() { var node = this, i = value.apply(node, arguments); return i && function(t) { node.setAttribute(name, i(t)); }; } tween._value = value; return tween; } export default function(name, value) { var key = "attr." + name; if (arguments.length < 2) return (key = this.tween(key)) && key._value; if (value == null) return this.tween(key, null); if (typeof value !== "function") throw new Error; var fullname = namespace(name); return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value)); } d3-transition-1.1.0/src/transition/delay.js 0000664 0000000 0000000 00000000776 13106367270 0020643 0 ustar 00root root 0000000 0000000 import {get, init} from "./schedule"; function delayFunction(id, value) { return function() { init(this, id).delay = +value.apply(this, arguments); }; } function delayConstant(id, value) { return value = +value, function() { init(this, id).delay = value; }; } export default function(value) { var id = this._id; return arguments.length ? this.each((typeof value === "function" ? delayFunction : delayConstant)(id, value)) : get(this.node(), id).delay; } d3-transition-1.1.0/src/transition/duration.js 0000664 0000000 0000000 00000001020 13106367270 0021351 0 ustar 00root root 0000000 0000000 import {get, set} from "./schedule"; function durationFunction(id, value) { return function() { set(this, id).duration = +value.apply(this, arguments); }; } function durationConstant(id, value) { return value = +value, function() { set(this, id).duration = value; }; } export default function(value) { var id = this._id; return arguments.length ? this.each((typeof value === "function" ? durationFunction : durationConstant)(id, value)) : get(this.node(), id).duration; } d3-transition-1.1.0/src/transition/ease.js 0000664 0000000 0000000 00000000534 13106367270 0020452 0 ustar 00root root 0000000 0000000 import {get, set} from "./schedule"; function easeConstant(id, value) { if (typeof value !== "function") throw new Error; return function() { set(this, id).ease = value; }; } export default function(value) { var id = this._id; return arguments.length ? this.each(easeConstant(id, value)) : get(this.node(), id).ease; } d3-transition-1.1.0/src/transition/filter.js 0000664 0000000 0000000 00000001076 13106367270 0021024 0 ustar 00root root 0000000 0000000 import {matcher} from "d3-selection"; import {Transition} from "./index"; export default function(match) { if (typeof match !== "function") match = matcher(match); for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) { if ((node = group[i]) && match.call(node, node.__data__, i, group)) { subgroup.push(node); } } } return new Transition(subgroups, this._parents, this._name, this._id); } d3-transition-1.1.0/src/transition/index.js 0000664 0000000 0000000 00000003544 13106367270 0020650 0 ustar 00root root 0000000 0000000 import {selection} from "d3-selection"; import transition_attr from "./attr"; import transition_attrTween from "./attrTween"; import transition_delay from "./delay"; import transition_duration from "./duration"; import transition_ease from "./ease"; import transition_filter from "./filter"; import transition_merge from "./merge"; import transition_on from "./on"; import transition_remove from "./remove"; import transition_select from "./select"; import transition_selectAll from "./selectAll"; import transition_selection from "./selection"; import transition_style from "./style"; import transition_styleTween from "./styleTween"; import transition_text from "./text"; import transition_transition from "./transition"; import transition_tween from "./tween"; var id = 0; export function Transition(groups, parents, name, id) { this._groups = groups; this._parents = parents; this._name = name; this._id = id; } export default function transition(name) { return selection().transition(name); } export function newId() { return ++id; } var selection_prototype = selection.prototype; Transition.prototype = transition.prototype = { constructor: Transition, select: transition_select, selectAll: transition_selectAll, filter: transition_filter, merge: transition_merge, selection: transition_selection, transition: transition_transition, call: selection_prototype.call, nodes: selection_prototype.nodes, node: selection_prototype.node, size: selection_prototype.size, empty: selection_prototype.empty, each: selection_prototype.each, on: transition_on, attr: transition_attr, attrTween: transition_attrTween, style: transition_style, styleTween: transition_styleTween, text: transition_text, remove: transition_remove, tween: transition_tween, delay: transition_delay, duration: transition_duration, ease: transition_ease }; d3-transition-1.1.0/src/transition/interpolate.js 0000664 0000000 0000000 00000000524 13106367270 0022062 0 ustar 00root root 0000000 0000000 import {color} from "d3-color"; import {interpolateNumber, interpolateRgb, interpolateString} from "d3-interpolate"; export default function(a, b) { var c; return (typeof b === "number" ? interpolateNumber : b instanceof color ? interpolateRgb : (c = color(b)) ? (b = c, interpolateRgb) : interpolateString)(a, b); } d3-transition-1.1.0/src/transition/merge.js 0000664 0000000 0000000 00000001215 13106367270 0020631 0 ustar 00root root 0000000 0000000 import {Transition} from "./index"; export default function(transition) { if (transition._id !== this._id) throw new Error; for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) { if (node = group0[i] || group1[i]) { merge[i] = node; } } } for (; j < m0; ++j) { merges[j] = groups0[j]; } return new Transition(merges, this._parents, this._name, this._id); } d3-transition-1.1.0/src/transition/on.js 0000664 0000000 0000000 00000001525 13106367270 0020152 0 ustar 00root root 0000000 0000000 import {get, set, init} from "./schedule"; function start(name) { return (name + "").trim().split(/^|\s+/).every(function(t) { var i = t.indexOf("."); if (i >= 0) t = t.slice(0, i); return !t || t === "start"; }); } function onFunction(id, name, listener) { var on0, on1, sit = start(name) ? init : set; return function() { var schedule = sit(this, id), on = schedule.on; // If this node shared a dispatch with the previous node, // just assign the updated shared dispatch and we’re done! // Otherwise, copy-on-write. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener); schedule.on = on1; }; } export default function(name, listener) { var id = this._id; return arguments.length < 2 ? get(this.node(), id).on.on(name) : this.each(onFunction(id, name, listener)); } d3-transition-1.1.0/src/transition/remove.js 0000664 0000000 0000000 00000000434 13106367270 0021031 0 ustar 00root root 0000000 0000000 function removeFunction(id) { return function() { var parent = this.parentNode; for (var i in this.__transition) if (+i !== id) return; if (parent) parent.removeChild(this); }; } export default function() { return this.on("end.remove", removeFunction(this._id)); } d3-transition-1.1.0/src/transition/schedule.js 0000664 0000000 0000000 00000011270 13106367270 0021330 0 ustar 00root root 0000000 0000000 import {dispatch} from "d3-dispatch"; import {timer, timeout} from "d3-timer"; var emptyOn = dispatch("start", "end", "interrupt"); var emptyTween = []; export var CREATED = 0; export var SCHEDULED = 1; export var STARTING = 2; export var STARTED = 3; export var RUNNING = 4; export var ENDING = 5; export var ENDED = 6; export default function(node, name, id, index, group, timing) { var schedules = node.__transition; if (!schedules) node.__transition = {}; else if (id in schedules) return; create(node, id, { name: name, index: index, // For context during callback. group: group, // For context during callback. on: emptyOn, tween: emptyTween, time: timing.time, delay: timing.delay, duration: timing.duration, ease: timing.ease, timer: null, state: CREATED }); } export function init(node, id) { var schedule = node.__transition; if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late"); return schedule; } export function set(node, id) { var schedule = node.__transition; if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late"); return schedule; } export function get(node, id) { var schedule = node.__transition; if (!schedule || !(schedule = schedule[id])) throw new Error("too late"); return schedule; } function create(node, id, self) { var schedules = node.__transition, tween; // Initialize the self timer when the transition is created. // Note the actual delay is not known until the first callback! schedules[id] = self; self.timer = timer(schedule, 0, self.time); function schedule(elapsed) { self.state = SCHEDULED; self.timer.restart(start, self.delay, self.time); // If the elapsed delay is less than our first sleep, start immediately. if (self.delay <= elapsed) start(elapsed - self.delay); } function start(elapsed) { var i, j, n, o; // If the state is not SCHEDULED, then we previously errored on start. if (self.state !== SCHEDULED) return stop(); for (i in schedules) { o = schedules[i]; if (o.name !== self.name) continue; // While this element already has a starting transition during this frame, // defer starting an interrupting transition until that transition has a // chance to tick (and possibly end); see d3/d3-transition#54! if (o.state === STARTED) return timeout(start); // Interrupt the active transition, if any. // Dispatch the interrupt event. if (o.state === RUNNING) { o.state = ENDED; o.timer.stop(); o.on.call("interrupt", node, node.__data__, o.index, o.group); delete schedules[i]; } // Cancel any pre-empted transitions. No interrupt event is dispatched // because the cancelled transitions never started. Note that this also // removes this transition from the pending list! else if (+i < id) { o.state = ENDED; o.timer.stop(); delete schedules[i]; } } // Defer the first tick to end of the current frame; see d3/d3#1576. // Note the transition may be canceled after start and before the first tick! // Note this must be scheduled before the start event; see d3/d3-transition#16! // Assuming this is successful, subsequent callbacks go straight to tick. timeout(function() { if (self.state === STARTED) { self.state = RUNNING; self.timer.restart(tick, self.delay, self.time); tick(elapsed); } }); // Dispatch the start event. // Note this must be done before the tween are initialized. self.state = STARTING; self.on.call("start", node, node.__data__, self.index, self.group); if (self.state !== STARTING) return; // interrupted self.state = STARTED; // Initialize the tween, deleting null tween. tween = new Array(n = self.tween.length); for (i = 0, j = -1; i < n; ++i) { if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) { tween[++j] = o; } } tween.length = j + 1; } function tick(elapsed) { var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1), i = -1, n = tween.length; while (++i < n) { tween[i].call(null, t); } // Dispatch the end event. if (self.state === ENDING) { self.on.call("end", node, node.__data__, self.index, self.group); stop(); } } function stop() { self.state = ENDED; self.timer.stop(); delete schedules[id]; for (var i in schedules) return; // eslint-disable-line no-unused-vars delete node.__transition; } } d3-transition-1.1.0/src/transition/select.js 0000664 0000000 0000000 00000001472 13106367270 0021016 0 ustar 00root root 0000000 0000000 import {selector} from "d3-selection"; import {Transition} from "./index"; import schedule, {get} from "./schedule"; export default function(select) { var name = this._name, id = this._id; if (typeof select !== "function") select = selector(select); for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) { if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) { if ("__data__" in node) subnode.__data__ = node.__data__; subgroup[i] = subnode; schedule(subgroup[i], name, id, i, subgroup, get(node, id)); } } } return new Transition(subgroups, this._parents, name, id); } d3-transition-1.1.0/src/transition/selectAll.js 0000664 0000000 0000000 00000001563 13106367270 0021450 0 ustar 00root root 0000000 0000000 import {selectorAll} from "d3-selection"; import {Transition} from "./index"; import schedule, {get} from "./schedule"; export default function(select) { var name = this._name, id = this._id; if (typeof select !== "function") select = selectorAll(select); for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { if (node = group[i]) { for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) { if (child = children[k]) { schedule(child, name, id, k, children, inherit); } } subgroups.push(children); parents.push(node); } } } return new Transition(subgroups, parents, name, id); } d3-transition-1.1.0/src/transition/selection.js 0000664 0000000 0000000 00000000256 13106367270 0021523 0 ustar 00root root 0000000 0000000 import {selection} from "d3-selection"; var Selection = selection.prototype.constructor; export default function() { return new Selection(this._groups, this._parents); } d3-transition-1.1.0/src/transition/style.js 0000664 0000000 0000000 00000003572 13106367270 0020702 0 ustar 00root root 0000000 0000000 import {interpolateTransformCss as interpolateTransform} from "d3-interpolate"; import {style} from "d3-selection"; import {tweenValue} from "./tween"; import interpolate from "./interpolate"; function styleRemove(name, interpolate) { var value00, value10, interpolate0; return function() { var value0 = style(this, name), value1 = (this.style.removeProperty(name), style(this, name)); return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value10 = value1); }; } function styleRemoveEnd(name) { return function() { this.style.removeProperty(name); }; } function styleConstant(name, interpolate, value1) { var value00, interpolate0; return function() { var value0 = style(this, name); return value0 === value1 ? null : value0 === value00 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value1); }; } function styleFunction(name, interpolate, value) { var value00, value10, interpolate0; return function() { var value0 = style(this, name), value1 = value(this); if (value1 == null) value1 = (this.style.removeProperty(name), style(this, name)); return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate(value00 = value0, value10 = value1); }; } export default function(name, value, priority) { var i = (name += "") === "transform" ? interpolateTransform : interpolate; return value == null ? this .styleTween(name, styleRemove(name, i)) .on("end.style." + name, styleRemoveEnd(name)) : this.styleTween(name, typeof value === "function" ? styleFunction(name, i, tweenValue(this, "style." + name, value)) : styleConstant(name, i, value + ""), priority); } d3-transition-1.1.0/src/transition/styleTween.js 0000664 0000000 0000000 00000001137 13106367270 0021700 0 ustar 00root root 0000000 0000000 function styleTween(name, value, priority) { function tween() { var node = this, i = value.apply(node, arguments); return i && function(t) { node.style.setProperty(name, i(t), priority); }; } tween._value = value; return tween; } export default function(name, value, priority) { var key = "style." + (name += ""); if (arguments.length < 2) return (key = this.tween(key)) && key._value; if (value == null) return this.tween(key, null); if (typeof value !== "function") throw new Error; return this.tween(key, styleTween(name, value, priority == null ? "" : priority)); } d3-transition-1.1.0/src/transition/text.js 0000664 0000000 0000000 00000000731 13106367270 0020520 0 ustar 00root root 0000000 0000000 import {tweenValue} from "./tween"; function textConstant(value) { return function() { this.textContent = value; }; } function textFunction(value) { return function() { var value1 = value(this); this.textContent = value1 == null ? "" : value1; }; } export default function(value) { return this.tween("text", typeof value === "function" ? textFunction(tweenValue(this, "text", value)) : textConstant(value == null ? "" : value + "")); } d3-transition-1.1.0/src/transition/transition.js 0000664 0000000 0000000 00000001263 13106367270 0021727 0 ustar 00root root 0000000 0000000 import {Transition, newId} from "./index"; import schedule, {get} from "./schedule"; export default function() { var name = this._name, id0 = this._id, id1 = newId(); for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { if (node = group[i]) { var inherit = get(node, id0); schedule(node, name, id1, i, group, { time: inherit.time + inherit.delay + inherit.duration, delay: 0, duration: inherit.duration, ease: inherit.ease }); } } } return new Transition(groups, this._parents, name, id1); } d3-transition-1.1.0/src/transition/tween.js 0000664 0000000 0000000 00000003752 13106367270 0020664 0 ustar 00root root 0000000 0000000 import {get, set} from "./schedule"; function tweenRemove(id, name) { var tween0, tween1; return function() { var schedule = set(this, id), tween = schedule.tween; // If this node shared tween with the previous node, // just assign the updated shared tween and we’re done! // Otherwise, copy-on-write. if (tween !== tween0) { tween1 = tween0 = tween; for (var i = 0, n = tween1.length; i < n; ++i) { if (tween1[i].name === name) { tween1 = tween1.slice(); tween1.splice(i, 1); break; } } } schedule.tween = tween1; }; } function tweenFunction(id, name, value) { var tween0, tween1; if (typeof value !== "function") throw new Error; return function() { var schedule = set(this, id), tween = schedule.tween; // If this node shared tween with the previous node, // just assign the updated shared tween and we’re done! // Otherwise, copy-on-write. if (tween !== tween0) { tween1 = (tween0 = tween).slice(); for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) { if (tween1[i].name === name) { tween1[i] = t; break; } } if (i === n) tween1.push(t); } schedule.tween = tween1; }; } export default function(name, value) { var id = this._id; name += ""; if (arguments.length < 2) { var tween = get(this.node(), id).tween; for (var i = 0, n = tween.length, t; i < n; ++i) { if ((t = tween[i]).name === name) { return t.value; } } return null; } return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value)); } export function tweenValue(transition, name, value) { var id = transition._id; transition.each(function() { var schedule = set(this, id); (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments); }); return function(node) { return get(node, id).value[name]; }; } d3-transition-1.1.0/test/ 0000775 0000000 0000000 00000000000 13106367270 0015173 5 ustar 00root root 0000000 0000000 d3-transition-1.1.0/test/.eslintrc 0000664 0000000 0000000 00000000304 13106367270 0017014 0 ustar 00root root 0000000 0000000 ecmaFeatures: modules: true env: es6: true browser: true node: true extends: "eslint:recommended" rules: no-cond-assign: 0 no-sparse-arrays: 0 no-unused-vars: 0 d3-transition-1.1.0/test/active-test.js 0000664 0000000 0000000 00000011612 13106367270 0017762 0 ustar 00root root 0000000 0000000 var tape = require("tape"), jsdom = require("./jsdom"), d3_timer = require("d3-timer"), d3_selection = require("d3-selection"), d3_transition = require("../"); tape("d3.active(node) returns null if the specified node has no active transition with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root); // No transitions pending. test.strictEqual(d3_transition.active(root), null); // Two transitions created. selection.transition().delay(50).duration(50); selection.transition("foo").duration(50); test.strictEqual(d3_transition.active(root), null); // One transition scheduled; one active with a different name. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root), null); }); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root), null); test.end(); }, 100); }); tape("d3.active(node, null) returns null if the specified node has no active transition with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root); // No transitions pending. test.strictEqual(d3_transition.active(root, null), null); // Two transitions created. selection.transition().delay(50).duration(50); selection.transition("foo").duration(50); test.strictEqual(d3_transition.active(root, null), null); // One transition scheduled; one active with a different name. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root, null), null); }); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root, null), null); test.end(); }, 100); }); tape("d3.active(node, undefined) returns null if the specified node has no active transition with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root); // No transitions pending. test.strictEqual(d3_transition.active(root, undefined), null); // Two transitions created. selection.transition().delay(50).duration(50); selection.transition("foo").duration(50); test.strictEqual(d3_transition.active(root, undefined), null); // One transition scheduled; one active with a different name. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root, undefined), null); }); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root, undefined), null); test.end(); }, 100); }); tape("d3.active(node, name) returns null if the specified node has no active transition with the specified name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root); // No transitions pending. test.strictEqual(d3_transition.active(root, "foo"), null); // Two transitions created. selection.transition("foo").delay(50).duration(50); selection.transition().duration(50); test.strictEqual(d3_transition.active(root, null), null); // One transition scheduled; one active with a different name. test.strictEqual(d3_transition.active(root, "foo"), null); // One transition scheduled. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root, "foo"), null); }); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(d3_transition.active(root, "foo"), null); test.end(); }, 100); }); tape("d3.active(node) returns the active transition on the specified node with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().on("start", check).tween("tween", tweened).on("end", ended); function check() { var t = d3_transition.active(root); test.deepEqual(t._groups, [[root]]); test.deepEqual(t._parents, [null]); test.strictEqual(t._name, null); test.strictEqual(t._id, transition._id); } function tweened() { check(); return function(t) { if (t >= 1) check(); }; } function ended() { check(); test.end(); } }); tape("d3.active(node, name) returns the active transition on the specified node with the specified name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition("foo").on("start", check).tween("tween", tweened).on("end", ended); function check() { var t = d3_transition.active(root, "foo"); test.deepEqual(t._groups, [[root]]); test.deepEqual(t._parents, [null]); test.strictEqual(t._name, "foo"); test.strictEqual(t._id, transition._id); } function tweened() { check(); return function(t) { if (t >= 1) check(); }; } function ended() { check(); test.end(); } }); d3-transition-1.1.0/test/error-test.js 0000664 0000000 0000000 00000006146 13106367270 0017646 0 ustar 00root root 0000000 0000000 var tape = require("tape"), jsdom = require("./jsdom"), d3_timer = require("d3-timer"), d3_selection = require("d3-selection"), d3_transition = require("../"); tape("transition.on(\"start\", error) terminates the transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().on("start", function() { throw new Error; }); process.once("uncaughtException", function() {}); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(root.__transition, undefined); test.end(); }); }); tape("transition.on(\"start\", error) with delay terminates the transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().delay(50).on("start", function() { throw new Error; }); process.once("uncaughtException", function() {}); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(root.__transition, undefined); test.end(); }, 50); }); tape("transition.tween(\"foo\", error) terminates the transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().tween("foo", function() { throw new Error; }); process.once("uncaughtException", function() {}); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(root.__transition, undefined); test.end(); }); }); tape("transition.tween(\"foo\", error) with delay terminates the transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().delay(50).tween("foo", function() { throw new Error; }); process.once("uncaughtException", function() {}); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(root.__transition, undefined); test.end(); }, 50); }); tape("transition.tween(\"foo\", deferredError) terminates the transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().duration(50).tween("foo", function() { return function(t) { if (t === 1) throw new Error; }; }); process.once("uncaughtException", function() {}); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(root.__transition, undefined); test.end(); }, 50); }); tape("transition.on(\"end\", error) terminates the transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().delay(50).duration(50).on("end", function() { throw new Error; }); process.once("uncaughtException", function() {}); // No transitions remaining after the transition ends. d3_timer.timeout(function() { test.strictEqual(root.__transition, undefined); test.end(); }, 100); }); d3-transition-1.1.0/test/interrupt-test.js 0000664 0000000 0000000 00000002257 13106367270 0020550 0 ustar 00root root 0000000 0000000 var tape = require("tape"), jsdom = require("./jsdom"), d3_selection = require("d3-selection"), d3_transition = require("../"); tape("d3.interrupt(node) cancels any pending transitions on the specified node", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition(), transition2 = transition1.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); d3_transition.interrupt(root); test.equal(root.__transition, undefined); test.end(); }); tape("selection.interrupt(name) only cancels pending transitions with the specified name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition("foo"), transition2 = selection.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); d3_transition.interrupt(root, "foo"); test.equal(transition1._id in root.__transition, false); test.equal(transition2._id in root.__transition, true); test.end(); }); d3-transition-1.1.0/test/jsdom.js 0000664 0000000 0000000 00000000166 13106367270 0016650 0 ustar 00root root 0000000 0000000 var jsdom = require("jsdom"); module.exports = function(html) { return (new jsdom.JSDOM(html)).window.document; }; d3-transition-1.1.0/test/selection/ 0000775 0000000 0000000 00000000000 13106367270 0017160 5 ustar 00root root 0000000 0000000 d3-transition-1.1.0/test/selection/interrupt-test.js 0000664 0000000 0000000 00000026421 13106367270 0022534 0 ustar 00root root 0000000 0000000 var tape = require("tape"), jsdom = require("../jsdom"), d3_selection = require("d3-selection"), d3_timer = require("d3-timer"), state = require("../transition/state"); require("../../"); tape("selection.interrupt() returns the selection", function(test) { var document = jsdom(), selection = d3_selection.select(document); test.equal(selection.interrupt(), selection); test.end(); }); tape("selection.interrupt() cancels any pending transitions on the selected elements", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition(), transition2 = transition1.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); test.equal(selection.interrupt(), selection); test.equal(root.__transition, undefined); test.end(); }); tape("selection.interrupt() only cancels pending transitions with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition("foo"), transition2 = selection.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); test.equal(selection.interrupt(), selection); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, false); test.end(); }); tape("selection.interrupt(null) only cancels pending transitions with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition("foo"), transition2 = selection.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); test.equal(selection.interrupt(null), selection); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, false); test.end(); }); tape("selection.interrupt(undefined) only cancels pending transitions with the null name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition("foo"), transition2 = selection.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); test.equal(selection.interrupt(undefined), selection); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, false); test.end(); }); tape("selection.interrupt(name) only cancels pending transitions with the specified name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition("foo"), transition2 = selection.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); test.equal(selection.interrupt("foo"), selection); test.equal(transition1._id in root.__transition, false); test.equal(transition2._id in root.__transition, true); test.end(); }); tape("selection.interrupt(name) coerces the name to a string", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition("foo"), transition2 = selection.transition(); test.equal(transition1._id in root.__transition, true); test.equal(transition2._id in root.__transition, true); test.equal(selection.interrupt({toString: function() { return "foo"; }}), selection); test.equal(transition1._id in root.__transition, false); test.equal(transition2._id in root.__transition, true); test.end(); }); tape("selection.interrupt() does nothing if there is no transition on the selected elements", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root); test.equal(root.__transition, undefined); test.equal(selection.interrupt(), selection); test.equal(root.__transition, undefined); test.end(); }); tape("selection.interrupt() dispatches an interrupt event to the started transition on the selected elements", function(test) { var root = jsdom().documentElement, interrupts = 0, selection = d3_selection.select(root), transition = selection.transition().on("interrupt", function() { ++interrupts; }); d3_timer.timeout(function() { var schedule = root.__transition[transition._id]; test.equal(schedule.state, state.STARTED); selection.interrupt(); test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); test.equal(interrupts, 1); test.end(); }); }); tape("selection.interrupt() destroys the schedule after dispatching the interrupt event", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().on("interrupt", interrupted); d3_timer.timeout(function() { selection.interrupt(); }); function interrupted() { test.equal(transition.delay(), 0); test.equal(transition.duration(), 250); test.equal(transition.on("interrupt"), interrupted); test.end(); } }); tape("selection.interrupt() does not dispatch an interrupt event to a starting transition", function(test) { var root = jsdom().documentElement, interrupts = 0, selection = d3_selection.select(root), transition = selection.transition().on("interrupt", function() { ++interrupts; }).on("start", started); function started() { var schedule = root.__transition[transition._id]; test.equal(schedule.state, state.STARTING); selection.interrupt(); test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); test.equal(interrupts, 0); test.end(); } }); tape("selection.interrupt() prevents a created transition from starting", function(test) { var root = jsdom().documentElement, starts = 0, selection = d3_selection.select(root), transition = selection.transition().on("start", function() { ++starts; }), schedule = root.__transition[transition._id]; test.equal(schedule.state, state.CREATED); selection.interrupt(); test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); d3_timer.timeout(function() { test.equal(starts, 0); test.end(); }, 10); }); tape("selection.interrupt() prevents a scheduled transition from starting", function(test) { var root = jsdom().documentElement, starts = 0, selection = d3_selection.select(root), transition = selection.transition().delay(50).on("start", function() { ++starts; }), schedule = root.__transition[transition._id]; d3_timer.timeout(function() { test.equal(schedule.state, state.SCHEDULED); selection.interrupt(); test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); }); d3_timer.timeout(function() { test.equal(starts, 0); test.end(); }, 60); }); tape("selection.interrupt() prevents a starting transition from initializing tweens", function(test) { var root = jsdom().documentElement, tweens = 0, selection = d3_selection.select(root), transition = selection.transition().tween("tween", function() { ++tweens; }).on("start", started), schedule = root.__transition[transition._id]; function started() { test.equal(schedule.state, state.STARTING); selection.interrupt(); test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); } d3_timer.timeout(function() { test.equal(tweens, 0); test.end(); }, 10); }); tape("selection.interrupt() during tween initialization prevents an active transition from continuing", function(test) { var root = jsdom().documentElement, tweens = 0, selection = d3_selection.select(root), transition = selection.transition().tween("tween", function() { selection.interrupt(); return function() { ++tweens; }; }), schedule = root.__transition[transition._id]; d3_timer.timeout(function() { test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); test.equal(tweens, 0); test.end(); }, 10); }); tape("selection.interrupt() prevents an active transition from continuing", function(test) { var root = jsdom().documentElement, interrupted = false, tweens = 0, selection = d3_selection.select(root), transition = selection.transition().tween("tween", function() { return function() { if (interrupted) ++tweens; }; }), schedule = root.__transition[transition._id]; d3_timer.timeout(function() { interrupted = true; test.equal(schedule.state, state.STARTED); selection.interrupt(); test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); }, 10); d3_timer.timeout(function() { test.equal(tweens, 0); test.end(); }, 50); }); tape("selection.interrupt() during the final tween invocation prevents the end event from being dispatched", function(test) { var root = jsdom().documentElement, ends = 0, selection = d3_selection.select(root), transition = selection.transition().duration(50).tween("tween", tween).on("end", function() { ++ends; }), schedule = root.__transition[transition._id]; function tween() { return function(t) { if (t >= 1) { test.equal(schedule.state, state.ENDING); selection.interrupt(); } }; } d3_timer.timeout(function() { test.equal(schedule.timer._call, null); test.equal(schedule.state, state.ENDED); test.equal(root.__transition, undefined); test.equal(ends, 0); test.end(); }, 60); }); tape("selection.interrupt() has no effect on an ended transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition().duration(50).on("end", ended), schedule = root.__transition[transition._id]; function ended() { d3_timer.timeout(function() { test.equal(schedule.state, state.ENDED); test.equal(schedule.timer._call, null); selection.interrupt(); test.equal(schedule.state, state.ENDED); test.equal(schedule.timer._call, null); test.equal(root.__transition, undefined); test.end(); }); } }); tape("selection.interrupt() has no effect on an interrupting transition", function(test) { var root = jsdom().documentElement, interrupts = 0, selection = d3_selection.select(root), transition = selection.transition().duration(50).on("interrupt", interrupted), schedule = root.__transition[transition._id]; d3_timer.timeout(function() { test.equal(schedule.state, state.STARTED); selection.interrupt(); test.equal(schedule.state, state.ENDED); test.equal(schedule.timer._call, null); test.equal(interrupts, 1); test.end(); }); function interrupted() { ++interrupts; selection.interrupt(); } }); d3-transition-1.1.0/test/selection/transition-test.js 0000664 0000000 0000000 00000012240 13106367270 0022664 0 ustar 00root root 0000000 0000000 var tape = require("tape"), jsdom = require("../jsdom"), d3_timer = require("d3-timer"), d3_ease = require("d3-ease"), d3_selection = require("d3-selection"), d3_transition = require("../../"); tape("selection.transition() returns an instanceof d3.transition", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition(); test.equal(transition instanceof d3_transition.transition, true); test.end(); }); tape("selection.transition() uses the default timing parameters", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition(), schedule = root.__transition[transition._id]; test.equal(schedule.time, d3_timer.now()); test.equal(schedule.delay, 0); test.equal(schedule.duration, 250); test.equal(schedule.ease, d3_ease.easeCubic); test.end(); }); tape("selection.transition() assigns a monotonically-increasing id", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition1 = selection.transition(), transition2 = selection.transition(), transition3 = selection.transition(); test.ok(transition2._id > transition1._id); test.ok(transition3._id > transition2._id); test.end(); }); tape("selection.transition() uses a default name of null", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition(), schedule = root.__transition[transition._id]; test.strictEqual(schedule.name, null); test.end(); }); tape("selection.transition(null) uses a name of null", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition(null), schedule = root.__transition[transition._id]; test.strictEqual(schedule.name, null); test.end(); }); tape("selection.transition(undefined) uses a name of null", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition(undefined), schedule = root.__transition[transition._id]; test.strictEqual(schedule.name, null); test.end(); }); tape("selection.transition(name) uses the specified name", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition("foo"), schedule = root.__transition[transition._id]; test.strictEqual(schedule.name, "foo"); test.end(); }); tape("selection.transition(name) coerces the name to a string", function(test) { var root = jsdom().documentElement, selection = d3_selection.select(root), transition = selection.transition({toString: function() { return "foo"; }}), schedule = root.__transition[transition._id]; test.strictEqual(schedule.name, "foo"); test.end(); }); tape("selection.transition(transition) inherits the id, name and timing from the corresponding parent in the specified transition", function(test) { var document = jsdom("