Skip to content

Commit 1751d05

Browse files
committed
Improve sizing and layout
1 parent 49b4de9 commit 1751d05

2 files changed

Lines changed: 60 additions & 26 deletions

File tree

src/tdamapper/_plot_pyvis.py

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5858
def _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

92124
def 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

115154
def _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

src/tdamapper/plot.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ def plot_plotly_update(
201201

202202
def plot_pyvis(
203203
self,
204-
notebook,
205204
output_file,
206205
colors,
207206
agg=np.nanmean,
@@ -213,8 +212,6 @@ def plot_pyvis(
213212
"""
214213
Draw an interactive HTML plot using PyVis.
215214
216-
:param notebook: Set to true when running inside Jupyter notebooks.
217-
:type notebook: bool
218215
:param output_file: The path where the html file is written.
219216
:type output_file: str
220217
:type colors: array-like of shape (n,) or list-like of size n
@@ -242,7 +239,6 @@ def plot_pyvis(
242239
"""
243240
return plot_pyvis(
244241
self,
245-
notebook=notebook,
246242
output_file=output_file,
247243
colors=colors,
248244
agg=agg,

0 commit comments

Comments
 (0)