Path.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import type { AbsoluteArray, AbsoluteSegment, CurveArray, PathArray } from '@antv/util';
  2. import type { DisplayObjectConfig } from '../dom';
  3. import { Point } from '../shapes';
  4. import { Rectangle } from '../shapes/Rectangle';
  5. import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
  6. import { DisplayObject } from './DisplayObject';
  7. export interface PathStyleProps extends BaseStyleProps {
  8. path?: string | PathArray;
  9. d?: string | PathArray;
  10. /**
  11. * marker will be positioned at the first point
  12. */
  13. markerStart?: DisplayObject;
  14. /**
  15. * marker will be positioned at the last point
  16. */
  17. markerEnd?: DisplayObject;
  18. markerMid?: DisplayObject;
  19. /**
  20. * offset relative to original position
  21. */
  22. markerStartOffset?: number;
  23. /**
  24. * offset relative to original position
  25. */
  26. markerEndOffset?: number;
  27. }
  28. export interface PathSegmentBBox {
  29. x: number;
  30. y: number;
  31. width: number;
  32. height: number;
  33. }
  34. export interface PathSegment {
  35. command: 'M' | 'L' | 'V' | 'H' | 'C' | 'S' | 'Q' | 'T' | 'A' | 'Z';
  36. currentPoint: [number, number];
  37. prePoint: [number, number];
  38. nextPoint: [number, number];
  39. startTangent: [number, number];
  40. endTangent: [number, number];
  41. params: AbsoluteSegment;
  42. arcParams: PathArcParams;
  43. /**
  44. * Used for hit test.
  45. */
  46. box: PathSegmentBBox;
  47. /**
  48. * Convert A to C.
  49. */
  50. cubicParams: [number, number, number, number, number, number];
  51. }
  52. export declare const EMPTY_PARSED_PATH: {
  53. absolutePath: AbsoluteArray;
  54. hasArc: boolean;
  55. segments: any[];
  56. polygons: any[];
  57. polylines: any[];
  58. curve: any;
  59. totalLength: number;
  60. rect: Rectangle;
  61. };
  62. export interface PathArcParams {
  63. cx: number;
  64. cy: number;
  65. rx: number;
  66. ry: number;
  67. startAngle: number;
  68. endAngle: number;
  69. xRotation: number;
  70. arcFlag: number;
  71. sweepFlag: number;
  72. }
  73. export interface ParsedPathStyleProps extends ParsedBaseStyleProps {
  74. path: {
  75. absolutePath: AbsoluteArray;
  76. hasArc: boolean;
  77. segments: PathSegment[];
  78. polygons: [number, number][][];
  79. polylines: [number, number][][];
  80. curve: CurveArray;
  81. totalLength: number;
  82. rect: Rectangle;
  83. };
  84. d?: {
  85. absolutePath: AbsoluteArray;
  86. hasArc: boolean;
  87. segments: PathSegment[];
  88. polygons: [number, number][][];
  89. polylines: [number, number][][];
  90. curve: CurveArray;
  91. totalLength: number;
  92. rect: Rectangle;
  93. };
  94. markerStart?: DisplayObject;
  95. markerMid?: DisplayObject;
  96. markerEnd?: DisplayObject;
  97. markerStartOffset?: number;
  98. markerEndOffset?: number;
  99. }
  100. export declare class Path extends DisplayObject<PathStyleProps, ParsedPathStyleProps> {
  101. private markerStartAngle;
  102. private markerEndAngle;
  103. /**
  104. * markers placed at the mid
  105. */
  106. private markerMidList;
  107. constructor({ style, ...rest }?: DisplayObjectConfig<PathStyleProps>);
  108. attributeChangedCallback<Key extends keyof PathStyleProps>(attrName: Key, oldValue: PathStyleProps[Key], newValue: PathStyleProps[Key], prevParsedValue: ParsedPathStyleProps[Key], newParsedValue: ParsedPathStyleProps[Key]): void;
  109. private transformMarker;
  110. private placeMarkerMid;
  111. /**
  112. * Returns the total length of the path.
  113. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getTotalLength
  114. */
  115. getTotalLength(): number;
  116. /**
  117. * Returns the point at a given distance along the path.
  118. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength
  119. */
  120. getPointAtLength(distance: number, inWorldSpace?: boolean): Point;
  121. /**
  122. * Returns the point at a given ratio of the total length in path.
  123. */
  124. getPoint(ratio: number, inWorldSpace?: boolean): Point;
  125. /**
  126. * Get start tangent vector
  127. */
  128. getStartTangent(): number[][];
  129. /**
  130. * Get end tangent vector
  131. */
  132. getEndTangent(): number[][];
  133. }
  134. //# sourceMappingURL=Path.d.ts.map