Skip to content

Commit

Permalink
OWTreeGraph: Output Flagged Data
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Oct 14, 2016
1 parent 7dc0295 commit ceb2a5e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Orange/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ def get_instances(self, nodes):
if subsets:
return self.instances[np.unique(np.hstack(subsets))]

def get_indices(self, nodes):
subsets = [node.subset for node in nodes]
if subsets:
return np.unique(np.hstack(subsets))

@staticmethod
def climb(node):
while node:
Expand Down
14 changes: 10 additions & 4 deletions Orange/widgets/visualize/owtreeviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PyQt4.QtGui import QColor, QBrush, QPen, QFontMetrics, QStyle, \
QSizePolicy, QGraphicsRectItem, QGraphicsTextItem, QLabel, QComboBox

from Orange.misc.flagged_data import create_flagged_table, FLAGGED_SIGNAL_NAME
from Orange.tree import TreeModel
from Orange.widgets.visualize.owtreeviewer2d import \
GraphicsNode, GraphicsEdge, OWTreeViewer2D
Expand All @@ -13,7 +14,7 @@

from Orange.widgets.settings import ContextSetting, ClassValuesContextHandler, \
Setting
from Orange.widgets import gui
from Orange.widgets import gui, widget
from Orange.widgets.utils.colorpalette import ContinuousPaletteGenerator


Expand Down Expand Up @@ -151,7 +152,8 @@ class OWTreeGraph(OWTreeViewer2D):
icon = "icons/TreeViewer.svg"
priority = 35
inputs = [("Tree", TreeModel, "ctree")]
outputs = [("Data", Table)]
outputs = [("Selected Data", Table, widget.Default),
(FLAGGED_SIGNAL_NAME, Table)]

settingsHandler = ClassValuesContextHandler()
target_class_index = ContextSetting(0)
Expand Down Expand Up @@ -266,7 +268,8 @@ def ctree(self, model=None):
self.info.setText('{} nodes, {} leaves'.
format(model.node_count(), model.leaf_count()))
self.setup_scene()
self.send("Data", None)
self.send("Selected Data", None)
self.send(FLAGGED_SIGNAL_NAME, create_flagged_table(self.dataset, None))

def walkcreate(self, node_inst, parent=None):
"""Create a structure of tree nodes from the given model"""
Expand All @@ -291,7 +294,10 @@ def update_selection(self):
nodes = [item.node_inst for item in self.scene.selectedItems()
if isinstance(item, TreeNode)]
data = self.model.get_instances(nodes)
self.send("Data", data)
self.send("Selected Data", data)
self.send(FLAGGED_SIGNAL_NAME,
create_flagged_table(self.dataset,
self.model.get_indices(nodes)))

def send_report(self):
if not self.model:
Expand Down
27 changes: 27 additions & 0 deletions Orange/widgets/visualize/tests/test_owtreegraph.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 Orange.classification import TreeLearner
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin
from Orange.widgets.visualize.owtreeviewer import \
OWTreeGraph


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

tree = TreeLearner()
cls.model = tree(cls.data)
cls.model.instances = cls.data

cls.signal_name = "Tree"
cls.signal_data = cls.model

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

def _select_data(self):
node = self.widget.scene.nodes()[0]
node.setSelected(True)

0 comments on commit ceb2a5e

Please sign in to comment.