shape-action.js 1.8 KB

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