-
Notifications
You must be signed in to change notification settings - Fork 236
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
Multicolors #10
Multicolors #10
Conversation
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.
Looking forward to this pulled in!
@@ -310,6 +308,7 @@ var ScatterView = widgets.WidgetView.extend( { | |||
this.previous_values["vz"] = this.model.get("vz")[pindex] | |||
this.attributes_changed["vz"] =["vz"] | |||
} | |||
|
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 guess here is similar code needed if color is a 2d array, if sequence_index changes, it needs to update 'color'. Make sure the animation works 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.
Done, It didn't know that there was animation on the color!
js/src/volume.js
Outdated
if(selected_previous.indexOf(i) != -1) | ||
cur_color_previous = color_selected_previous | ||
colors_previous.setXYZ(i, cur_color_previous[0], cur_color_previous[1], cur_color_previous[2]); | ||
} | ||
|
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 will decrease the performance for having a million points, but a single color. So I'd rather see that if it is a single color, to not create an array.
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.
Done
js/src/volume.js
Outdated
if(!color_previous) | ||
color_previous = color; | ||
console.log("color",color) | ||
console.log("color_previous",color_previous) |
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 remove these.
3 similar comments
Could you fix the indenting a bit? For the rest it is working, animation etc? We could really use unittests at the js side now. But setting this up with opengl rendering won't be easy... |
Yes unitest would be nice, but I have no clue how to implement them. |
3 similar comments
3 similar comments
Better than array of string would be numpy 2d vector of rgba values. Size (n_samples, 4). That would work out of the box with matplotlib's colormaps. |
Yes, and another option would be to have a float->color mapping on the js side (color scales). Lets see if this would be work out:
So this can work out I think, no ambiguity about how color would be interpreted. The color scale is not something I want to address now. @jeammimi If you feel like implementing the rgb values by float, I'm happy to see this in this PR (hint: see _.isNumber, otherwise @slinnarsson can give it a try? |
A different PR is fine as well, shall i accept this first? |
I can give it a try. For the color scale, I am not familiar with it. So I think it will be for another time. |
Ok it is done. traitlets/traitlets.py:565: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
silent = bool(old_value == new_value) |
So now it works for these cases:
|
1 similar comment
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.
Ok, thanks a lot for your contributions. I do have some comments, would be really great if you take this into account, they are important for maintenance and future development.
If you want you can share your name/twitter/email or whatever, so I could give you credits for the next release.
js/src/volume.js
Outdated
//OD | ||
color = to_rgb(variable) | ||
return color | ||
} |
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 suggest refactoring this a bit, so it's easier to read/maintain.
instead of returning the color, and checking the color dim, you could do sth like this:
color = to_rgb(variable)
return function(glyph_index) {
return color
}
js/src/volume.js
Outdated
|
||
for(var i = 0; i < max_count; i++) { | ||
tmp_color[i] = to_rgb(to_convert[i]) | ||
} |
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.
And here:
... convert ...
return function(glyph_index) {
return tmp_color[glyph_index]
}
etc..
js/src/volume.js
Outdated
else{ | ||
var cur_color = color[i]; | ||
} | ||
|
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.
And then here you could use cur_color = color(i)
js/src/volume.js
Outdated
} | ||
else{ | ||
var cur_color_previous = color_previous[i]; | ||
} |
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.
and here cur_color_previous = color_previous(i)
js/src/volume.js
Outdated
if (this.model.get("color") ) { | ||
color = this.model.get("color") | ||
if ( typeof color == "string" || typeof color[0] == "string" || typeof color[0][0] == "string") { | ||
if (!(typeof color == "string" || typeof color[0] == "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.
Could you make this a bit simpler, sth like:
if ( ... 0 or 1d check ) {
// don't do anything, we don't have a sequence,
}
else if ( .. 2d check ...) {
// we have a sequence
...
}
I think this is more easy to read.
Please be consistent with whitespace, no whitespace after if(
,
js/src/volume.js
Outdated
var color_previous = "color" in this.previous_values ? to_rgb(this.previous_values["color"]) : color; | ||
|
||
function get_value_index_color(variable,index,max_count){ | ||
//Return a two D array (max_count,3) |
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 this function should go top level, it can be reused if for instance we're gonna support lines. And instead of returning a color, I think it should return a function. (see the rest of the comments)
Could you document it, by starting with this list:
- shape is 0 dim, and it's a string, interpret as color
- shape is 1 dim, items are strings, seperate color for each item
- shape is 2 dim, items are strings, sequence of the above
- shape is 1 dim, items are floats, it should be of length 3 -> rgb values
- shape is 2 dim, items are float, it should be of shape (len(x), 3) -> rgb values
- shape is 3 dim, items are float, it should be (sequence_length, len(x), 3) -> rgb values
and then explaining how all these cases get handled. At the moment it's hard to say what is going on by quickly going over the code.
And please use this style (note the whitespace):
function get_value_index_color(variable, index, max_count) {
Lost of comments, sorry for that ;). Btw, we could think of doing unittests/test, but not on travis. Now it is possible to do a p3.savefig('test_multicolor.png') in the notebook, and compare say that image against an previous image to see we didn't mess up. |
Ok, I modified everything accordingly. |
1 similar comment
Looking good 👍 , I'll pull this in. |
Great! |
I'll put something like this as an example: |
I added size as well, it can be a float or a sequence. |
Yes it is super nice. |
Yes, just pushed it to master. |
Fantastic! Thanks for doing this. The demo looks great.
/Sten
…--
Sten Linnarsson, PhD
Professor of Molecular Systems Biology
Karolinska Institutet
Unit of Molecular Neurobiology
Department of Medical Biochemistry and Biophysics
Scheeles väg 1, 171 77 Stockholm, Sweden
+46 8 52 48 75 77 (office)
+46 70 399 32 06 (mobile)
On 6 Mar 2017, at 15:05, Maarten Breddels ***@***.***> wrote:
Yes, just pushed it to master.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I think there is a problem with the implementation for size. |
I think you should modify line 419 of volume.js with if (this.model.get("size") && !_.isNumber(this.model.get("size")) && typeof this.model.get("size")[0][0] != "undefined" ) { because if it is a number aparently it does not like being checked for an array |
Yes, i fixed that, i'll push it to master. |
fixed. |
Multicolors - per glyph color
Added the possibility that color is a string a list of string or a 2d array of string