edge.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { Size, KeyValue } from '@antv/x6-common';
  2. import { Point, Polyline } from '@antv/x6-geometry';
  3. import { Registry } from '../registry/registry';
  4. import { Attr, Router, Connector, EdgeAnchor, NodeAnchor, ConnectionPoint } from '../registry';
  5. import { Markup } from '../view/markup';
  6. import { Store } from './store';
  7. import { Cell } from './cell';
  8. import { Node } from './node';
  9. export declare class Edge<Properties extends Edge.Properties = Edge.Properties> extends Cell<Properties> {
  10. protected static defaults: Edge.Defaults;
  11. protected readonly store: Store<Edge.Properties>;
  12. protected get [Symbol.toStringTag](): string;
  13. constructor(metadata?: Edge.Metadata);
  14. protected preprocess(metadata: Edge.Metadata, ignoreIdCheck?: boolean): Properties;
  15. protected setup(): void;
  16. isEdge(): this is Edge;
  17. disconnect(options?: Edge.SetOptions): this;
  18. get source(): Edge.TerminalData;
  19. set source(data: Edge.TerminalData);
  20. getSource(): Edge.TerminalData;
  21. getSourceCellId(): string;
  22. getSourcePortId(): string | undefined;
  23. setSource(node: Node, args?: Edge.SetCellTerminalArgs, options?: Edge.SetOptions): this;
  24. setSource(edge: Edge, args?: Edge.SetEdgeTerminalArgs, options?: Edge.SetOptions): this;
  25. setSource(point: Point | Point.PointLike, args?: Edge.SetTerminalCommonArgs, options?: Edge.SetOptions): this;
  26. setSource(args: Edge.TerminalData, options?: Edge.SetOptions): this;
  27. get target(): Edge.TerminalData;
  28. set target(data: Edge.TerminalData);
  29. getTarget(): Edge.TerminalData;
  30. getTargetCellId(): string;
  31. getTargetPortId(): string | undefined;
  32. setTarget(edge: Node, args?: Edge.SetCellTerminalArgs, options?: Edge.SetOptions): this;
  33. setTarget(edge: Edge, args?: Edge.SetEdgeTerminalArgs, options?: Edge.SetOptions): this;
  34. setTarget(point: Point | Point.PointLike, args?: Edge.SetTerminalCommonArgs, options?: Edge.SetOptions): this;
  35. setTarget(args: Edge.TerminalData, options?: Edge.SetOptions): this;
  36. getTerminal(type: Edge.TerminalType): Edge.TerminalData;
  37. setTerminal(type: Edge.TerminalType, terminal: Node | Edge | Point | Point.PointLike | Edge.TerminalData, args?: Edge.SetTerminalCommonArgs | Edge.SetOptions, options?: Edge.SetOptions): this;
  38. getSourcePoint(): Point;
  39. getTargetPoint(): Point;
  40. protected getTerminalPoint(type: Edge.TerminalType): Point;
  41. getSourceCell(): Cell<Cell.Properties> | null;
  42. getTargetCell(): Cell<Cell.Properties> | null;
  43. protected getTerminalCell(type: Edge.TerminalType): Cell<Cell.Properties> | null;
  44. getSourceNode(): Node<Node.Properties> | null;
  45. getTargetNode(): Node<Node.Properties> | null;
  46. protected getTerminalNode(type: Edge.TerminalType): Node | null;
  47. get router(): Edge.RouterData | undefined;
  48. set router(data: Edge.RouterData | undefined);
  49. getRouter(): Edge.RouterData;
  50. setRouter(name: string, args?: KeyValue, options?: Edge.SetOptions): this;
  51. setRouter(router: Edge.RouterData, options?: Edge.SetOptions): this;
  52. removeRouter(options?: Edge.SetOptions): this;
  53. get connector(): Edge.ConnectorData | undefined;
  54. set connector(data: Edge.ConnectorData | undefined);
  55. getConnector(): any;
  56. setConnector(name: string, args?: KeyValue, options?: Edge.SetOptions): this;
  57. setConnector(connector: Edge.ConnectorData, options?: Edge.SetOptions): this;
  58. removeConnector(options?: Edge.SetOptions): Store<Edge.Properties>;
  59. getDefaultLabel(): Edge.Label;
  60. get labels(): Edge.Label[];
  61. set labels(labels: Edge.Label[]);
  62. getLabels(): Edge.Label[];
  63. setLabels(labels: Edge.Label | Edge.Label[] | string | string[], options?: Edge.SetOptions): this;
  64. insertLabel(label: Edge.Label | string, index?: number, options?: Edge.SetOptions): this;
  65. appendLabel(label: Edge.Label | string, options?: Edge.SetOptions): this;
  66. getLabelAt(index: number): Edge.Label | null;
  67. setLabelAt(index: number, label: Edge.Label | string, options?: Edge.SetOptions): this;
  68. removeLabelAt(index: number, options?: Edge.SetOptions): Edge.Label | null;
  69. protected parseLabel(label: string | Edge.Label): Edge.Label;
  70. protected onLabelsChanged({ previous, current, }: Cell.ChangeArgs<Edge.Label[]>): void;
  71. get vertices(): Point.PointLike | Point.PointLike[];
  72. set vertices(vertices: Point.PointLike | Point.PointLike[]);
  73. getVertices(): any[];
  74. setVertices(vertices: Point.PointLike | Point.PointLike[], options?: Edge.SetOptions): this;
  75. insertVertex(vertice: Point.PointLike, index?: number, options?: Edge.SetOptions): this;
  76. appendVertex(vertex: Point.PointLike, options?: Edge.SetOptions): this;
  77. getVertexAt(index: number): any;
  78. setVertexAt(index: number, vertice: Point.PointLike, options?: Edge.SetOptions): this;
  79. removeVertexAt(index: number, options?: Edge.SetOptions): this;
  80. protected onVertexsChanged({ previous, current, }: Cell.ChangeArgs<Point.PointLike[]>): void;
  81. getDefaultMarkup(): any;
  82. getMarkup(): any;
  83. /**
  84. * Translate the edge vertices (and source and target if they are points)
  85. * by `tx` pixels in the x-axis and `ty` pixels in the y-axis.
  86. */
  87. translate(tx: number, ty: number, options?: Cell.TranslateOptions): this;
  88. /**
  89. * Scales the edge's points (vertices) relative to the given origin.
  90. */
  91. scale(sx: number, sy: number, origin?: Point | Point.PointLike, options?: Edge.SetOptions): this;
  92. protected applyToPoints(worker: (p: Point.PointLike) => Point.PointLike, options?: Edge.SetOptions): this;
  93. getBBox(): import("@antv/x6-geometry").Rectangle;
  94. getConnectionPoint(): Point;
  95. getPolyline(): Polyline;
  96. updateParent(options?: Edge.SetOptions): Cell<Cell.Properties> | null;
  97. hasLoop(options?: {
  98. deep?: boolean;
  99. }): boolean;
  100. getFragmentAncestor(): Cell | null;
  101. isFragmentDescendantOf(cell: Cell): boolean;
  102. }
  103. export declare namespace Edge {
  104. type RouterData = Router.NativeItem | Router.ManaualItem;
  105. type ConnectorData = Connector.NativeItem | Connector.ManaualItem;
  106. }
  107. export declare namespace Edge {
  108. interface Common extends Cell.Common {
  109. source?: TerminalData;
  110. target?: TerminalData;
  111. router?: RouterData;
  112. connector?: ConnectorData;
  113. labels?: Label[] | string[];
  114. defaultLabel?: Label;
  115. vertices?: (Point.PointLike | Point.PointData)[];
  116. defaultMarkup?: Markup;
  117. }
  118. interface TerminalOptions {
  119. sourceCell?: Cell | string;
  120. sourcePort?: string;
  121. sourcePoint?: Point.PointLike | Point.PointData;
  122. targetCell?: Cell | string;
  123. targetPort?: string;
  124. targetPoint?: Point.PointLike | Point.PointData;
  125. source?: string | Cell | Point.PointLike | Point.PointData | TerminalPointData | TerminalCellLooseData;
  126. target?: string | Cell | Point.PointLike | Point.PointData | TerminalPointData | TerminalCellLooseData;
  127. }
  128. export interface BaseOptions extends Common, Cell.Metadata {
  129. }
  130. export interface Metadata extends Omit<BaseOptions, TerminalType>, TerminalOptions {
  131. }
  132. export interface Defaults extends Common, Cell.Defaults {
  133. }
  134. export interface Properties extends Cell.Properties, Omit<BaseOptions, 'tools'> {
  135. }
  136. export interface Config extends Omit<Defaults, TerminalType>, TerminalOptions, Cell.Config<Metadata, Edge> {
  137. }
  138. export {};
  139. }
  140. export declare namespace Edge {
  141. interface SetOptions extends Cell.SetOptions {
  142. }
  143. type TerminalType = 'source' | 'target';
  144. interface SetTerminalCommonArgs {
  145. selector?: string;
  146. magnet?: string;
  147. connectionPoint?: string | ConnectionPoint.NativeItem | ConnectionPoint.ManaualItem;
  148. }
  149. type NodeAnchorItem = string | NodeAnchor.NativeItem | NodeAnchor.ManaualItem;
  150. type EdgeAnchorItem = string | EdgeAnchor.NativeItem | EdgeAnchor.ManaualItem;
  151. interface SetCellTerminalArgs extends SetTerminalCommonArgs {
  152. port?: string;
  153. priority?: boolean;
  154. anchor?: NodeAnchorItem;
  155. }
  156. interface SetEdgeTerminalArgs extends SetTerminalCommonArgs {
  157. anchor?: EdgeAnchorItem;
  158. }
  159. interface TerminalPointData extends SetTerminalCommonArgs, Point.PointLike {
  160. }
  161. interface TerminalCellData extends SetCellTerminalArgs {
  162. cell: string;
  163. port?: string;
  164. }
  165. interface TerminalCellLooseData extends SetCellTerminalArgs {
  166. cell: string | Cell;
  167. port?: string;
  168. }
  169. type TerminalData = TerminalPointData | TerminalCellLooseData;
  170. function equalTerminals(a: TerminalData, b: TerminalData): boolean;
  171. }
  172. export declare namespace Edge {
  173. interface Label extends KeyValue {
  174. markup?: Markup;
  175. attrs?: Attr.CellAttrs;
  176. /**
  177. * If the distance is in the `[0,1]` range (inclusive), then the position
  178. * of the label is defined as a percentage of the total length of the edge
  179. * (the normalized length). For example, passing the number `0.5` positions
  180. * the label to the middle of the edge.
  181. *
  182. * If the distance is larger than `1` (exclusive), the label will be
  183. * positioned distance pixels away from the beginning of the path along
  184. * the edge.
  185. *
  186. * If the distance is a negative number, the label will be positioned
  187. * distance pixels away from the end of the path along the edge.
  188. */
  189. position?: LabelPosition;
  190. size?: Size;
  191. }
  192. interface LabelPositionOptions {
  193. /**
  194. * Forces absolute coordinates for distance.
  195. */
  196. absoluteDistance?: boolean;
  197. /**
  198. * Forces reverse absolute coordinates (if absoluteDistance = true)
  199. */
  200. reverseDistance?: boolean;
  201. /**
  202. * Forces absolute coordinates for offset.
  203. */
  204. absoluteOffset?: boolean;
  205. /**
  206. * Auto-adjusts the angle of the label to match path gradient at position.
  207. */
  208. keepGradient?: boolean;
  209. /**
  210. * Whether rotates labels so they are never upside-down.
  211. */
  212. ensureLegibility?: boolean;
  213. }
  214. interface LabelPositionObject {
  215. distance: number;
  216. offset?: number | {
  217. x?: number;
  218. y?: number;
  219. };
  220. angle?: number;
  221. options?: LabelPositionOptions;
  222. }
  223. type LabelPosition = number | LabelPositionObject;
  224. const defaultLabel: Label;
  225. function parseStringLabel(text: string): Label;
  226. }
  227. export declare namespace Edge {
  228. const toStringTag: string;
  229. function isEdge(instance: any): instance is Edge;
  230. }
  231. export declare namespace Edge {
  232. const registry: Registry<Definition, never, Config & {
  233. inherit?: string | Definition | undefined;
  234. }>;
  235. }
  236. export declare namespace Edge {
  237. type EdgeClass = typeof Edge;
  238. export interface Definition extends EdgeClass {
  239. new <T extends Properties = Properties>(metadata: T): Edge;
  240. }
  241. export function define(config: Config): Definition;
  242. export function create(options: Metadata): Edge<Properties>;
  243. export {};
  244. }
  245. export declare namespace Edge {
  246. }