Skip to content

Commit

Permalink
Merge pull request #3751 from janezd/scatterplot-resize-signals
Browse files Browse the repository at this point in the history
OWScatterplotGraph: Emit signals when resizing data points
  • Loading branch information
VesnaT authored Apr 15, 2019
2 parents f1b1616 + 0bc55e5 commit 9cf23e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ def get_size_data(self):
(in methods `get_<something>`).
"""
too_many_labels = Signal(bool)
begin_resizing = Signal()
step_resizing = Signal()
end_resizing = Signal()

label_only_selected = Setting(False)
point_width = Setting(10)
Expand Down Expand Up @@ -766,17 +769,24 @@ def __call__(self):
size = size_data
widget.scatterplot_item.setSize(size)
widget.scatterplot_item_sel.setSize(size + SELECTION_WIDTH)
if widget.timer is None:
widget.end_resizing.emit()
else:
widget.step_resizing.emit()

if self.n_valid <= MAX_N_VALID_SIZE_ANIMATE and \
np.all(current_size_data > 0) and np.any(diff != 0):
# If encountered any strange behaviour when updating sizes,
# implement it with threads
self.begin_resizing.emit()
self.timer = QTimer(self.scatterplot_item, interval=50)
self.timer.timeout.connect(Timeout())
self.timer.start()
else:
self.begin_resizing.emit()
self.scatterplot_item.setSize(size_data)
self.scatterplot_item_sel.setSize(size_data + SELECTION_WIDTH)
self.end_resizing.emit()

update_point_size = update_sizes # backward compatibility (needed?!)
update_size = update_sizes
Expand Down
9 changes: 9 additions & 0 deletions Orange/widgets/visualize/tests/test_owscatterplotbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,16 @@ def test_sizes_selection(self):
@patch("Orange.widgets.visualize.owscatterplotgraph"
".MAX_N_VALID_SIZE_ANIMATE", 5)
def test_size_animation(self):
begin_resizing = QSignalSpy(self.graph.begin_resizing)
step_resizing = QSignalSpy(self.graph.step_resizing)
end_resizing = QSignalSpy(self.graph.end_resizing)
self._update_sizes_for_points(5)
# first end_resizing is triggered in reset, thus wait for step_resizing
step_resizing.wait(200)
end_resizing.wait(200)
self.assertEqual(len(begin_resizing), 2) # reset and update
self.assertEqual(len(step_resizing), 5)
self.assertEqual(len(end_resizing), 2) # reset and update
self.assertEqual(self.graph.scatterplot_item.setSize.call_count, 6)
self._update_sizes_for_points(6)
self.graph.scatterplot_item.setSize.assert_called_once()
Expand Down

0 comments on commit 9cf23e6

Please sign in to comment.