Skip to content

Commit cb108dc

Browse files
committed
add calc test for heatmap and contour
1 parent b913a5b commit cb108dc

File tree

2 files changed

+216
-1
lines changed

2 files changed

+216
-1
lines changed

test/jasmine/tests/contour_test.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
var Plots = require('@src/plots/plots');
2+
var Lib = require('@src/lib');
3+
24
var Contour = require('@src/traces/contour');
35
var makeColorMap = require('@src/traces/contour/make_color_map');
46
var colorScales = require('@src/components/colorscale/scales');
57

8+
var customMatchers = require('../assets/custom_matchers');
9+
10+
611
describe('contour defaults', function() {
712
'use strict';
813

@@ -132,3 +137,106 @@ describe('contour makeColorMap', function() {
132137
]);
133138
});
134139
});
140+
141+
describe('contour calc', function() {
142+
'use strict';
143+
144+
beforeAll(function() {
145+
jasmine.addMatchers(customMatchers);
146+
});
147+
148+
function _calc(trace) {
149+
var base = { type: 'contour' },
150+
trace = Lib.extendFlat({}, base, trace),
151+
gd = { data: [trace] };
152+
153+
Plots.supplyDefaults(gd);
154+
var fullTrace = gd._fullData[0];
155+
156+
return Contour.calc(gd, fullTrace)[0];
157+
}
158+
159+
it('should fill in bricks if x/y not given', function() {
160+
var out = _calc({
161+
z: [[1, 2, 3], [3, 1, 2]]
162+
});
163+
164+
expect(out.x).toBeCloseToArray([0, 1, 2]);
165+
expect(out.y).toBeCloseToArray([0, 1]);
166+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
167+
});
168+
169+
it('should fill in bricks with x0/dx + y0/dy', function() {
170+
var out = _calc({
171+
z: [[1, 2, 3], [3, 1, 2]],
172+
x0: 10,
173+
dx: 0.5,
174+
y0: -2,
175+
dy: -2
176+
});
177+
178+
expect(out.x).toBeCloseToArray([10, 10.5, 11]);
179+
expect(out.y).toBeCloseToArray([-2, -4]);
180+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
181+
});
182+
183+
it('should convert x/y coordinates into bricks', function() {
184+
var out = _calc({
185+
x: [1, 2, 3],
186+
y: [2, 6],
187+
z: [[1, 2, 3], [3, 1, 2]]
188+
});
189+
190+
expect(out.x).toBeCloseToArray([1, 2, 3]);
191+
expect(out.y).toBeCloseToArray([2, 6]);
192+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
193+
});
194+
195+
it('should trim brick-link /y coordinates', function() {
196+
var out = _calc({
197+
x: [1, 2, 3, 4],
198+
y: [2, 6, 10],
199+
z: [[1, 2, 3], [3, 1, 2]]
200+
});
201+
202+
expect(out.x).toBeCloseToArray([1, 2, 3]);
203+
expect(out.y).toBeCloseToArray([2, 6]);
204+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
205+
});
206+
207+
it('should handle 1-xy + 1-brick case', function() {
208+
var out = _calc({
209+
x: [2],
210+
y: [3],
211+
z: [[1]]
212+
});
213+
214+
expect(out.x).toBeCloseToArray([2]);
215+
expect(out.y).toBeCloseToArray([3]);
216+
expect(out.z).toBeCloseTo2DArray([[1]]);
217+
});
218+
219+
it('should handle 1-xy + multi-brick case', function() {
220+
var out = _calc({
221+
x: [2],
222+
y: [3],
223+
z: [[1, 2, 3], [3, 1, 2]]
224+
});
225+
226+
expect(out.x).toBeCloseToArray([2, 3, 4]);
227+
expect(out.y).toBeCloseToArray([3, 4]);
228+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
229+
});
230+
231+
it('should handle 0-xy + multi-brick case', function() {
232+
var out = _calc({
233+
x: [],
234+
y: [],
235+
z: [[1, 2, 3], [3, 1, 2]]
236+
});
237+
238+
expect(out.x).toBeCloseToArray([0, 1, 2]);
239+
expect(out.y).toBeCloseToArray([0, 1]);
240+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
241+
});
242+
});

test/jasmine/tests/heatmap_test.js

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
var Plots = require('@src/plots/plots');
2+
var Lib = require('@src/lib');
3+
14
var convertColumnXYZ = require('@src/traces/heatmap/convert_column_xyz');
25
var Heatmap = require('@src/traces/heatmap');
3-
var Plots = require('@src/plots/plots');
6+
7+
var customMatchers = require('../assets/custom_matchers');
48

59

610
describe('heatmap supplyDefaults', function() {
@@ -192,3 +196,106 @@ describe('heatmap convertColumnXYZ', function() {
192196
]);
193197
});
194198
});
199+
200+
describe('heatmap calc', function() {
201+
'use strict';
202+
203+
beforeAll(function() {
204+
jasmine.addMatchers(customMatchers);
205+
});
206+
207+
function _calc(trace) {
208+
var base = { type: 'heatmap' },
209+
trace = Lib.extendFlat({}, base, trace),
210+
gd = { data: [trace] };
211+
212+
Plots.supplyDefaults(gd);
213+
var fullTrace = gd._fullData[0];
214+
215+
return Heatmap.calc(gd, fullTrace)[0];
216+
}
217+
218+
it('should fill in bricks if x/y not given', function() {
219+
var out = _calc({
220+
z: [[1, 2, 3], [3, 1, 2]]
221+
});
222+
223+
expect(out.x).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]);
224+
expect(out.y).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]);
225+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
226+
});
227+
228+
it('should fill in bricks with x0/dx + y0/dy', function() {
229+
var out = _calc({
230+
z: [[1, 2, 3], [3, 1, 2]],
231+
x0: 10,
232+
dx: 0.5,
233+
y0: -2,
234+
dy: -2
235+
});
236+
237+
expect(out.x).toBeCloseToArray([9.75, 10.25, 10.75, 11.25]);
238+
expect(out.y).toBeCloseToArray([-1, -3, -5]);
239+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
240+
});
241+
242+
it('should convert x/y coordinates into bricks', function() {
243+
var out = _calc({
244+
x: [1, 2, 3],
245+
y: [2, 6],
246+
z: [[1, 2, 3], [3, 1, 2]]
247+
});
248+
249+
expect(out.x).toBeCloseToArray([0.5, 1.5, 2.5, 3.5]);
250+
expect(out.y).toBeCloseToArray([0, 4, 8]);
251+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
252+
});
253+
254+
it('should respect brick-link /y coordinates', function() {
255+
var out = _calc({
256+
x: [1, 2, 3, 4],
257+
y: [2, 6, 10],
258+
z: [[1, 2, 3], [3, 1, 2]]
259+
});
260+
261+
expect(out.x).toBeCloseToArray([1, 2, 3, 4]);
262+
expect(out.y).toBeCloseToArray([2, 6, 10]);
263+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
264+
});
265+
266+
it('should handle 1-xy + 1-brick case', function() {
267+
var out = _calc({
268+
x: [2],
269+
y: [3],
270+
z: [[1]]
271+
});
272+
273+
expect(out.x).toBeCloseToArray([1.5, 2.5]);
274+
expect(out.y).toBeCloseToArray([2.5, 3.5]);
275+
expect(out.z).toBeCloseTo2DArray([[1]]);
276+
});
277+
278+
it('should handle 1-xy + multi-brick case', function() {
279+
var out = _calc({
280+
x: [2],
281+
y: [3],
282+
z: [[1, 2, 3], [3, 1, 2]]
283+
});
284+
285+
expect(out.x).toBeCloseToArray([1.5, 2.5, 3.5, 4.5]);
286+
expect(out.y).toBeCloseToArray([2.5, 3.5, 4.5, 5.5]);
287+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
288+
});
289+
290+
it('should handle 0-xy + multi-brick case', function() {
291+
var out = _calc({
292+
x: [],
293+
y: [],
294+
z: [[1, 2, 3], [3, 1, 2]]
295+
});
296+
297+
expect(out.x).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5, 3.5]);
298+
expect(out.y).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]);
299+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
300+
});
301+
});

0 commit comments

Comments
 (0)