Skip to content

Commit 7ae7159

Browse files
committed
fix and 🔒 regl-line2d grid data
1 parent 0d5a638 commit 7ae7159

File tree

3 files changed

+93
-41
lines changed

3 files changed

+93
-41
lines changed

src/plot_api/subroutines.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ exports.doLegend = function(gd) {
451451

452452
exports.doTicksRelayout = function(gd) {
453453
Axes.doTicks(gd, 'redraw');
454+
455+
if(gd._fullLayout._hasOnlyLargeSploms) {
456+
Registry.subplotsRegistry.splom.plot(gd);
457+
}
458+
454459
exports.drawMainTitle(gd);
455460
return Plots.previousPromises(gd);
456461
};

src/traces/splom/base_plot.js

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,16 @@ function drawGrid(gd) {
9494
if(!splomGrid) {
9595
splomGrid = fullLayout._splomGrid = createLine(regl);
9696
}
97-
splomGrid.update(makeGridData(gd));
97+
98+
splomGrid._data = makeGridData(gd);
99+
splomGrid.update(splomGrid._data);
98100
splomGrid.draw();
99101
}
100102

101-
// this clocks in at ~30ms at 50x50 - we could perf this up!
102103
function makeGridData(gd) {
103104
var fullLayout = gd._fullLayout;
104105
var gs = fullLayout._size;
105106
var fullView = [0, 0, fullLayout.width, fullLayout.height];
106-
var splomXa = Object.keys(fullLayout._splomAxes.x);
107-
var splomYa = Object.keys(fullLayout._splomAxes.y);
108107
var lookup = {};
109108
var k;
110109

@@ -128,45 +127,39 @@ function makeGridData(gd) {
128127
}
129128
}
130129

131-
for(var i = 0; i < splomXa.length; i++) {
132-
var xa = AxisIDs.getFromId(gd, splomXa[i]);
130+
for(k in fullLayout._splomSubplots) {
131+
var sp = fullLayout._plots[k];
132+
var xa = sp.xaxis;
133+
var ya = sp.yaxis;
133134
var xVals = xa._vals;
134-
var xShowZl = showZeroLine(xa);
135-
136-
for(var j = 0; j < splomYa.length; j++) {
137-
var ya = AxisIDs.getFromId(gd, splomYa[j]);
138-
var yVals = ya._vals;
139-
var yShowZl = showZeroLine(ya);
140-
141-
// ya.l2p assumes top-to-bottom coordinate system (a la SVG),
142-
// we need to compute bottom-to-top offsets and slopes:
143-
var yOffset = gs.b + ya.domain[0] * gs.h;
144-
var ym = -ya._m;
145-
var yb = -ym * ya.r2l(ya.range[0], ya.calendar);
146-
147-
var x, y;
148-
149-
if(xa.showgrid) {
150-
for(k = 0; k < xVals.length; k++) {
151-
x = xa._offset + xa.l2p(xVals[k].x);
152-
push('grid', xa, x, yOffset, x, yOffset + ya._length);
153-
}
154-
}
155-
if(xShowZl) {
156-
x = xa._offset + xa.l2p(0);
157-
push('zeroline', xa, x, yOffset, x, yOffset + ya._length);
158-
}
159-
if(ya.showgrid) {
160-
for(k = 0; k < yVals.length; k++) {
161-
y = yOffset + yb + ym * yVals[k].x;
162-
push('grid', ya, xa._offset, y, xa._offset + xa._length, y);
163-
}
135+
var yVals = ya._vals;
136+
// ya.l2p assumes top-to-bottom coordinate system (a la SVG),
137+
// we need to compute bottom-to-top offsets and slopes:
138+
var yOffset = gs.b + ya.domain[0] * gs.h;
139+
var ym = -ya._m;
140+
var yb = -ym * ya.r2l(ya.range[0], ya.calendar);
141+
var x, y;
142+
143+
if(xa.showgrid) {
144+
for(k = 0; k < xVals.length; k++) {
145+
x = xa._offset + xa.l2p(xVals[k].x);
146+
push('grid', xa, x, yOffset, x, yOffset + ya._length);
164147
}
165-
if(yShowZl) {
166-
y = yOffset + yb + 0;
167-
push('zeroline', ya, xa._offset, y, xa._offset + xa._length, y);
148+
}
149+
if(showZeroLine(xa)) {
150+
x = xa._offset + xa.l2p(0);
151+
push('zeroline', xa, x, yOffset, x, yOffset + ya._length);
152+
}
153+
if(ya.showgrid) {
154+
for(k = 0; k < yVals.length; k++) {
155+
y = yOffset + yb + ym * yVals[k].x;
156+
push('grid', ya, xa._offset, y, xa._offset + xa._length, y);
168157
}
169158
}
159+
if(showZeroLine(ya)) {
160+
y = yOffset + yb + 0;
161+
push('zeroline', ya, xa._offset, y, xa._offset + xa._length, y);
162+
}
170163
}
171164

172165
var gridBatches = [];
@@ -178,7 +171,6 @@ function makeGridData(gd) {
178171
}
179172

180173
// just like in Axes.doTicks but without the loop over traces
181-
// TODO dry this up
182174
function showZeroLine(ax) {
183175
var rng = Lib.simpleMap(ax.range, ax.r2l);
184176
var p0 = ax.l2p(0);

test/jasmine/tests/splom_test.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ describe('@gl Test splom interactions:', function() {
335335
});
336336

337337
it('should destroy gl objects on Plots.cleanPlot', function(done) {
338-
Plotly.plot(gd, Lib.extendDeep({}, require('@mocks/splom_large.json'))).then(function() {
338+
var fig = Lib.extendDeep({}, require('@mocks/splom_large.json'));
339+
340+
Plotly.plot(gd, fig).then(function() {
339341
expect(gd._fullLayout._splomGrid).toBeDefined();
340342
expect(gd.calcdata[0][0].t._scene).toBeDefined();
341343

@@ -349,4 +351,57 @@ describe('@gl Test splom interactions:', function() {
349351
.then(done);
350352
});
351353

354+
it('when hasOnlyLargeSploms, should create correct regl-line2d data for grid', function(done) {
355+
var fig = Lib.extendDeep({}, require('@mocks/splom_large.json'));
356+
var cnt = 1;
357+
358+
function _assert(dims) {
359+
var gridData = gd._fullLayout._splomGrid._data;
360+
var gridLengths = gridData.map(function(d) { return d.data.length; });
361+
var msg = ' - call #' + cnt;
362+
363+
expect(Object.keys(gridData).length)
364+
.toBe(dims.length, '# of batches' + msg);
365+
gridLengths.forEach(function(l, i) {
366+
expect(l).toBe(dims[i], '# of coords in batch ' + i + msg);
367+
});
368+
cnt++;
369+
}
370+
371+
Plotly.plot(gd, fig).then(function() {
372+
_assert([1198, 3478, 16318, 118]);
373+
return Plotly.restyle(gd, 'showupperhalf', false);
374+
})
375+
.then(function() {
376+
_assert([1198, 1882, 8452, 4]);
377+
return Plotly.restyle(gd, 'diagonal.visible', false);
378+
})
379+
.then(function() {
380+
_assert([1138, 1702, 7636, 4]);
381+
return Plotly.restyle(gd, {
382+
showupperhalf: true,
383+
showlowerhalf: false
384+
});
385+
})
386+
.then(function() {
387+
_assert([64, 1594, 7852, 112]);
388+
return Plotly.restyle(gd, 'diagonal.visible', true);
389+
})
390+
.then(function() {
391+
_assert([58, 1768, 8680, 118]);
392+
return Plotly.relayout(gd, {
393+
'xaxis.gridcolor': null,
394+
'xaxis.gridwidth': null,
395+
'yaxis.zerolinecolor': null,
396+
'yaxis.zerolinewidth': null
397+
});
398+
})
399+
.then(function() {
400+
// one batch for all 'grid' lines
401+
// and another for all 'zeroline' lines
402+
_assert([8740, 1888]);
403+
})
404+
.catch(failTest)
405+
.then(done);
406+
});
352407
});

0 commit comments

Comments
 (0)