Skip to content

Commit d4a2a53

Browse files
committed
fix and 🔒 in-and-out of hasOnlyLargeSploms regime
1 parent 7ae7159 commit d4a2a53

File tree

2 files changed

+89
-6
lines changed

2 files changed

+89
-6
lines changed

src/plots/plots.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,14 @@ plots.supplyDefaults = function(gd) {
414414

415415
// turn on flag to optimize large splom-only graphs
416416
// mostly by omitting SVG layers during Cartesian.drawFramework
417-
if(
417+
newFullLayout._hasOnlyLargeSploms = (
418418
newFullLayout._basePlotModules.length === 1 &&
419419
newFullLayout._basePlotModules[0].name === 'splom' &&
420420
splomXa.length > 15 &&
421421
splomYa.length > 15 &&
422422
newFullLayout.shapes.length === 0 &&
423423
newFullLayout.images.length === 0
424-
) {
425-
newFullLayout._hasOnlyLargeSploms = 1;
426-
}
424+
);
427425

428426
// TODO remove in v2.0.0
429427
// add has-plot-type refs to fullLayout for backward compatibility

test/jasmine/tests/splom_test.js

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
var Plotly = require('@lib');
12
var Lib = require('@src/lib');
2-
var supplyAllDefaults = require('../assets/supply_defaults');
33
var Plots = require('@src/plots/plots');
4+
var SUBPLOT_PATTERN = require('@src/plots/cartesian/constants').SUBPLOT_PATTERN;
45

5-
var Plotly = require('@lib');
6+
var d3 = require('d3');
7+
var supplyAllDefaults = require('../assets/supply_defaults');
68
var createGraphDiv = require('../assets/create_graph_div');
79
var destroyGraphDiv = require('../assets/destroy_graph_div');
810
var failTest = require('../assets/fail_test');
@@ -404,4 +406,87 @@ describe('@gl Test splom interactions:', function() {
404406
.catch(failTest)
405407
.then(done);
406408
});
409+
410+
it('should update properly in-and-out of hasOnlyLargeSploms regime', function(done) {
411+
var figLarge = Lib.extendDeep({}, require('@mocks/splom_large.json'));
412+
var dimsLarge = figLarge.data[0].dimensions;
413+
var dimsSmall = dimsLarge.slice(0, 5);
414+
var cnt = 1;
415+
416+
function _assert(exp) {
417+
var msg = ' - call #' + cnt;
418+
var subplots = d3.selectAll('g.cartesianlayer > g.subplot');
419+
420+
expect(subplots.size())
421+
.toBe(exp.subplotCnt, '# of <g.subplot>' + msg);
422+
423+
var failedSubplots = [];
424+
subplots.each(function(d, i) {
425+
var actual = this.children.length;
426+
var expected = typeof exp.innerSubplotNodeCnt === 'function' ?
427+
exp.innerSubplotNodeCnt(d, i) :
428+
exp.innerSubplotNodeCnt;
429+
if(actual !== expected) {
430+
failedSubplots.push([d, actual, 'vs', expected].join(' '));
431+
}
432+
});
433+
expect(failedSubplots)
434+
.toEqual([], '# of nodes inside <g.subplot>' + msg);
435+
436+
expect(!!gd._fullLayout._splomGrid)
437+
.toBe(exp.hasSplomGrid, 'has regl-line2d splom grid' + msg);
438+
439+
cnt++;
440+
}
441+
442+
Plotly.plot(gd, figLarge).then(function() {
443+
_assert({
444+
subplotCnt: 400,
445+
innerSubplotNodeCnt: 5,
446+
hasSplomGrid: true
447+
});
448+
return Plotly.restyle(gd, 'dimensions', [dimsSmall]);
449+
})
450+
.then(function() {
451+
_assert({
452+
subplotCnt: 25,
453+
innerSubplotNodeCnt: 17,
454+
hasSplomGrid: false
455+
});
456+
457+
// make sure 'new' subplot layers are in order
458+
var gridIndex = -1;
459+
var xaxisIndex = -1;
460+
var subplot0 = d3.select('g.cartesianlayer > g.subplot').node();
461+
for(var i in subplot0.children) {
462+
var cl = subplot0.children[i].classList;
463+
if(cl) {
464+
if(cl.contains('gridlayer')) gridIndex = +i;
465+
else if(cl.contains('xaxislayer-above')) xaxisIndex = +i;
466+
}
467+
}
468+
// from large -> small splom:
469+
// grid layer would be above xaxis layer,
470+
// if we didn't clear subplot children.
471+
expect(gridIndex).toBe(1, '<g.gridlayer> index');
472+
expect(xaxisIndex).toBe(14, '<g.xaxislayer-above> index');
473+
474+
return Plotly.restyle(gd, 'dimensions', [dimsLarge]);
475+
})
476+
.then(function() {
477+
_assert({
478+
subplotCnt: 400,
479+
// from small -> large splom:
480+
// no need to clear subplots children in existing subplots,
481+
// new subplots though have reduced number of children.
482+
innerSubplotNodeCnt: function(d) {
483+
var p = d.match(SUBPLOT_PATTERN);
484+
return (p[1] > 5 || p[2] > 5) ? 5 : 17;
485+
},
486+
hasSplomGrid: true
487+
});
488+
})
489+
.catch(failTest)
490+
.then(done);
491+
});
407492
});

0 commit comments

Comments
 (0)