Skip to content

Commit 40f93f7

Browse files
committed
add svg vs gl scatter autorange 🔒s
1 parent 36b4e25 commit 40f93f7

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

test/jasmine/tests/gl2d_plot_interact_test.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,103 @@ describe('@gl Test gl2d plots', function() {
833833
.then(done);
834834
});
835835
});
836+
837+
describe('Test scattergl autorange:', function() {
838+
afterEach(destroyGraphDiv);
839+
840+
describe('should return the same value as SVG scatter for ~small~ data', function() {
841+
var specs = [
842+
{name: 'lines+markers', fig: require('@mocks/gl2d_10.json')},
843+
{name: 'bubbles', fig: require('@mocks/gl2d_12.json')},
844+
{name: 'line on log axes', fig: require('@mocks/gl2d_14.json')},
845+
{name: 'fill to zero', fig: require('@mocks/gl2d_axes_labels2.json')},
846+
{name: 'annotations', fig: require('@mocks/gl2d_annotations.json')}
847+
];
848+
849+
specs.forEach(function(s) {
850+
it('- case ' + s.name, function(done) {
851+
var gd = createGraphDiv();
852+
var glRangeX;
853+
var glRangeY;
854+
855+
// ensure the mocks have auto-range turned on
856+
var glFig = Lib.extendDeep({}, s.fig);
857+
Lib.extendDeep(glFig.layout, {xaxis: {autorange: true}});
858+
Lib.extendDeep(glFig.layout, {yaxis: {autorange: true}});
859+
860+
var svgFig = Lib.extendDeep({}, glFig);
861+
svgFig.data.forEach(function(t) { t.type = 'scatter'; });
862+
863+
Plotly.newPlot(gd, glFig).then(function() {
864+
glRangeX = gd._fullLayout.xaxis.range;
865+
glRangeY = gd._fullLayout.yaxis.range;
866+
})
867+
.then(function() {
868+
return Plotly.newPlot(gd, svgFig);
869+
})
870+
.then(function() {
871+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray(glRangeX, 'x range');
872+
expect(gd._fullLayout.yaxis.range).toBeCloseToArray(glRangeY, 'y range');
873+
})
874+
.catch(fail)
875+
.then(done);
876+
});
877+
});
878+
});
879+
880+
describe('should return the approximative values for ~big~ data', function() {
881+
beforeEach(function() {
882+
spyOn(ScatterGl, 'plot');
883+
});
884+
885+
// threshold for 'fast' axis expansion routine
886+
var N = 1e5;
887+
var x = new Array(N);
888+
var y = new Array(N);
889+
var ms = new Array(N);
890+
891+
Lib.seedPseudoRandom();
892+
893+
for(var i = 0; i < N; i++) {
894+
x[i] = Lib.pseudoRandom();
895+
y[i] = Lib.pseudoRandom();
896+
ms[i] = 10 * Lib.pseudoRandom() + 20;
897+
}
898+
899+
it('- case scalar marker.size', function(done) {
900+
var gd = createGraphDiv();
901+
902+
Plotly.newPlot(gd, [{
903+
type: 'scattergl',
904+
mode: 'markers',
905+
x: x,
906+
y: y,
907+
marker: {size: 10}
908+
}])
909+
.then(function() {
910+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.02, 1.02], 'x range');
911+
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.04, 1.04], 'y range');
912+
})
913+
.catch(fail)
914+
.then(done);
915+
});
916+
917+
it('- case array marker.size', function(done) {
918+
var gd = createGraphDiv();
919+
920+
Plotly.newPlot(gd, [{
921+
type: 'scattergl',
922+
mode: 'markers',
923+
x: x,
924+
y: y,
925+
marker: {size: ms}
926+
}])
927+
.then(function() {
928+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.05, 1.05], 'x range');
929+
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.11, 1.11], 'y range');
930+
})
931+
.catch(fail)
932+
.then(done);
933+
});
934+
});
935+
});

0 commit comments

Comments
 (0)