Skip to content
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

Merged
merged 1 commit into from
May 5, 2017
Merged

[ENH] Mosaic: Selectable color variable #2133

merged 1 commit into from
May 5, 2017

Conversation

jerneju
Copy link
Contributor

@jerneju jerneju commented Mar 23, 2017

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
  • Code changes
  • Tests
  • Documentation

@codecov-io
Copy link

codecov-io commented Mar 23, 2017

Codecov Report

Merging #2133 into master will increase coverage by 0.05%.
The diff coverage is 100%.

@@            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

elif data.domain.attributes[0]:
color_var = data.domain.attributes[0]
else:
color_var = data.domian.metas[0]
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

selection = ContextSetting(set())

color_var = None
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@jerneju jerneju Mar 24, 2017

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.

@jerneju
Copy link
Contributor Author

jerneju commented Mar 24, 2017

Vizrank has to be changed. At the moment it still uses class variable and not color.

box2, self, "variable_color",
callback=self.update_colors,
model=self.color_model, **common_options)
"""
Copy link
Contributor

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.

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)
Copy link
Contributor

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.

Copy link
Contributor

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.

orientation=Qt.Horizontal, contentsLength=12,
callback=self.update_colors,
sendSelectedValue=True, valueType=str)

Copy link
Contributor

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.
  1. Replace the None option in the combo with Pearson residuals
  2. You can then eliminate the radio buttons.
  3. 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.

@@ -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)
Copy link
Contributor

@janezd janezd Mar 31, 2017

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.

@janezd
Copy link
Contributor

janezd commented Mar 31, 2017

Also, please rebase.

@jerneju jerneju changed the title Mosaic: change the variable used for coloring [WIP] Mosaic: change the variable used for coloring Apr 14, 2017

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
Copy link
Contributor

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.

@@ -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):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attr.is_primitive

color_var = self.data.domain[variable_color]
self.interior_coloring = self.CLASS_DISTRIBUTION
self.bar_button.setEnabled(True)
class_vars = color_var
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use color_var?

@lanzagar lanzagar self-assigned this Apr 25, 2017
@lanzagar lanzagar changed the title [WIP] Mosaic: change the variable used for coloring [FIX] Mosaic: Selectable color variable May 5, 2017
@lanzagar lanzagar changed the title [FIX] Mosaic: Selectable color variable [ENH] Mosaic: Selectable color variable May 5, 2017
@lanzagar lanzagar merged commit 1690956 into biolab:master May 5, 2017
@jerneju jerneju deleted the gh-2036-mosaic branch May 5, 2017 14:58
self.interior_coloring_opts, box="Interior Coloring",
callback=self.coloring_changed)
box2 = gui.vBox(self.controlArea, box="Interior Coloring")
dmod = DomainModel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please tell more.

mstrazar pushed a commit to mstrazar/orange3 that referenced this pull request May 6, 2017
mstrazar pushed a commit to mstrazar/orange3 that referenced this pull request May 6, 2017
@astaric astaric mentioned this pull request May 8, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants