Skip to content

Commit e5e3366

Browse files
committed
Projections: Allow transparent subset
1 parent b7d0da8 commit e5e3366

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

Orange/widgets/visualize/owscatterplotgraph.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def get_size_data(self):
531531

532532
COLOR_NOT_SUBSET = (128, 128, 128, 0)
533533
COLOR_SUBSET = (128, 128, 128, 255)
534-
COLOR_DEFAULT = (128, 128, 128, 0)
534+
COLOR_DEFAULT = (128, 128, 128, 255)
535535

536536
MAX_VISIBLE_LABELS = 500
537537

@@ -1048,15 +1048,19 @@ def _get_same_colors(self, subset):
10481048
"""
10491049
color = self.plot_widget.palette().color(OWPalette.Data)
10501050
pen = [_make_pen(color, 1.5)] * self.n_shown # use a single QPen instance
1051+
1052+
# Prepare all brushes; we use the first two or the last
1053+
brushes = []
1054+
for c in (self.COLOR_SUBSET, self.COLOR_NOT_SUBSET, self.COLOR_DEFAULT):
1055+
color = QColor(*c)
1056+
if color.alpha():
1057+
color.setAlpha(self.alpha_value)
1058+
brushes.append(QBrush(color))
1059+
10511060
if subset is not None:
1052-
brush = np.where(
1053-
subset,
1054-
*(QBrush(QColor(*col))
1055-
for col in (self.COLOR_SUBSET, self.COLOR_NOT_SUBSET)))
1061+
brush = np.where(subset, *brushes[:2])
10561062
else:
1057-
color = QColor(*self.COLOR_DEFAULT)
1058-
color.setAlpha(self.alpha_value)
1059-
brush = [QBrush(color)] * self.n_shown # use a single QBrush instance
1063+
brush = brushes[-1:] * self.n_shown # use a single QBrush instance
10601064
return pen, brush
10611065

10621066
def _get_continuous_colors(self, c_data, subset):
@@ -1102,7 +1106,7 @@ def create_brush(col):
11021106

11031107
if subset is not None:
11041108
brush[:, 3] = 0
1105-
brush[subset, 3] = 255
1109+
brush[subset, 3] = self.alpha_value
11061110

11071111
cached_brushes = {}
11081112
brush = np.array([reuse(cached_brushes, create_brush, *col)
@@ -1133,7 +1137,7 @@ def _get_discrete_colors(self, c_data, subset):
11331137
pens = np.array(
11341138
[_make_pen(col.darker(self.DarkerValue), 1.5) for col in colors])
11351139
pen = pens[c_data]
1136-
if subset is None and self.alpha_value < 255:
1140+
if self.alpha_value < 255:
11371141
for col in colors:
11381142
col.setAlpha(self.alpha_value)
11391143
brushes = np.array([QBrush(col) for col in colors])
@@ -1504,7 +1508,7 @@ def _update_colored_legend(self, legend, labels, symbols):
15041508
for color, label, symbol in zip(colors, labels, symbols):
15051509
color = QColor(*color)
15061510
pen = _make_pen(color.darker(self.DarkerValue), 1.5)
1507-
color.setAlpha(255 if self.subset_is_shown else self.alpha_value)
1511+
color.setAlpha(self.alpha_value)
15081512
brush = QBrush(color)
15091513
legend.addItem(
15101514
SymbolItemSample(pen=pen, brush=brush, size=10, symbol=symbol),

Orange/widgets/visualize/tests/test_owscatterplot.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ def test_subset_data(self):
567567
self.send_signal(w.Inputs.data_subset, data[::30])
568568
self.assertEqual(len(w.subset_indices), 5)
569569

570+
def test_opacity_warning(self):
571+
data = Table("iris")
572+
w = self.widget
573+
self.send_signal(w.Inputs.data, data)
574+
w.graph.controls.alpha_value.setSliderPosition(10)
575+
self.assertFalse(w.Warning.transparent_subset.is_shown())
576+
self.send_signal(w.Inputs.data_subset, data[::30])
577+
self.assertTrue(w.Warning.transparent_subset.is_shown())
578+
w.graph.controls.alpha_value.setSliderPosition(200)
579+
self.assertFalse(w.Warning.transparent_subset.is_shown())
580+
w.graph.controls.alpha_value.setSliderPosition(10)
581+
self.assertTrue(w.Warning.transparent_subset.is_shown())
582+
self.send_signal(w.Inputs.data_subset, None)
583+
self.assertFalse(w.Warning.transparent_subset.is_shown())
584+
570585
def test_metas_zero_column(self):
571586
"""
572587
Prevent crash when metas column is zero.

Orange/widgets/visualize/tests/test_owscatterplotbase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,9 @@ def run_tests():
614614
self.assertEqual(brushes[0].color().alpha(), 0)
615615
self.assertEqual(brushes[1].color().alpha(), 0)
616616
self.assertEqual(brushes[4].color().alpha(), 0)
617-
self.assertEqual(brushes[5].color().alpha(), 255)
618-
self.assertEqual(brushes[6].color().alpha(), 255)
619-
self.assertEqual(brushes[7].color().alpha(), 255)
617+
self.assertEqual(brushes[5].color().alpha(), 123)
618+
self.assertEqual(brushes[6].color().alpha(), 123)
619+
self.assertEqual(brushes[7].color().alpha(), 123)
620620

621621
graph = self.graph
622622

Orange/widgets/visualize/utils/widget.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def can_draw_density(self):
250250

251251
def colors_changed(self):
252252
self.graph.update_colors()
253+
self._update_opacity_warning()
253254
self.cb_class_density.setEnabled(self.can_draw_density())
254255

255256
# Labels
@@ -378,6 +379,8 @@ class Warning(OWProjectionWidgetBase.Warning):
378379
"input data")
379380
subset_independent = Msg(
380381
"No subset data instances appear in input data")
382+
transparent_subset = Msg(
383+
"Increase opacity if subset is difficult to see")
381384

382385
settingsHandler = DomainContextHandler()
383386
selection = Setting(None, schema_only=True)
@@ -473,7 +476,6 @@ def enable_controls(self):
473476
@check_sql_input
474477
def set_subset_data(self, subset):
475478
self.subset_data = subset
476-
self.controls.graph.alpha_value.setEnabled(subset is None)
477479

478480
def handleNewSignals(self):
479481
self._handle_subset_data()
@@ -482,6 +484,7 @@ def handleNewSignals(self):
482484
self.setup_plot()
483485
else:
484486
self.graph.update_point_props()
487+
self._update_opacity_warning()
485488
self.unconditional_commit()
486489

487490
def _handle_subset_data(self):
@@ -497,6 +500,10 @@ def _handle_subset_data(self):
497500
elif self.subset_indices - ids:
498501
self.Warning.subset_not_subset()
499502

503+
def _update_opacity_warning(self):
504+
self.Warning.transparent_subset(
505+
shown=self.subset_indices and self.graph.alpha_value < 128)
506+
500507
def set_input_summary(self, data):
501508
summary = len(data) if data else self.info.NoInput
502509
detail = format_summary_details(data) if data else ""

0 commit comments

Comments
 (0)