|
1 | 1 | var d3 = require('d3');
|
2 | 2 |
|
3 | 3 | var Plotly = require('@lib/index');
|
| 4 | +var Lib = require('@src/lib'); |
4 | 5 |
|
5 | 6 | var createGraphDiv = require('../assets/create_graph_div');
|
6 | 7 | var destroyGraphDiv = require('../assets/destroy_graph_div');
|
@@ -62,6 +63,101 @@ describe('Test plot structure', function() {
|
62 | 63 | });
|
63 | 64 | });
|
64 | 65 |
|
| 66 | + describe('contour/heatmap traces', function() { |
| 67 | + var mock = require('@mocks/connectgaps_2d.json'); |
| 68 | + |
| 69 | + function extendMock() { |
| 70 | + var mockCopy = Lib.extendDeep(mock); |
| 71 | + |
| 72 | + // add a colorbar for testing |
| 73 | + mockCopy.data[0].showscale = true; |
| 74 | + |
| 75 | + return mockCopy; |
| 76 | + } |
| 77 | + |
| 78 | + describe('initial structure', function() { |
| 79 | + beforeEach(function(done) { |
| 80 | + var mockCopy = extendMock(); |
| 81 | + |
| 82 | + Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout) |
| 83 | + .then(done); |
| 84 | + }); |
| 85 | + |
| 86 | + it('has four *subplot* nodes', function() { |
| 87 | + var nodes = d3.selectAll('g.subplot'); |
| 88 | + expect(nodes.size()).toEqual(4); |
| 89 | + }); |
| 90 | + |
| 91 | + // N.B. the contour traces both have a heatmap fill |
| 92 | + it('has four heatmap image nodes', function() { |
| 93 | + var hmNodes = d3.selectAll('g.hm'); |
| 94 | + expect(hmNodes.size()).toEqual(4); |
| 95 | + |
| 96 | + var imageNodes = d3.selectAll('image'); |
| 97 | + expect(imageNodes.size()).toEqual(4); |
| 98 | + }); |
| 99 | + |
| 100 | + it('has two contour nodes', function() { |
| 101 | + var nodes = d3.selectAll('g.contour'); |
| 102 | + expect(nodes.size()).toEqual(2); |
| 103 | + }); |
| 104 | + |
| 105 | + it('has one colorbar nodes', function() { |
| 106 | + var nodes = d3.selectAll('rect.cbbg'); |
| 107 | + expect(nodes.size()).toEqual(1); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + describe('structure after restyle', function() { |
| 112 | + beforeEach(function(done) { |
| 113 | + var mockCopy = extendMock(); |
| 114 | + var gd = createGraphDiv(); |
| 115 | + |
| 116 | + Plotly.plot(gd, mockCopy.data, mockCopy.layout); |
| 117 | + |
| 118 | + Plotly.restyle(gd, { |
| 119 | + type: 'scatter', |
| 120 | + x: [[1, 2, 3]], |
| 121 | + y: [[2, 1, 2]], |
| 122 | + z: null |
| 123 | + }, 0); |
| 124 | + |
| 125 | + Plotly.restyle(gd, 'type', 'contour', 1); |
| 126 | + |
| 127 | + Plotly.restyle(gd, 'type', 'heatmap', 2) |
| 128 | + .then(done); |
| 129 | + }); |
| 130 | + |
| 131 | + it('has four *subplot* nodes', function() { |
| 132 | + var nodes = d3.selectAll('g.subplot'); |
| 133 | + expect(nodes.size()).toEqual(4); |
| 134 | + }); |
| 135 | + |
| 136 | + it('has two heatmap image nodes', function() { |
| 137 | + var hmNodes = d3.selectAll('g.hm'); |
| 138 | + expect(hmNodes.size()).toEqual(2); |
| 139 | + |
| 140 | + var imageNodes = d3.selectAll('image'); |
| 141 | + expect(imageNodes.size()).toEqual(2); |
| 142 | + }); |
| 143 | + |
| 144 | + it('has two contour nodes', function() { |
| 145 | + var nodes = d3.selectAll('g.contour'); |
| 146 | + expect(nodes.size()).toEqual(2); |
| 147 | + }); |
| 148 | + |
| 149 | + it('has one scatter node', function() { |
| 150 | + var nodes = d3.selectAll('g.trace.scatter'); |
| 151 | + expect(nodes.size()).toEqual(1); |
| 152 | + }); |
| 153 | + |
| 154 | + it('has no colorbar node', function() { |
| 155 | + var nodes = d3.selectAll('rect.cbbg'); |
| 156 | + expect(nodes.size()).toEqual(0); |
| 157 | + }); |
| 158 | + }); |
| 159 | + }); |
| 160 | + |
65 | 161 | describe('pie traces', function() {
|
66 | 162 | var mock = require('@mocks/pie_simple.json');
|
67 | 163 |
|
|
0 commit comments