Skip to content

Commit

Permalink
Fix plotlyviz color values (#226)
Browse files Browse the repository at this point in the history
fix `visuals._tooltip_copmonets` to be more flexible. And in
plotlyviz.scomplex_to_graph, don't cast to 2d
  • Loading branch information
deargle authored May 11, 2021
1 parent 94461a5 commit c7e09ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Fixed

- `min_cluster_samples` now only accepts an int -- now AgglomerativeClustering works (#224)
- `plotlyviz.scomplex_to_graph` no longer casts `color_values` to a 2d array, and `visuals._tooltip_components` now generates
either 1d or 2d `member_histogram` depending on dimensionality of `color_values` (#225)

## 2.0.0

Expand Down
4 changes: 2 additions & 2 deletions kmapper/plotlyviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ def scomplex_to_graph(
):

color_values = np.array(color_values)
if color_values.ndim == 1:
color_values = color_values.reshape(-1, 1)

json_dict = {"nodes": [], "links": []}
node_id_to_num = {}
Expand Down Expand Up @@ -334,9 +332,11 @@ def get_mapper_graph(
colorscale=colorscale,
node_color_function=node_color_function,
)

colorf_distribution = _graph_data_distribution(
simplicial_complex, color_values, node_color_function, colorscale
)

mapper_summary = _format_meta(
simplicial_complex,
color_function_name=color_function_name,
Expand Down
17 changes: 12 additions & 5 deletions kmapper/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,19 @@ def _tooltip_components(
projection_stats = _format_projection_statistics(member_ids, lens, lens_names)
cluster_stats = _format_cluster_statistics(member_ids, X, X_names)

member_histogram = []
for color_values_vector in color_values.T:
_member_histogram = _build_histogram(
color_values_vector[member_ids], colorscale=colorscale, nbins=nbins
color_values = np.array(color_values)

if color_values.ndim == 2:
member_histogram = []
for color_values_vector in color_values.T:
_member_histogram = _build_histogram(
color_values_vector[member_ids], colorscale=colorscale, nbins=nbins
)
member_histogram.append(_member_histogram)
else:
member_histogram = _build_histogram(
color_values[member_ids], colorscale=colorscale, nbins=nbins
)
member_histogram.append(_member_histogram)

return projection_stats, cluster_stats, member_histogram

Expand Down
9 changes: 9 additions & 0 deletions test/test_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
_map_val2color,
plotly_graph,
scomplex_to_graph,
node_hist_fig
)
from kmapper.utils import _test_raised_deprecation_warning

Expand Down Expand Up @@ -92,3 +93,11 @@ def test_color_function_deprecated_replaced():
colorscale=default_colorscale,
)
_test_raised_deprecation_warning(w)

def test_hovering_widgets_node_hist_fig(sc):
kmgraph, mapper_summary, n_color_distribution = get_mapper_graph(
sc, colorscale=default_colorscale
)
fnode = kmgraph["nodes"][0]
node_hist_fig(fnode["distribution"])
pass

0 comments on commit c7e09ed

Please sign in to comment.