3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('anim-shape', function (Y, NAME) {
10 * Adds support for the <code>transform</code> attribute of <code>Graphic</code>
11 * <code>Shape</code> instances.
13 * @submodule anim-shape-transform
14 * @deprecated Use anim-shape instead.
17 * Adds support for the <code>transform</code>, <code>fill</code>, and <code> attributes of <code>Graphic</code>
18 * <code>Shape</code> instances. The <code>anim-shape</code> submodule can be used for all animations involving
19 * <code>Graphic</code> <code>Shape</code> attributes.
22 * @submodule anim-shape
30 GETUPDATEDSTOPS = function(anim, from, to, elapsed, duration, fn)
33 getUpdatedColorValue = Y.Anim.getUpdatedColorValue,
49 for(; i < len; i = i + 1)
56 if(toStop.hasOwnProperty(prop))
60 stop[prop] = Y.Color.toHex(getUpdatedColorValue(Y.Color.toHex(fromStop[prop]), Y.Color.toHex(toStop[prop]), elapsed, duration, fn));
64 stop[prop] = fn(elapsed, NUM(fromStop[prop]), NUM(toStop[prop]) - NUM(fromStop[prop]), duration);
72 FILLANDSTROKEBEHAVIOR = {
73 set: function(anim, att, from, to, elapsed, duration, fn) {
76 getUpdatedColorValue = Y.Anim.getUpdatedColorValue,
77 getUpdatedStops = GETUPDATEDSTOPS;
80 if(to.hasOwnProperty(i) && i != TYPE)
85 updated[i] = getUpdatedColorValue(from[i], to[i], elapsed, duration, fn);
88 updated[i] = getUpdatedStops(anim, from[i], to[i], elapsed, duration, fn);
91 updated[i] = fn(elapsed, NUM(from[i]), NUM(to[i]) - NUM(from[i]), duration);
96 anim._node.set(att, updated);
99 Y.Anim.behaviors.fill = FILLANDSTROKEBEHAVIOR;
100 Y.Anim.behaviors.stroke = FILLANDSTROKEBEHAVIOR;
102 Y.Anim.behaviors.transform = {
103 set: function(anim, att, from, to, elapsed, duration, fn) {
104 var node = anim._node,
118 toArgs = to[i].concat();
119 fromArgs = from[i].concat();
120 transformTo = toArgs.shift();
121 transformFrom = fromArgs.shift();
122 argLen = toArgs.length;
123 transform += transformTo + "(";
124 for(j = 0; j < argLen; ++j)
126 transform += fn(elapsed, NUM(fromArgs[j]), NUM(toArgs[j]) - NUM(fromArgs[j]), duration);
136 node.set('transform', transform);
138 node._transform = TOSTRING;
141 get: function(anim) {
142 var node = anim._node,
143 fromMatrix = node.matrix,
144 toAttr = anim.get("to") || {},
145 toString = anim.get("to").transform,
146 fromString = node.get("transform"),
147 toArray = Y.MatrixUtil.getTransformArray(toString),
148 fromArray = fromString ? Y.MatrixUtil.getTransformArray(fromString) : null,
156 if(!fromArray || fromArray.length < 1)
159 len = toArray.length;
160 for(i = 0; i < len; ++i)
162 transformFunction = toArray[i][0];
163 fromArray[i] = Y.MatrixUtil.getTransformFunctionArray(transformFunction);
168 else if(Y.MatrixUtil.compareTransformSequence(toArray, fromArray))
175 toMatrix = new Y.Matrix();
176 len = toArray.length;
177 for(i = 0; i < len; ++i)
179 transformFunction = toArray[i].shift();
180 transformFunction = transformFunction == "matrix" ? "multiply" : transformFunction;
181 toMatrix[transformFunction].apply(toMatrix, toArray[i]);
184 TO = toMatrix.decompose();
185 from = fromMatrix.decompose();
195 }, '3.7.2', {"requires": ["anim-base", "anim-easing", "anim-color", "matrix"]});