-
Notifications
You must be signed in to change notification settings - Fork 31
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
Gradient Coloring Option for Feature Metadata #484
base: master
Are you sure you want to change the base?
Conversation
I think I found out a way to (sort of) fix this problem, but I'm not yet sure why it works. Could you try removing I am really not sure why the overflow thing breaks it in Firefox, since this same setting (overflow auto) is also used for the barplot layer legends, and those look fine in Firefox. I thought there was something weird going on with the My best guess right now is that something about the overflow setting (in combination with the other CSS in effect on the main legend element) results in Firefox thinking that a scrollbar should be present, which maybe somehow messes with the SVG / element dimensions. Strangely, this fix has the bizarre side effect (...just in Chrome, as far as I can tell) of making the default width of a continuous legend too wide. Although I guess this is a better problem to have :) Notably-- removing overflow: auto will only be useful for the main legend when a continuous scale is being used. This is because we rely on overflow (and the ability to scroll stuff) when displaying categorical legends with a bunch of values -- without overflow these'll go off the legend. If we wind up going with this as a solution, I think we'd need to add/remove the |
I simplified this PR a bit. Please look at updated PR description. |
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.
Thanks @kwcantrell! This is looking good.
Co-authored-by: Marcus Fedarko <[email protected]>
@kwcantrell looks like the js style checker failed. Just flagging for your visibility. |
The following artifacts were built for this PR: empire-biplot.qzv, empire.qzv, empress-tree.qzv, just-fm.qzv, plain.qzv |
Thanks @fedarko and @ElDeveloper! I think I have addressed all of your comments so this pr should be good to merge. |
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 one comment/question. Thanks so much @kwcantrell
Co-authored-by: Marcus Fedarko <[email protected]>
@kwcantrell I just went over the changes. It looks like the only two TODOs left are the non-numeric warning and testing |
@fedarko I updated the message for the non-numeric warning message for feature metadata coloring and added some test. I fixed the bug were the gradient bar would overflow the legend. I changed |
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 have a few suggestions for fixes. I think once all of these are in we can merge this in. Thanks so much @kwcantrell!
empress/support_files/js/legend.js
Outdated
@@ -742,6 +744,28 @@ define(["jquery", "underscore", "util"], function ($, _, util) { | |||
}; | |||
}; | |||
|
|||
Legend.prototype.setMissingNonNumericWarning = function ( |
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 works -- and I'm OK with merging it in as is, as long as the other changes I've suggested here are addressed -- but I think we could probably structure this code more clearly. To me, it is confusing that the Legend
defaults to the barplot messages, and that these messages have to be passed in from Empress
object (but the barplot messages are already located here).
I propose we restructure this so that the Legend
class (on creation) takes as input an optional legendUse
parameter of tree
or barplot
, which then adjusts what the full and short missing non-numeric warnings are (so all of the warning text will live in legend.js
). That said: I'm totally OK with deferring this to a future issue so we can get this PR in soon.
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 agree, this was a fairly lazy solution. The goal was to modify the existing code as little as possible hence why it defaults to the barplot messages.
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.
Instead of adding a special parameter, I will make Legend an abstract class and add SampleFeatureColoringLegend and BarplotLegend that will inherit it. This will also make it a lot easier to change the behavior of the different legend types.
One more note sorry --
This works, thank you! However, the bug still seems to be a problem (albeit much less noticeable) when the warning message is shown: It's def not something we gotta fix right now (the |
I fixed the legend gradient bar issue by placing the gradient svg within a div container. It now will be initialized as 80% of the legend size but will not be resized if the user resizes the legend. I also abstracted the legend class and added SampleFeatureColorLegend and BarplotLegend. |
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.
Changes look good -- the suggestions here are only minor things. The warning messages / legend style fixes are dope.
However, I found two bugs with this PR that we need to fix before merging. Will comment with that.
Looks good. Did some more testing of this. Found two bugs we need to fix: 1. Turning feature metadata coloring off and on againAlthough the
GIF of this happening: There are probs multiple ways to fix this, but I think one of the easiest might be resetting 2. Nodes left as the "default color" in the gradient are not assigned a proper color, and are left out of the tree exportThis is a weird one. I was playing around with the tree exporting, and noticed that the tree nodes corresponding to non-numeric values seemed to be invisible in Chromium's SVG viewer: In Inkscape, however, these same nodes seemed visible (same region, same SVG file): It turns out that these nodes are getting assigned an invalid color, and I guess different SVG renderers will interpret this invalid color arbitrarily. I'm copying in one of the lines from the SVG file: <line x1="1923.2021484375" y1="564.703125" x2="1928.596923828125" y2="566.2871704101562" stroke="rgb(NaN,NaN,NaN)" /> Furthermore, I think this problem isn't just with the tree exporting -- these nodes actually aren't getting assigned colors, and we've been lucky in that this lack of color somehow gets turned into I believe we need to fix this problem by adding another parameter to the empress/empress/support_files/js/colorer.js Lines 260 to 265 in df3a4da
The code should be extendable with something like: if (this._missingNonNumerics) {
// (this next line will depend on if nonNumericColor is a hex
// string, RGB tuple, RGB integer, etc.)
var nonNumericColorChroma = chroma(nonNumericColor);
_.each(split.nonNumeric, function (nn) {
scope.__valueToColor[nn] = nonNumericColorChroma;
});
} We should test this, also (I think extending the current I guess the bright side is that having this parameter in here will make it easier in the future to let users change the color of missing / non-numeric barplots -- so there's that. |
@kwcantrell can you resolve the conflicts? |
Co-authored-by: Marcus Fedarko <[email protected]>
Good catch! I like the idea of adding a parameter to let users choose what color to assign non-numeric values in the case of continuous coloring. However, that would be a bit out of scope for this pr. So to fix the 2nd bug you found, I choose to simply remove non-numeric values from |
@fedarko would you be able to look at @kwcantrell's answer to your comment? What else do we need to get this branch merged? |
@kwcantrell, I was able to confirm that the issues that @fedarko pointed out were no longer there (missing data branches are assigned a 64,64,64 color value during export, and the exception is no longer raised. However, I did find a minor glitch related to the continuous values checkbox. It seems like the box is leftover after the menu is reset when the feature-metadata coloring is turned off. Once you click that while a non-continuous colorscheme is selected the checkbox disappears. After the checkbox disappears everything continues to work well. See this animated GIF: Just in case, this is the code I ran to generate an additional 2 columns with continuous metadata: import qiime2 as q2, pandas as pd, numpy as np
df = q2.Artifact.load('docs/moving-pictures/taxonomy.qza').view(pd.DataFrame)
# continuous category
df['seven_little_numbers'] = np.random.randint(0, 7, len(df))
# continuous category with missing values
df['six_little_numbers'] = df['seven_little_numbers'].copy()
df.loc[df.six_little_numbers == 0, 'six_little_numbers'] = 'I am not a number, I am a free man'
df.to_csv('docs/moving-pictures/feature-metadata.tsv', sep='\t') qiime empress community-plot \
--i-tree docs/moving-pictures/rooted-tree.qza \
--i-feature-table docs/moving-pictures/table.qza \
--m-sample-metadata-file docs/moving-pictures/sample_metadata.tsv \
--m-feature-metadata-file docs/moving-pictures/feature-metadata.tsv \
--o-visualization docs/moving-pictures/empress-tree.qzv |
Address #405 This PR adds a gradient color option for feature metadata (similar to gradient option for barplots). There is one small issue I wasn't sure how to resolve though which you can see in the image below (look at the legend).
Basically, the gradient color bar extends beyond the initial size of the legend which triggers the scroll bar. I would like to have both the legend title and gradient color bar visible without triggering the scroll bar but there is some odd css that I can't figure out. @fedarko would you have any idea?
I will address the above issues in another PR. I want to get the basics of this PR merged in with master so that it would be possible to recreate the figure for the stacked faiths pd manuscript. This PR in its current form allows users to use a gradient color map on feature metadata. It will also display an error message to the user if they try to use gradient coloring on non-numeric data/only one unique number (similar to how barplots handle it). There is still an issue where gradient color triggers a scroll bar in the legend. But I will address that in a follow up PR (unless @fedarko or @ElDeveloper think it should be resolved here).