generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Links.ts
64 lines (59 loc) · 1.99 KB
/
Links.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { ExcalidrawAutomate } from "obsidian-excalidraw-plugin/lib/ExcalidrawAutomate";
import ExcaliBrain from "src/excalibrain-main";
import { ExcaliBrainSettings } from "src/Settings";
import { LinkDirection, RelationType, Role } from "src/types";
import { Link } from "./Link";
import { Node } from "./Node";
const SEPARATOR = "|:?:|"
export class Links {
links: Map<string,Link> = new Map<string,Link>();
reverseLinks: Set<string> = new Set<string>();
constructor(private plugin:ExcaliBrain) {
}
addLink(
nodeA: Node,
nodeB: Node,
nodeBRole: Role,
relation: RelationType,
hierarchyDefinition: string,
linkDirection: LinkDirection,
ea: ExcalidrawAutomate,
settings: ExcaliBrainSettings
) {
const key1 = nodeA.page.path+SEPARATOR+nodeB.page.path;
if(this.links.has(key1) || this.reverseLinks.has(key1)) {
return;
}
const key2 = nodeB.page.path+SEPARATOR+nodeA.page.path;
const link = new Link(
linkDirection===(settings.inverseArrowDirection ? LinkDirection.TO : LinkDirection.FROM)
? nodeB
: nodeA,
linkDirection===(settings.inverseArrowDirection ? LinkDirection.TO : LinkDirection.FROM)
? nodeA
: nodeB,
linkDirection===(settings.inverseArrowDirection ? LinkDirection.TO : LinkDirection.FROM)
? nodeBRole === Role.LEFT || nodeBRole === Role.RIGHT
? nodeBRole === Role.LEFT ? Role.LEFT : Role.RIGHT
: nodeBRole === Role.CHILD
? Role.PARENT
: Role.CHILD
: nodeBRole,
relation,
hierarchyDefinition,
ea,
settings,
this.plugin
)
this.links.set(key1, link),
this.reverseLinks.add(key2)
}
render(linksToHide:string[]) {
this.links.forEach(link=>
link.render(
linksToHide.some(lth=>link.hierarchyDefinition?.includes(lth)) ||
(link.isInferred && linksToHide.includes("inferred-link"))
)
);
}
}