Skip to content

Commit 4bb3d40

Browse files
committed
fix #2410 - show/hide axis lines
1 parent 36b8483 commit 4bb3d40

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/plot_api/subroutines.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ exports.lsInner = function(gd) {
272272
* -----
273273
* x2
274274
*/
275+
var xPath = 'M0,0';
275276
if(shouldShowLinesOrTicks(xa, subplot)) {
276277
leftYLineWidth = findCounterAxisLineWidth(xa, 'left', ya, axList);
277278
xLinesXLeft = xa._offset - (leftYLineWidth ? (pad + leftYLineWidth) : 0);
@@ -288,17 +289,17 @@ exports.lsInner = function(gd) {
288289
xa._linepositions[subplot] = [xLinesYBottom, xLinesYTop];
289290
}
290291

291-
var xPath = mainPath(xa, xLinePath, xLinePathFree);
292+
xPath = mainPath(xa, xLinePath, xLinePathFree);
292293
if(extraSubplot && xa.showline && (xa.mirror === 'all' || xa.mirror === 'allticks')) {
293294
xPath += xLinePath(xLinesYBottom) + xLinePath(xLinesYTop);
294295
}
295296

296297
plotinfo.xlines
297-
.attr('d', xPath || 'M0,0')
298298
.style('stroke-width', xa._lw + 'px')
299299
.call(Color.stroke, xa.showline ?
300300
xa.linecolor : 'rgba(0,0,0,0)');
301301
}
302+
plotinfo.xlines.attr('d', xPath);
302303

303304
/*
304305
* y lines that meet x axes get longer only by margin.pad, because
@@ -311,6 +312,7 @@ exports.lsInner = function(gd) {
311312
* |
312313
* +-----
313314
*/
315+
var yPath = 'M0,0';
314316
if(shouldShowLinesOrTicks(ya, subplot)) {
315317
connectYBottom = findCounterAxisLineWidth(ya, 'bottom', xa, axList);
316318
yLinesYBottom = ya._offset + ya._length + (connectYBottom ? pad : 0);
@@ -324,17 +326,17 @@ exports.lsInner = function(gd) {
324326
ya._linepositions[subplot] = [yLinesXLeft, yLinesXRight];
325327
}
326328

327-
var yPath = mainPath(ya, yLinePath, yLinePathFree);
329+
yPath = mainPath(ya, yLinePath, yLinePathFree);
328330
if(extraSubplot && ya.showline && (ya.mirror === 'all' || ya.mirror === 'allticks')) {
329331
yPath += yLinePath(yLinesXLeft) + yLinePath(yLinesXRight);
330332
}
331333

332334
plotinfo.ylines
333-
.attr('d', yPath || 'M0,0')
334335
.style('stroke-width', ya._lw + 'px')
335336
.call(Color.stroke, ya.showline ?
336337
ya.linecolor : 'rgba(0,0,0,0)');
337338
}
339+
plotinfo.ylines.attr('d', yPath);
338340
});
339341

340342
Plotly.Axes.makeClipPaths(gd);

test/jasmine/tests/cartesian_test.js

+31
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,37 @@ describe('relayout', function() {
268268

269269
});
270270

271+
describe('axis line visibility', function() {
272+
var gd;
273+
274+
beforeEach(function() {
275+
gd = createGraphDiv();
276+
});
277+
278+
afterEach(destroyGraphDiv);
279+
280+
it('can show and hide axis lines', function(done) {
281+
Plotly.newPlot(gd, [{y: [1, 2]}], {width: 400, height: 400})
282+
.then(function() {
283+
expect(gd.querySelector('.xlines-above').attributes.d.value).toBe('M0,0');
284+
expect(gd.querySelector('.ylines-above').attributes.d.value).toBe('M0,0');
285+
286+
return Plotly.relayout(gd, {'xaxis.showline': true, 'yaxis.showline': true});
287+
})
288+
.then(function() {
289+
expect(gd.querySelector('.xlines-above').attributes.d.value).not.toBe('M0,0');
290+
expect(gd.querySelector('.ylines-above').attributes.d.value).not.toBe('M0,0');
291+
292+
return Plotly.relayout(gd, {'xaxis.showline': false, 'yaxis.showline': false});
293+
})
294+
.then(function() {
295+
expect(gd.querySelector('.xlines-above').attributes.d.value).toBe('M0,0');
296+
expect(gd.querySelector('.ylines-above').attributes.d.value).toBe('M0,0');
297+
})
298+
.catch(failTest)
299+
.then(done);
300+
});
301+
});
271302
});
272303

273304
describe('subplot creation / deletion:', function() {

0 commit comments

Comments
 (0)