group-action.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Group animate functions
  3. * @author sima.zhang1990@gmail.com
  4. */
  5. import { getCoordInfo, getScaledMatrix, doAnimation } from './util';
  6. import { getClip } from '../util/helper';
  7. import { Shape } from '../graphic/index';
  8. function _groupScaleIn(container, animateCfg, coord, zeroY, type) {
  9. var {
  10. start,
  11. end,
  12. width,
  13. height
  14. } = getCoordInfo(coord);
  15. var x;
  16. var y;
  17. var clip = new Shape.Rect({
  18. attrs: {
  19. x: start.x,
  20. y: end.y,
  21. width,
  22. height
  23. }
  24. });
  25. if (type === 'y') {
  26. x = start.x + width / 2;
  27. y = zeroY.y < start.y ? zeroY.y : start.y;
  28. } else if (type === 'x') {
  29. x = zeroY.x > start.x ? zeroY.x : start.x;
  30. y = start.y + height / 2;
  31. } else if (type === 'xy') {
  32. if (coord.isPolar) {
  33. x = coord.center.x;
  34. y = coord.center.y;
  35. } else {
  36. x = (start.x + end.x) / 2;
  37. y = (start.y + end.y) / 2;
  38. }
  39. }
  40. var endMatrix = getScaledMatrix(clip, [x, y], type);
  41. clip.isClip = true;
  42. clip.endState = {
  43. matrix: endMatrix
  44. };
  45. clip.set('canvas', container.get('canvas'));
  46. container.attr('clip', clip);
  47. var onEnd = function onEnd() {
  48. container.attr('clip', null);
  49. clip.remove(true);
  50. };
  51. doAnimation(clip, clip.endState, animateCfg, onEnd);
  52. }
  53. function _shapeScale(container, animateCfg, type) {
  54. var shapes = container.get('children');
  55. var x;
  56. var y;
  57. var endMatrix;
  58. for (var i = 0, len = shapes.length; i < len; i++) {
  59. var shape = shapes[i];
  60. var box = shape.getBBox();
  61. x = (box.minX + box.maxX) / 2;
  62. y = (box.minY + box.maxY) / 2;
  63. endMatrix = getScaledMatrix(shape, [x, y], type);
  64. doAnimation(shape, {
  65. matrix: endMatrix
  66. }, animateCfg);
  67. }
  68. }
  69. function groupScaleInX(container, animateCfg, coord, zeroY) {
  70. _groupScaleIn(container, animateCfg, coord, zeroY, 'x');
  71. }
  72. function groupScaleInY(container, animateCfg, coord, zeroY) {
  73. _groupScaleIn(container, animateCfg, coord, zeroY, 'y');
  74. }
  75. function groupScaleInXY(container, animateCfg, coord, zeroY) {
  76. _groupScaleIn(container, animateCfg, coord, zeroY, 'xy');
  77. }
  78. function shapesScaleInX(container, animateCfg) {
  79. _shapeScale(container, animateCfg, 'x');
  80. }
  81. function shapesScaleInY(container, animateCfg) {
  82. _shapeScale(container, animateCfg, 'y');
  83. }
  84. function shapesScaleInXY(container, animateCfg) {
  85. _shapeScale(container, animateCfg, 'xy');
  86. }
  87. function groupWaveIn(container, animateCfg, coord) {
  88. var clip = getClip(coord);
  89. clip.set('canvas', container.get('canvas'));
  90. container.attr('clip', clip);
  91. var onEnd = function onEnd() {
  92. container.attr('clip', null);
  93. clip.remove(true);
  94. };
  95. var endState = {};
  96. if (coord.isPolar) {
  97. var {
  98. startAngle,
  99. endAngle
  100. } = coord;
  101. endState.endAngle = endAngle;
  102. clip.attr('endAngle', startAngle);
  103. } else {
  104. var {
  105. start,
  106. end
  107. } = coord;
  108. var width = Math.abs(start.x - end.x);
  109. var height = Math.abs(start.y - end.y);
  110. if (coord.isTransposed) {
  111. clip.attr('height', 0);
  112. endState.height = height;
  113. } else {
  114. clip.attr('width', 0);
  115. endState.width = width;
  116. }
  117. }
  118. doAnimation(clip, endState, animateCfg, onEnd);
  119. }
  120. export { groupWaveIn, groupScaleInX, groupScaleInY, groupScaleInXY, shapesScaleInX, shapesScaleInY, shapesScaleInXY };