diff --git a/Orange/widgets/unsupervised/owmds.py b/Orange/widgets/unsupervised/owmds.py index 8acf3802b3e..dddc450deb4 100644 --- a/Orange/widgets/unsupervised/owmds.py +++ b/Orange/widgets/unsupervised/owmds.py @@ -141,6 +141,7 @@ class OWMDS(widget.OWWidget): shape_value = settings.ContextSetting("") size_value = settings.ContextSetting("") label_value = settings.ContextSetting("") + label_only_selected = settings.Setting(False) symbol_size = settings.Setting(8) symbol_opacity = settings.Setting(230) @@ -232,6 +233,9 @@ def __init__(self): box, self, "label_value", label="Label:", callback=self._on_label_index_changed, **common_options) self.cb_label_value.setModel(self.labelvar_model) + gui.checkBox( + gui.indentedBox(box), self, 'label_only_selected', + 'Label only selected points', callback=self._on_label_index_changed) form = QtGui.QFormLayout( labelAlignment=Qt.AlignLeft, @@ -930,9 +934,18 @@ def jitter(x, factor=1, rstate=None): self.plot.addItem(item) if self._label_data is not None: - for (x, y), text_item in zip(self.embedding, self._label_data): - self.plot.addItem(text_item) - text_item.setPos(x, y) + if self.label_only_selected: + if self._selection_mask is not None: + for (x, y), text_item, selected \ + in zip(self.embedding, self._label_data, + self._selection_mask): + if selected: + self.plot.addItem(text_item) + text_item.setPos(x, y) + else: + for (x, y), text_item in zip(self.embedding, self._label_data): + self.plot.addItem(text_item) + text_item.setPos(x, y) self._legend_item = LegendItem() viewbox = self.plot.getViewBox() diff --git a/Orange/widgets/utils/plot/owplotgui.py b/Orange/widgets/utils/plot/owplotgui.py index eabc9df779d..ff8ce174c2b 100644 --- a/Orange/widgets/utils/plot/owplotgui.py +++ b/Orange/widgets/utils/plot/owplotgui.py @@ -373,8 +373,11 @@ def animations_check_box(self, widget): ''' self._check_box(widget, 'use_animations', 'Use animations', 'update_animations') - def _slider(self, widget, value, label, min_value, max_value, step, cb_name): - gui.hSlider(widget, self._plot, value, label=label, minValue=min_value, maxValue=max_value, step=step, callback=self._get_callback(cb_name)) + def _slider(self, widget, value, label, min_value, max_value, step, cb_name, + show_number=False): + gui.hSlider(widget, self._plot, value, label=label, minValue=min_value, + maxValue=max_value, step=step, createLabel=show_number, + callback=self._get_callback(cb_name)) def point_size_slider(self, widget): ''' diff --git a/Orange/widgets/visualize/owscatterplot.py b/Orange/widgets/visualize/owscatterplot.py index 3a59440dbda..4afe7237994 100644 --- a/Orange/widgets/visualize/owscatterplot.py +++ b/Orange/widgets/visualize/owscatterplot.py @@ -102,8 +102,8 @@ def __init__(self): vizrank_box = gui.hBox(box) gui.separator(vizrank_box, width=common_options["labelWidth"]) self.vizrank_button = gui.button( - vizrank_box, self, "Rank Projections", callback=self.vizrank.reshow, - tooltip="Find projections with good class separation") + vizrank_box, self, "Score Plots", callback=self.vizrank.reshow, + tooltip="Find plots with good class separation") self.vizrank_button.setEnabled(False) gui.separator(box) @@ -144,11 +144,15 @@ def __init__(self): box = gui.vBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) - gui.checkBox(box, self, value='graph.tooltip_shows_all', - label='Show all data on mouse hover') + gui.checkBox( + box, self, value='graph.tooltip_shows_all', + label='Show all data on mouse hover') self.cb_class_density = gui.checkBox( box, self, value='graph.class_density', label='Show class density', callback=self.update_density) + gui.checkBox( + box, self, 'graph.label_only_selected', + 'Label only selected points', callback=self.graph.update_labels) self.zoom_select_toolbar = g.zoom_select_toolbar( gui.vBox(self.controlArea, "Zoom/Select"), nomargin=True, diff --git a/Orange/widgets/visualize/owscatterplotgraph.py b/Orange/widgets/visualize/owscatterplotgraph.py index f047236f45c..443c7902f6f 100644 --- a/Orange/widgets/visualize/owscatterplotgraph.py +++ b/Orange/widgets/visualize/owscatterplotgraph.py @@ -455,6 +455,7 @@ def _define_symbols(): class OWScatterPlotGraph(gui.OWComponent, ScaleScatterPlotData): attr_color = ContextSetting("", ContextSetting.OPTIONAL) attr_label = ContextSetting("", ContextSetting.OPTIONAL) + label_only_selected = Setting(False) attr_shape = ContextSetting("", ContextSetting.OPTIONAL) attr_size = ContextSetting("", ContextSetting.OPTIONAL) @@ -842,7 +843,8 @@ def create_labels(self): self.labels.append(ti) def update_labels(self): - if not self.attr_label: + if not self.attr_label or \ + self.label_only_selected and self.selection is None: for label in self.labels: label.setText("") return @@ -852,8 +854,13 @@ def update_labels(self): formatter = self.raw_data.domain[self.attr_label].str_val label_data = map(formatter, label_column) black = pg.mkColor(0, 0, 0) - for label, text in zip(self.labels, label_data): - label.setText(text, black) + if self.label_only_selected: + for label, text, selected \ + in zip(self.labels, label_data, self.selection): + label.setText(text if selected else "", black) + else: + for label, text in zip(self.labels, label_data): + label.setText(text, black) def get_shape_index(self): shape_index = -1 @@ -991,6 +998,8 @@ def select_by_rectangle(self, value_rect): def unselect_all(self): self.selection = None self.update_colors(keep_colors=True) + if self.label_only_selected: + self.update_labels() self.master.selection_changed() def select(self, points): @@ -1009,6 +1018,8 @@ def select(self, points): else: # Handle shift and no modifiers self.selection[indices] = True self.update_colors(keep_colors=True) + if self.label_only_selected: + self.update_labels() self.master.selection_changed() def get_selection(self):