|
| 1 | +var Plotly = require('@lib'); |
| 2 | +var Lib = require('@src/lib'); |
| 3 | + |
| 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 mouseEvent = require('../assets/mouse_event'); |
| 8 | + |
| 9 | +var customAssertions = require('../assets/custom_assertions'); |
| 10 | +var assertHoverLabelContent = customAssertions.assertHoverLabelContent; |
| 11 | + |
| 12 | +describe('Test scatterpolargl hover:', function() { |
| 13 | + var gd; |
| 14 | + |
| 15 | + afterEach(function() { |
| 16 | + Plotly.purge(gd); |
| 17 | + destroyGraphDiv(); |
| 18 | + }); |
| 19 | + |
| 20 | + function run(specs) { |
| 21 | + gd = createGraphDiv(); |
| 22 | + |
| 23 | + var fig = Lib.extendDeep( |
| 24 | + {width: 700, height: 500}, |
| 25 | + specs.mock || require('@mocks/glpolar_scatter.json') |
| 26 | + ); |
| 27 | + |
| 28 | + if(specs.patch) { |
| 29 | + fig = specs.patch(fig); |
| 30 | + } |
| 31 | + |
| 32 | + var pos = specs.pos || [200, 200]; |
| 33 | + |
| 34 | + return Plotly.newPlot(gd, fig).then(function() { |
| 35 | + mouseEvent('mousemove', pos[0], pos[1]); |
| 36 | + assertHoverLabelContent(specs); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + [{ |
| 41 | + desc: 'base', |
| 42 | + nums: 'r: 2.920135\nθ: 138.2489°', |
| 43 | + name: 'Trial 4' |
| 44 | + }, { |
| 45 | + desc: '(no labels - out of sector)', |
| 46 | + patch: function(fig) { |
| 47 | + fig.layout.polar.sector = [15, 75]; |
| 48 | + return fig; |
| 49 | + }, |
| 50 | + pos: [144, 350], |
| 51 | + nums: '', |
| 52 | + name: '' |
| 53 | + }, { |
| 54 | + desc: 'on a `thetaunit: radians` polar subplot', |
| 55 | + patch: function(fig) { |
| 56 | + fig.layout.polar.angularaxis.thetaunit = 'radians'; |
| 57 | + return fig; |
| 58 | + }, |
| 59 | + nums: 'r: 2.920135\nθ: 2.412898', |
| 60 | + name: 'Trial 4' |
| 61 | + }, { |
| 62 | + desc: 'on log radial axis', |
| 63 | + patch: function(fig) { |
| 64 | + fig.layout.polar.radialaxis.type = 'log'; |
| 65 | + return fig; |
| 66 | + }, |
| 67 | + nums: 'r: 1.108937\nθ: 115.4969°', |
| 68 | + name: 'Trial 3' |
| 69 | + }, { |
| 70 | + desc: 'on category axes', |
| 71 | + mock: require('@mocks/polar_categories.json'), |
| 72 | + patch: function(fig) { |
| 73 | + fig.data.forEach(function(t) { |
| 74 | + t.type = 'scatterpolargl'; |
| 75 | + t.fill = 'none'; |
| 76 | + }); |
| 77 | + return fig; |
| 78 | + }, |
| 79 | + pos: [470, 80], |
| 80 | + nums: 'r: 4\nθ: d', |
| 81 | + name: 'angular cate...' |
| 82 | + }] |
| 83 | + .forEach(function(specs) { |
| 84 | + it('should generate correct hover labels ' + specs.desc, function(done) { |
| 85 | + run(specs).catch(fail).then(done); |
| 86 | + }); |
| 87 | + }); |
| 88 | +}); |
0 commit comments