shape-action.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Animation functions for shape
  3. * @author sima.zhang1990@gmail.com
  4. */
  5. var Util = require('../util/common');
  6. var Helpers = require('./util');
  7. /*
  8. function waveIn(shape, animateCfg, coord) {
  9. const clip = Helpers.getClip(coord);
  10. clip.set('canvas', shape.get('canvas'));
  11. shape.attr('clip', clip);
  12. const onEnd = function() {
  13. shape.attr('clip', null);
  14. clip.remove(true);
  15. };
  16. Helpers.doAnimation(clip, clip.endState, animateCfg, onEnd);
  17. }
  18. function scaleInX(shape, animateCfg) {
  19. const box = shape.getBBox();
  20. const points = shape.get('origin').points;
  21. let x;
  22. const y = (box.minY + box.maxY) / 2;
  23. if (points[0].y - points[1].y > 0) { // 当顶点在零点之下
  24. x = box.maxX;
  25. } else {
  26. x = box.minX;
  27. }
  28. const scaledMatrix = Helpers.getScaledMatrix(shape, [ x, y ], 'x');
  29. Helpers.doAnimation(shape, { matrix: scaledMatrix }, animateCfg);
  30. }
  31. function scaleInY(shape, animateCfg) {
  32. const box = shape.getBBox();
  33. const points = shape.get('origin').points;
  34. const x = (box.minX + box.maxX) / 2;
  35. let y;
  36. if (points[0].y - points[1].y <= 0) { // 当顶点在零点之下
  37. y = box.maxY;
  38. } else {
  39. y = box.minY;
  40. }
  41. const scaledMatrix = Helpers.getScaledMatrix(shape, [ x, y ], 'x');
  42. Helpers.doAnimation(shape, { matrix: scaledMatrix }, animateCfg);
  43. }
  44. */
  45. function fadeIn(shape, animateCfg) {
  46. var fillOpacity = Util.isNil(shape.attr('fillOpacity')) ? 1 : shape.attr('fillOpacity');
  47. var strokeOpacity = Util.isNil(shape.attr('strokeOpacity')) ? 1 : shape.attr('strokeOpacity');
  48. shape.attr('fillOpacity', 0);
  49. shape.attr('strokeOpacity', 0);
  50. var endState = {
  51. fillOpacity: fillOpacity,
  52. strokeOpacity: strokeOpacity
  53. };
  54. Helpers.doAnimation(shape, endState, animateCfg);
  55. }
  56. module.exports = {
  57. // waveIn,
  58. // scaleInX,
  59. // scaleInY,
  60. fadeIn: fadeIn
  61. };