-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH] Mosaic: Selectable color variable #2133
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2133 +/- ##
==========================================
+ Coverage 72.49% 72.55% +0.05%
==========================================
Files 319 319
Lines 55241 55314 +73
==========================================
+ Hits 40049 40133 +84
+ Misses 15192 15181 -11 |
Orange/widgets/visualize/owmosaic.py
Outdated
elif data.domain.attributes[0]: | ||
color_var = data.domain.attributes[0] | ||
else: | ||
color_var = data.domian.metas[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domian
? Add tests for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the first meta attribute is a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the first meta attribute is a string, nothing happens. But I am still testing.
Orange/widgets/visualize/owmosaic.py
Outdated
selection = ContextSetting(set()) | ||
|
||
color_var = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does work, but we define instance attributes in __init__
. Settings are an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... if this line is needed at all. I may be stupid, by I don't see what color_var
is doing and whether it's a string or a list of strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not needed, I thought that I needed it, but then I have forgotten to erase it. Any yes, Lint reports that this variable is unused.
Vizrank has to be changed. At the moment it still uses class variable and not color. |
Orange/widgets/visualize/owmosaic.py
Outdated
box2, self, "variable_color", | ||
callback=self.update_colors, | ||
model=self.color_model, **common_options) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you actually use a DomainModel
here? Use "Pearson residuals" as placeholder, perhaps followed by a class and then other attributes. If Pearson is a placeholder, self.variable_color
will be None when the user selects it.
If you for any reason can't use the domain model, remove this comment.
Orange/widgets/visualize/owmosaic.py
Outdated
metas = [v for v in self.data.domain.metas if v != color_var] | ||
domain = Domain(attributes, class_vars, metas) | ||
data = self.data.from_table(domain, self.data) | ||
self.set_data(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I see correctly that the combo calls update_colors
, which calls change_domain
, which in turn calls set_data
? And set_data
is a callback for signal Data, which ... basically resets the widget, including closing the context and so forth?
I think widgets should never call signal handlers like set_data
. If set_data
does some things that need to be done when changing the combo (like stopping the vizrank, updating the graph), extract those into a separate function and call it from set_data
and from update_colors
(or change_domain
).
Besides, remove change_domain
altogether. The widget should output the same domain. Changing the coloring must not replace the class attribute, it should only affect the visual appearance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that changing the color should retain the selection.
Orange/widgets/visualize/owmosaic.py
Outdated
orientation=Qt.Horizontal, contentsLength=12, | ||
callback=self.update_colors, | ||
sendSelectedValue=True, valueType=str) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changed GUI is confusing.
- If the combo is set to None, the two radio buttons below have no effect.
- If the radio button is set to "Pearson", then the combo has no effect.
- Replace the None option in the combo with Pearson residuals
- You can then eliminate the radio buttons.
- The checkbox should then be active (only if) combo is not Pearson residuals. If you use DomainModel, you will check for this with, simply,
self.variable_color is not None
.
Orange/widgets/visualize/owmosaic.py
Outdated
@@ -281,6 +281,7 @@ class OWMosaicDisplay(OWWidget): | |||
variable2 = ContextSetting("", exclude_metas=False) | |||
variable3 = ContextSetting("", exclude_metas=False) | |||
variable4 = ContextSetting("", exclude_metas=False) | |||
variable_color = ContextSetting("(No class)", exclude_metas=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use a model (see below), change the default to None
.
Also, please rebase. |
Orange/widgets/visualize/owmosaic.py
Outdated
|
||
def get_attr_list(self): | ||
return [ | ||
a for a in [self.variable1, self.variable2, | ||
self.variable3, self.variable4] | ||
if a and a != "(None)"] | ||
if a and a != "(None)"], \ | ||
self.variable_color if self.variable_color != "(Pearson residuals)" else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like this method is now only called in one additional place (L484), where you discard the first list of attributes and only use the color variable.
Why don't you just use self.variable_color
there, and you even have an if
already (just change "is None" to "== Pearson")
I would, however, prefer to put the string "(Pearson residuals)" in a constant at the top and use that. You currently already use the hard-coded string 7 times in this PR.
Orange/widgets/visualize/owmosaic.py
Outdated
@@ -383,19 +382,34 @@ def init_combos(self, data): | |||
if attr.is_discrete or attr.is_continuous: | |||
for combo in self.attr_combos: | |||
combo.addItem(icons[attr], attr.name) | |||
self.cb_attr_color.addItem("(Pearson residuals)") | |||
for attr in chain(data.domain.class_vars, data.domain.attributes, data.domain.metas): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC we wanted to transition to a new order in dropdowns of: class_vars, metas, attributes?
Since some data can have thousands of attributes and scrolling to the end can be a pain.
To be double-checked.
Even better - use DomainModel. I think it should be possible to add a custom string at the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, DomainModel enables us to add a custom string at the beginning. Now class variables, attributes and metas are added into a combo in an alphabetical order.
Orange/widgets/visualize/owmosaic.py
Outdated
@@ -383,19 +382,34 @@ def init_combos(self, data): | |||
if attr.is_discrete or attr.is_continuous: | |||
for combo in self.attr_combos: | |||
combo.addItem(icons[attr], attr.name) | |||
self.cb_attr_color.addItem("(Pearson residuals)") | |||
for attr in chain(data.domain.class_vars, data.domain.attributes, data.domain.metas): | |||
if attr.is_discrete or attr.is_continuous: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attr.is_primitive
Orange/widgets/visualize/owmosaic.py
Outdated
color_var = self.data.domain[variable_color] | ||
self.interior_coloring = self.CLASS_DISTRIBUTION | ||
self.bar_button.setEnabled(True) | ||
class_vars = color_var |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use color_var
?
self.interior_coloring_opts, box="Interior Coloring", | ||
callback=self.coloring_changed) | ||
box2 = gui.vBox(self.controlArea, box="Interior Coloring") | ||
dmod = DomainModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please tell more.
Issue
Mosaic plot uses only class variable to color the visualization.
#2036
Description of changes
A new option added to the control area that allows the user to change the variable used for coloring. It defaults to class_var when it is available.
Includes