Skip to content

Commit

Permalink
Network Explorer: Clear selection on new network (on none)
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Jan 29, 2021
1 parent 247b3d8 commit b4517a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions orangecontrib/network/widgets/OWNxExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def set_checkboxes(value):
if self.positions is None:
set_actual_edges()
self.set_random_positions()
self.clear()
self.graph.reset_graph()
self.relayout()
else:
Expand Down Expand Up @@ -547,6 +548,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
12 changes: 11 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,16 @@ 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)


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

0 comments on commit b4517a9

Please sign in to comment.