Skip to content

Commit

Permalink
speed up 'axrange' edits
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
etpinard committed Sep 28, 2018
1 parent 73acd7e commit cc5f0ca
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1738,8 +1738,8 @@ function addAxRangeSequence(seq, rangesAltered) {
// subroutine of its own so that finalDraw always gets
// executed after drawData
var doTicks = rangesAltered ?
function(gd) { return subroutines.doTicksRelayout(gd, rangesAltered); } :
subroutines.doTicksRelayout;
function(gd) { return Axes.doTicks(gd, Object.keys(rangesAltered), true); } :
function(gd) { return Axes.doTicks(gd, 'redraw'); };

seq.push(
subroutines.doAutoRangeAndConstraints,
Expand Down
8 changes: 2 additions & 6 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,8 @@ exports.doLegend = function(gd) {
return Plots.previousPromises(gd);
};

exports.doTicksRelayout = function(gd, rangesAltered) {
if(rangesAltered) {
Axes.doTicks(gd, Object.keys(rangesAltered), true);
} else {
Axes.doTicks(gd, 'redraw');
}
exports.doTicksRelayout = function(gd) {
Axes.doTicks(gd, 'redraw');

if(gd._fullLayout._hasOnlyLargeSploms) {
clearGlCanvases(gd);
Expand Down
12 changes: 10 additions & 2 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Queue = require('@src/lib/queue');
var Scatter = require('@src/traces/scatter');
var Bar = require('@src/traces/bar');
var Legend = require('@src/components/legend');
var Axes = require('@src/plots/cartesian/axes');
var pkg = require('../../../package.json');
var subroutines = require('@src/plot_api/subroutines');
var helpers = require('@src/plot_api/helpers');
Expand Down Expand Up @@ -531,12 +532,14 @@ describe('Test plot api', function() {
mockedMethods.forEach(function(m) {
spyOn(subroutines, m);
});
spyOn(Axes, 'doTicks');
});

function mock(gd) {
mockedMethods.forEach(function(m) {
subroutines[m].calls.reset();
});
Axes.doTicks.calls.reset();

supplyAllDefaults(gd);
Plots.doCalcdata(gd);
Expand Down Expand Up @@ -634,7 +637,7 @@ describe('Test plot api', function() {
});

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

function _assert(msg) {
expect(gd.calcdata).toBeDefined();
Expand All @@ -644,6 +647,9 @@ describe('Test plot api', function() {
'# of ' + m + ' calls - ' + msg
);
});
expect(Axes.doTicks).toHaveBeenCalledTimes(1);
expect(Axes.doTicks.calls.allArgs()[0][1]).toEqual(['x']);
expect(Axes.doTicks.calls.allArgs()[0][2]).toBe(true, 'skip-axis-title argument');
}

var specs = [
Expand Down Expand Up @@ -2588,6 +2594,7 @@ describe('Test plot api', function() {
spyOn(annotations, 'drawOne').and.callThrough();
spyOn(annotations, 'draw').and.callThrough();
spyOn(images, 'draw').and.callThrough();
spyOn(Axes, 'doTicks').and.callThrough();
});

afterEach(destroyGraphDiv);
Expand Down Expand Up @@ -2823,10 +2830,11 @@ describe('Test plot api', function() {
Plotly.newPlot(gd, data, layout)
.then(countPlots)
.then(function() {
expect(Axes.doTicks).toHaveBeenCalledWith(gd, '');
return Plotly.react(gd, data, layout2);
})
.then(function() {
expect(subroutines.doTicksRelayout).toHaveBeenCalledTimes(1);
expect(Axes.doTicks).toHaveBeenCalledWith(gd, 'redraw');
expect(subroutines.layoutStyles).not.toHaveBeenCalled();
})
.catch(failTest)
Expand Down
78 changes: 78 additions & 0 deletions test/jasmine/tests/splom_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Plotly = require('@lib');
var Lib = require('@src/lib');
var Plots = require('@src/plots/plots');
var Axes = require('@src/plots/cartesian/axes');
var SUBPLOT_PATTERN = require('@src/plots/cartesian/constants').SUBPLOT_PATTERN;

var d3 = require('d3');
Expand Down Expand Up @@ -747,6 +748,83 @@ describe('Test splom interactions:', function() {
});
});

describe('Test splom update switchboard:', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});

var methods;

function addSpies() {
methods.forEach(function(m) {
var obj = m[0];
var k = m[1];
spyOn(obj, k).and.callThrough();
});
}

function assertSpies(msg, exp) {
methods.forEach(function(m, i) {
var obj = m[0];
var k = m[1];
var expi = exp[i];
expect(obj[k]).toHaveBeenCalledTimes(expi[1], expi[0]);
obj[k].calls.reset();
});
}

it('@gl should trigger minimal sequence for axis range updates (large splom case)', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/splom_large.json'));
var matrix, regl, splomGrid;

Plotly.plot(gd, fig).then(function() {
var fullLayout = gd._fullLayout;
var trace = gd._fullData[0];
var scene = fullLayout._splomScenes[trace.uid];
matrix = scene.matrix;
regl = matrix.regl;
splomGrid = fullLayout._splomGrid;

methods = [
[Plots, 'supplyDefaults'],
[Axes, 'doTicks'],
[regl, 'clear'],
[splomGrid, 'update']
];
addSpies();

expect(fullLayout.xaxis.range).toBeCloseToArray([-0.0921, 0.9574], 1, 'xrng (base)');

return Plotly.relayout(gd, 'xaxis.range', [0, 1]);
})
.then(function() {
var msg = 'after update';

assertSpies(msg, [
['supplyDefaults', 1],
['doTicks', 1],
['regl clear', 1],
['splom grid update', 1],
['splom grid draw', 1],
['splom matrix update', 1],
['splom matrix draw', 1]
]);

expect(gd.layout.xaxis.range).toBeCloseToArray([0, 1], 1, 'xrng ' + msg);
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([0, 1], 1, 'xrng ' + msg);
})
.catch(failTest)
.then(done);
});
});

describe('Test splom hover:', function() {
var gd;

Expand Down

0 comments on commit cc5f0ca

Please sign in to comment.