Skip to content

Commit 09ccade

Browse files
Merge pull request #149 from savitakartik/on_click_layout_changes
hopefully fixes layout overlap in Mutations
2 parents cc5f803 + bd57c2e commit 09ccade

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

tsqc/pages/mutations.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from bokeh.models import HoverTool
88

99
from .. import config
10+
from ..plot_helpers import center_plot_title
1011
from ..plot_helpers import customise_ticks
1112
from ..plot_helpers import filter_points
1213
from ..plot_helpers import hover_points
@@ -124,9 +125,10 @@ def get_mut_data(x_range, y_range, index):
124125
def update_pop_freq_plot(x_range, y_range, index):
125126
if not index:
126127
return hv.Bars([], "population", "frequency").opts(
127-
title="Population frequencies",
128+
title="Tap on a mutation",
128129
default_tools=[],
129130
tools=["hover"],
131+
hooks=[center_plot_title],
130132
)
131133

132134
mut_data = get_mut_data(x_range, y_range, index)
@@ -141,49 +143,53 @@ def update_pop_freq_plot(x_range, y_range, index):
141143
"frequency": [mut_data[col] for col in pops],
142144
}
143145
)
146+
df = df[df["frequency"] > 0]
147+
144148
bars = hv.Bars(df, "population", "frequency").opts(
145149
framewise=True,
146-
title="Population frequencies",
150+
title=f"Mutation {mut_data['id']}",
147151
ylim=(0, max(df["frequency"]) * 1.1),
148152
xrotation=45,
149153
tools=["hover"],
150154
default_tools=[],
155+
yticks=3,
156+
yformatter="%.3f",
157+
hooks=[center_plot_title],
151158
)
152159
return bars
153160
else:
154161
return hv.Bars([], "population", "frequency").opts(
162+
title="Tap on a mutation",
155163
default_tools=[],
156164
tools=["hover"],
165+
hooks=[center_plot_title],
157166
)
158167

159168
def update_mut_info_table(x_range, y_range, index):
160169
if not index:
161-
return hv.Table([], kdims=["Detail"], vdims=["value"]).opts(
162-
title="Tap on a mutation"
163-
)
170+
return hv.Table([], kdims=["mutation"], vdims=["value"])
164171
mut_data = get_mut_data(x_range, y_range, index)
165172
pops = [col for col in mut_data.index if "pop_" in col]
166173
mut_data = mut_data.drop(pops)
167-
return hv.Table(mut_data.items(), kdims=["Column"], vdims=["Value"]).opts(
168-
title=f"Mutation {mut_data['id']}"
169-
)
174+
mut_data["time"] = mut_data["time"].round(2)
175+
if "log_time" in mut_data:
176+
mut_data["log_time"] = mut_data["log_time"].round(2)
177+
return hv.Table(mut_data.items(), kdims=["mutation"], vdims=["value"])
170178

171179
pop_data_dynamic = hv.DynamicMap(
172180
update_pop_freq_plot, streams=[range_stream, selection_stream]
173181
)
182+
pop_data_dynamic.opts(align=("center"))
174183
mut_info_table_dynamic = hv.DynamicMap(
175184
update_mut_info_table, streams=[range_stream, selection_stream]
176185
)
177-
178-
tap_widgets_layout = (mut_info_table_dynamic + pop_data_dynamic).cols(1)
186+
tap_widgets_layout = (pop_data_dynamic + mut_info_table_dynamic).cols(1)
179187

180188
return pn.Row(
181-
pn.Column(layout.opts(shared_axes=True).cols(1)),
182-
pn.panel(
189+
layout.opts(shared_axes=True).cols(1),
190+
pn.Column(
183191
tap_widgets_layout,
184192
align="center",
185-
sizing_mode="stretch_width",
186-
margin=(0, 0, 0, 200),
187193
),
188194
)
189195

tsqc/plot_helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ def customise_ticks(plot, element):
9595
first, last = int(np.round(p.y_range.start)), int(np.round(p.y_range.end))
9696
p.yaxis.ticker = [first, last]
9797
p.yaxis.major_label_overrides = {first: str(first), last: str(last)}
98+
99+
100+
def center_plot_title(plot, element):
101+
plot.state.title.align = "center"

0 commit comments

Comments
 (0)