Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Network Explorer: Clear selection on new network and when removing network #184

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion orangecontrib/network/widgets/OWNxExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,14 @@ def set_checkboxes(value):
if self.positions is None:
set_actual_edges()
self.set_random_positions()
self.clear()
self.graph.reset_graph()
self.relayout(True)
else:
self.graph.update_point_props()
self.update_marks()
self.update_selection_buttons()
self.unconditional_commit()

def init_attr_values(self):
super().init_attr_values()
Expand All @@ -527,7 +529,7 @@ def randomize(self):

def set_random_positions(self):
if self.network is None:
self.position = None
self.positions = None
else:
self.positions = np.random.uniform(size=(self.number_of_nodes, 2))

Expand Down Expand Up @@ -564,6 +566,10 @@ def send_data(self):
else:
Outputs.distances.send(distances.submatrix(sorted(selected_indices)))

def clear(self):
super().clear()
self.nSelected = 0

def get_coordinates_data(self):
if self.positions is not None:
return self.positions.T
Expand Down
13 changes: 12 additions & 1 deletion orangecontrib/network/widgets/tests/test_OWNxExplorer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from unittest.mock import Mock

import numpy as np

Expand Down Expand Up @@ -36,7 +37,6 @@ def test_too_many_labels(self):

def test_subset_selection(self):
# test if selecting from the graph works

self.send_signal(self.widget.Inputs.network, self.network)
self.assertEqual(self.widget.nSelected, 0)
self.send_signal(self.widget.Inputs.node_data, self.data)
Expand Down Expand Up @@ -96,6 +96,17 @@ def test_input_subset(self):
sub_mask = self.widget.get_subset_mask()
self.assertIsNone(sub_mask)

def test_clear_selection_on_no_data(self):
self.widget.relayout = Mock()
self.send_signal(self.widget.Inputs.network, self.network)
self.widget.graph.selection_select(np.arange(0, 5))
self.assertEqual(self.widget.nSelected, 5)
self.assertIsNotNone(self.widget.selection)
self.send_signal(self.widget.Inputs.network, None)
self.assertEqual(self.widget.nSelected, 0)
self.assertIsNone(self.widget.selection)
Copy link
Contributor

@VesnaT VesnaT Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer testing a widgets behavior to its properties. This test does not assure no selection on the output.
Adding
self.assertIsNone(self.get_output(self.widget.Outputs.selected_data))
results in a failed test.

self.assertIsNone(self.get_output(self.widget.Outputs.selected_data))


if __name__ == "__main__":
unittest.main()