| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style | |
| 5 * license that can be found in the LICENSE file or at | |
| 6 * https://developers.google.com/open-source/licenses/bsd | |
| 7 */ | |
| 8 library charted.selection.transition; | |
| 9 | |
| 10 import "dart:html" show Element,document; | |
| 11 import "package:charted/core/timer.dart"; | |
| 12 import "package:charted/selection/selection.dart"; | |
| 13 import "package:charted/core/interpolators.dart"; | |
| 14 | |
| 15 part 'src/transition_impl.dart'; | |
| 16 | |
| 17 typedef Interpolator AttrTweenCallback(datum, int ei, String attr); | |
| 18 typedef Interpolator StyleTweenCallback(datum, int ei, String style); | |
| 19 | |
| 20 /** | |
| 21 * Transitions are created using the transition operator on a selection. | |
| 22 * Transitions start automatically upon creation after a delay which defaults | |
| 23 * to zero; however, note that a zero-delay transition actually starts after a | |
| 24 * minimal (~17ms) delay, pending the first timer callback. | |
| 25 * Transitions have a default duration of 250ms. | |
| 26 */ | |
| 27 abstract class Transition { | |
| 28 | |
| 29 /** A settable default easing type */ | |
| 30 static EasingFunction defaultEasingType = easeCubic(); | |
| 31 | |
| 32 /** A settable default easing mode */ | |
| 33 static EasingModeFunction defaultEasingMode = reflectEasingFn; | |
| 34 | |
| 35 /** A settable default transition duration */ | |
| 36 static int defaultDurationMilliseconds = 250; | |
| 37 | |
| 38 /** Sets the ease function of the transition, default is cubic-in-out. */ | |
| 39 Interpolator ease; | |
| 40 | |
| 41 /** | |
| 42 * Specifies the transition delay in milliseconds. All elements are given the | |
| 43 * same delay. The default delay is 0. | |
| 44 */ | |
| 45 void delay(int millisecond); | |
| 46 | |
| 47 /** | |
| 48 * Sets the delay with a ChartedCallback function which would be evaluated for | |
| 49 * each selected element (in order), being passed the current datum d, the | |
| 50 * current index i, and the current DOM element. The function's return value | |
| 51 * is then used to set each element's delay. | |
| 52 */ | |
| 53 void delayWithCallback(SelectionCallback fn); | |
| 54 | |
| 55 /** | |
| 56 * Specifies per-element duration in milliseconds. All elements are given the | |
| 57 * same duration in millisecond. The default duration is 250ms. | |
| 58 */ | |
| 59 void duration(int millisecond); | |
| 60 | |
| 61 /** | |
| 62 * Sets the duration with a ChartedCallback which would be evaluated for each | |
| 63 * selected element (in order), being passed the current datum d, the current | |
| 64 * index i, and the current DOM element. The function's return value is then | |
| 65 * used to set each element's duration. | |
| 66 */ | |
| 67 void durationWithCallback(SelectionCallback fn); | |
| 68 | |
| 69 /** | |
| 70 * Sets the attribute [name] on all elements when [val] is not null. | |
| 71 * Removes the attribute when [val] is null. | |
| 72 */ | |
| 73 void attr(String name, val); | |
| 74 | |
| 75 /** | |
| 76 * Same as [attr], but calls [fn] for each non-null element in | |
| 77 * the selection (with data associated to the element, index of the | |
| 78 * element in it's group and the element itself) to get the value | |
| 79 * of the attribute. | |
| 80 */ | |
| 81 void attrWithCallback(String name, SelectionCallback fn); | |
| 82 | |
| 83 /** | |
| 84 * Transitions the value of the attribute with the specified name according to | |
| 85 * the specified tween function. The starting and ending value of the | |
| 86 * transition are determined by tween; the tween function is invoked when the | |
| 87 * transition starts on each element, being passed the current datum d, the | |
| 88 * current index i and the current attribute value a. The return value of | |
| 89 * tween must be an interpolator: a function that maps a parametric value t in | |
| 90 * the domain [0,1] to a color, number or arbitrary value. | |
| 91 */ | |
| 92 void attrTween(String name, AttrTweenCallback tween); | |
| 93 | |
| 94 /** | |
| 95 * Transitions the value of the CSS style property with the specified name to | |
| 96 * the specified value. An optional priority may also be specified, either as | |
| 97 * null or the string "important" (without the exclamation point). The | |
| 98 * starting value of the transition is the current computed style property | |
| 99 * value, and the ending value is the specified value. All elements are | |
| 100 * transitioned to the same style property value. | |
| 101 */ | |
| 102 void style(String property, String val, [String priority]); | |
| 103 | |
| 104 /** | |
| 105 * Transitions the style with a CartedCallback which would be evaluated for | |
| 106 * each selected element (in order), being passed the current datum d and the | |
| 107 * current index i, and the current DOM element. | |
| 108 * The function's return value is then used to transition each element's | |
| 109 * style property. | |
| 110 */ | |
| 111 void styleWithCallback(String property, | |
| 112 SelectionCallback<String> fn, [String priority]); | |
| 113 | |
| 114 /** | |
| 115 * Transitions the value of the CSS style property with the specified name | |
| 116 * according to the specified tween function. An optional priority may also | |
| 117 * be specified, either as null or the string "important" (without the | |
| 118 * exclamation point). The starting and ending value of the transition are | |
| 119 * determined by tween; the tween function is invoked when the transition | |
| 120 * starts on each element, being passed the current datum d, the current index | |
| 121 * i and the current attribute value a. The return value of tween must be an | |
| 122 * interpolator: a function that maps a parametric value t in the domain [0,1] | |
| 123 * to a color, number or arbitrary value. | |
| 124 */ | |
| 125 void styleTween(String property, StyleTweenCallback tween, [String priority]); | |
| 126 | |
| 127 /** Interrupts the transition. */ | |
| 128 void interrupt(); | |
| 129 | |
| 130 /** | |
| 131 * For each element in the current transition, selects the first descendant | |
| 132 * element that matches the specified selector string. If no element matches | |
| 133 * the specified selector for the current element, the element at the current | |
| 134 * index will be null in the returned selection; operators (with the exception | |
| 135 * of data) automatically skip null elements, thereby preserving the index of | |
| 136 * the existing selection. If the current element has associated data, this | |
| 137 * data is inherited by the returned subselection, and automatically bound to | |
| 138 * the newly selected elements. If multiple elements match the selector, only | |
| 139 * the first matching element in document traversal order will be selected. | |
| 140 */ | |
| 141 Transition select(String selector); | |
| 142 | |
| 143 /** | |
| 144 * For each element in the current transition, selects descendant elements | |
| 145 * that match the specified selector string. The returned selection is grouped | |
| 146 * by the ancestor node in the current selection. If no element matches the | |
| 147 * specified selector for the current element, the group at the current index | |
| 148 * will be empty in the returned selection. The subselection does not inherit | |
| 149 * data from the current selection; however, if data was previously bound to | |
| 150 * the selected elements, that data will be available to operators. | |
| 151 */ | |
| 152 Transition selectAll(String selector); | |
| 153 | |
| 154 /** | |
| 155 * Creates a new transition on the same selected elements that starts with | |
| 156 * this transition ends. The new transition inherits this transition’s | |
| 157 * duration and easing. This can be used to define chained transitions without | |
| 158 * needing to listen for "end" events. Only works when parent delay and | |
| 159 * duration are constant. | |
| 160 */ | |
| 161 Transition transition(); | |
| 162 | |
| 163 /** | |
| 164 * Removes all selected elements from the DOM at the end of the transition. | |
| 165 * If any of the selected elements have another transition scheduled when | |
| 166 * this transition ends, said elements will not be removed. | |
| 167 */ | |
| 168 void remove(); | |
| 169 | |
| 170 /** Factory method to create an instance of the default implementation */ | |
| 171 factory Transition(Selection selection) => new _TransitionImpl(selection); | |
| 172 } | |
| OLD | NEW |