Skip to content

Commit

Permalink
Merge pull request tskit-dev#218 from benjeffery/axes-detail
Browse files Browse the repository at this point in the history
Add units to time axis and title case axes labels
  • Loading branch information
benjeffery authored Nov 6, 2024
2 parents 023262f + a6dba76 commit da4b11d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_component(page, port, tmpdir, save_screenshots):
page.screenshot(path="tables.png")

page.get_by_role("button", name="Mutations").click()
expect(page.get_by_text("Log y-axis")).to_be_visible()
expect(page.get_by_text("Log Y-axis")).to_be_visible()
expect(page.get_by_title("Reset").locator("div")).to_be_visible()
if save_screenshots:
page.screenshot(path="mutations.png")
Expand Down
18 changes: 9 additions & 9 deletions tsbrowse/pages/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def make_edges_panel(log_y, node_type, tsm):
edges_df = tsm.edges_df
if node_type == "Child node":
time_column = "child_time"
y_label = "time of child node"
y_label = f"Time of Child Node ({tsm.ts.time_units})"
else:
time_column = "parent_time"
y_label = "time of parent node"
y_label = f"Time of Parent Node ({tsm.ts.time_units})"

if log_y:
log_time_column = f"log_{time_column}"
Expand Down Expand Up @@ -62,24 +62,24 @@ def make_edges_panel(log_y, node_type, tsm):
"Genomic span",
"auto",
log_y=log_y,
xlabel="genomic span",
ylabel="number of edges",
xlabel="Genomic Span",
ylabel="Number of Edges",
)
tspan_hist = make_hist(
edges_df["time_span"],
"Time span",
"auto",
log_y=log_y,
xlabel="time span",
ylabel="number of edges",
xlabel=f"Time span ({tsm.ts.time_units})",
ylabel="Number of Edges",
)
area_hist = make_hist(
edges_df["span"] * edges_df["time_span"],
"Edge area",
"auto",
log_y=log_y,
xlabel="time span * genomic span",
ylabel="number of edges",
xlabel="Time Span * Genomic Span",
ylabel="Number of Edges",
)
area_hist.opts(hv.opts.Histogram(xrotation=90))
gspan_hist.opts(hv.opts.Histogram(xrotation=90))
Expand All @@ -93,7 +93,7 @@ class EdgesPage:
title = "Edges"

def __init__(self, tsm):
log_y_checkbox = pn.widgets.Checkbox(name="Log y-axis", value=False)
log_y_checkbox = pn.widgets.Checkbox(name="Log Y-axis", value=False)
node_type_radio = pn.widgets.RadioBoxGroup(
options=["Parent node", "Child node"], value="Parent node", inline=True
)
Expand Down
14 changes: 12 additions & 2 deletions tsbrowse/pages/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def make_muts_panel(log_y, tsm):
colorbar_position="left",
clabel="inheritors",
tools=[hover_tool, "tap"],
xlabel="Position",
ylabel=f"Time ({tsm.ts.time_units})"
if not log_y
else f"Log (Time ({tsm.ts.time_units}))",
)

range_stream = hv.streams.RangeXY(source=points)
Expand All @@ -64,10 +68,16 @@ def make_muts_panel(log_y, tsm):

time_hist = hv.DynamicMap(
make_hist_on_axis(dimension=y_dim, points=points), streams=streams
).opts(
xlabel=f"Time ({tsm.ts.time_units})"
if not log_y
else f"Log (Time ({tsm.ts.time_units}))",
)
site_hist = hv.DynamicMap(
make_hist_on_axis(dimension="position", points=points),
streams=streams,
).opts(
xlabel="Position",
)

breakpoints = tsm.ts.breakpoints(as_array=True)
Expand All @@ -84,7 +94,7 @@ def make_muts_panel(log_y, tsm):
width=config.PLOT_WIDTH,
height=100,
hooks=[customise_ticks],
xlabel="tree density",
xlabel="Tree Density",
)

layout = (main << time_hist << site_hist) + trees_hist
Expand Down Expand Up @@ -235,7 +245,7 @@ class MutationsPage:

def __init__(self, tsm):
self.tsm = tsm
log_y_checkbox = pn.widgets.Checkbox(name="Log y-axis", value=False)
log_y_checkbox = pn.widgets.Checkbox(name="Log Y-axis", value=False)
muts_panel = pn.Column(pn.bind(make_muts_panel, log_y=log_y_checkbox, tsm=tsm))
plot_options = pn.Column(
pn.pane.Markdown("# Mutations"),
Expand Down
13 changes: 9 additions & 4 deletions tsbrowse/pages/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, tsm):
df_nodes = df_nodes[(df_nodes.ancestors_span != -np.inf)]
bins = min(50, int(np.sqrt(len(df_nodes))))

log_y_checkbox = pn.widgets.Checkbox(name="log y-axis of histogram", value=True)
log_y_checkbox = pn.widgets.Checkbox(name="Log Y-axis of Histogram", value=True)

def make_node_hist_panel(tsm, log_y):
nodes_hist = make_hist(
Expand All @@ -28,8 +28,8 @@ def make_node_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="ancestor span",
ylabel="number of nodes",
xlabel="Ancestor Span",
ylabel="Number of Nodes",
)

return pn.Column(pn.Row(nodes_hist))
Expand All @@ -42,7 +42,12 @@ def make_node_plot(data, node_types):
x="ancestors_span",
y="time",
hover_cols=["id", "ancestors_span", "time"],
).opts(width=config.PLOT_WIDTH, height=config.PLOT_HEIGHT)
).opts(
width=config.PLOT_WIDTH,
height=config.PLOT_HEIGHT,
xlabel="Ancestor Span",
ylabel=f"Time ({tsm.ts.time_units})",
)

range_stream = hv.streams.RangeXY(source=points)
streams = [range_stream]
Expand Down
26 changes: 13 additions & 13 deletions tsbrowse/pages/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, tsm):

spans = df_trees.right - df_trees.left

log_y_checkbox = pn.widgets.Checkbox(name="log y-axis", value=True)
log_y_checkbox = pn.widgets.Checkbox(name="Log Y-axis", value=True)

plot_options = pn.Column(
pn.pane.Markdown("# Trees"),
Expand All @@ -29,8 +29,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="number of sites",
ylabel="number of trees",
xlabel="Number of Sites",
ylabel="Number of Trees",
)

spans_hist = make_hist(
Expand All @@ -39,8 +39,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="genomic span",
ylabel="number of trees",
xlabel="Genomic Span",
ylabel="Number of Trees",
)

muts_hist = make_hist(
Expand All @@ -49,8 +49,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="number of mutations",
ylabel="number of trees",
xlabel="Number of Mutations",
ylabel="Number of Trees",
)

tbl_hist = make_hist(
Expand All @@ -59,8 +59,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="total branch length",
ylabel="number of trees",
xlabel="Total Banch Length",
ylabel="Number of Trees",
)

mean_arity_hist = make_hist(
Expand All @@ -69,8 +69,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="mean arity",
ylabel="number of trees",
xlabel="Mean Arity",
ylabel="Number of Trees",
)

max_arity_hist = make_hist(
Expand All @@ -79,8 +79,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="max arity",
ylabel="number of trees",
xlabel="Max Arity",
ylabel="Number of Trees",
)
return pn.Column(
pn.Row(
Expand Down

0 comments on commit da4b11d

Please sign in to comment.