-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtable_test.js
146 lines (129 loc) · 5.07 KB
/
table_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var Plotly = require('@lib');
var Lib = require('@src/lib');
var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
describe('table plots', function() {
'use strict';
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(destroyGraphDiv);
function initialize(mock, gd) {
return Plotly.plot(gd, mock.data, mock.layout);
}
function countCells() {
return d3.selectAll('.cell-rect').size();
}
it('should be able switch to table trace from another plot type', function(done) {
var mock = {
data: [
{
mode: 'markers',
type: 'scatter'
}
],
layout: {
hovermode: 'closest'
}
};
initialize(mock, gd)
.then(function() {
return Plotly.restyle(gd, {type: 'table'})
.then(function() {
return Plotly.restyle(
gd, {'header.values[0]': ['First Column']}
);
})
.then(function() {
return Plotly.restyle(
gd, {'header.values[1]': ['Second Column']}
);
})
.then(function() {
return Plotly.restyle(gd,
{
'cells.values': [
['First Row First Col', 'First Row Second Col'],
['Second Row First Col', 'Second Row Second Col']
]
}
);
});
})
.then(function() {
expect(gd.data[0].type).toBe('table');
expect(countCells()).toBe(6);
})
.then(done);
});
it('should be able to use Plotly.restyle on an existing table', function(done) {
var mock = Lib.extendDeep({}, require('@mocks/table_plain_birds.json'));
var newColors = ['yellow', 'gray'];
initialize(mock, gd)
.then(function() {
return Plotly.restyle(gd, {'cells.fill': newColors})
.then(function() {
Plotly.restyle(gd, {'header.font.size': 20});
});
})
.then(function() {
expect(gd.data[0].cells[0]).toBe('yellow');
expect(gd.data[0].cells[1]).toBe('gray');
expect(gd.data[0].header.font.size).toBe(20);
})
.then(done);
});
it('should work with Plotly.restyle for a specific trace index', function(done) {
var mock = Lib.extendDeep({}, require('@mocks/table_latex_multitrace.json'));
var initialFontSizeFirstTrace;
var initialFontSizeSecondTrace;
initialize(mock, gd)
.then(function() {
initialFontSizeFirstTrace = gd.data[0].header.font.size;
initialFontSizeSecondTrace = gd.data[1].header.font.size;
expect(initialFontSizeFirstTrace === initialFontSizeSecondTrace).toBe(true);
return Plotly.restyle(gd, {'header.font.size': initialFontSizeFirstTrace + 1}, 0)
.then(function() {
Plotly.restyle(gd, {'header.font.size': initialFontSizeSecondTrace + 2}, 1);
});
})
.then(function() {
expect(gd.data[0].header.font.size).toBe(initialFontSizeFirstTrace + 1);
expect(gd.data[1].header.font.size).toBe(initialFontSizeFirstTrace + 2);
expect(initialFontSizeFirstTrace !== initialFontSizeSecondTrace).toBe(true);
})
.then(done);
});
it('should work with Plotly.relayout', function(done) {
var mock = Lib.extendDeep({}, require('@mocks/table_latex_multitrace.json'));
var newTitle = 'New Title';
initialize(mock, gd)
.then(function() {
return Plotly.relayout(gd, {'title': newTitle});
})
.then(function() {
expect(gd.layout.title).toBe(newTitle);
})
.then(done);
});
it('should work with Plotly.update', function(done) {
var mock = Lib.extendDeep({}, require('@mocks/table_plain_birds.json'));
var newTitle = 'New Title';
var initialFontSize;
initialize(mock, gd)
.then(function() {
initialFontSize = gd.data[0].header.font.size;
return Plotly.update(gd,
{'header.font.size': initialFontSize + 1},
{'title': newTitle}
);
})
.then(function() {
expect(gd.layout.title).toBe(newTitle);
expect(gd.data[0].header.font.size).toBe(initialFontSize + 1);
})
.then(done);
});
});