1
1
import io
2
+ from typing import Any , Optional , Union
2
3
3
4
import pandas as pd
4
5
import plotly .graph_objects as go
@@ -10,10 +11,10 @@ def __init__(
10
11
self ,
11
12
id : str ,
12
13
state : State ,
13
- data : pd .DataFrame = None ,
14
- fig : go .Figure = None ,
15
- title : str = None ,
16
- sub_title : str = None ,
14
+ data : Union [ pd .DataFrame , Any ] = None ,
15
+ fig : Optional [ go .Figure ] = None ,
16
+ title : Optional [ str ] = None ,
17
+ sub_title : Optional [ str ] = None ,
17
18
):
18
19
self .id = id
19
20
self .state = state
@@ -36,21 +37,29 @@ def _on_download(self):
36
37
buffer .write (self .sub_title + "\n " + str (data ))
37
38
download (self .state , content = bytes (buffer .getvalue (), "UTF-8" ), name = "data.csv" )
38
39
39
- def _to_state (self ) -> dict [str ]:
40
+ def _to_state (self ) -> dict [str , Any ]:
40
41
return {
41
- "data" : None if self is None else self .data ,
42
- "fig" : None if self is None else self .fig ,
43
- "title" : None if self is None else self .title ,
44
- "sub_title" : None if self is None else self .sub_title ,
45
- "on_action" : None if self is None else self .on_action ,
42
+ "data" : self .data ,
43
+ "fig" : self .fig ,
44
+ "title" : self .title ,
45
+ "sub_title" : self .sub_title ,
46
+ "on_action" : self .on_action ,
46
47
}
47
48
48
- def to_state (self ) -> dict [str ]:
49
+ def to_state (self ) -> dict [str , Any ]:
49
50
return self ._to_state ()
50
51
51
- def _to_empty () -> dict [str ,]:
52
- return Viz ._to_state (None )
52
+ @staticmethod
53
+ def _to_empty () -> dict [str , None ]:
54
+ return {
55
+ "data" : None ,
56
+ "fig" : None ,
57
+ "title" : None ,
58
+ "sub_title" : None ,
59
+ "on_action" : None ,
60
+ }
53
61
62
+ @staticmethod
54
63
def init (viz_set : set [str ]) -> dict [str , dict ]:
55
64
viz : dict [str , dict ] = {}
56
65
for viz_id in viz_set :
0 commit comments