group-action.js 3.6 KB

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