@@ -27,7 +27,7 @@ def __fmt(x, max_len=3):
2727 return f'{ x :{fmt }} '
2828
2929
30- def _colorbar (width , height , cmap , cmin , cmax , title ):
30+ def _colorbar (height , cmap , cmin , cmax , title ):
3131 colorbar_fig = go .Figure ()
3232 colorbar_fig .add_trace (go .Scatter (
3333 x = [None ], y = [None ],
@@ -47,7 +47,7 @@ def _colorbar(width, height, cmap, cmin, cmax, title):
4747 xaxis = dict (visible = False ),
4848 yaxis = dict (visible = False ),
4949 margin = dict (l = 50 , r = 50 , t = 0 , b = 0 ),
50- # width=width ,
50+ width = 200 ,
5151 height = height ,
5252 plot_bgcolor = 'rgba(0,0,0,0)' ,
5353 paper_bgcolor = 'rgba(0,0,0,0)' ,
@@ -57,41 +57,72 @@ def _colorbar(width, height, cmap, cmin, cmax, title):
5757
5858def _combine (network , colorbar ):
5959 network_html = network .generate_html ()
60- colorbar_html = pio .to_html (colorbar , include_plotlyjs = 'cdn' , full_html = False )
60+ colorbar_html = pio .to_html (colorbar , include_plotlyjs = 'cdn' , full_html = False , config = { 'displayModeBar' : False } )
6161 combined_html = f"""
6262 <!DOCTYPE html>
6363 <html>
6464 <head>
6565 <title>Network with Colorbar</title>
6666 <style>
6767 body {{
68- display: flex;
69- flex-direction: row;
7068 margin: 0;
71- padding: 0;
7269 height: 100vh;
70+ display: flex;
71+ }}
72+
73+ .container {{
74+ flex: 1;
75+ display: flex;
76+ flex-direction: row;
7377 }}
78+
7479 .network {{
7580 flex: 3;
81+ display: flex;
82+ justify-content: center;
83+ align-items: start;
84+ background-color: #f0f0f0;
85+ height: 100%;
86+ }}
87+
88+ .network-content {{
89+ width: 100%;
90+ height: 100%;
91+ }}
92+
93+ .colorbar {{
94+ flex: 3;
95+ display: flex;
96+ justify-content: center;
97+ align-items: start;
98+ background-color: #f0f0f0;
99+ height: 100%;
100+ }}
101+
102+ .colorbar-content {{
103+ width: 100%;
104+ height: 100%;
76105 }}
77106 </style>
78107 </head>
79108 <body>
80- <div class="network">
81- { network_html }
82- </div>
83- <div class="colorbar">
84- { colorbar_html }
109+ <div class="container">
110+ <div class="network">
111+ { network_html }
112+ </div>
113+ <div class="colorbar">
114+ { colorbar_html }
115+ </div>
85116 </div>
86117 </body>
87118 </html>
88119 """
89120 return combined_html
121+ #return network_html
90122
91123
92124def plot_pyvis (
93125 mapper_plot ,
94- notebook ,
95126 output_file ,
96127 colors ,
97128 agg ,
@@ -100,34 +131,41 @@ def plot_pyvis(
100131 height ,
101132 cmap ,
102133):
103- net = _compute_net (
134+ net , cmin , cmax = _compute_net (
104135 mapper_plot = mapper_plot ,
105136 width = width ,
106137 height = height ,
107138 colors = colors ,
108139 agg = agg ,
109140 cmap = cmap ,
110- notebook = notebook ,
111141 )
112- net .show (output_file , notebook = notebook )
142+ colorbar = _colorbar (
143+ height = height ,
144+ cmap = cmap ,
145+ cmin = cmin ,
146+ cmax = cmax ,
147+ title = title
148+ )
149+ combined_html = _combine (net , colorbar )
150+ with open (output_file , 'w' ) as file :
151+ file .write (combined_html )
113152
114153
115154def _compute_net (
116155 mapper_plot ,
117- notebook ,
118156 colors ,
119157 agg ,
120158 width ,
121159 height ,
122160 cmap ,
123161):
124162 net = Network (
125- height = height ,
126- width = width ,
163+ height = f' { height } px' ,
164+ width = f' { width } px' ,
127165 directed = False ,
128- notebook = notebook ,
129- select_menu = True ,
130- filter_menu = True ,
166+ notebook = True ,
167+ select_menu = False ,
168+ filter_menu = False ,
131169 neighborhood_highlight = True ,
132170 )
133171 net .toggle_physics (False )
@@ -210,4 +248,4 @@ def _blend_color(source, target):
210248 edge_width = 1.5
211249 net .add_edge (source_id , target_id , color = edge_color , width = edge_width )
212250
213- return net
251+ return net , min_node_color , max_node_color
0 commit comments