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