@antv/layout 1.0.0-alpha.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +223 -22
  2. package/dist/c1c68049e416ee50a3be.worker.js +2 -0
  3. package/dist/c1c68049e416ee50a3be.worker.js.map +1 -0
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/esm/c1c68049e416ee50a3be.worker.js +2 -0
  7. package/esm/c1c68049e416ee50a3be.worker.js.map +1 -0
  8. package/esm/index.esm.js +1 -1
  9. package/esm/index.esm.js.map +1 -1
  10. package/lib/{Circular.d.ts → circular.d.ts} +7 -7
  11. package/lib/concentric.d.ts +7 -7
  12. package/lib/d3Force/forceInBox.d.ts +8 -8
  13. package/lib/d3Force/index.d.ts +21 -11
  14. package/lib/dagre/acyclic.d.ts +4 -0
  15. package/lib/dagre/add-border-segments.d.ts +2 -0
  16. package/lib/dagre/coordinate-system.d.ts +4 -0
  17. package/lib/dagre/data/list.d.ts +12 -0
  18. package/lib/dagre/greedy-fas.d.ts +3 -0
  19. package/lib/dagre/layout.d.ts +18 -0
  20. package/lib/dagre/nesting-graph.d.ts +8 -0
  21. package/lib/dagre/normalize.d.ts +5 -0
  22. package/lib/dagre/order/add-subgraph-constraints.d.ts +3 -0
  23. package/lib/dagre/order/barycenter.d.ts +14 -0
  24. package/lib/dagre/order/build-layer-graph.d.ts +3 -0
  25. package/lib/dagre/order/cross-count.d.ts +3 -0
  26. package/lib/dagre/order/index.d.ts +2 -0
  27. package/lib/dagre/order/init-data-order.d.ts +6 -0
  28. package/lib/dagre/order/init-order.d.ts +3 -0
  29. package/lib/dagre/order/resolve-conflicts.d.ts +20 -0
  30. package/lib/dagre/order/sort-subgraph.d.ts +7 -0
  31. package/lib/dagre/order/sort.d.ts +7 -0
  32. package/lib/dagre/parent-dummy-chains.d.ts +3 -0
  33. package/lib/dagre/position/bk.d.ts +25 -0
  34. package/lib/dagre/position/index.d.ts +7 -0
  35. package/lib/dagre/rank/feasible-tree.d.ts +5 -0
  36. package/lib/dagre/rank/index.d.ts +2 -0
  37. package/lib/dagre/rank/network-simplex.d.ts +16 -0
  38. package/lib/dagre/rank/util.d.ts +6 -0
  39. package/lib/dagre/util.d.ts +35 -0
  40. package/lib/dagre.d.ts +31 -0
  41. package/lib/force/index.d.ts +25 -12
  42. package/lib/force/types.d.ts +3 -3
  43. package/lib/forceAtlas2/body.d.ts +33 -0
  44. package/lib/forceAtlas2/index.d.ts +106 -0
  45. package/lib/forceAtlas2/quad.d.ts +27 -0
  46. package/lib/forceAtlas2/quadTree.d.ts +20 -0
  47. package/lib/fruchterman.d.ts +53 -0
  48. package/lib/grid.d.ts +7 -7
  49. package/lib/index.d.ts +5 -0
  50. package/lib/mds.d.ts +7 -7
  51. package/lib/radial/index.d.ts +7 -7
  52. package/lib/radial/{RadialNonoverlapForce.d.ts → radial-nonoverlap-force.d.ts} +1 -1
  53. package/lib/random.d.ts +7 -7
  54. package/lib/registry.d.ts +3 -3
  55. package/lib/supervisor.d.ts +51 -0
  56. package/lib/types.d.ts +137 -60
  57. package/lib/util/function.d.ts +7 -1
  58. package/lib/util/math.d.ts +1 -1
  59. package/lib/util/number.d.ts +0 -2
  60. package/lib/util/object.d.ts +5 -5
  61. package/lib/util/string.d.ts +0 -1
  62. package/lib/worker.d.ts +2 -1
  63. package/package.json +16 -5
  64. package/dist/3ba7fd533dbbec02abdf.worker.js +0 -2
  65. package/dist/3ba7fd533dbbec02abdf.worker.js.map +0 -1
  66. package/esm/3ba7fd533dbbec02abdf.worker.js +0 -2
  67. package/esm/3ba7fd533dbbec02abdf.worker.js.map +0 -1
  68. package/lib/Supervisor.d.ts +0 -65
@@ -1,30 +1,30 @@
1
- import type { Graph, CircularLayoutOptions, SyncLayout, LayoutMapping } from "./types";
1
+ import type { Graph, CircularLayoutOptions, Layout, LayoutMapping } from "./types";
2
2
  /**
3
3
  * Layout arranging the nodes in a circle.
4
4
  *
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new CircularLayout({ radius: 10 });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new CircularLayout({ radius: 10 });
12
- * const positions = layout.execute(graph, { radius: 20 }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { radius: 20 }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { radius: 20 });
15
+ * await layout.assign(graph, { radius: 20 });
16
16
  */
17
- export declare class CircularLayout implements SyncLayout<CircularLayoutOptions> {
17
+ export declare class CircularLayout implements Layout<CircularLayoutOptions> {
18
18
  options: CircularLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: CircularLayoutOptions);
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: CircularLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: CircularLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: CircularLayoutOptions): void;
28
+ assign(graph: Graph, options?: CircularLayoutOptions): Promise<void>;
29
29
  private genericCircularLayout;
30
30
  }
@@ -1,30 +1,30 @@
1
- import type { Graph, LayoutMapping, ConcentricLayoutOptions, SyncLayout } from "./types";
1
+ import type { Graph, LayoutMapping, ConcentricLayoutOptions, Layout } from "./types";
2
2
  /**
3
3
  * Layout arranging the nodes in concentrics
4
4
  *
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new ConcentricLayout({ nodeSpacing: 10 });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new ConcentricLayout({ nodeSpacing: 10});
12
- * const positions = layout.execute(graph, { nodeSpacing: 10 }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { nodeSpacing: 10 }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { nodeSpacing: 10 });
15
+ * await layout.assign(graph, { nodeSpacing: 10 });
16
16
  */
17
- export declare class ConcentricLayout implements SyncLayout<ConcentricLayoutOptions> {
17
+ export declare class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
18
18
  options: ConcentricLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: ConcentricLayoutOptions);
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: ConcentricLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: ConcentricLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: ConcentricLayoutOptions): void;
28
+ assign(graph: Graph, options?: ConcentricLayoutOptions): Promise<void>;
29
29
  private genericConcentricLayout;
30
30
  }
@@ -7,21 +7,21 @@ interface INode {
7
7
  cluster: any;
8
8
  }
9
9
  export default function forceInBox(): {
10
- (alpha: number): any | undefined;
10
+ (alpha: number): any;
11
11
  initialize(_: any): void;
12
12
  template: (x: any) => string | any;
13
- groupBy: (x: any) => ((d: INode) => any) | any;
13
+ groupBy: (x: any) => any | ((d: INode) => any);
14
14
  enableGrouping: (x: any) => boolean | any;
15
15
  strength: (x: any) => number | any;
16
16
  centerX: (_: any) => number | any;
17
17
  centerY: (_: any) => number | any;
18
- nodes: (_: any) => INode[] | any;
18
+ nodes: (_: any) => any | INode[];
19
19
  links: (_: any) => any[] | any;
20
- forceNodeSize: (_: any) => ((d: any) => number) | any;
21
- nodeSize: (_: any) => ((d: any) => number) | any;
22
- forceCharge: (_: any) => ((d: any) => number) | any;
23
- forceLinkDistance: (_: any) => ((d: any) => number) | any;
24
- forceLinkStrength: (_: any) => ((d: any) => number) | any;
20
+ forceNodeSize: (_: any) => any | ((d: any) => number);
21
+ nodeSize: (_: any) => any | ((d: any) => number);
22
+ forceCharge: (_: any) => any | ((d: any) => number);
23
+ forceLinkDistance: (_: any) => any | ((d: any) => number);
24
+ forceLinkStrength: (_: any) => any | ((d: any) => number);
25
25
  offset: (_: any) => number[] | any;
26
26
  getFocis: () => any;
27
27
  };
@@ -1,45 +1,55 @@
1
- import { Graph, Node, LayoutMapping, D3ForceLayoutOptions, SyncLayout } from "../types";
1
+ import * as d3Force from "d3-force";
2
+ import { Graph, Node, LayoutMapping, OutNode, D3ForceLayoutOptions, Edge, LayoutWithIterations } from "../types";
2
3
  /**
3
4
  * Layout the nodes' positions with d3's basic classic force
4
5
  *
5
6
  * @example
6
7
  * // Assign layout options when initialization.
7
8
  * const layout = new D3ForceLayout({ center: [100, 100] });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
9
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
10
  *
10
11
  * // Or use different options later.
11
12
  * const layout = new D3ForceLayout({ center: [100, 100] });
12
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
14
  *
14
15
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { center: [100, 100] });
16
+ * await layout.assign(graph, { center: [100, 100] });
16
17
  */
17
- export declare class D3ForceLayout implements SyncLayout<D3ForceLayoutOptions> {
18
+ export declare class D3ForceLayout implements LayoutWithIterations<D3ForceLayoutOptions> {
18
19
  options: D3ForceLayoutOptions;
19
20
  id: string;
20
21
  private forceSimulation;
21
- /** The sign of running */
22
- private running;
22
+ private lastLayoutNodes;
23
+ private lastLayoutEdges;
24
+ private lastAssign;
25
+ private lastGraph;
23
26
  constructor(options?: D3ForceLayoutOptions);
24
27
  /**
25
28
  * Return the positions of nodes and edges(if needed).
26
29
  */
27
- execute(graph: Graph, options?: D3ForceLayoutOptions): LayoutMapping;
30
+ execute(graph: Graph, options?: D3ForceLayoutOptions): Promise<LayoutMapping>;
28
31
  /**
29
32
  * To directly assign the positions to the nodes.
30
33
  */
31
- assign(graph: Graph, options?: D3ForceLayoutOptions): void;
34
+ assign(graph: Graph, options?: D3ForceLayoutOptions): Promise<void>;
32
35
  /**
33
36
  * Stop simulation immediately.
34
37
  */
35
38
  stop(): void;
36
- isRunning(): boolean;
39
+ /**
40
+ * Manually steps the simulation by the specified number of iterations.
41
+ * @see https://github.com/d3/d3-force#simulation_tick
42
+ */
43
+ tick(iterations?: number): {
44
+ nodes: OutNode[];
45
+ edges: Edge[];
46
+ };
37
47
  private genericForceLayout;
38
48
  /**
39
49
  * Prevent overlappings.
40
50
  * @param {object} simulation force simulation of d3
41
51
  */
42
- overlapProcess(simulation: any, options: {
52
+ overlapProcess(simulation: d3Force.Simulation<any, any>, options: {
43
53
  nodeSize: number | number[] | ((d?: Node) => number) | undefined;
44
54
  nodeSpacing: number | number[] | ((d?: Node) => number) | undefined;
45
55
  collideStrength: number;
@@ -0,0 +1,4 @@
1
+ import { Graph } from "../types";
2
+ declare const run: (g: Graph, acyclicer: string) => void;
3
+ declare const undo: (g: Graph) => void;
4
+ export { run, undo };
@@ -0,0 +1,2 @@
1
+ import { Graph } from "../types";
2
+ export declare const addBorderSegments: (g: Graph) => void;
@@ -0,0 +1,4 @@
1
+ import { DagreRankdir, Graph } from "../types";
2
+ declare const adjust: (g: Graph, rankdir: DagreRankdir) => void;
3
+ declare const undo: (g: Graph, rankdir: DagreRankdir) => void;
4
+ export { adjust, undo };
@@ -0,0 +1,12 @@
1
+ declare type LinkedNode<T> = {
2
+ prev?: LinkedNode<T>;
3
+ next?: LinkedNode<T>;
4
+ } & T;
5
+ export default class List<T> {
6
+ shortcut: LinkedNode<T>;
7
+ constructor();
8
+ dequeue(): LinkedNode<T>;
9
+ enqueue(entry: LinkedNode<T>): void;
10
+ toString(): string;
11
+ }
12
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Edge } from "@antv/graphlib";
2
+ import { EdgeData, Graph as IGraph } from "../types";
3
+ export declare const greedyFAS: (g: IGraph, weightFn?: (e: Edge<EdgeData>) => number) => Edge<EdgeData>[];
@@ -0,0 +1,18 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { DagreAlign, DagreRankdir, Graph as IGraph } from "../types";
3
+ export declare const layout: (g: IGraph, options: {
4
+ keepNodeOrder: boolean;
5
+ prevGraph: IGraph | null;
6
+ edgeLabelSpace?: boolean;
7
+ align?: DagreAlign;
8
+ nodesep?: number;
9
+ edgesep?: number;
10
+ ranksep?: number;
11
+ acyclicer: string;
12
+ nodeOrder: ID[];
13
+ ranker: "network-simplex" | "tight-tree" | "longest-path";
14
+ rankdir: DagreRankdir;
15
+ }) => {
16
+ width: number;
17
+ height: number;
18
+ };
@@ -0,0 +1,8 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph as IGraph } from "../types";
3
+ declare const run: (g: IGraph) => {
4
+ nestingRoot: ID;
5
+ nodeRankFactor: number;
6
+ };
7
+ declare const cleanup: (g: IGraph, nestingRoot?: ID) => void;
8
+ export { run, cleanup };
@@ -0,0 +1,5 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph as IGraph } from "../types";
3
+ declare const run: (g: IGraph, dummyChains: ID[]) => void;
4
+ declare const undo: (g: IGraph, dummyChains: ID[]) => void;
5
+ export { run, undo };
@@ -0,0 +1,3 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ export declare const addSubgraphConstraints: (g: Graph, cg: Graph, vs: ID[]) => void;
@@ -0,0 +1,14 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ /**
4
+ * TODO: The median method consistently performs better than the barycenter method and has a slight theoretical advantage
5
+ */
6
+ export declare const barycenter: (g: Graph, movable: ID[]) => ({
7
+ v: ID;
8
+ barycenter?: undefined;
9
+ weight?: undefined;
10
+ } | {
11
+ v: ID;
12
+ barycenter: number;
13
+ weight: number;
14
+ })[];
@@ -0,0 +1,3 @@
1
+ import { Graph } from "@antv/graphlib";
2
+ import { EdgeData, Graph as IGraph, NodeData } from "../../types";
3
+ export declare const buildLayerGraph: (g: IGraph, rank: number, direction: "in" | "out") => Graph<NodeData, EdgeData>;
@@ -0,0 +1,3 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ export declare const crossCount: (g: Graph, layering: ID[][]) => number;
@@ -0,0 +1,2 @@
1
+ import { Graph as IGraph } from "../../types";
2
+ export declare const order: (g: IGraph, keepNodeOrder?: boolean) => void;
@@ -0,0 +1,6 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ /**
4
+ * 按照数据中的结果设置fixorder
5
+ */
6
+ export declare const initDataOrder: (g: Graph, nodeOrder?: ID[]) => void;
@@ -0,0 +1,3 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ export declare const initOrder: (g: Graph) => ID[][];
@@ -0,0 +1,20 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ export declare type ConflictEntry = {
4
+ i: number;
5
+ indegree?: number;
6
+ in?: ConflictEntry[];
7
+ out?: ConflictEntry[];
8
+ vs: ID[];
9
+ barycenter?: number;
10
+ weight?: number;
11
+ merged?: boolean;
12
+ fixorder?: number;
13
+ order?: number;
14
+ };
15
+ declare const resolveConflicts: (entries: {
16
+ v: ID;
17
+ barycenter?: number;
18
+ weight?: number;
19
+ }[], cg: Graph) => ConflictEntry[];
20
+ export default resolveConflicts;
@@ -0,0 +1,7 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph } from "../../types";
3
+ export declare const sortSubgraph: (g: Graph, v: ID, cg: Graph, biasRight?: boolean, usePrev?: boolean, keepNodeOrder?: boolean) => {
4
+ vs: ID[];
5
+ barycenter?: number;
6
+ weight?: number;
7
+ };
@@ -0,0 +1,7 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { ConflictEntry } from "./resolve-conflicts";
3
+ export declare const sort: (entries: ConflictEntry[], biasRight?: boolean, usePrev?: boolean, keepNodeOrder?: boolean) => {
4
+ vs: ID[];
5
+ barycenter?: number;
6
+ weight?: number;
7
+ };
@@ -0,0 +1,3 @@
1
+ import { ID } from "@antv/graphlib";
2
+ import { Graph as IGraph } from "../types";
3
+ export declare const parentDummyChains: (g: IGraph, dummyChains: ID[]) => void;
@@ -0,0 +1,25 @@
1
+ import { ID, Node } from "@antv/graphlib";
2
+ import { DagreAlign, Graph as IGraph, NodeData } from "../../types";
3
+ declare type Conflicts = Record<ID, Record<ID, boolean>>;
4
+ export declare const findType1Conflicts: (g: IGraph, layering?: ID[][]) => {};
5
+ export declare const findType2Conflicts: (g: IGraph, layering?: ID[][]) => {};
6
+ export declare const findOtherInnerSegmentNode: (g: IGraph, v: ID) => Node<NodeData>;
7
+ export declare const addConflict: (conflicts: Conflicts, v: ID, w: ID) => void;
8
+ export declare const hasConflict: (conflicts: Conflicts, v: ID, w: ID) => boolean;
9
+ export declare const verticalAlignment: (g: IGraph, layering: ID[][], conflicts: Conflicts, neighborFn: (v: ID) => Node<NodeData>[]) => {
10
+ root: Record<ID, ID>;
11
+ align: Record<ID, ID>;
12
+ };
13
+ export declare const horizontalCompaction: (g: IGraph, layering: ID[][], root: Record<ID, ID>, align: Record<ID, ID>, nodesep: number, edgesep: number, reverseSep?: boolean) => Record<ID, number>;
14
+ export declare const buildBlockGraph: (g: IGraph, layering: ID[][], root: Record<ID, ID>, nodesep: number, edgesep: number, reverseSep?: boolean) => IGraph;
15
+ export declare const findSmallestWidthAlignment: (g: IGraph, xss: Record<string, Record<string, number>>) => Record<string, number>;
16
+ export declare function alignCoordinates(xss: Record<string, Record<string, number>>, alignTo: Record<string, number>): void;
17
+ export declare const balance: (xss: Record<string, Record<string, number>>, align?: DagreAlign) => Record<string, number>;
18
+ export declare const positionX: (g: IGraph, options?: Partial<{
19
+ align: DagreAlign;
20
+ nodesep: number;
21
+ edgesep: number;
22
+ }>) => Record<string, number>;
23
+ export declare const sep: (nodeSep: number, edgeSep: number, reverseSep: boolean) => (g: IGraph, v: ID, w: ID) => number;
24
+ export declare const width: (g: IGraph, v: ID) => number;
25
+ export {};
@@ -0,0 +1,7 @@
1
+ import { DagreAlign, Graph as IGraph } from "../../types";
2
+ export declare const position: (g: IGraph, options?: Partial<{
3
+ align: DagreAlign;
4
+ nodesep: number;
5
+ edgesep: number;
6
+ ranksep: number;
7
+ }>) => void;
@@ -0,0 +1,5 @@
1
+ import { Graph } from "@antv/graphlib";
2
+ import { Graph as IGraph } from "../../types";
3
+ declare const feasibleTree: (g: IGraph) => Graph<import("@antv/graphlib").PlainObject, import("@antv/graphlib").PlainObject>;
4
+ declare const feasibleTreeWithLayer: (g: IGraph) => Graph<import("@antv/graphlib").PlainObject, import("@antv/graphlib").PlainObject>;
5
+ export { feasibleTree, feasibleTreeWithLayer };
@@ -0,0 +1,2 @@
1
+ import { Graph as IGraph } from "../../types";
2
+ export declare const rank: (g: IGraph, ranker: "network-simplex" | "tight-tree" | "longest-path") => void;
@@ -0,0 +1,16 @@
1
+ import { Edge, ID } from "@antv/graphlib";
2
+ import { EdgeData, Graph as IGraph } from "../../types";
3
+ export declare const networkSimplex: (og: IGraph) => void;
4
+ export declare const initCutValues: (t: IGraph, g: IGraph) => void;
5
+ export declare const calcCutValue: (t: IGraph, g: IGraph, child: ID) => number;
6
+ export declare const initLowLimValues: (tree: IGraph, root?: ID) => void;
7
+ export declare const leaveEdge: (tree: IGraph) => Edge<EdgeData>;
8
+ export declare const enterEdge: (t: IGraph, g: IGraph, edge: Edge<EdgeData>) => Edge<EdgeData>;
9
+ /**
10
+ *
11
+ * @param t
12
+ * @param g
13
+ * @param e edge to remove
14
+ * @param f edge to add
15
+ */
16
+ export declare const exchangeEdges: (t: IGraph, g: IGraph, e: Edge<EdgeData>, f: Edge<EdgeData>) => void;
@@ -0,0 +1,6 @@
1
+ import { Edge } from "@antv/graphlib";
2
+ import { EdgeData, Graph } from "../../types";
3
+ declare const longestPath: (g: Graph) => void;
4
+ declare const longestPathWithLayer: (g: Graph) => void;
5
+ declare const slack: (g: Graph, e: Edge<EdgeData>) => number;
6
+ export { longestPath, longestPathWithLayer, slack };
@@ -0,0 +1,35 @@
1
+ import { ID, Graph, Node } from "@antv/graphlib";
2
+ import { EdgeData, Graph as IGraph, NodeData } from "../types";
3
+ export declare const addDummyNode: (g: IGraph, type: string, data: NodeData, name: string) => ID;
4
+ export declare const simplify: (g: IGraph) => Graph<NodeData, EdgeData>;
5
+ export declare const asNonCompoundGraph: (g: IGraph) => IGraph;
6
+ export declare const zipObject: <T = any>(keys: ID[], values: T[]) => Record<ID, T>;
7
+ export declare const successorWeights: (g: IGraph) => Record<ID, Record<string, number>>;
8
+ export declare const predecessorWeights: (g: IGraph) => Record<ID, Record<ID, number>>;
9
+ export declare const intersectRect: (rect: {
10
+ x?: number;
11
+ y?: number;
12
+ width?: number;
13
+ height?: number;
14
+ }, point: {
15
+ x?: number;
16
+ y?: number;
17
+ }) => {
18
+ x: number;
19
+ y: number;
20
+ };
21
+ export declare const buildLayerMatrix: (g: IGraph) => ID[][];
22
+ export declare const normalizeRanks: (g: IGraph) => void;
23
+ export declare const removeEmptyRanks: (g: IGraph, nodeRankFactor?: number) => void;
24
+ export declare const addBorderNode: (g: IGraph, prefix: string, rank?: number, order?: number) => ID;
25
+ export declare const maxRank: (g: IGraph) => number;
26
+ export declare const partition: <T = any>(collection: T[], fn: (val: T) => boolean) => {
27
+ lhs: T[];
28
+ rhs: T[];
29
+ };
30
+ export declare const minBy: <T = any>(array: T[], func: (param: T) => number) => T;
31
+ /**
32
+ * @description DFS traversal.
33
+ * @description.zh-CN DFS 遍历。
34
+ */
35
+ export declare const dfs: (graph: IGraph, node: Node<NodeData> | Node<NodeData>[], order: "pre" | "post", isDirected: boolean) => ID[];
package/lib/dagre.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { Graph as IGraph, Layout, LayoutMapping, Node, DagreLayoutOptions } from "./types";
2
+ /**
3
+ * Layout arranging the nodes in a circle.
4
+ *
5
+ * @example
6
+ * // Assign layout options when initialization.
7
+ * const layout = new CircularLayout({ radius: 10 });
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
+ *
10
+ * // Or use different options later.
11
+ * const layout = new CircularLayout({ radius: 10 });
12
+ * const positions = await layout.execute(graph, { radius: 20 }); // { nodes: [], edges: [] }
13
+ *
14
+ * // If you want to assign the positions directly to the nodes, use assign method.
15
+ * await layout.assign(graph, { radius: 20 });
16
+ */
17
+ export declare class DagreLayout implements Layout<DagreLayoutOptions> {
18
+ options: DagreLayoutOptions;
19
+ id: string;
20
+ constructor(options?: DagreLayoutOptions);
21
+ /**
22
+ * Return the positions of nodes and edges(if needed).
23
+ */
24
+ execute(graph: IGraph, options?: DagreLayoutOptions): Promise<LayoutMapping>;
25
+ /**
26
+ * To directly assign the positions to the nodes.
27
+ */
28
+ assign(graph: IGraph, options?: DagreLayoutOptions): Promise<void>;
29
+ private genericDagreLayout;
30
+ layoutNode: (node: Node) => boolean;
31
+ }
@@ -1,4 +1,4 @@
1
- import { Graph, LayoutMapping, ForceLayoutOptions, SyncLayout, Point } from "../types";
1
+ import { Graph, LayoutMapping, ForceLayoutOptions, Point, LayoutWithIterations } from "../types";
2
2
  import { CalcGraph, FormatedOptions } from "./types";
3
3
  /**
4
4
  * Layout with faster force
@@ -6,16 +6,16 @@ import { CalcGraph, FormatedOptions } from "./types";
6
6
  * @example
7
7
  * // Assign layout options when initialization.
8
8
  * const layout = new ForceLayout({ center: [100, 100] });
9
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
9
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
10
10
  *
11
11
  * // Or use different options later.
12
12
  * const layout = new ForceLayout({ center: [100, 100] });
13
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
14
14
  *
15
15
  * // If you want to assign the positions directly to the nodes, use assign method.
16
- * layout.assign(graph, { center: [100, 100] });
16
+ * await layout.assign(graph, { center: [100, 100] });
17
17
  */
18
- export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
18
+ export declare class ForceLayout implements LayoutWithIterations<ForceLayoutOptions> {
19
19
  options: ForceLayoutOptions;
20
20
  id: string;
21
21
  /**
@@ -26,15 +26,33 @@ export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
26
26
  * compare with minMovement to end the nodes' movement
27
27
  */
28
28
  private judgingDistance;
29
+ private running;
30
+ private lastLayoutNodes;
31
+ private lastLayoutEdges;
32
+ private lastAssign;
33
+ private lastCalcGraph;
34
+ private lastGraph;
35
+ private lastOptions;
36
+ private lastVelMap;
37
+ private lastResult;
29
38
  constructor(options?: ForceLayoutOptions);
30
39
  /**
31
40
  * Return the positions of nodes and edges(if needed).
32
41
  */
33
- execute(graph: Graph, options?: ForceLayoutOptions): LayoutMapping;
42
+ execute(graph: Graph, options?: ForceLayoutOptions): Promise<LayoutMapping>;
34
43
  /**
35
44
  * To directly assign the positions to the nodes.
36
45
  */
37
- assign(graph: Graph, options?: ForceLayoutOptions): void;
46
+ assign(graph: Graph, options?: ForceLayoutOptions): Promise<void>;
47
+ /**
48
+ * Stop simulation immediately.
49
+ */
50
+ stop(): void;
51
+ /**
52
+ * Manually steps the simulation by the specified number of iterations.
53
+ * @see https://github.com/d3/d3-force#simulation_tick
54
+ */
55
+ tick(iterations?: number): LayoutMapping;
38
56
  private genericForceLayout;
39
57
  /**
40
58
  * Format merged layout options.
@@ -117,9 +135,4 @@ export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
117
135
  updatePosition(graph: Graph, calcGraph: CalcGraph, velMap: {
118
136
  [id: string]: Point;
119
137
  }, options: FormatedOptions): void;
120
- /**
121
- * Stop the animation for no-silence force.
122
- * TODO: confirm the controller and worker's controller
123
- */
124
- stop(): void;
125
138
  }
@@ -6,13 +6,13 @@ export interface CalcNodeData extends NodeData {
6
6
  mass: number;
7
7
  nodeStrength: number;
8
8
  }
9
- export type CalcNode = INode<CalcNodeData>;
9
+ export declare type CalcNode = INode<CalcNodeData>;
10
10
  export interface CalcEdgeData extends EdgeData {
11
11
  linkDistance?: number;
12
12
  edgeStrength?: number;
13
13
  }
14
- export type CalcEdge = IEdge<CalcEdgeData>;
15
- export type CalcGraph = IGraph<CalcNodeData, CalcEdgeData>;
14
+ export declare type CalcEdge = IEdge<CalcEdgeData>;
15
+ export declare type CalcGraph = IGraph<CalcNodeData, CalcEdgeData>;
16
16
  interface FormatCentripetalOptions extends CentripetalOptions {
17
17
  leaf: (node: Node, nodes: Node[], edges: Edge[]) => number;
18
18
  /** Force strength for single nodes. */
@@ -0,0 +1,33 @@
1
+ import Quad from './quad';
2
+ /**
3
+ * @fileOverview body
4
+ * @author shiwu.wyy@antfin.com
5
+ */
6
+ declare type BodyProps = {
7
+ id?: Number;
8
+ rx: number;
9
+ ry: number;
10
+ fx?: number;
11
+ fy?: number;
12
+ mass: number;
13
+ degree: number;
14
+ g?: number;
15
+ };
16
+ export default class Body {
17
+ id: Number;
18
+ rx: number;
19
+ ry: number;
20
+ fx: number;
21
+ fy: number;
22
+ mass: number;
23
+ degree: number;
24
+ g: number;
25
+ constructor(params: BodyProps);
26
+ distanceTo(bo: Body): number;
27
+ setPos(x: number, y: number): void;
28
+ resetForce(): void;
29
+ addForce(b: Body): void;
30
+ in(quad: Quad): boolean;
31
+ add(bo: Body): Body;
32
+ }
33
+ export {};