Skip to content

Commit

Permalink
Merge pull request #3459 from VesnaT/fix_linproj
Browse files Browse the repository at this point in the history
Linear Projection: Setup model_selected before calculating __invalidated
  • Loading branch information
janezd authored Dec 11, 2018
2 parents 90e05be + 0fd6a28 commit 54b9ff4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Orange/widgets/visualize/owlinearprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ def colors_changed(self):

def set_data(self, data):
super().set_data(data)
self._check_options()
self._init_vizrank()
self.init_projection()

def use_context(self):
self.model_selected.clear()
self.model_other.clear()
if self.data is not None and len(self.selected_vars):
d, selected = self.data.domain, [v[0] for v in self.selected_vars]
self.model_selected[:] = [d[attr] for attr in selected]
Expand All @@ -368,10 +375,6 @@ def set_data(self, data):
self.model_selected[:] = self.continuous_variables[:3]
self.model_other[:] = self.continuous_variables[3:]

self._check_options()
self._init_vizrank()
self.init_projection()

def _check_options(self):
buttons = self.radio_placement.buttons
for btn in buttons:
Expand Down Expand Up @@ -463,13 +466,6 @@ def projection_name():
("Jittering", self.graph.jitter_size != 0 and
"{} %".format(self.graph.jitter_size))))

def clear(self):
if self.model_selected:
self.model_selected.clear()
if self.model_other:
self.model_other.clear()
super().clear()

@classmethod
def migrate_settings(cls, settings_, version):
if version < 2:
Expand Down
23 changes: 23 additions & 0 deletions Orange/widgets/visualize/tests/test_owlinearprojection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
from unittest.mock import Mock
import numpy as np

from AnyQt.QtCore import QItemSelectionModel
Expand Down Expand Up @@ -159,6 +160,28 @@ def test_set_radius_no_data(self):
self.send_signal(w.Inputs.data, None)
w.controls.graph.hide_radius.setSliderPosition(3)

def test_invalidated_model_selected(self):
self.widget.setup_plot = Mock()
self.send_signal(self.widget.Inputs.data, self.data)
self.widget.setup_plot.assert_called_once()

self.widget.setup_plot.reset_mock()
self.widget.model_selected[:] = self.data.domain[2:]
self.widget.variables_selection.removed.emit()
self.widget.setup_plot.assert_called_once()

self.widget.setup_plot.reset_mock()
self.send_signal(self.widget.Inputs.data, self.data[:, 2:])
self.widget.setup_plot.assert_not_called()

self.widget.model_selected[:] = self.data.domain[3:]
self.widget.variables_selection.removed.emit()
self.widget.setup_plot.assert_called_once()

self.widget.setup_plot.reset_mock()
self.send_signal(self.widget.Inputs.data, self.data)
self.widget.setup_plot.assert_called_once()


class LinProjVizRankTests(WidgetTest):
"""
Expand Down

0 comments on commit 54b9ff4

Please sign in to comment.