|
1 |
| -var Fx = require('@src/plots/cartesian/graph_interact'); |
| 1 | +var Plotly = require('@lib/index'); |
2 | 2 | var Plots = require('@src/plots/plots');
|
3 | 3 |
|
| 4 | +var Fx = require('@src/plots/cartesian/graph_interact'); |
| 5 | + |
| 6 | +var d3 = require('d3'); |
| 7 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 8 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 9 | + |
| 10 | + |
| 11 | +describe('Fx defaults', function() { |
| 12 | + 'use strict'; |
| 13 | + |
| 14 | + var layoutIn, layoutOut, fullData; |
| 15 | + |
| 16 | + beforeEach(function() { |
| 17 | + layoutIn = {}; |
| 18 | + layoutOut = { |
| 19 | + _has: Plots._hasPlotType |
| 20 | + }; |
| 21 | + fullData = [{}]; |
| 22 | + }); |
| 23 | + |
| 24 | + it('should default (blank version)', function() { |
| 25 | + Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
| 26 | + expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); |
| 27 | + expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should default (cartesian version)', function() { |
| 31 | + layoutOut._basePlotModules = [{ name: 'cartesian' }]; |
| 32 | + |
| 33 | + Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
| 34 | + expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); |
| 35 | + expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
| 36 | + expect(layoutOut._isHoriz).toBe(false, 'isHoriz to false'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should default (cartesian horizontal version)', function() { |
| 40 | + layoutOut._basePlotModules = [{ name: 'cartesian' }]; |
| 41 | + fullData[0] = { orientation: 'h' }; |
| 42 | + |
| 43 | + Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
| 44 | + expect(layoutOut.hovermode).toBe('y', 'hovermode to y'); |
| 45 | + expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
| 46 | + expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should default (gl3d version)', function() { |
| 50 | + layoutOut._basePlotModules = [{ name: 'gl3d' }]; |
| 51 | + |
| 52 | + Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
| 53 | + expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); |
| 54 | + expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should default (geo version)', function() { |
| 58 | + layoutOut._basePlotModules = [{ name: 'geo' }]; |
4 | 59 |
|
5 |
| -describe('Test FX', function() { |
| 60 | + Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
| 61 | + expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); |
| 62 | + expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should default (multi plot type version)', function() { |
| 66 | + layoutOut._basePlotModules = [{ name: 'cartesian' }, { name: 'gl3d' }]; |
| 67 | + |
| 68 | + Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
| 69 | + expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); |
| 70 | + expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
| 71 | + }); |
| 72 | +}); |
| 73 | + |
| 74 | +describe('relayout', function() { |
6 | 75 | 'use strict';
|
7 | 76 |
|
8 |
| - describe('defaults', function() { |
9 |
| - |
10 |
| - var layoutIn, layoutOut, fullData; |
11 |
| - |
12 |
| - beforeEach(function() { |
13 |
| - layoutIn = {}; |
14 |
| - layoutOut = { |
15 |
| - _has: Plots._hasPlotType |
16 |
| - }; |
17 |
| - fullData = [{}]; |
18 |
| - }); |
19 |
| - |
20 |
| - it('should default (blank version)', function() { |
21 |
| - Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
22 |
| - expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); |
23 |
| - expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
24 |
| - }); |
25 |
| - |
26 |
| - it('should default (cartesian version)', function() { |
27 |
| - layoutOut._basePlotModules = [{ name: 'cartesian' }]; |
28 |
| - |
29 |
| - Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
30 |
| - expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); |
31 |
| - expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
32 |
| - expect(layoutOut._isHoriz).toBe(false, 'isHoriz to false'); |
33 |
| - }); |
34 |
| - |
35 |
| - it('should default (cartesian horizontal version)', function() { |
36 |
| - layoutOut._basePlotModules = [{ name: 'cartesian' }]; |
37 |
| - fullData[0] = { orientation: 'h' }; |
38 |
| - |
39 |
| - Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
40 |
| - expect(layoutOut.hovermode).toBe('y', 'hovermode to y'); |
41 |
| - expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
42 |
| - expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true'); |
43 |
| - }); |
44 |
| - |
45 |
| - it('should default (gl3d version)', function() { |
46 |
| - layoutOut._basePlotModules = [{ name: 'gl3d' }]; |
47 |
| - |
48 |
| - Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
49 |
| - expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); |
50 |
| - expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
51 |
| - }); |
52 |
| - |
53 |
| - it('should default (geo version)', function() { |
54 |
| - layoutOut._basePlotModules = [{ name: 'geo' }]; |
55 |
| - |
56 |
| - Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
57 |
| - expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest'); |
58 |
| - expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
59 |
| - }); |
60 |
| - |
61 |
| - it('should default (multi plot type version)', function() { |
62 |
| - layoutOut._basePlotModules = [{ name: 'cartesian' }, { name: 'gl3d' }]; |
63 |
| - |
64 |
| - Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData); |
65 |
| - expect(layoutOut.hovermode).toBe('x', 'hovermode to x'); |
66 |
| - expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom'); |
67 |
| - }); |
| 77 | + var gd; |
| 78 | + |
| 79 | + beforeEach(function() { |
| 80 | + gd = createGraphDiv(); |
| 81 | + }); |
| 82 | + |
| 83 | + afterEach(destroyGraphDiv); |
| 84 | + |
| 85 | + it('should update main drag with correct', function(done) { |
| 86 | + |
| 87 | + function assertMainDrag(cursor, isActive) { |
| 88 | + expect(d3.selectAll('rect.nsewdrag').size()).toEqual(1, 'number of nodes'); |
| 89 | + var mainDrag = d3.select('rect.nsewdrag'), |
| 90 | + node = mainDrag.node(); |
| 91 | + |
| 92 | + expect(mainDrag.classed('cursor-' + cursor)).toBe(true, 'cursor ' + cursor); |
| 93 | + expect(mainDrag.style('pointer-events')).toEqual('all', 'pointer event'); |
| 94 | + expect(!!node.onmousedown).toBe(isActive, 'mousedown handler'); |
| 95 | + } |
| 96 | + |
| 97 | + Plotly.plot(gd, [{ |
| 98 | + y: [2, 1, 2] |
| 99 | + }]).then(function() { |
| 100 | + assertMainDrag('crosshair', true); |
| 101 | + |
| 102 | + return Plotly.relayout(gd, 'dragmode', 'pan'); |
| 103 | + }).then(function() { |
| 104 | + assertMainDrag('move', true); |
| 105 | + |
| 106 | + return Plotly.relayout(gd, 'dragmode', 'drag'); |
| 107 | + }).then(function() { |
| 108 | + assertMainDrag('crosshair', true); |
| 109 | + |
| 110 | + return Plotly.relayout(gd, 'xaxis.fixedrange', true); |
| 111 | + }).then(function() { |
| 112 | + assertMainDrag('ns-resize', true); |
| 113 | + |
| 114 | + return Plotly.relayout(gd, 'yaxis.fixedrange', true); |
| 115 | + }).then(function() { |
| 116 | + assertMainDrag('pointer', false); |
| 117 | + |
| 118 | + return Plotly.relayout(gd, 'dragmode', 'drag'); |
| 119 | + }).then(function() { |
| 120 | + assertMainDrag('pointer', false); |
| 121 | + |
| 122 | + return Plotly.relayout(gd, 'dragmode', 'lasso'); |
| 123 | + }).then(function() { |
| 124 | + assertMainDrag('pointer', true); |
| 125 | + |
| 126 | + return Plotly.relayout(gd, 'dragmode', 'select'); |
| 127 | + }).then(function() { |
| 128 | + assertMainDrag('pointer', true); |
| 129 | + |
| 130 | + return Plotly.relayout(gd, 'xaxis.fixedrange', false); |
| 131 | + }).then(function() { |
| 132 | + assertMainDrag('ew-resize', true); |
| 133 | + }).then(done); |
68 | 134 | });
|
69 | 135 | });
|
0 commit comments