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

Linear Projection: Setup model_selected before calculating __invalidated #3459

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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