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

Fix color clustering #2377

Merged
merged 18 commits into from
Feb 22, 2018
Merged

Fix color clustering #2377

merged 18 commits into from
Feb 22, 2018

Conversation

dy
Copy link
Contributor

@dy dy commented Feb 16, 2018

That fixes #2376, #2374 and #2354.
By accident pushed 41c067a to master, this should fix that.

cc @alexcjohnson @etpinard

  • add baseline images

@dy dy requested a review from etpinard February 16, 2018 20:07
package.json Outdated
@@ -100,7 +100,7 @@
"regl": "^1.3.1",
"regl-error2d": "^2.0.3",
"regl-line2d": "^2.1.4",
"regl-scatter2d": "^2.1.13",
"regl-scatter2d": "^2.1.16",
Copy link
Contributor

Choose a reason for hiding this comment

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

can you update the package-lock file?

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!

});

scene.fill2d.update(scene.fillOptions);
scene.fill2d.update(fillOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to git add the json mock corresponding to gl2d_line_select.png

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the one that accidentally made it into master, as mentioned above

By accident pushed 41c067a to master, this should fix that.

But since I had that in master as the base of my own PR, I removed it there #2379 (comment)

@@ -863,9 +863,11 @@ function plot(container, subplot, cdata) {

fillOptions.opacity = trace.opacity;
fillOptions.positions = pos;

return fillOptions;
Copy link
Contributor

@etpinard etpinard Feb 16, 2018

Choose a reason for hiding this comment

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

Can you briefly explain why this fixes #2376 ?

Copy link
Contributor Author

@dy dy Feb 19, 2018

Choose a reason for hiding this comment

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

That fixes #2354. That is internal regl-line2d behavior: when we do line2d.update([opts1, undefined, opts2, ...rest]), the second line in batch is ignored instead of being removed. I made it accept null, indicating that batch item should be removed.

@etpinard etpinard added bug something broken status: reviewable labels Feb 16, 2018
@@ -781,9 +781,9 @@ function plot(container, subplot, cdata) {
}
// fill requires linked traces, so we generate it's positions here
if(scene.fill2d) {
scene.fillOptions.forEach(function(fillOptions, i) {
var fillOptions = scene.fillOptions.map(function(fillOptions, i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a jasmine test to 🔒 this down?

@alexcjohnson
Copy link
Collaborator

Playing with this branch - looking great up to 90K points!
90k points
But then something changes, kind of gradually between 90K and 92K - here's 92K, where it looks like the marker outline colors pick randomly from the marker colors?
92k points
Then go a bit farther and the marker colors also get randomized - here's 100K points.
100k points

The code I used for this is (basically copied from one of the issue codepens):

var x_array = [], color_array = [], opacity = [], size = [];

for (var i = 0; i < N; i++){ // N = eg 90000, 92000, 100000
  x_array.push(i);
  color_array.push(Math.random());
  opacity.push(Math.random());
  size.push(Math.random() * 3 + 3);
}

var trace1 = {
  x: x_array, y: color_array,
  mode: 'markers',
  marker: {
    size: size, color: color_array, opacity: opacity,
    colorscale: [[0, 'rgb(255, 0, 0)'], [0.5, 'rgb(0, 255, 0)'], [1.0, 'rgb(0, 0, 255)']]
  },
  type: 'scattergl'
};

var layout = {
  title: 'Scatter Plot with a Color Dimension'
};

Plotly.newPlot(gd, [trace1], layout);

@dy
Copy link
Contributor Author

dy commented Feb 19, 2018

@alexcjohnson that is regl limitation of uint32 buffers, we can't go over 65536 various colors, that is reached at ~91k points.

@@ -10260,115 +10238,6 @@
"update-diff": "1.1.0"
}
},
"regl-scatter2d": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this gone?

"version": "0.44.0",
"resolved": "https://registry.npmjs.org/mapbox-gl/-/mapbox-gl-0.44.0.tgz",
"integrity": "sha512-vMeZaLXjG1B1BKOD9HB11sb9UIUvbzXWJu0NR38j9Uyp1h5xUXqh1Rqe+EhxQp3jzlHIv/LVhFKCJjQQKA2LoA==",
"version": "0.44.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not bump mapbox-gl in this PR?

@alexcjohnson
Copy link
Collaborator

@alexcjohnson that is regl limitation of uint32 buffers, we can't go over 65536 various colors, that is reached at ~91k points.

Makes sense, but we need to do something reasonable in this case (which should be well within the range that scattergl is expected to support), and not have it break like this. My eyes can't distinguish 65k colors, so we should be able to find a way to discretize the colors to fit within that limit.

@dy
Copy link
Contributor Author

dy commented Feb 20, 2018

@alexcjohnson fixed by d604a76

@alexcjohnson
Copy link
Collaborator

@alexcjohnson fixed by d604a76

Beautiful! Here's 1M points now, looks lovely.
screen shot 2018-02-19 at 10 47 54 pm

Is there an obvious way to test this? I wouldn't want to make a mock with 100k or more points in it, is there a way to trigger the difference at a lower volume? Or perhaps draw something like this programmatically (but not random like in my test) and read a few pixels?


for(var i = 0; i < N; i++) {
x.push(i);
color.push(Math.random());
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe I'm being paranoid, but I still don't like random in tests. Can we do something repeatable like

var randSeed = 2000000000;
function seed() {
randSeed = 2000000000;
}
function rand() {
var lastVal = randSeed;
randSeed = (69069 * randSeed + 1) % 4294967296;
// don't let consecutive vals be too close together
// gets away from really trying to be random, in favor of better local uniformity
if(Math.abs(randSeed - lastVal) < 429496729) return rand();
return randSeed / 4294967296;
}
?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha right. Good call!

Copy link
Contributor

Choose a reason for hiding this comment

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

done via
20c3a00 and eae6da2

randSeed = 2000000000;
};

lib.pseudoRandom = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea - I bet we'll find other places this should be used too.

@alexcjohnson
Copy link
Collaborator

By accident pushed 41c067a to master, this should fix that.

Merging master 1154589 includes the commit where I 🔪 gl2d_line_select.json, right? I don't see it generated in https://circleci.com/gh/plotly/plotly.js/7082#artifacts/containers/0. So now we need to add it back into this PR. After that this looks great to me! 💃

@etpinard
Copy link
Contributor

etpinard commented Feb 21, 2018

Merging master 1154589 includes the commit where I gl2d_line_select.json, right? I

Good 👁️ with commit f8b4e52 we get:

image

Some weird things happened on CI during this push, so I decided to bump glslify to get clean npm i through. This partly fixes #2386


@dfcreative anything else you may want to add to this PR?

@dy
Copy link
Contributor Author

dy commented Feb 22, 2018

@etpinard so far looks great, thanks a lot for helping out! 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scattergl lines don't show up under select/lasso drag modes
3 participants