Skip to content

Commit 2da497c

Browse files
authored
Merge pull request #1988 from ales-erjavec/fixes/paint-data-input-colors
[FIX] owpaintdata: Adjust color model to input dataset
2 parents 8921dd8 + 784589c commit 2da497c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Orange/widgets/data/owpaintdata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ def __init__(self):
794794

795795
self.input_data = None
796796
self.input_classes = []
797+
self.input_colors = None
797798
self.input_has_attr2 = True
798799
self.current_tool = None
799800
self._selected_indices = None
@@ -1016,9 +1017,12 @@ def _check_and_set_data(data):
10161017
if data.domain.class_vars:
10171018
self.Warning.continuous_target()
10181019
self.input_classes = ["C1"]
1020+
self.input_colors = None
10191021
y = np.zeros(len(data))
10201022
else:
10211023
self.input_classes = y.values
1024+
self.input_colors = y.colors
1025+
10221026
y = data[:, y].Y
10231027

10241028
self.input_has_attr2 = len(data.domain.attributes) >= 2
@@ -1036,7 +1040,16 @@ def reset_to_input(self):
10361040
self.undo_stack.clear()
10371041

10381042
index = self.selected_class_label()
1043+
if self.input_colors is not None:
1044+
colors = self.input_colors
1045+
else:
1046+
colors = colorpalette.DefaultRGBColors
1047+
palette = colorpalette.ColorPaletteGenerator(
1048+
number_of_colors=len(colors), rgb_colors=colors)
1049+
self.colors = palette
1050+
self.class_model.colors = palette
10391051
self.class_model[:] = self.input_classes
1052+
10401053
newindex = min(max(index, 0), len(self.class_model) - 1)
10411054
itemmodels.select_row(self.classValuesView, newindex)
10421055

Orange/widgets/data/tests/test_owpaintdata.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55
from AnyQt.QtCore import QRectF, QPointF
66

7-
from Orange.data import Table
7+
from Orange.data import Table, DiscreteVariable, ContinuousVariable, Domain
88
from Orange.widgets.data import owpaintdata
99
from Orange.widgets.data.owpaintdata import OWPaintData
1010
from Orange.widgets.tests.base import WidgetTest, datasets
@@ -47,3 +47,12 @@ def test_output_shares_internal_buffer(self):
4747
np.testing.assert_equal(output1.Y, output1_copy.Y)
4848

4949
self.assertTrue(np.any(output1.X != output2.X))
50+
51+
def test_20_values_class(self):
52+
domain = Domain(
53+
[ContinuousVariable("A"),
54+
ContinuousVariable("B")],
55+
DiscreteVariable("C", values=[chr(ord("a") + i) for i in range(20)])
56+
)
57+
data = Table(domain, [[0.1, 0.2, "a"], [0.4, 0.7, "t"]])
58+
self.send_signal("Data", data)

0 commit comments

Comments
 (0)