Skip to content

Commit d4893ea

Browse files
committed
tests: add test for 'Annotated Heatmap' example
1 parent b831cc8 commit d4893ea

File tree

1 file changed

+284
-3
lines changed

1 file changed

+284
-3
lines changed

export-server/tests/charts/scientific/heatmap.test.js

Lines changed: 284 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('scientific charts, part 2', () => {
3838
// (due to heatmap colouring).
3939

4040
// Currently, the server cannot handle that and returns HTTP status code 500.
41-
// Reasons seem to be the heatmap colouring and the labels.
4241
assert.ok(body == '{"success":false,"failure":"promise-rejected"}');
4342
});
4443
});
@@ -87,13 +86,295 @@ describe('scientific charts, part 2', () => {
8786
// (due to heatmap colouring).
8887

8988
// Currently, the server cannot handle that and returns HTTP status code 500.
90-
// Reasons seem to be the heatmap colouring and the labels.
9189
assert.ok(body == '{"success":false,"failure":"promise-rejected"}');
9290
});
9391
});
9492
});
9593

96-
// TODO: Annotated Heatmap - https://plotly.com/javascript/heatmaps/#annotated-heatmap
94+
it('Annotated Heatmap', () => {
95+
const options = {
96+
port: 3000,
97+
host: 'localhost',
98+
method: 'POST'
99+
};
100+
101+
const req = http.request(options);
102+
// Data taken from https://plotly.com/javascript/heatmaps/#annotated-heatmap example.
103+
const payload = `{
104+
"data": [
105+
{
106+
"x": [ "A", "B", "C", "D", "E" ],
107+
"y": [ "W", "X", "Y", "Z" ],
108+
"z": [ [ 0, 0, 0.75, 0.75, 0 ],
109+
[ 0, 0, 0.75, 0.75, 0 ],
110+
[ 0.75, 0.75, 0.75, 0.75, 0.75 ],
111+
[ 0, 0, 0, 0.75, 0 ] ],
112+
"type": "heatmap",
113+
"colorscale": [
114+
[ 0, "#3D9970" ],
115+
[ 1, "#001f3f" ]
116+
],
117+
"showscale": false
118+
}
119+
],
120+
"layout": {
121+
"title": {
122+
"text": "Annotated Heatmap"
123+
},
124+
"annotations": [
125+
{
126+
"xref": "x1",
127+
"yref": "y1",
128+
"x": "A",
129+
"y": "W",
130+
"text": 0,
131+
"font": {
132+
"color": "black"
133+
},
134+
"showarrow": false
135+
},
136+
{
137+
"xref": "x1",
138+
"yref": "y1",
139+
"x": "B",
140+
"y": "W",
141+
"text": 0,
142+
"font": {
143+
"color": "black"
144+
},
145+
"showarrow": false
146+
},
147+
{
148+
"xref": "x1",
149+
"yref": "y1",
150+
"x": "C",
151+
"y": "W",
152+
"text": 0.75,
153+
"font": {
154+
"color": "white"
155+
},
156+
"showarrow": false
157+
},
158+
{
159+
"xref": "x1",
160+
"yref": "y1",
161+
"x": "D",
162+
"y": "W",
163+
"text": 0.75,
164+
"font": {
165+
"color": "white"
166+
},
167+
"showarrow": false
168+
},
169+
{
170+
"xref": "x1",
171+
"yref": "y1",
172+
"x": "E",
173+
"y": "W",
174+
"text": 0,
175+
"font": {
176+
"color": "black"
177+
},
178+
"showarrow": false
179+
},
180+
{
181+
"xref": "x1",
182+
"yref": "y1",
183+
"x": "A",
184+
"y": "X",
185+
"text": 0,
186+
"font": {
187+
"color": "black"
188+
},
189+
"showarrow": false
190+
},
191+
{
192+
"xref": "x1",
193+
"yref": "y1",
194+
"x": "B",
195+
"y": "X",
196+
"text": 0,
197+
"font": {
198+
"color": "black"
199+
},
200+
"showarrow": false
201+
},
202+
{
203+
"xref": "x1",
204+
"yref": "y1",
205+
"x": "C",
206+
"y": "X",
207+
"text": 0.75,
208+
"font": {
209+
"color": "white"
210+
},
211+
"showarrow": false
212+
},
213+
{
214+
"xref": "x1",
215+
"yref": "y1",
216+
"x": "D",
217+
"y": "X",
218+
"text": 0.75,
219+
"font": {
220+
"color": "white"
221+
},
222+
"showarrow": false
223+
},
224+
{
225+
"xref": "x1",
226+
"yref": "y1",
227+
"x": "E",
228+
"y": "X",
229+
"text": 0,
230+
"font": {
231+
"color": "black"
232+
},
233+
"showarrow": false
234+
},
235+
{
236+
"xref": "x1",
237+
"yref": "y1",
238+
"x": "A",
239+
"y": "Y",
240+
"text": 0.75,
241+
"font": {
242+
"color": "white"
243+
},
244+
"showarrow": false
245+
},
246+
{
247+
"xref": "x1",
248+
"yref": "y1",
249+
"x": "B",
250+
"y": "Y",
251+
"text": 0.75,
252+
"font": {
253+
"color": "white"
254+
},
255+
"showarrow": false
256+
},
257+
{
258+
"xref": "x1",
259+
"yref": "y1",
260+
"x": "C",
261+
"y": "Y",
262+
"text": 0.75,
263+
"font": {
264+
"color": "white"
265+
},
266+
"showarrow": false
267+
},
268+
{
269+
"xref": "x1",
270+
"yref": "y1",
271+
"x": "D",
272+
"y": "Y",
273+
"text": 0.75,
274+
"font": {
275+
"color": "white"
276+
},
277+
"showarrow": false
278+
},
279+
{
280+
"xref": "x1",
281+
"yref": "y1",
282+
"x": "E",
283+
"y": "Y",
284+
"text": 0.75,
285+
"font": {
286+
"color": "white"
287+
},
288+
"showarrow": false
289+
},
290+
{
291+
"xref": "x1",
292+
"yref": "y1",
293+
"x": "A",
294+
"y": "Z",
295+
"text": 0,
296+
"font": {
297+
"color": "black"
298+
},
299+
"showarrow": false
300+
},
301+
{
302+
"xref": "x1",
303+
"yref": "y1",
304+
"x": "B",
305+
"y": "Z",
306+
"text": 0,
307+
"font": {
308+
"color": "black"
309+
},
310+
"showarrow": false
311+
},
312+
{
313+
"xref": "x1",
314+
"yref": "y1",
315+
"x": "C",
316+
"y": "Z",
317+
"text": 0,
318+
"font": {
319+
"color": "black"
320+
},
321+
"showarrow": false
322+
},
323+
{
324+
"xref": "x1",
325+
"yref": "y1",
326+
"x": "D",
327+
"y": "Z",
328+
"text": 0.75,
329+
"font": {
330+
"color": "white"
331+
},
332+
"showarrow": false
333+
},
334+
{
335+
"xref": "x1",
336+
"yref": "y1",
337+
"x": "E",
338+
"y": "Z",
339+
"text": 0,
340+
"font": {
341+
"color": "black"
342+
},
343+
"showarrow": false
344+
}
345+
],
346+
"xaxis": {
347+
"ticks": "",
348+
"side": "top"
349+
},
350+
"yaxis": {
351+
"ticks": "",
352+
"ticksuffix": " ",
353+
"width": 700,
354+
"height": 700,
355+
"autosize": false
356+
}
357+
}
358+
}`;
359+
req.write(payload);
360+
req.end();
361+
362+
req.on('response', (response) => {
363+
assert.strictEqual(500, response.statusCode);
364+
let body = '';
365+
response.on('data', (chunk) => {
366+
body += chunk;
367+
});
368+
response.on('end', () => {
369+
// Browser-based answer is an SVG with embedded binary PNG image data
370+
// (due to heatmap colouring).
371+
372+
// Currently, the server cannot handle that and returns HTTP status code 500.
373+
assert.ok(body == '{"success":false,"failure":"promise-rejected"}');
374+
});
375+
});
376+
});
377+
97378
// TODO: Heatmap with Unequal Block Sizes - https://plotly.com/javascript/heatmaps/#heatmap-with-unequal-block-sizes
98379

99380
/*

0 commit comments

Comments
 (0)