waveIn.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.WaveIn = void 0;
  4. const d3_shape_1 = require("d3-shape");
  5. const g_1 = require("@antv/g");
  6. const utils_1 = require("../shape/utils");
  7. const coordinate_1 = require("../utils/coordinate");
  8. const utils_2 = require("./utils");
  9. const scaleInX_1 = require("./scaleInX");
  10. /**
  11. * Transform mark from transparent to solid.
  12. */
  13. const WaveIn = (options) => {
  14. const ZERO = 0.0001;
  15. // @see https://g-next.antv.vision/zh/docs/api/css/css-properties-values-api#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7
  16. g_1.CSS.registerProperty({
  17. name: 'waveInArcAngle',
  18. inherits: false,
  19. initialValue: '',
  20. interpolable: true,
  21. syntax: g_1.PropertySyntax.NUMBER,
  22. });
  23. return (from, to, value, coordinate, defaults) => {
  24. const [shape] = from;
  25. if (!(0, coordinate_1.isPolar)(coordinate)) {
  26. return (0, scaleInX_1.ScaleInX)(options)(from, to, value, coordinate, defaults);
  27. }
  28. const center = coordinate.getCenter();
  29. const { __data__, style } = shape;
  30. const { radius = 0, inset = 0, fillOpacity = 1, strokeOpacity = 1, opacity = 1, } = style;
  31. const { points, y, y1 } = __data__;
  32. const path = (0, d3_shape_1.arc)()
  33. .cornerRadius(radius)
  34. .padAngle((inset * Math.PI) / 180);
  35. const arcObject = (0, utils_1.getArcObject)(coordinate, points, [y, y1]);
  36. const { startAngle, endAngle } = arcObject;
  37. const pathForConversion = new g_1.Path({});
  38. const createArcPath = (arcParams) => {
  39. pathForConversion.attr({
  40. d: path(arcParams),
  41. transform: `translate(${center[0]}, ${center[1]})`,
  42. });
  43. const convertedPathDefinition = (0, g_1.convertToPath)(pathForConversion);
  44. pathForConversion.style.transform = '';
  45. return convertedPathDefinition;
  46. };
  47. const keyframes = [
  48. // Use custom interpolable CSS property.
  49. {
  50. waveInArcAngle: startAngle + ZERO,
  51. fillOpacity: 0,
  52. strokeOpacity: 0,
  53. opacity: 0,
  54. },
  55. {
  56. waveInArcAngle: startAngle + ZERO,
  57. fillOpacity,
  58. strokeOpacity,
  59. opacity,
  60. offset: 0.01,
  61. },
  62. {
  63. waveInArcAngle: endAngle,
  64. fillOpacity,
  65. strokeOpacity,
  66. opacity,
  67. },
  68. ];
  69. const animation = shape.animate(keyframes, (0, utils_2.effectTiming)(defaults, value, options));
  70. animation.onframe = function () {
  71. shape.style.path = createArcPath(Object.assign(Object.assign({}, arcObject), { endAngle: Number(shape.style.waveInArcAngle) }));
  72. };
  73. animation.onfinish = function () {
  74. shape.style.path = createArcPath(Object.assign(Object.assign({}, arcObject), { endAngle: endAngle }));
  75. };
  76. return animation;
  77. };
  78. };
  79. exports.WaveIn = WaveIn;
  80. exports.WaveIn.props = {};
  81. //# sourceMappingURL=waveIn.js.map