group-action.js 3.6 KB

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