Skip to content

Commit

Permalink
Clustergram whitespaces (#646)
Browse files Browse the repository at this point in the history
* Hide dendograms axis if that doesn't contain lines

* Hide dendograms axis if cluster is None

* Add test for cluster is None

* Fix state whitespaces in the clustegram test app

* Remove percy from clustergram cluster test

Co-authored-by: Hammad Khan <[email protected]>
  • Loading branch information
nickmelnikov82 and HammadTheOne authored Jan 17, 2022
1 parent 71b7855 commit 330a830
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dash_bio/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_bio/bundle.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions dash_bio/component_factory/_clustergram.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ def linkage(x, **kwargs):
self._display_ratio = [self._display_ratio[0], 0]
elif self._cluster == "col":
self._display_ratio = [0, self._display_ratio[1]]
elif self._cluster is None:
self._display_ratio = [0, 0]

self._hidden_labels = []

Expand Down Expand Up @@ -642,9 +644,11 @@ def figure(self, computed_traces=None):
# the argument can be either in list form or float form
# first is ratio for row; second is ratio for column
if self._display_ratio[0] != 0:
row_ratio = 0.95 / float(1 + int(1 / self._display_ratio[0]))
row_ratio = 0 if len(row_dendro_traces) == 0 else 0.95 / float(
1 + int(1 / self._display_ratio[0]))
if self._display_ratio[1] != 0:
col_ratio = 0.95 / float(1 + int(1 / self._display_ratio[1]))
col_ratio = 0 if len(col_dendro_traces) == 0 else 0.95 / float(
1 + int(1 / self._display_ratio[1]))

# the row/column labels take up 0.05 of the graph, and the rest
# is taken up by the heatmap and dendrogram for each dimension
Expand Down
2 changes: 1 addition & 1 deletion inst/deps/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/deps/bundle.js.map

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions tests/dashbio_demos/dash-clustergram/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ def update_col_threshold_max(dataset_name, contents):
Input('selected-rows', 'value'),
Input('selected-columns', 'value'),
Input('hide-labels', 'value')],
state=[State('clustergram-datasets', 'value'),
State('file-upload', 'contents'),
State('data-meta-storage', 'data')]
[State('clustergram-datasets', 'value'),
State('file-upload', 'contents'),
State('data-meta-storage', 'data')]
)
def store_fig_options(
cluster_by,
Expand Down Expand Up @@ -606,10 +606,10 @@ def store_fig_options(
Output('group-markers', 'data'),
[Input('clustergram', 'clickData'),
Input('remove-all-group-markers', 'n_clicks')],
state=[State('curves-dict', 'data'),
State('annotation', 'value'),
State('clustergram-annot-color', 'value'),
State('group-markers', 'data')]
[State('curves-dict', 'data'),
State('annotation', 'value'),
State('clustergram-annot-color', 'value'),
State('group-markers', 'data')]
)
def add_marker(
click_data,
Expand Down Expand Up @@ -659,7 +659,7 @@ def add_marker(
@_app.callback(
Output('clustergram-info', 'children'),
[Input('data-meta-storage', 'modified_timestamp')],
state=[State('data-meta-storage', 'data')]
[State('data-meta-storage', 'data')]
)
def update_description_info(_, data):
if data is None:
Expand Down Expand Up @@ -688,11 +688,11 @@ def update_description_info(_, data):
Input('group-markers', 'data'),
Input('selected-rows', 'value'),
Input('selected-columns', 'value')],
state=[State('fig-options-storage', 'data'),
State('clustergram-datasets', 'value'),
State('file-upload', 'contents'),
State('file-upload', 'filename'),
State('computed-traces', 'data')]
[State('fig-options-storage', 'data'),
State('clustergram-datasets', 'value'),
State('file-upload', 'contents'),
State('file-upload', 'filename'),
State('computed-traces', 'data')]
)
def display_clustergram(
_,
Expand Down Expand Up @@ -809,7 +809,7 @@ def display_clustergram(
@_app.callback(
Output('selected-rows', 'options'),
[Input('data-meta-storage', 'modified_timestamp')],
state=[State('data-meta-storage', 'data')]
[State('data-meta-storage', 'data')]
)
def update_row_options(_, data):
if data is not None:
Expand All @@ -819,7 +819,7 @@ def update_row_options(_, data):
@_app.callback(
Output('selected-columns', 'options'),
[Input('data-meta-storage', 'modified_timestamp')],
state=[State('data-meta-storage', 'data')]
[State('data-meta-storage', 'data')]
)
def update_col_options(_, data):
if data is not None:
Expand All @@ -832,8 +832,8 @@ def update_col_options(_, data):
Output('selected-rows', 'value'),
[Input('data-meta-storage', 'modified_timestamp'),
Input('selected-rows', 'options')],
state=[State('clustergram-datasets', 'value'),
State('file-upload', 'contents')]
[State('clustergram-datasets', 'value'),
State('file-upload', 'contents')]
)
def clear_rows(_, row_options, dataset_name, contents):
# if loading in a non-default dataset, clear all row selections
Expand All @@ -846,8 +846,8 @@ def clear_rows(_, row_options, dataset_name, contents):
Output('selected-columns', 'value'),
[Input('data-meta-storage', 'modified_timestamp'),
Input('selected-columns', 'options')],
state=[State('clustergram-datasets', 'value'),
State('file-upload', 'contents')]
[State('clustergram-datasets', 'value'),
State('file-upload', 'contents')]
)
def clear_cols(_, col_options, dataset_name, contents):
if dataset_name is None or col_options is None:
Expand Down Expand Up @@ -880,7 +880,7 @@ def show_uploaded_filename(contents, filename, dataset_name):
Output('clustergram-datasets', 'value'),
[Input('file-upload', 'contents'),
Input('file-upload', 'filename')],
state=[State('clustergram-datasets', 'value')]
[State('clustergram-datasets', 'value')]
)
def clear_preloaded_on_upload(contents, filename, current):
if contents is not None:
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_clustergram.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,19 @@ def test_dbcl009_column_colors(dash_duo):
dash_duo.start_server(app, dev_tools_props_check=True)
dash_duo.wait_for_element('g.subplot.x7y7')
dash_duo.percy_snapshot('test-clust_col_colors', convert_canvases=True)


def test_dbcl010_hide_dendogram_axis_when_cluster_is_none(dash_duo):

app = dash.Dash(__name__)

app.layout = html.Div(
nested_component_layout(
dash_bio.Clustergram(data=_data, cluster=None)
)
)

dash_duo.start_server(app, dev_tools_props_check=True)

assert len(dash_duo.find_elements("g.subplot.x3y3")) == 0
assert len(dash_duo.find_elements("g.subplot.x9y9")) == 0

0 comments on commit 330a830

Please sign in to comment.