Skip to content

Commit

Permalink
OWSieveDiagram: Output Selected and Annotated Data
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Oct 20, 2016
1 parent 786c0b9 commit 987e0ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Orange/widgets/visualize/owsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
from Orange.preprocess import Discretize
from Orange.preprocess.discretize import EqualFreq
from Orange.statistics.contingency import get_contingency
from Orange.widgets import gui
from Orange.widgets import gui, widget
from Orange.widgets.settings import DomainContextHandler, ContextSetting
from Orange.widgets.utils import to_html as to_html
from Orange.widgets.utils.annotated_data import (create_annotated_table,
ANNOTATED_DATA_SIGNAL_NAME)
from Orange.widgets.utils.itemmodels import VariableListModel
from Orange.widgets.visualize.utils import (
CanvasText, CanvasRectangle, ViewWithPress, VizRankDialogAttrPair)
Expand Down Expand Up @@ -60,7 +62,8 @@ class OWSieveDiagram(OWWidget):

inputs = [("Data", Table, "set_data", Default),
("Features", AttributeList, "set_input_features")]
outputs = [("Selection", Table)]
outputs = [("Selected Data", Table, widget.Default),
(ANNOTATED_DATA_SIGNAL_NAME, Table)]

graph_name = "canvas"

Expand Down Expand Up @@ -244,7 +247,9 @@ def update_selection(self):
Filter and output the data.
"""
if self.areas is None or not self.selection:
self.send("Selection", None)
self.send("Selected Data", None)
self.send(ANNOTATED_DATA_SIGNAL_NAME,
create_annotated_table(self.data, []))
return

filts = []
Expand All @@ -267,11 +272,13 @@ def update_selection(self):
else:
filts = filter.Values(filts, conjunction=False)
selection = filts(self.discrete_data)
idset = set(selection.ids)
sel_idx = [i for i, id in enumerate(self.data.ids) if id in idset]
if self.discrete_data is not self.data:
idset = set(selection.ids)
sel_idx = [i for i, id in enumerate(self.data.ids) if id in idset]
selection = self.data[sel_idx]
self.send("Selection", selection)
self.send("Selected Data", selection)
self.send(ANNOTATED_DATA_SIGNAL_NAME,
create_annotated_table(self.data, sel_idx))

def update_graph(self):
# Function uses weird names like r, g, b, but it does it with utmost
Expand Down
27 changes: 27 additions & 0 deletions Orange/widgets/visualize/tests/test_owsieve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
from PyQt4.QtCore import QEvent, QPoint, Qt
from PyQt4.QtGui import QMouseEvent

from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin
from Orange.widgets.visualize.owsieve import OWSieveDiagram


class TestOWSieveDiagram(WidgetTest, WidgetOutputsTestMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
WidgetOutputsTestMixin.init(cls)

cls.signal_name = "Data"
cls.signal_data = cls.data

def setUp(self):
self.widget = self.create_widget(OWSieveDiagram)

def _select_data(self):
area = self.widget.areas[0]
self.widget.select_area(area, QMouseEvent(
QEvent.MouseButtonPress, QPoint(), Qt.LeftButton,
Qt.LeftButton, Qt.KeyboardModifiers()))
return [0, 4, 6, 7, 11, 17, 19, 21, 22, 24, 26, 39, 40, 43, 44, 46]

0 comments on commit 987e0ca

Please sign in to comment.