Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68f5dbc

Browse files
committed
fix and test errorbar visibility toggling
1 parent fe7db79 commit 68f5dbc

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/components/errorbars/plot.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ module.exports = function plot(traces, plotinfo, transitionOpts) {
4343
trace.marker.maxdisplayed > 0
4444
);
4545

46-
if(!yObj.visible && !xObj.visible) return;
46+
if(!yObj.visible && !xObj.visible) d = [];
4747

4848
var errorbars = d3.select(this).selectAll('g.errorbar')
4949
.data(d, keyFunc);
5050

5151
errorbars.exit().remove();
5252

53+
if(!d.length) return;
54+
55+
if(!xObj.visible) errorbars.selectAll('path.xerror').remove();
56+
if(!yObj.visible) errorbars.selectAll('path.yerror').remove();
57+
5358
errorbars.style('opacity', 1);
5459

5560
var enter = errorbars.enter().append('g')

test/jasmine/tests/errorbars_test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var Plotly = require('@lib/index');
2+
3+
var d3 = require('d3');
4+
var createGraphDiv = require('../assets/create_graph_div');
5+
var destroyGraphDiv = require('../assets/destroy_graph_div');
6+
var fail = require('../assets/fail_test');
7+
var customMatchers = require('../assets/custom_matchers');
8+
9+
10+
describe('errorbar plotting', function() {
11+
var gd;
12+
13+
beforeEach(function() {
14+
gd = createGraphDiv();
15+
jasmine.addMatchers(customMatchers);
16+
});
17+
18+
afterEach(destroyGraphDiv);
19+
20+
it('should autorange to the visible bars and remove invisible bars', function(done) {
21+
function check(xrange, yrange, xcount, ycount) {
22+
var xa = gd._fullLayout.xaxis;
23+
var ya = gd._fullLayout.yaxis;
24+
expect(xa.range).toBeCloseToArray(xrange, 3);
25+
expect(ya.range).toBeCloseToArray(yrange, 3);
26+
27+
expect(d3.selectAll('.xerror').size()).toBe(xcount);
28+
expect(d3.selectAll('.yerror').size()).toBe(ycount);
29+
}
30+
Plotly.newPlot(gd, [{
31+
y: [1, 2, 3],
32+
error_x: {type: 'constant', value: 0.5},
33+
error_y: {type: 'sqrt'}
34+
}], {
35+
width: 400, height: 400
36+
})
37+
.then(function() {
38+
check([-0.6667, 2.6667], [-0.2629, 4.9949], 3, 3);
39+
return Plotly.restyle(gd, {'error_x.visible': false});
40+
})
41+
.then(function() {
42+
check([-0.1511, 2.1511], [-0.2629, 4.9949], 0, 3);
43+
return Plotly.restyle(gd, {'error_y.visible': false});
44+
})
45+
.then(function() {
46+
check([-0.1511, 2.1511], [0.8451, 3.1549], 0, 0);
47+
return Plotly.restyle(gd, {'error_x.visible': true, 'error_y.visible': true});
48+
})
49+
.then(function() {
50+
check([-0.6667, 2.6667], [-0.2629, 4.9949], 3, 3);
51+
})
52+
.catch(fail)
53+
.then(done);
54+
});
55+
});

0 commit comments

Comments
 (0)