Skip to content

Commit

Permalink
Merge pull request #6677 from janezd/vizrank-disable-when-no-data
Browse files Browse the repository at this point in the history
Minor fixes in Mosaic and Sieve vizrank
  • Loading branch information
VesnaT committed Dec 15, 2023
2 parents 292045c + a66c3c8 commit dcd7f72
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
29 changes: 19 additions & 10 deletions Orange/widgets/visualize/owmosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from Orange.statistics.distribution import get_distribution, get_distributions
from Orange.widgets import gui, settings
from Orange.widgets.settings import (
Setting, DomainContextHandler, ContextSetting, SettingProvider)
Setting, DomainContextHandler, ContextSetting)
from Orange.widgets.utils import to_html, get_variable_values_sorted
from Orange.widgets.utils.annotated_data import (create_annotated_table,
ANNOTATED_DATA_SIGNAL_NAME)
Expand Down Expand Up @@ -52,14 +52,24 @@ def __init__(self, parent, data, attr_color, attr_range_index):
["a single variable", "two variables", "three variables",
"four variables", "at most two variables",
"at most three variables", "at most four variables"])
item0 = combo.model().item(0)
enabled = Qt.ItemIsSelectable | Qt.ItemIsEnabled

def disable_item(i):
enabled = Qt.ItemIsSelectable | Qt.ItemIsEnabled
item = combo.model().item(i)
item.setFlags(item.flags() & ~enabled)
if self.attr_range_index == i:
# select one attribute less, or a pair instead of a single
self.attr_range_index = i - 1 if i else 1

if self.attr_color is None:
item0.setFlags(item0.flags() & ~enabled)
else:
item0.setFlags(item0.flags() | enabled)
disable_item(0) # can't do a single attribute with Pearson
if len(data.domain.attributes) < 4:
disable_item(3) # four attributes
if len(data.domain.attributes) < 3:
disable_item(2) # three attributes

combo.activated.connect(self.on_attrs_changed)
combo.setCurrentIndex(attr_range_index)
combo.setCurrentIndex(self.attr_range_index)
box.layout().addWidget(label)
box.layout().addWidget(combo)
gui.rubber(box)
Expand Down Expand Up @@ -227,7 +237,6 @@ class Outputs:
annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)

settingsHandler = DomainContextHandler()
vizrank = SettingProvider(MosaicVizRank)
settings_version = 2
use_boxes = Setting(True)
variable1: Variable = ContextSetting(None)
Expand Down Expand Up @@ -394,8 +403,8 @@ def set_data(self, data):
self.openContext(self.data)

def init_vizrank(self):
if self.data is not None and len(self.data) > 1 \
and len(self.data.domain.attributes) >= 1:
if self.discrete_data is not None and len(self.discrete_data) > 1 \
and len(self.discrete_data.domain.attributes) >= 2:
attr_range_index = self.vizrank_attr_range_index
if self.variable_color is None:
if attr_range_index == 0:
Expand Down
1 change: 0 additions & 1 deletion Orange/widgets/visualize/owsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__(self, data, attr1, attr2):


class SieveRank(VizRankDialogAttrPair):
caption_title = "Sieve Rank"
sort_names_in_row = True

def compute_score(self, state):
Expand Down
24 changes: 24 additions & 0 deletions Orange/widgets/visualize/tests/test_owmosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,30 @@ def test_max_attr_combo_1_disabling(self):
model = combo.model()
self.assertEqual(model.item(0).flags() & enabled, enabled)

def test_disable_combo_3_4(self):
def assert_enabled(*args, sel=1):
enabled = Qt.ItemIsSelectable | Qt.ItemIsEnabled
vizrank = widget.vizrank_dialog
combo = vizrank.attrs_combo
model = combo.model()
for opt in (2, 3):
self.assertEqual(model.item(opt).flags() & enabled,
enabled if opt + 1 in args else Qt.NoItemFlags)
self.assertEqual(combo.currentIndex(), sel)

widget = self.widget

data = Table("iris.tab")
widget.vizrank_attr_range_index = 3
self.send_signal(self.widget.Inputs.data, data)
assert_enabled(3, 4, sel=3)

self.send_signal(self.widget.Inputs.data, data[:, :3])
assert_enabled(3, sel=2)

self.send_signal(self.widget.Inputs.data, data[:, :2])
assert_enabled(sel=1)

def test_attr_range(self):
data = Table("iris.tab")
domain = data.domain
Expand Down
2 changes: 0 additions & 2 deletions i18n/si.jaml
Original file line number Diff line number Diff line change
Expand Up @@ -14346,8 +14346,6 @@ widgets/visualize/owsieve.py:
class `ChiSqStats`:
def `__init__`:
ignore: false
class `SieveRank`:
Sieve Rank: Rangiranje
class `OWSieveDiagram`:
Sieve Diagram: Sievov diagram
'Visualize the observed and expected frequencies ': 'Prikaz pri膷akovanih in opa啪enih pogostosti '
Expand Down

0 comments on commit dcd7f72

Please sign in to comment.