Skip to content

Commit 2d5cc0d

Browse files
committed
use shouldShowZeroLine for splom regl grids
- lock down showline/zeroline behavior - draw zeroline above grid lines - adapt regl grid test values
1 parent c1fb32d commit 2d5cc0d

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

src/traces/splom/base_plot.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
var createLine = require('regl-line2d');
1212

1313
var Registry = require('../../registry');
14-
var Lib = require('../../lib');
1514
var prepareRegl = require('../../lib/prepare_regl');
1615
var getModuleCalcData = require('../../plots/get_data').getModuleCalcData;
1716
var Cartesian = require('../../plots/cartesian');
18-
var AxisIDs = require('../../plots/cartesian/axis_ids');
17+
var getFromId = require('../../plots/cartesian/axis_ids').getFromId;
18+
var shouldShowZeroLine = require('../../plots/cartesian/axes').shouldShowZeroLine;
1919

2020
var SPLOM = 'splom';
2121

@@ -63,13 +63,13 @@ function dragOne(gd, trace, stash, scene) {
6363
var i = visibleDims[k];
6464
var rng = ranges[k] = new Array(4);
6565

66-
var xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
66+
var xa = getFromId(gd, trace._diag[i][0]);
6767
if(xa) {
6868
rng[0] = xa.r2l(xa.range[0]);
6969
rng[2] = xa.r2l(xa.range[1]);
7070
}
7171

72-
var ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
72+
var ya = getFromId(gd, trace._diag[i][1]);
7373
if(ya) {
7474
rng[1] = ya.r2l(ya.range[0]);
7575
rng[3] = ya.r2l(ya.range[1]);
@@ -144,17 +144,17 @@ function makeGridData(gd) {
144144
push('grid', xa, x, yOffset, x, yOffset + ya._length);
145145
}
146146
}
147-
if(showZeroLine(xa)) {
148-
x = xa._offset + xa.l2p(0);
149-
push('zeroline', xa, x, yOffset, x, yOffset + ya._length);
150-
}
151147
if(ya.showgrid) {
152148
for(k = 0; k < yVals.length; k++) {
153149
y = yOffset + yb + ym * yVals[k].x;
154150
push('grid', ya, xa._offset, y, xa._offset + xa._length, y);
155151
}
156152
}
157-
if(showZeroLine(ya)) {
153+
if(shouldShowZeroLine(gd, xa, ya)) {
154+
x = xa._offset + xa.l2p(0);
155+
push('zeroline', xa, x, yOffset, x, yOffset + ya._length);
156+
}
157+
if(shouldShowZeroLine(gd, ya, xa)) {
158158
y = yOffset + yb + 0;
159159
push('zeroline', ya, xa._offset, y, xa._offset + xa._length, y);
160160
}
@@ -168,20 +168,6 @@ function makeGridData(gd) {
168168
return gridBatches;
169169
}
170170

171-
// just like in Axes.doTicks but without the loop over traces
172-
function showZeroLine(ax) {
173-
var rng = Lib.simpleMap(ax.range, ax.r2l);
174-
var p0 = ax.l2p(0);
175-
176-
return (
177-
ax.zeroline &&
178-
ax._vals && ax._vals.length &&
179-
(rng[0] * rng[1] <= 0) &&
180-
(ax.type === 'linear' || ax.type === '-') &&
181-
((p0 > 1 && p0 < ax._length - 1) || !ax.showline)
182-
);
183-
}
184-
185171
function clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata) {
186172
var oldModules = oldFullLayout._modules || [];
187173
var newModules = newFullLayout._modules || [];

test/image/baselines/splom_large.png

19.3 KB
Loading

test/image/mocks/splom_large.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@
297297
"yaxis": {
298298
"zerolinecolor": "red",
299299
"zerolinewidth": 2
300+
},
301+
"xaxis2": {
302+
"zeroline": false
303+
},
304+
"yaxis2": {
305+
"rangemode": "tozero",
306+
"zeroline": true,
307+
"showline": true
300308
}
301309
}
302310
}

test/jasmine/tests/splom_test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,26 +478,26 @@ describe('Test splom interactions:', function() {
478478
}
479479

480480
Plotly.plot(gd, fig).then(function() {
481-
_assert([1198, 3478, 16318, 118]);
481+
_assert([1198, 16678, 3358, 118]);
482482
return Plotly.restyle(gd, 'showupperhalf', false);
483483
})
484484
.then(function() {
485-
_assert([1198, 1882, 8452, 4]);
485+
_assert([1198, 8488, 1768, 4]);
486486
return Plotly.restyle(gd, 'diagonal.visible', false);
487487
})
488488
.then(function() {
489-
_assert([1138, 1702, 7636, 4]);
489+
_assert([1138, 7636, 1594, 4]);
490490
return Plotly.restyle(gd, {
491491
showupperhalf: true,
492492
showlowerhalf: false
493493
});
494494
})
495495
.then(function() {
496-
_assert([64, 1594, 7852, 112]);
496+
_assert([64, 8176, 1582, 112]);
497497
return Plotly.restyle(gd, 'diagonal.visible', true);
498498
})
499499
.then(function() {
500-
_assert([58, 1768, 8680, 118]);
500+
_assert([58, 9022, 1756, 118]);
501501
return Plotly.relayout(gd, {
502502
'xaxis.gridcolor': null,
503503
'xaxis.gridwidth': null,
@@ -508,7 +508,7 @@ describe('Test splom interactions:', function() {
508508
.then(function() {
509509
// one batch for all 'grid' lines
510510
// and another for all 'zeroline' lines
511-
_assert([8740, 1888]);
511+
_assert([9082, 1876]);
512512
})
513513
.catch(failTest)
514514
.then(done);

0 commit comments

Comments
 (0)