animate.js 1.4 KB

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