|
| 1 | +from typing import Any, List, Optional |
| 2 | + |
| 3 | +from algorithm_visualizer import LogTracer, Tracer, _Number, _Serializable |
| 4 | + |
| 5 | +class GraphTracer(Tracer): |
| 6 | + def set(self, array2d: List[List[_Serializable]] = None): |
| 7 | + if array2d is None: |
| 8 | + array2d = [] |
| 9 | + self.command("set", array2d) |
| 10 | + |
| 11 | + def directed(self, isDirected: bool = True): |
| 12 | + self.command("directed", isDirected) |
| 13 | + |
| 14 | + def weighted(self, isWeighted: bool = True): |
| 15 | + self.command("weighted", isWeighted) |
| 16 | + return self |
| 17 | + |
| 18 | + def layoutCircle(self): |
| 19 | + self.command("layoutCircle") |
| 20 | + return self |
| 21 | + |
| 22 | + def layoutTree(self, root: Any = 0, sorted: bool = False): |
| 23 | + self.command("layoutTree", root, sorted) |
| 24 | + return self |
| 25 | + |
| 26 | + def layoutRandom(self): |
| 27 | + self.command("layoutRandom") |
| 28 | + return self |
| 29 | + |
| 30 | + def addNode( |
| 31 | + self, |
| 32 | + id: _Serializable, |
| 33 | + weight: Optional[_Number] = None, |
| 34 | + x: int = 0, |
| 35 | + y: int = 0, |
| 36 | + visitedCount: int = 0, |
| 37 | + selectedCount: int = 0 |
| 38 | + ): |
| 39 | + self.command("addNode", id, weight, x, y, visitedCount, selectedCount) |
| 40 | + |
| 41 | + def updateNode( |
| 42 | + self, |
| 43 | + id: _Serializable, |
| 44 | + weight: Optional[_Number] = None, |
| 45 | + x: int = 0, |
| 46 | + y: int = 0, |
| 47 | + visitedCount: int = 0, |
| 48 | + selectedCount: int = 0 |
| 49 | + ): |
| 50 | + self.command("updateNode", id, weight, x, y, visitedCount, selectedCount) |
| 51 | + |
| 52 | + def removeNode(self, id: _Serializable): |
| 53 | + self.command("removeNode", id) |
| 54 | + |
| 55 | + def addEdge( |
| 56 | + self, |
| 57 | + source: _Serializable, |
| 58 | + target: _Serializable, |
| 59 | + weight: Optional[_Number] = None, |
| 60 | + visitedCount: int = 0, |
| 61 | + selectedCount: int = 0 |
| 62 | + ): |
| 63 | + self.command("addEdge", source, target, weight, visitedCount, selectedCount) |
| 64 | + |
| 65 | + def updateEdge( |
| 66 | + self, |
| 67 | + source: _Serializable, |
| 68 | + target: _Serializable, |
| 69 | + weight: Optional[_Number] = None, |
| 70 | + visitedCount: int = 0, |
| 71 | + selectedCount: int = 0 |
| 72 | + ): |
| 73 | + self.command("updateEdge", source, target, weight, visitedCount, selectedCount) |
| 74 | + |
| 75 | + def removeEdge(self, source: _Serializable, target: _Serializable): |
| 76 | + self.command("removeEdge", source, target) |
| 77 | + |
| 78 | + def visit( |
| 79 | + self, |
| 80 | + target: _Serializable, |
| 81 | + source: _Serializable = None, |
| 82 | + weight: Optional[_Number] = None |
| 83 | + ): |
| 84 | + self.command("visit", target, source, weight) |
| 85 | + |
| 86 | + def leave( |
| 87 | + self, |
| 88 | + target: _Serializable, |
| 89 | + source: _Serializable = None, |
| 90 | + weight: Optional[_Number] = None |
| 91 | + ): |
| 92 | + self.command("leave", target, source, weight) |
| 93 | + |
| 94 | + def select(self, target: _Serializable, source: _Serializable = None): |
| 95 | + self.command("select", target, source) |
| 96 | + |
| 97 | + def deselect(self, target: _Serializable, source: _Serializable = None): |
| 98 | + self.command("deselect", target, source) |
| 99 | + |
| 100 | + def log(self, log: LogTracer): |
| 101 | + self.command("log", log.key) |
0 commit comments