Skip to content

Commit 6ab1214

Browse files
committed
Scatter plot: save group selections
1 parent 6602407 commit 6ab1214

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Orange/widgets/visualize/owscatterplot.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Outputs:
117117
annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)
118118
features = Output("Features", Table, dynamic=False)
119119

120+
settings_version = 2
120121
settingsHandler = DomainContextHandler()
121122

122123
auto_send_selection = Setting(True)
@@ -401,8 +402,9 @@ def apply_selection(self):
401402
"""Apply selection saved in workflow."""
402403
if self.data is not None and self.selection is not None:
403404
self.graph.selection = np.zeros(len(self.data), dtype=np.uint8)
404-
self.selection = [x for x in self.selection if x < len(self.data)]
405-
self.graph.selection[self.selection] = 1
405+
self.selection = [x for x in self.selection if x[0] < len(self.data)]
406+
selection_array = np.array(self.selection).T
407+
self.graph.selection[selection_array[0]] = selection_array[1]
406408
self.graph.update_colors(keep_colors=True)
407409

408410
@Inputs.features
@@ -477,7 +479,7 @@ def send_data(self):
477479

478480
# Store current selection in a setting that is stored in workflow
479481
if selection is not None and len(selection):
480-
self.selection = list(selection)
482+
self.selection = list(zip(selection, graph.selection[selection]))
481483
else:
482484
self.selection = None
483485

@@ -520,6 +522,13 @@ def onDeleteWidget(self):
520522
self.graph.plot_widget.getViewBox().deleteLater()
521523
self.graph.plot_widget.clear()
522524

525+
@classmethod
526+
def migrate_settings(cls, settings, version):
527+
if "selection" in settings \
528+
and settings["selection"] \
529+
and not isinstance(settings["selection"][0], tuple):
530+
settings["selection"] = [(a, 1) for a in settings["selection"]]
531+
523532

524533
def main(argv=None):
525534
import sys

Orange/widgets/visualize/tests/test_owscatterplot.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_none_data(self):
227227

228228
def test_points_selection(self):
229229
# Opening widget with saved selection should restore it
230-
self.widget.selection = list(range(50))
230+
self.widget.selection = [(i, 1) for i in range(50)]
231231
self.send_signal(self.widget.Inputs.data, self.data) # iris
232232
selected_data = self.get_output(self.widget.Outputs.selected_data)
233233
self.assertEqual(len(selected_data), 50)
@@ -238,10 +238,15 @@ def test_points_selection(self):
238238
selected_data = self.get_output(self.widget.Outputs.selected_data)
239239
self.assertIsNone(selected_data)
240240

241+
def test_migrate_selection(self):
242+
settings = dict(selection=list(range(2)))
243+
OWScatterPlot.migrate_settings(settings, 0)
244+
self.assertEqual(settings["selection"], [(0, 1), (1, 1)])
245+
241246
def test_invalid_points_selection(self):
242247
# if selection contains rows that are not present in the current
243248
# dataset, widget should select what can be selected.
244-
self.widget.selection = list(range(50))
249+
self.widget.selection = [(i, 1) for i in range(50)]
245250
self.send_signal(self.widget.Inputs.data, self.data[:10])
246251
selected_data = self.get_output(self.widget.Outputs.selected_data)
247252
self.assertEqual(len(selected_data), 10)

0 commit comments

Comments
 (0)