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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,4 +789,47 @@ describe('@gl Test gl2d plots', function() {
.catch(fail)
.then(done);
});

it('should be able to draw more than 4096 colors', function(done) {
var gd = createGraphDiv();
var x = [];
var color = [];
var N = 1e5;
var w = 500;
var h = 500;

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

}

Plotly.newPlot(gd, [{
type: 'scattergl',
mode: 'markers',
x: x,
y: color,
marker: {
color: color,
colorscale: [
[0, 'rgb(255, 0, 0)'],
[0.5, 'rgb(0, 255, 0)'],
[1.0, 'rgb(0, 0, 255)']
]
}
}], {
width: w,
height: h,
margin: {l: 0, t: 0, b: 0, r: 0}
})
.then(function() {
var total = readPixel(gd.querySelector('.gl-canvas-context'), 0, 0, w, h)
.reduce(function(acc, v) { return acc + v; }, 0);

// the total value was 3762487 before PR
// https://github.com/plotly/plotly.js/pull/2377
expect(total).toBeGreaterThan(4e6);
})
.catch(fail)
.then(done);
});
});