|
| 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