forked from algorithm-visualizer/tracers.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
99 lines (81 loc) · 2.97 KB
/
graph.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from .log import LogTracer, Tracer
from algorithm_visualizer.types import Number, Serializable, SerializableSequence, UNDEFINED
class GraphTracer(Tracer):
def set(self, array2d: SerializableSequence[SerializableSequence[Serializable]] = UNDEFINED):
self.command("set", array2d)
def directed(self, isDirected: bool = UNDEFINED):
self.command("directed", isDirected)
def weighted(self, isWeighted: bool = UNDEFINED) -> "GraphTracer":
self.command("weighted", isWeighted)
return self
def layoutCircle(self) -> "GraphTracer":
self.command("layoutCircle")
return self
def layoutTree(self, root: Serializable = UNDEFINED, sorted: bool = UNDEFINED) -> "GraphTracer":
self.command("layoutTree", root, sorted)
return self
def layoutRandom(self) -> "GraphTracer":
self.command("layoutRandom")
return self
def addNode(
self,
id: Serializable,
weight: Number = UNDEFINED,
x: int = 0,
y: int = 0,
visitedCount: int = 0,
selectedCount: int = 0
):
self.command("addNode", id, weight, x, y, visitedCount, selectedCount)
def updateNode(
self,
id: Serializable,
weight: Number = UNDEFINED,
x: int = UNDEFINED,
y: int = UNDEFINED,
visitedCount: int = UNDEFINED,
selectedCount: int = UNDEFINED
):
self.command("updateNode", id, weight, x, y, visitedCount, selectedCount)
def removeNode(self, id: Serializable):
self.command("removeNode", id)
def addEdge(
self,
source: Serializable,
target: Serializable,
weight: Number = UNDEFINED,
visitedCount: int = UNDEFINED,
selectedCount: int = UNDEFINED
):
self.command("addEdge", source, target, weight, visitedCount, selectedCount)
def updateEdge(
self,
source: Serializable,
target: Serializable,
weight: Number = UNDEFINED,
visitedCount: int = UNDEFINED,
selectedCount: int = UNDEFINED
):
self.command("updateEdge", source, target, weight, visitedCount, selectedCount)
def removeEdge(self, source: Serializable, target: Serializable):
self.command("removeEdge", source, target)
def visit(
self,
target: Serializable,
source: Serializable = UNDEFINED,
weight: Number = UNDEFINED
):
self.command("visit", target, source, weight)
def leave(
self,
target: Serializable,
source: Serializable = UNDEFINED,
weight: Number = UNDEFINED
):
self.command("leave", target, source, weight)
def select(self, target: Serializable, source: Serializable = UNDEFINED):
self.command("select", target, source)
def deselect(self, target: Serializable, source: Serializable = UNDEFINED):
self.command("deselect", target, source)
def log(self, log: LogTracer):
self.command("log", log.key)