Skip to content

Commit cc5f0ca

Browse files
committed
speed up 'axrange' edits
- by just calling 'Axes.doTicks' instead of full `doTicksRelayout` which includes drawing the title - this also fixes (and locks) a bug where large splom would draw twice (once in doTicksRelayout and once in the drawData subroutine).
1 parent 73acd7e commit cc5f0ca

File tree

4 files changed

+92
-10
lines changed

4 files changed

+92
-10
lines changed

Diff for: src/plot_api/plot_api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1738,8 +1738,8 @@ function addAxRangeSequence(seq, rangesAltered) {
17381738
// subroutine of its own so that finalDraw always gets
17391739
// executed after drawData
17401740
var doTicks = rangesAltered ?
1741-
function(gd) { return subroutines.doTicksRelayout(gd, rangesAltered); } :
1742-
subroutines.doTicksRelayout;
1741+
function(gd) { return Axes.doTicks(gd, Object.keys(rangesAltered), true); } :
1742+
function(gd) { return Axes.doTicks(gd, 'redraw'); };
17431743

17441744
seq.push(
17451745
subroutines.doAutoRangeAndConstraints,

Diff for: src/plot_api/subroutines.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,8 @@ exports.doLegend = function(gd) {
498498
return Plots.previousPromises(gd);
499499
};
500500

501-
exports.doTicksRelayout = function(gd, rangesAltered) {
502-
if(rangesAltered) {
503-
Axes.doTicks(gd, Object.keys(rangesAltered), true);
504-
} else {
505-
Axes.doTicks(gd, 'redraw');
506-
}
501+
exports.doTicksRelayout = function(gd) {
502+
Axes.doTicks(gd, 'redraw');
507503

508504
if(gd._fullLayout._hasOnlyLargeSploms) {
509505
clearGlCanvases(gd);

Diff for: test/jasmine/tests/plot_api_test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Queue = require('@src/lib/queue');
66
var Scatter = require('@src/traces/scatter');
77
var Bar = require('@src/traces/bar');
88
var Legend = require('@src/components/legend');
9+
var Axes = require('@src/plots/cartesian/axes');
910
var pkg = require('../../../package.json');
1011
var subroutines = require('@src/plot_api/subroutines');
1112
var helpers = require('@src/plot_api/helpers');
@@ -531,12 +532,14 @@ describe('Test plot api', function() {
531532
mockedMethods.forEach(function(m) {
532533
spyOn(subroutines, m);
533534
});
535+
spyOn(Axes, 'doTicks');
534536
});
535537

536538
function mock(gd) {
537539
mockedMethods.forEach(function(m) {
538540
subroutines[m].calls.reset();
539541
});
542+
Axes.doTicks.calls.reset();
540543

541544
supplyAllDefaults(gd);
542545
Plots.doCalcdata(gd);
@@ -634,7 +637,7 @@ describe('Test plot api', function() {
634637
});
635638

636639
it('should trigger minimal sequence for cartesian axis range updates', function() {
637-
var seq = ['doAutoRangeAndConstraints', 'doTicksRelayout', 'drawData', 'finalDraw'];
640+
var seq = ['doAutoRangeAndConstraints', 'drawData', 'finalDraw'];
638641

639642
function _assert(msg) {
640643
expect(gd.calcdata).toBeDefined();
@@ -644,6 +647,9 @@ describe('Test plot api', function() {
644647
'# of ' + m + ' calls - ' + msg
645648
);
646649
});
650+
expect(Axes.doTicks).toHaveBeenCalledTimes(1);
651+
expect(Axes.doTicks.calls.allArgs()[0][1]).toEqual(['x']);
652+
expect(Axes.doTicks.calls.allArgs()[0][2]).toBe(true, 'skip-axis-title argument');
647653
}
648654

649655
var specs = [
@@ -2588,6 +2594,7 @@ describe('Test plot api', function() {
25882594
spyOn(annotations, 'drawOne').and.callThrough();
25892595
spyOn(annotations, 'draw').and.callThrough();
25902596
spyOn(images, 'draw').and.callThrough();
2597+
spyOn(Axes, 'doTicks').and.callThrough();
25912598
});
25922599

25932600
afterEach(destroyGraphDiv);
@@ -2823,10 +2830,11 @@ describe('Test plot api', function() {
28232830
Plotly.newPlot(gd, data, layout)
28242831
.then(countPlots)
28252832
.then(function() {
2833+
expect(Axes.doTicks).toHaveBeenCalledWith(gd, '');
28262834
return Plotly.react(gd, data, layout2);
28272835
})
28282836
.then(function() {
2829-
expect(subroutines.doTicksRelayout).toHaveBeenCalledTimes(1);
2837+
expect(Axes.doTicks).toHaveBeenCalledWith(gd, 'redraw');
28302838
expect(subroutines.layoutStyles).not.toHaveBeenCalled();
28312839
})
28322840
.catch(failTest)

Diff for: test/jasmine/tests/splom_test.js

+78
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Plotly = require('@lib');
22
var Lib = require('@src/lib');
33
var Plots = require('@src/plots/plots');
4+
var Axes = require('@src/plots/cartesian/axes');
45
var SUBPLOT_PATTERN = require('@src/plots/cartesian/constants').SUBPLOT_PATTERN;
56

67
var d3 = require('d3');
@@ -747,6 +748,83 @@ describe('Test splom interactions:', function() {
747748
});
748749
});
749750

751+
describe('Test splom update switchboard:', function() {
752+
var gd;
753+
754+
beforeEach(function() {
755+
gd = createGraphDiv();
756+
});
757+
758+
afterEach(function() {
759+
Plotly.purge(gd);
760+
destroyGraphDiv();
761+
});
762+
763+
var methods;
764+
765+
function addSpies() {
766+
methods.forEach(function(m) {
767+
var obj = m[0];
768+
var k = m[1];
769+
spyOn(obj, k).and.callThrough();
770+
});
771+
}
772+
773+
function assertSpies(msg, exp) {
774+
methods.forEach(function(m, i) {
775+
var obj = m[0];
776+
var k = m[1];
777+
var expi = exp[i];
778+
expect(obj[k]).toHaveBeenCalledTimes(expi[1], expi[0]);
779+
obj[k].calls.reset();
780+
});
781+
}
782+
783+
it('@gl should trigger minimal sequence for axis range updates (large splom case)', function(done) {
784+
var fig = Lib.extendDeep({}, require('@mocks/splom_large.json'));
785+
var matrix, regl, splomGrid;
786+
787+
Plotly.plot(gd, fig).then(function() {
788+
var fullLayout = gd._fullLayout;
789+
var trace = gd._fullData[0];
790+
var scene = fullLayout._splomScenes[trace.uid];
791+
matrix = scene.matrix;
792+
regl = matrix.regl;
793+
splomGrid = fullLayout._splomGrid;
794+
795+
methods = [
796+
[Plots, 'supplyDefaults'],
797+
[Axes, 'doTicks'],
798+
[regl, 'clear'],
799+
[splomGrid, 'update']
800+
];
801+
addSpies();
802+
803+
expect(fullLayout.xaxis.range).toBeCloseToArray([-0.0921, 0.9574], 1, 'xrng (base)');
804+
805+
return Plotly.relayout(gd, 'xaxis.range', [0, 1]);
806+
})
807+
.then(function() {
808+
var msg = 'after update';
809+
810+
assertSpies(msg, [
811+
['supplyDefaults', 1],
812+
['doTicks', 1],
813+
['regl clear', 1],
814+
['splom grid update', 1],
815+
['splom grid draw', 1],
816+
['splom matrix update', 1],
817+
['splom matrix draw', 1]
818+
]);
819+
820+
expect(gd.layout.xaxis.range).toBeCloseToArray([0, 1], 1, 'xrng ' + msg);
821+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([0, 1], 1, 'xrng ' + msg);
822+
})
823+
.catch(failTest)
824+
.then(done);
825+
});
826+
});
827+
750828
describe('Test splom hover:', function() {
751829
var gd;
752830

0 commit comments

Comments
 (0)