-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathheatmapgl_test.js
131 lines (112 loc) · 3.79 KB
/
heatmapgl_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
var supplyDefaults = require('@src/traces/heatmapgl').supplyDefaults;
var Plots = require('@src/plots/plots');
var Plotly = require('@lib/index');
var schema = Plotly.PlotSchema.get();
var attributeList = Object.getOwnPropertyNames(schema.traces.heatmapgl.attributes);
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
describe('heatmapgl supplyDefaults', function() {
'use strict';
var traceIn;
var traceOut;
var defaultColor = '#444';
var layout = {
font: Plots.layoutAttributes.font,
_dfltTitle: {colorbar: 'cb'},
_subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']}
};
beforeEach(function() {
traceOut = {};
});
it('should set visible to false when z is empty', function() {
traceIn = {
z: []
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
traceIn = {
z: [[]]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
traceIn = {
z: [[], [], []]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
traceIn = {
type: 'heatmapgl',
z: [[1, 2], []]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
traceIn = {
type: 'heatmapgl',
z: [[], [1, 2], [1, 2, 3]]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
});
it('should set visible to false when z is non-numeric', function() {
traceIn = {
type: 'heatmapgl',
z: [['a', 'b'], ['c', 'd']]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
});
it('should set visible to false when z isn\'t column not a 2d array', function() {
traceIn = {
x: [1, 1, 1, 2, 2],
y: [1, 2, 3, 1, 2],
z: [1, ['this is considered a column'], 1, 2, 3]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).not.toBe(false);
traceIn = {
x: [1, 1, 1, 2, 2],
y: [1, 2, 3, 1, 2],
z: [[0], ['this is not considered a column'], 1, ['nor 2d']]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
});
it('should only coerce attributes that are part of scheme', function() {
traceIn = {
type: 'heatmapgl',
z: [[0, 1], [1, 0]]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
var allKeys = Object.getOwnPropertyNames(traceOut);
allKeys.forEach(function(key) {
if(key[0] !== '_') {
expect(attributeList.indexOf(key)).not.toBe(-1, key);
}
});
});
});
describe('heatmapgl plotting', function() {
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(destroyGraphDiv);
it('can do scaleanchor', function(done) {
var data = [{
z: [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
type: 'heatmapgl',
showscale: false
}];
var layout = {
xaxis: {scaleanchor: 'y'},
width: 500,
height: 300,
margin: {l: 50, r: 50, t: 50, b: 50}
};
Plotly.newPlot(gd, data, layout)
.then(function() {
expect(layout.xaxis.range).toBeCloseToArray([-1, 3], 3);
})
.then(done, done.fail);
});
});