animate.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. /**
  3. * Animate configuration and register
  4. * @author sima.zhang1990@gmail.com
  5. */
  6. var Util = require('../util/common');
  7. var defaultAnimationCfg = {
  8. appear: {
  9. duration: 450,
  10. easing: 'quadraticOut'
  11. },
  12. // 'appear' animation options
  13. update: {
  14. duration: 300,
  15. easing: 'quadraticOut'
  16. },
  17. // 'update' animation options
  18. enter: {
  19. duration: 300,
  20. easing: 'quadraticOut'
  21. },
  22. // 'enter' animation options
  23. leave: {
  24. duration: 350,
  25. easing: 'quadraticIn'
  26. } // 'leave' animation options
  27. };
  28. var Animate = {
  29. defaultCfg: {},
  30. Action: {},
  31. getAnimation: function getAnimation(geomType, coord, animationType) {
  32. var geomAnimateCfg = this.defaultCfg[geomType];
  33. if (geomAnimateCfg) {
  34. var animation = geomAnimateCfg[animationType];
  35. if (Util.isFunction(animation)) {
  36. return animation(coord);
  37. }
  38. }
  39. return false;
  40. },
  41. getAnimateCfg: function getAnimateCfg(geomType, animationType) {
  42. var defaultCfg = defaultAnimationCfg[animationType];
  43. var geomConfig = this.defaultCfg[geomType];
  44. if (geomConfig && geomConfig.cfg && geomConfig.cfg[animationType]) {
  45. return Util.deepMix({}, defaultCfg, geomConfig.cfg[animationType]);
  46. }
  47. return defaultCfg;
  48. },
  49. registerAnimation: function registerAnimation(animationName, animationFun) {
  50. if (!this.Action) {
  51. this.Action = {};
  52. }
  53. this.Action[animationName] = animationFun;
  54. }
  55. };
  56. module.exports = Animate;