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

Multicolors #10

Merged
merged 11 commits into from
Mar 6, 2017
Merged

Multicolors #10

merged 11 commits into from
Mar 6, 2017

Conversation

jeammimi
Copy link
Contributor

@jeammimi jeammimi commented Mar 3, 2017

Added the possibility that color is a string a list of string or a 2d array of string

Copy link
Collaborator

@maartenbreddels maartenbreddels left a 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"]
}

Copy link
Collaborator

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.

Copy link
Contributor Author

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]);
}

Copy link
Collaborator

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.

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

Please remove these.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling b787a84 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling b787a84 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling b787a84 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling b787a84 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@maartenbreddels
Copy link
Collaborator

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

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 3, 2017

Yes unitest would be nice, but I have no clue how to implement them.
Yes everything I could think of testing worked. (And the animation with the color is really nice)
Do you want me to add the netbook I used for testing?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling ac132bf on jeammimi:multicolors into 852c259 on maartenbreddels:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling ac132bf on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling ac132bf on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling ac132bf on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling fe7adff on jeammimi:multicolors into 852c259 on maartenbreddels:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling fe7adff on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling fe7adff on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.47% when pulling fe7adff on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@slinnarsson
Copy link

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.

@maartenbreddels
Copy link
Collaborator

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:

  • 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
  • no color scale / colormap is set
  • shape is 1 dim, items are floats, it should be of length 3 -> rgb values (possibly later 4 for opacity)
  • 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
  • color scale / colormap is set
    • shape is 0 dim, item if float, use the colorscale to map to color
    • shape is 1 dim, it's a seperate color for each item
    • shape is 2 dim, again a sequence

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?

@maartenbreddels
Copy link
Collaborator

A different PR is fine as well, shall i accept this first?

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

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.
I will implement 1D 2D 3D with shape 3.
Transparency could be nice, but I don't know where it should be specified in the javascript part.

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

Ok it is done.
The only thing is that there is a warning that appears with traitlets when the array color is numeric.

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)

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

So now it works for these cases:

  • 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

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-4.1%) to 82.353% when pulling d0b0d73 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-4.1%) to 82.353% when pulling d0b0d73 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

Copy link
Collaborator

@maartenbreddels maartenbreddels left a 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
}
Copy link
Collaborator

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])
}
Copy link
Collaborator

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];
}

Copy link
Collaborator

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];
}
Copy link
Collaborator

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")){
Copy link
Collaborator

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

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) {

@maartenbreddels
Copy link
Collaborator

Lost of comments, sorry for that ;).
Color scale and transparency is another thing.. don't worry about it for the moment, at least we know that we have a list of unambigious behavious for 'scatter'.

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.
Maybe not yet for this PR, but just to let you know.

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

Ok, I modified everything accordingly.
The function get_value_index_color is now cleaner and easy to read I think.
The only thing I changed is that I don't create anymore the array tmp_color.
It is better for the memory, and I think that at worse the conversion is made twice.
Here is my email jeanmichel.arbona at gmail.com

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-4.3%) to 82.207% when pulling a4433a1 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-4.3%) to 82.207% when pulling a4433a1 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-4.3%) to 82.207% when pulling 18efca2 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-4.3%) to 82.207% when pulling 18efca2 on jeammimi:multicolors into 852c259 on maartenbreddels:master.

@maartenbreddels
Copy link
Collaborator

Looking good 👍 , I'll pull this in.

@maartenbreddels maartenbreddels merged commit 7386ab3 into widgetti:master Mar 6, 2017
@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

Great!

@maartenbreddels
Copy link
Collaborator

I'll put something like this as an example:
https://www.astro.rug.nl/~breddels/test/wave/
I think it demonstates most of the features. Some arrays can be constant (x and z in this case), and y and color are a sequence.

@maartenbreddels
Copy link
Collaborator

I added size as well, it can be a float or a sequence.

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

Yes it is super nice.
Here the size is also a sequence no ? You implemented it ?

@maartenbreddels
Copy link
Collaborator

Yes, just pushed it to master.

@slinnarsson
Copy link

slinnarsson commented Mar 6, 2017 via email

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

I think there is a problem with the implementation for size.
I don't know why but when size is a float, the sequence does not work.

@jeammimi
Copy link
Contributor Author

jeammimi commented Mar 6, 2017

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

@maartenbreddels
Copy link
Collaborator

Yes, i fixed that, i'll push it to master.

@maartenbreddels
Copy link
Collaborator

fixed.

mpu-creare pushed a commit to mpu-creare/ipyvolume that referenced this pull request Mar 26, 2018
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.

4 participants