|
| 1 | +var d3 = require('d3'); |
| 2 | + |
| 3 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 4 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 5 | + |
| 6 | +/** |
| 7 | + * common test that components work as registered |
| 8 | + * expects bar, scatter3d, filter, and calendars to be registered |
| 9 | + * but the test is that they may have been registered in any order |
| 10 | + */ |
| 11 | +module.exports = function checkComponent(Plotly) { |
| 12 | + describe('core (svg 2d, scatter) and registered (bar) traces and transforms', function() { |
| 13 | + var gd; |
| 14 | + |
| 15 | + var mock = { |
| 16 | + data: [ |
| 17 | + { |
| 18 | + // x data is date so we coerce a calendar |
| 19 | + x: ['2001-01-01', '2002-01-01', '2003-01-01'], |
| 20 | + y: [1, 3, 5] |
| 21 | + }, |
| 22 | + { |
| 23 | + x: ['2001-01-01', '2002-01-01', '2003-01-01'], |
| 24 | + y: [1, 3, 5], |
| 25 | + type: 'bar', |
| 26 | + transforms: [{ |
| 27 | + type: 'filter', |
| 28 | + operation: '<', |
| 29 | + target: 'y', |
| 30 | + value: '4', |
| 31 | + // need an explicit calendar, as filter uses a default of null |
| 32 | + // the rest of them get the default calendar filled in |
| 33 | + valuecalendar: 'nepali' |
| 34 | + }] |
| 35 | + } |
| 36 | + ] |
| 37 | + }; |
| 38 | + |
| 39 | + beforeEach(function(done) { |
| 40 | + gd = createGraphDiv(); |
| 41 | + Plotly.plot(gd, mock.data, mock.layout).then(done); |
| 42 | + }); |
| 43 | + |
| 44 | + afterEach(destroyGraphDiv); |
| 45 | + |
| 46 | + it('should graph scatter traces with calendar attributes', function() { |
| 47 | + var nodes = d3.selectAll('g.trace.scatter'); |
| 48 | + |
| 49 | + expect(nodes.size()).toEqual(1); |
| 50 | + |
| 51 | + // compare to core_test |
| 52 | + expect(gd._fullLayout.calendar).toBe('gregorian'); |
| 53 | + expect(gd._fullLayout.xaxis.calendar).toBe('gregorian'); |
| 54 | + expect(gd._fullData[0].xcalendar).toBe('gregorian'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should graph bar traces with calendar attributes', function() { |
| 58 | + var nodes = d3.selectAll('g.trace.bars'); |
| 59 | + |
| 60 | + expect(nodes.size()).toEqual(1); |
| 61 | + expect(gd._fullData[1].xcalendar).toBe('gregorian'); |
| 62 | + expect(gd._fullData[1].transforms[0].valuecalendar).toBe('nepali'); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe('registered subplot (gl3d)', function() { |
| 67 | + var gd; |
| 68 | + |
| 69 | + var mock = require('@mocks/gl3d_world-cals'); |
| 70 | + // just pick out the scatter3d trace |
| 71 | + mock.data = [mock.data[1]]; |
| 72 | + var xaxisCalendar = mock.layout.scene.xaxis.calendar; |
| 73 | + var zDataCalendar = mock.data[0].zcalendar; |
| 74 | + |
| 75 | + beforeEach(function(done) { |
| 76 | + gd = createGraphDiv(); |
| 77 | + Plotly.plot(gd, mock.data, mock.layout).then(done); |
| 78 | + }); |
| 79 | + |
| 80 | + afterEach(destroyGraphDiv); |
| 81 | + |
| 82 | + it('should graph gl3d axes and 3d plot types with calendars', function() { |
| 83 | + expect(xaxisCalendar).toBeDefined(); |
| 84 | + expect(zDataCalendar).toBeDefined(); |
| 85 | + |
| 86 | + expect(gd._fullLayout.scene.xaxis.calendar).toBe(xaxisCalendar); |
| 87 | + expect(gd._fullData[0].zcalendar).toBe(zDataCalendar); |
| 88 | + }); |
| 89 | + }); |
| 90 | +}; |
0 commit comments