basicTransition.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { isFunction, isObject, retrieve2 } from 'zrender/lib/core/util.js';
  41. import { makeInner } from '../util/model.js'; // Stored properties for further transition.
  42. export var transitionStore = makeInner();
  43. /**
  44. * Return null if animation is disabled.
  45. */
  46. export function getAnimationConfig(animationType, animatableModel, dataIndex, // Extra opts can override the option in animatable model.
  47. extraOpts, // TODO It's only for pictorial bar now.
  48. extraDelayParams) {
  49. var animationPayload; // Check if there is global animation configuration from dataZoom/resize can override the config in option.
  50. // If animation is enabled. Will use this animation config in payload.
  51. // If animation is disabled. Just ignore it.
  52. if (animatableModel && animatableModel.ecModel) {
  53. var updatePayload = animatableModel.ecModel.getUpdatePayload();
  54. animationPayload = updatePayload && updatePayload.animation;
  55. }
  56. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  57. var isUpdate = animationType === 'update';
  58. if (animationEnabled) {
  59. var duration = void 0;
  60. var easing = void 0;
  61. var delay = void 0;
  62. if (extraOpts) {
  63. duration = retrieve2(extraOpts.duration, 200);
  64. easing = retrieve2(extraOpts.easing, 'cubicOut');
  65. delay = 0;
  66. } else {
  67. duration = animatableModel.getShallow(isUpdate ? 'animationDurationUpdate' : 'animationDuration');
  68. easing = animatableModel.getShallow(isUpdate ? 'animationEasingUpdate' : 'animationEasing');
  69. delay = animatableModel.getShallow(isUpdate ? 'animationDelayUpdate' : 'animationDelay');
  70. } // animation from payload has highest priority.
  71. if (animationPayload) {
  72. animationPayload.duration != null && (duration = animationPayload.duration);
  73. animationPayload.easing != null && (easing = animationPayload.easing);
  74. animationPayload.delay != null && (delay = animationPayload.delay);
  75. }
  76. if (isFunction(delay)) {
  77. delay = delay(dataIndex, extraDelayParams);
  78. }
  79. if (isFunction(duration)) {
  80. duration = duration(dataIndex);
  81. }
  82. var config = {
  83. duration: duration || 0,
  84. delay: delay,
  85. easing: easing
  86. };
  87. return config;
  88. } else {
  89. return null;
  90. }
  91. }
  92. function animateOrSetProps(animationType, el, props, animatableModel, dataIndex, cb, during) {
  93. var isFrom = false;
  94. var removeOpt;
  95. if (isFunction(dataIndex)) {
  96. during = cb;
  97. cb = dataIndex;
  98. dataIndex = null;
  99. } else if (isObject(dataIndex)) {
  100. cb = dataIndex.cb;
  101. during = dataIndex.during;
  102. isFrom = dataIndex.isFrom;
  103. removeOpt = dataIndex.removeOpt;
  104. dataIndex = dataIndex.dataIndex;
  105. }
  106. var isRemove = animationType === 'leave';
  107. if (!isRemove) {
  108. // Must stop the remove animation.
  109. el.stopAnimation('leave');
  110. }
  111. var animationConfig = getAnimationConfig(animationType, animatableModel, dataIndex, isRemove ? removeOpt || {} : null, animatableModel && animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  112. if (animationConfig && animationConfig.duration > 0) {
  113. var duration = animationConfig.duration;
  114. var animationDelay = animationConfig.delay;
  115. var animationEasing = animationConfig.easing;
  116. var animateConfig = {
  117. duration: duration,
  118. delay: animationDelay || 0,
  119. easing: animationEasing,
  120. done: cb,
  121. force: !!cb || !!during,
  122. // Set to final state in update/init animation.
  123. // So the post processing based on the path shape can be done correctly.
  124. setToFinal: !isRemove,
  125. scope: animationType,
  126. during: during
  127. };
  128. isFrom ? el.animateFrom(props, animateConfig) : el.animateTo(props, animateConfig);
  129. } else {
  130. el.stopAnimation(); // If `isFrom`, the props is the "from" props.
  131. !isFrom && el.attr(props); // Call during at least once.
  132. during && during(1);
  133. cb && cb();
  134. }
  135. }
  136. /**
  137. * Update graphic element properties with or without animation according to the
  138. * configuration in series.
  139. *
  140. * Caution: this method will stop previous animation.
  141. * So do not use this method to one element twice before
  142. * animation starts, unless you know what you are doing.
  143. * @example
  144. * graphic.updateProps(el, {
  145. * position: [100, 100]
  146. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  147. * // Or
  148. * graphic.updateProps(el, {
  149. * position: [100, 100]
  150. * }, seriesModel, function () { console.log('Animation done!'); });
  151. */
  152. function updateProps(el, props, // TODO: TYPE AnimatableModel
  153. animatableModel, dataIndex, cb, during) {
  154. animateOrSetProps('update', el, props, animatableModel, dataIndex, cb, during);
  155. }
  156. export { updateProps };
  157. /**
  158. * Init graphic element properties with or without animation according to the
  159. * configuration in series.
  160. *
  161. * Caution: this method will stop previous animation.
  162. * So do not use this method to one element twice before
  163. * animation starts, unless you know what you are doing.
  164. */
  165. export function initProps(el, props, animatableModel, dataIndex, cb, during) {
  166. animateOrSetProps('enter', el, props, animatableModel, dataIndex, cb, during);
  167. }
  168. /**
  169. * If element is removed.
  170. * It can determine if element is having remove animation.
  171. */
  172. export function isElementRemoved(el) {
  173. if (!el.__zr) {
  174. return true;
  175. }
  176. for (var i = 0; i < el.animators.length; i++) {
  177. var animator = el.animators[i];
  178. if (animator.scope === 'leave') {
  179. return true;
  180. }
  181. }
  182. return false;
  183. }
  184. /**
  185. * Remove graphic element
  186. */
  187. export function removeElement(el, props, animatableModel, dataIndex, cb, during) {
  188. // Don't do remove animation twice.
  189. if (isElementRemoved(el)) {
  190. return;
  191. }
  192. animateOrSetProps('leave', el, props, animatableModel, dataIndex, cb, during);
  193. }
  194. function fadeOutDisplayable(el, animatableModel, dataIndex, done) {
  195. el.removeTextContent();
  196. el.removeTextGuideLine();
  197. removeElement(el, {
  198. style: {
  199. opacity: 0
  200. }
  201. }, animatableModel, dataIndex, done);
  202. }
  203. export function removeElementWithFadeOut(el, animatableModel, dataIndex) {
  204. function doRemove() {
  205. el.parent && el.parent.remove(el);
  206. } // Hide label and labelLine first
  207. // TODO Also use fade out animation?
  208. if (!el.isGroup) {
  209. fadeOutDisplayable(el, animatableModel, dataIndex, doRemove);
  210. } else {
  211. el.traverse(function (disp) {
  212. if (!disp.isGroup) {
  213. // Can invoke doRemove multiple times.
  214. fadeOutDisplayable(disp, animatableModel, dataIndex, doRemove);
  215. }
  216. });
  217. }
  218. }
  219. /**
  220. * Save old style for style transition in universalTransition module.
  221. * It's used when element will be reused in each render.
  222. * For chart like map, heatmap, which will always create new element.
  223. * We don't need to save this because universalTransition can get old style from the old element
  224. */
  225. export function saveOldStyle(el) {
  226. transitionStore(el).oldStyle = el.style;
  227. }
  228. export function getOldStyle(el) {
  229. return transitionStore(el).oldStyle;
  230. }