Skip to content

Commit 849ae1f

Browse files
authored
Merge pull request #3316 from janezd/remove-overlap
[ENH] projections: Remove sizing by overlap
2 parents 0c3958e + 18a5517 commit 849ae1f

File tree

5 files changed

+10
-63
lines changed

5 files changed

+10
-63
lines changed

Orange/widgets/tests/base.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ def test_attr_models(self):
848848
controls = self.widget.controls
849849
self.assertEqual(len(controls.attr_color.model()), 8)
850850
self.assertEqual(len(controls.attr_shape.model()), 3)
851-
self.assertTrue(7 < len(controls.attr_size.model()) < 10)
851+
self.assertTrue(5 < len(controls.attr_size.model()) < 8)
852852
self.assertEqual(len(controls.attr_label.model()), 8)
853853

854854
# color and label should contain all variables
@@ -864,14 +864,6 @@ def test_attr_models(self):
864864
self.assertNotIn(var, controls.attr_size.model())
865865
self.assertIn(var, controls.attr_shape.model())
866866

867-
def test_overlap(self):
868-
"""Test option 'Overlap' in 'Size' combo box"""
869-
self.send_signal(self.widget.Inputs.data, self.data)
870-
self.assertEqual(len(set(self.widget.graph.get_sizes())), 1)
871-
simulate.combobox_activate_item(self.widget.controls.attr_size,
872-
OWPlotGUI.SizeByOverlap)
873-
self.assertGreater(len(set(self.widget.graph.get_sizes())), 1)
874-
875867
def test_attr_label_metas(self, timeout=DEFAULT_TIMEOUT):
876868
"""Set 'Label' from string meta attribute"""
877869
cont = Continuize(multinomial_treatment=Continuize.AsOrdinal)

Orange/widgets/unsupervised/tests/test_owmds.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import numpy as np
99

10-
from AnyQt.QtTest import QSignalSpy
11-
1210
from Orange.data import Table
1311
from Orange.distance import Euclidean
1412
from Orange.misc import DistMatrix
@@ -18,7 +16,6 @@
1816
)
1917
from Orange.widgets.tests.utils import simulate
2018
from Orange.widgets.unsupervised.owmds import OWMDS
21-
from Orange.widgets.utils.plot import OWPlotGUI
2219

2320

2421
class TestOWMDS(WidgetTest, ProjectionWidgetTestMixin,
@@ -275,16 +272,6 @@ def test_saved_matrix_and_data(self):
275272
self.send_signal(self.widget.Inputs.data, towns_data)
276273
self.assertIn(towns_data.domain["label"], attr_label.model())
277274

278-
def test_overlap(self):
279-
self.send_signal(self.signal_name, self.signal_data)
280-
if self.widget.isBlocking():
281-
spy = QSignalSpy(self.widget.blockingStateChanged)
282-
self.assertTrue(spy.wait(5000))
283-
self.assertEqual(len(set(self.widget.graph.get_sizes())), 1)
284-
simulate.combobox_activate_item(self.widget.controls.attr_size,
285-
OWPlotGUI.SizeByOverlap)
286-
self.assertEqual(len(set(self.widget.graph.get_sizes())), 1)
287-
288275

289276
if __name__ == "__main__":
290277
unittest.main()

Orange/widgets/utils/plot/owplotgui.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
import os
2929

3030
import unicodedata
31-
from functools import reduce
32-
from operator import itemgetter
3331

34-
from Orange.data import ContinuousVariable, DiscreteVariable, Variable
32+
from Orange.data import ContinuousVariable, DiscreteVariable
3533
from Orange.widgets import gui
3634
from Orange.widgets.utils import itemmodels
3735
from Orange.widgets.utils.listfilter import variables_filter
@@ -430,19 +428,16 @@ class OWPlotGUI:
430428

431429
def __init__(self, plot):
432430
self._plot = plot
433-
self.color_model = DomainModel(placeholder="(Same color)",
434-
valid_types=DomainModel.PRIMITIVE)
435-
self.shape_model = DomainModel(placeholder="(Same shape)",
436-
valid_types=DiscreteVariable)
437-
self.size_model = DomainModel(placeholder="(Same size)",
438-
order=(self.SizeByOverlap,) + DomainModel.SEPARATED,
439-
valid_types=ContinuousVariable)
431+
self.color_model = DomainModel(
432+
placeholder="(Same color)", valid_types=DomainModel.PRIMITIVE)
433+
self.shape_model = DomainModel(
434+
placeholder="(Same shape)", valid_types=DiscreteVariable)
435+
self.size_model = DomainModel(
436+
placeholder="(Same size)", valid_types=ContinuousVariable)
440437
self.label_model = DomainModel(placeholder="(No labels)")
441438
self.points_models = [self.color_model, self.shape_model,
442439
self.size_model, self.label_model]
443440

444-
SizeByOverlap = "Overlap"
445-
446441
Spacing = 0
447442

448443
ShowLegend = 2

Orange/widgets/visualize/utils/widget.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from collections import Counter, defaultdict
21
from xml.sax.saxutils import escape
3-
from math import log2
42

53
import numpy as np
64

@@ -22,7 +20,6 @@
2220
from Orange.widgets.utils.colorpalette import (
2321
ColorPaletteGenerator, ContinuousPaletteGenerator, DefaultRGBColors
2422
)
25-
from Orange.widgets.utils.plot import OWPlotGUI
2623
from Orange.widgets.utils.sql import check_sql_input
2724
from Orange.widgets.visualize.owscatterplotgraph import OWScatterPlotBase
2825
from Orange.widgets.visualize.utils.component import OWGraphWithAnchors
@@ -98,13 +95,6 @@ def get_subset_mask(self):
9895
"""
9996
return None
10097

101-
@staticmethod
102-
def __get_overlap_groups(x, y):
103-
coord_to_id = defaultdict(list)
104-
for i, xy in enumerate(zip(x, y)):
105-
coord_to_id[xy].append(i)
106-
return coord_to_id
107-
10898
def get_column(self, attr, filter_valid=True,
10999
merge_infrequent=False, return_labels=False):
110100
"""
@@ -172,11 +162,6 @@ def get_column(self, attr, filter_valid=True,
172162
# Sizes
173163
def get_size_data(self):
174164
"""Return the column corresponding to `attr_size`"""
175-
if self.attr_size == OWPlotGUI.SizeByOverlap:
176-
x, y = self.get_coordinates_data()
177-
coord_to_id = self.__get_overlap_groups(x, y)
178-
overlaps = [len(coord_to_id[xy]) for xy in zip(x, y)]
179-
return [1 + log2(o) for o in overlaps]
180165
return self.get_column(self.attr_size)
181166

182167
def impute_sizes(self, size_data):
@@ -195,22 +180,11 @@ def impute_sizes(self, size_data):
195180

196181
def sizes_changed(self):
197182
self.graph.update_sizes()
198-
self.graph.update_colors() # Needed for overlapping
199183

200184
# Colors
201185
def get_color_data(self):
202186
"""Return the column corresponding to color data"""
203-
colors = self.get_column(self.attr_color, merge_infrequent=True)
204-
if self.attr_size == OWPlotGUI.SizeByOverlap:
205-
# color overlapping points by most frequent color
206-
x, y = self.get_coordinates_data()
207-
coord_to_id = self.__get_overlap_groups(x, y)
208-
majority_colors = np.empty(len(x))
209-
for i, xy in enumerate(zip(x, y)):
210-
cnt = Counter(colors[j] for j in coord_to_id[xy])
211-
majority_colors[i] = cnt.most_common(1)[0][0]
212-
return majority_colors
213-
return colors
187+
return self.get_column(self.attr_color, merge_infrequent=True)
214188

215189
def get_color_labels(self):
216190
"""

doc/visual-programming/source/widgets/visualize/scatterplot.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ the left side of the widget. A snapshot below shows the scatterplot of the
4141
2. Set the color of the displayed points (you will get colors for discrete
4242
values and grey-scale points for continuous). Set label, shape and
4343
size to differentiate between points. Set symbol size and opacity for
44-
all data points. Set the desired colors scale. To visualize the number
45-
of overlapping points use *Overlap* for size.
44+
all data points. Set the desired colors scale.
4645
3. Adjust *plot properties*:
4746

4847
- *Show legend* displays a legend on the right. Click and drag the legend to move it.

0 commit comments

Comments
 (0)