Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {GraphElement} from "./graphelement";
import {Graph} from "./graph";
import {Node} from "./node";
import {GLOBAL_PARAMS} from "../helper/serializableitem";
const LINK_PARAMS = ["source", "target", ...GLOBAL_PARAMS];
const LINK_SIM_PARAMS = ["index"];
export class Link extends GraphElement {
public source: Node;
public target: Node;
constructor(graph: Graph) {
super(graph);
this.isLink = true;
}
public delete() {
return this.graph.deleteLink(this);
}
public add(graph: Graph = this.graph) {
this.graph = graph;
return this.graph.addLink(this);
}
/**
* Determines if the given node is part of the link structure.
* @param node Node to check for.
* @returns True, if node is either source or target node of link.
*/
public contains(node: Node): boolean {
return this.source === node || this.target === node;
}
public serialize(): any {
return this.serializeProperties(LINK_PARAMS);
}
public getCleanInstance(): any {
return {
...this.serialize(),
...this.serializeProperties(LINK_SIM_PARAMS)
};
}
}