shape-action.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Animation functions for shape
  3. * @author sima.zhang1990@gmail.com
  4. */
  5. import { isNil } from '../util/common';
  6. import { doAnimation } from './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 = isNil(shape.attr('fillOpacity')) ? 1 : shape.attr('fillOpacity');
  47. var strokeOpacity = isNil(shape.attr('strokeOpacity')) ? 1 : shape.attr('strokeOpacity');
  48. shape.attr('fillOpacity', 0);
  49. shape.attr('strokeOpacity', 0);
  50. var endState = {
  51. fillOpacity,
  52. strokeOpacity
  53. };
  54. doAnimation(shape, endState, animateCfg);
  55. }
  56. export { fadeIn };