group.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Group animation
  3. * @author sima.zhang1990@gmail.com
  4. */
  5. import { mix, deepMix, each, isFunction } from '../util/common';
  6. import Shape from '../graphic/engine/shape';
  7. import Timeline from '../graphic/animate/timeline';
  8. import Animator from '../graphic/animate/animator';
  9. import Animate from './animate';
  10. import * as Action from './group-action';
  11. var timeline;
  12. Shape.prototype.animate = function () {
  13. var attrs = mix({}, this.get('attrs'));
  14. return new Animator(this, attrs, timeline);
  15. };
  16. Animate.Action = Action;
  17. Animate.defaultCfg = {
  18. line(coord) {
  19. if (coord.isPolar) {
  20. return Action.groupScaleInXY;
  21. }
  22. return Action.groupWaveIn;
  23. },
  24. area(coord) {
  25. if (coord.isPolar) {
  26. return Action.groupScaleInXY;
  27. }
  28. return Action.groupWaveIn;
  29. },
  30. path(coord) {
  31. if (coord.isPolar) {
  32. return Action.groupScaleInXY;
  33. }
  34. return Action.groupWaveIn;
  35. },
  36. point() {
  37. return Action.shapesScaleInXY;
  38. },
  39. interval(coord) {
  40. var result;
  41. if (coord.isPolar) {
  42. result = Action.groupScaleInXY;
  43. if (coord.transposed) {
  44. result = Action.groupWaveIn;
  45. }
  46. } else {
  47. result = coord.transposed ? Action.groupScaleInX : Action.groupScaleInY;
  48. }
  49. return result;
  50. },
  51. schema() {
  52. return Action.groupWaveIn;
  53. }
  54. };
  55. function getAnimate(geomType, coord, animationName) {
  56. var result;
  57. if (animationName) {
  58. result = Animate.Action[animationName];
  59. } else {
  60. result = Animate.getAnimation(geomType, coord, 'appear');
  61. }
  62. return result;
  63. }
  64. function getAnimateCfg(geomType, animateCfg) {
  65. var defaultCfg = Animate.getAnimateCfg(geomType, 'appear');
  66. if (animateCfg && animateCfg.appear) {
  67. return deepMix({}, defaultCfg, animateCfg.appear);
  68. }
  69. return defaultCfg;
  70. }
  71. export default {
  72. afterCanvasInit()
  73. /* chart */
  74. {
  75. timeline = new Timeline();
  76. timeline.play();
  77. },
  78. beforeCanvasDraw(chart) {
  79. if (chart.get('animate') === false) {
  80. return;
  81. }
  82. var geoms = chart.get('geoms');
  83. var coord = chart.get('coord');
  84. var animateCfg;
  85. var animate;
  86. each(geoms, function (geom) {
  87. var type = geom.get('type');
  88. var container = geom.get('container');
  89. if (geom.get('animateCfg') !== false) {
  90. animateCfg = getAnimateCfg(type, geom.get('animateCfg'));
  91. animate = getAnimate(type, coord, animateCfg.animation);
  92. if (isFunction(animate)) {
  93. animate(container, animateCfg);
  94. } else if (Animate.defaultCfg[type]) {
  95. animate = Animate.defaultCfg[type](coord);
  96. var yScale = geom.getYScale();
  97. var zeroY = coord.convertPoint({
  98. x: 0,
  99. y: yScale.scale(geom.getYMinValue())
  100. });
  101. animate && animate(container, animateCfg, coord, zeroY);
  102. }
  103. }
  104. });
  105. },
  106. afterCanvasDestroyed()
  107. /* chart */
  108. {
  109. timeline.stop();
  110. }
  111. };