group-action.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Group animate functions
  3. * @author sima.zhang1990@gmail.com
  4. */
  5. var Util = require('./util');
  6. var Helper = require('../util/helper');
  7. var _require = require('../graphic/index'),
  8. Shape = _require.Shape;
  9. function _groupScaleIn(container, animateCfg, coord, zeroY, type) {
  10. var _Util$getCoordInfo = Util.getCoordInfo(coord),
  11. start = _Util$getCoordInfo.start,
  12. end = _Util$getCoordInfo.end,
  13. width = _Util$getCoordInfo.width,
  14. height = _Util$getCoordInfo.height;
  15. var x;
  16. var y;
  17. var clip = new Shape.Rect({
  18. attrs: {
  19. x: start.x,
  20. y: end.y,
  21. width: width,
  22. height: 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 = Util.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. Util.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 = Util.getScaledMatrix(shape, [x, y], type);
  64. Util.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 = Helper.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 startAngle = coord.startAngle,
  98. endAngle = coord.endAngle;
  99. endState.endAngle = endAngle;
  100. clip.attr('endAngle', startAngle);
  101. } else {
  102. var start = coord.start,
  103. end = coord.end;
  104. var width = Math.abs(start.x - end.x);
  105. var height = Math.abs(start.y - end.y);
  106. if (coord.isTransposed) {
  107. clip.attr('height', 0);
  108. endState.height = height;
  109. } else {
  110. clip.attr('width', 0);
  111. endState.width = width;
  112. }
  113. }
  114. Util.doAnimation(clip, endState, animateCfg, onEnd);
  115. }
  116. module.exports = {
  117. groupWaveIn: groupWaveIn,
  118. groupScaleInX: groupScaleInX,
  119. groupScaleInY: groupScaleInY,
  120. groupScaleInXY: groupScaleInXY,
  121. shapesScaleInX: shapesScaleInX,
  122. shapesScaleInY: shapesScaleInY,
  123. shapesScaleInXY: shapesScaleInXY
  124. };