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

On-par autorange for scattergl #2404

Merged
merged 9 commits into from
Feb 28, 2018
100 changes: 100 additions & 0 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,103 @@ describe('@gl Test gl2d plots', function() {
.then(done);
});
});

describe('Test scattergl autorange:', function() {
afterEach(destroyGraphDiv);

describe('should return the same value as SVG scatter for ~small~ data', function() {
var specs = [
{name: 'lines+markers', fig: require('@mocks/gl2d_10.json')},
{name: 'bubbles', fig: require('@mocks/gl2d_12.json')},
{name: 'line on log axes', fig: require('@mocks/gl2d_14.json')},
{name: 'fill to zero', fig: require('@mocks/gl2d_axes_labels2.json')},
{name: 'annotations', fig: require('@mocks/gl2d_annotations.json')}
];

specs.forEach(function(s) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lovely!

it('- case ' + s.name, function(done) {
var gd = createGraphDiv();
var glRangeX;
var glRangeY;

// ensure the mocks have auto-range turned on
var glFig = Lib.extendDeep({}, s.fig);
Lib.extendDeep(glFig.layout, {xaxis: {autorange: true}});
Lib.extendDeep(glFig.layout, {yaxis: {autorange: true}});

var svgFig = Lib.extendDeep({}, glFig);
svgFig.data.forEach(function(t) { t.type = 'scatter'; });

Plotly.newPlot(gd, glFig).then(function() {
glRangeX = gd._fullLayout.xaxis.range;
glRangeY = gd._fullLayout.yaxis.range;
})
.then(function() {
return Plotly.newPlot(gd, svgFig);
})
.then(function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray(glRangeX, 'x range');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray(glRangeY, 'y range');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beautiful test!

})
.catch(fail)
.then(done);
});
});
});

describe('should return the approximative values for ~big~ data', function() {
beforeEach(function() {
spyOn(ScatterGl, 'plot');
});

// threshold for 'fast' axis expansion routine
var N = 1e5;
var x = new Array(N);
var y = new Array(N);
var ms = new Array(N);

Lib.seedPseudoRandom();

for(var i = 0; i < N; i++) {
x[i] = Lib.pseudoRandom();
y[i] = Lib.pseudoRandom();
ms[i] = 10 * Lib.pseudoRandom() + 20;
}

it('- case scalar marker.size', function(done) {
var gd = createGraphDiv();

Plotly.newPlot(gd, [{
type: 'scattergl',
mode: 'markers',
x: x,
y: y,
marker: {size: 10}
}])
.then(function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.02, 1.02], 'x range');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.04, 1.04], 'y range');
})
.catch(fail)
.then(done);
});

it('- case array marker.size', function(done) {
var gd = createGraphDiv();

Plotly.newPlot(gd, [{
type: 'scattergl',
mode: 'markers',
x: x,
y: y,
marker: {size: ms}
}])
.then(function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.05, 1.05], 'x range');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.11, 1.11], 'y range');
})
.catch(fail)
.then(done);
});
});
});