waveIn.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { arc } from 'd3-shape';
  2. import { Path, CSS, PropertySyntax, convertToPath } from '@antv/g';
  3. import { getArcObject } from '../shape/utils';
  4. import { isPolar } from '../utils/coordinate';
  5. import { effectTiming } from './utils';
  6. import { ScaleInX } from './scaleInX';
  7. /**
  8. * Transform mark from transparent to solid.
  9. */
  10. export const WaveIn = (options) => {
  11. const ZERO = 0.0001;
  12. // @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
  13. CSS.registerProperty({
  14. name: 'waveInArcAngle',
  15. inherits: false,
  16. initialValue: '',
  17. interpolable: true,
  18. syntax: PropertySyntax.NUMBER,
  19. });
  20. return (from, to, value, coordinate, defaults) => {
  21. const [shape] = from;
  22. if (!isPolar(coordinate)) {
  23. return ScaleInX(options)(from, to, value, coordinate, defaults);
  24. }
  25. const center = coordinate.getCenter();
  26. const { __data__, style } = shape;
  27. const { radius = 0, inset = 0, fillOpacity = 1, strokeOpacity = 1, opacity = 1, } = style;
  28. const { points, y, y1 } = __data__;
  29. const path = arc()
  30. .cornerRadius(radius)
  31. .padAngle((inset * Math.PI) / 180);
  32. const arcObject = getArcObject(coordinate, points, [y, y1]);
  33. const { startAngle, endAngle } = arcObject;
  34. const pathForConversion = new Path({});
  35. const createArcPath = (arcParams) => {
  36. pathForConversion.attr({
  37. d: path(arcParams),
  38. transform: `translate(${center[0]}, ${center[1]})`,
  39. });
  40. const convertedPathDefinition = convertToPath(pathForConversion);
  41. pathForConversion.style.transform = '';
  42. return convertedPathDefinition;
  43. };
  44. const keyframes = [
  45. // Use custom interpolable CSS property.
  46. {
  47. waveInArcAngle: startAngle + ZERO,
  48. fillOpacity: 0,
  49. strokeOpacity: 0,
  50. opacity: 0,
  51. },
  52. {
  53. waveInArcAngle: startAngle + ZERO,
  54. fillOpacity,
  55. strokeOpacity,
  56. opacity,
  57. offset: 0.01,
  58. },
  59. {
  60. waveInArcAngle: endAngle,
  61. fillOpacity,
  62. strokeOpacity,
  63. opacity,
  64. },
  65. ];
  66. const animation = shape.animate(keyframes, effectTiming(defaults, value, options));
  67. animation.onframe = function () {
  68. shape.style.path = createArcPath(Object.assign(Object.assign({}, arcObject), { endAngle: Number(shape.style.waveInArcAngle) }));
  69. };
  70. animation.onfinish = function () {
  71. shape.style.path = createArcPath(Object.assign(Object.assign({}, arcObject), { endAngle: endAngle }));
  72. };
  73. return animation;
  74. };
  75. };
  76. WaveIn.props = {};
  77. //# sourceMappingURL=waveIn.js.map