animate.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  2. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4. /**
  5. * Animate configuration and register
  6. * @author sima.zhang1990@gmail.com
  7. */
  8. import { isFunction, deepMix } from '../util/common';
  9. var defaultAnimationCfg = {
  10. appear: {
  11. duration: 450,
  12. easing: 'quadraticOut'
  13. },
  14. // 'appear' animation options
  15. update: {
  16. duration: 300,
  17. easing: 'quadraticOut'
  18. },
  19. // 'update' animation options
  20. enter: {
  21. duration: 300,
  22. easing: 'quadraticOut'
  23. },
  24. // 'enter' animation options
  25. leave: {
  26. duration: 350,
  27. easing: 'quadraticIn'
  28. } // 'leave' animation options
  29. };
  30. var Animate = {
  31. defaultCfg: {},
  32. Action: {},
  33. getAnimation(geomType, coord, animationType) {
  34. var geomAnimateCfg = this.defaultCfg[geomType];
  35. if (geomAnimateCfg) {
  36. var animation = geomAnimateCfg[animationType];
  37. if (isFunction(animation)) {
  38. return animation(coord);
  39. }
  40. }
  41. return false;
  42. },
  43. getAnimateCfg(geomType, animationType) {
  44. var defaultCfg = defaultAnimationCfg[animationType];
  45. var geomConfig = this.defaultCfg[geomType];
  46. if (geomConfig && geomConfig.cfg && geomConfig.cfg[animationType]) {
  47. return deepMix({}, defaultCfg, geomConfig.cfg[animationType]);
  48. }
  49. return defaultCfg;
  50. },
  51. registerAnimation(animationName, animationFun) {
  52. if (!this.Action) {
  53. this.Action = {};
  54. }
  55. this.Action = _objectSpread(_objectSpread({}, this.Action), {}, {
  56. [animationName]: animationFun
  57. });
  58. }
  59. };
  60. export default Animate;