Skip to content

Commit deefe87

Browse files
committed
mv histogram2d hover test to histogram2d_test.js
1 parent 401029a commit deefe87

File tree

2 files changed

+153
-140
lines changed

2 files changed

+153
-140
lines changed

test/jasmine/tests/histogram2d_test.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ var calc = require('@src/traces/histogram2d/calc');
66

77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
var mouseEvent = require('../assets/mouse_event');
910
var failTest = require('../assets/fail_test');
1011
var supplyAllDefaults = require('../assets/supply_defaults');
1112

13+
var customAssertions = require('../assets/custom_assertions');
14+
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
15+
1216
describe('Test histogram2d', function() {
1317
'use strict';
1418

@@ -328,3 +332,152 @@ describe('Test histogram2d', function() {
328332
});
329333
});
330334
});
335+
336+
describe('Test histogram2d hover:', function() {
337+
var gd;
338+
339+
beforeEach(function() {
340+
gd = createGraphDiv();
341+
});
342+
343+
afterEach(destroyGraphDiv);
344+
345+
function _hover(xpx, ypx) {
346+
Lib.clearThrottle();
347+
mouseEvent('mousemove', xpx, ypx);
348+
}
349+
350+
it('should display correct label content with specified format', function(done) {
351+
Plotly.plot(gd, [{
352+
type: 'histogram2d',
353+
x: [0, 1, 2, 0, 1, 2, 1],
354+
y: [0, 0, 0, 1, 1, 1, 1],
355+
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
356+
histfunc: 'sum',
357+
name: 'one',
358+
zhoverformat: '.2f',
359+
showscale: false
360+
}, {
361+
type: 'histogram2d',
362+
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
363+
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
364+
name: 'two',
365+
showscale: false
366+
}], {
367+
width: 500,
368+
height: 400,
369+
margin: {l: 0, t: 0, r: 0, b: 0}
370+
})
371+
.then(function() {
372+
_hover(250, 100);
373+
assertHoverLabelContent({
374+
nums: 'x: 1\ny: 3\nz: 2',
375+
name: 'two'
376+
});
377+
378+
_hover(250, 300);
379+
assertHoverLabelContent({
380+
nums: 'x: 1\ny: 1\nz: 5.56',
381+
name: 'one'
382+
});
383+
})
384+
.then(function() {
385+
return Plotly.restyle(gd, 'hovertemplate', 'f(%{x:.3f},%{y:.3f})=%{z}');
386+
})
387+
.then(function() {
388+
_hover(250, 100);
389+
assertHoverLabelContent({
390+
nums: 'f(1.000,3.000)=2',
391+
name: 'two'
392+
});
393+
394+
_hover(250, 300);
395+
assertHoverLabelContent({
396+
nums: 'f(1.000,1.000)=5.56',
397+
name: 'one'
398+
});
399+
})
400+
.then(function() {
401+
return Plotly.restyle(gd, 'hoverlabel.namelength', 0);
402+
})
403+
.then(function() {
404+
_hover(250, 100);
405+
assertHoverLabelContent({
406+
nums: 'f(1.000,3.000)=2',
407+
name: ''
408+
});
409+
410+
_hover(250, 300);
411+
assertHoverLabelContent({
412+
nums: 'f(1.000,1.000)=5.56',
413+
name: ''
414+
});
415+
})
416+
.catch(failTest)
417+
.then(done);
418+
});
419+
420+
describe('hover info', function() {
421+
it('shows the data range when bins have multiple values', function(done) {
422+
Plotly.plot(gd, [{
423+
x: [0, 2, 3, 4, 5, 6, 7],
424+
y: [1, 3, 4, 5, 6, 7, 8],
425+
xbins: {start: -0.5, end: 8.5, size: 3},
426+
ybins: {start: 0.5, end: 9.5, size: 3},
427+
type: 'histogram2d'
428+
}], {
429+
width: 500,
430+
height: 400,
431+
margin: {l: 0, t: 0, r: 0, b: 0}
432+
})
433+
.then(function() {
434+
_hover(250, 200);
435+
assertHoverLabelContent({
436+
nums: 'x: 3 - 5\ny: 4 - 6\nz: 3'
437+
});
438+
})
439+
.catch(failTest)
440+
.then(done);
441+
});
442+
443+
it('shows the data range when bins have multiple values (case 2)', function(done) {
444+
Plotly.plot(gd, [{
445+
type: 'histogram2d',
446+
x: ['a', 'b', 'c', 'a'],
447+
y: [7, 2, 3, 7],
448+
nbinsy: 3
449+
}], {
450+
width: 600,
451+
height: 600
452+
})
453+
.then(function() {
454+
_hover(250, 250);
455+
assertHoverLabelContent({nums: ['x: b', 'y: 4 - 5', 'z: 0'].join('\n')});
456+
})
457+
.catch(failTest)
458+
.then(done);
459+
});
460+
461+
it('shows the exact data when bins have single values', function(done) {
462+
Plotly.plot(gd, [{
463+
x: [0, 0, 3.3, 3.3, 3.3, 7, 7],
464+
y: [2, 2, 4.2, 4.2, 4.2, 8.8, 8.8],
465+
xbins: {start: -0.5, end: 8.5, size: 3},
466+
ybins: {start: 0.5, end: 9.5, size: 3},
467+
type: 'histogram2d'
468+
}], {
469+
width: 500,
470+
height: 400,
471+
margin: {l: 0, t: 0, r: 0, b: 0}
472+
})
473+
.then(function() {
474+
_hover(250, 200);
475+
assertHoverLabelContent({
476+
nums: 'x: 3.3\ny: 4.2\nz: 3'
477+
});
478+
})
479+
.catch(failTest)
480+
.then(done);
481+
});
482+
});
483+
});

test/jasmine/tests/hover_label_test.js

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -928,76 +928,6 @@ describe('hover info', function() {
928928
.then(done);
929929
});
930930

931-
it('should display correct label content with specified format - histogram2d', function(done) {
932-
Plotly.plot(gd, [{
933-
type: 'histogram2d',
934-
x: [0, 1, 2, 0, 1, 2, 1],
935-
y: [0, 0, 0, 1, 1, 1, 1],
936-
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
937-
histfunc: 'sum',
938-
name: 'one',
939-
zhoverformat: '.2f',
940-
showscale: false
941-
}, {
942-
type: 'histogram2d',
943-
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
944-
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
945-
name: 'two',
946-
showscale: false
947-
}], {
948-
width: 500,
949-
height: 400,
950-
margin: {l: 0, t: 0, r: 0, b: 0}
951-
})
952-
.then(function() {
953-
_hover(gd, 250, 100);
954-
assertHoverLabelContent({
955-
nums: 'x: 1\ny: 3\nz: 2',
956-
name: 'two'
957-
});
958-
959-
_hover(gd, 250, 300);
960-
assertHoverLabelContent({
961-
nums: 'x: 1\ny: 1\nz: 5.56',
962-
name: 'one'
963-
});
964-
})
965-
.then(function() {
966-
return Plotly.restyle(gd, 'hovertemplate', 'f(%{x:.3f},%{y:.3f})=%{z}');
967-
})
968-
.then(function() {
969-
_hover(gd, 250, 100);
970-
assertHoverLabelContent({
971-
nums: 'f(1.000,3.000)=2',
972-
name: 'two'
973-
});
974-
975-
_hover(gd, 250, 300);
976-
assertHoverLabelContent({
977-
nums: 'f(1.000,1.000)=5.56',
978-
name: 'one'
979-
});
980-
})
981-
.then(function() {
982-
return Plotly.restyle(gd, 'hoverlabel.namelength', 0);
983-
})
984-
.then(function() {
985-
_hover(gd, 250, 100);
986-
assertHoverLabelContent({
987-
nums: 'f(1.000,3.000)=2',
988-
name: ''
989-
});
990-
991-
_hover(gd, 250, 300);
992-
assertHoverLabelContent({
993-
nums: 'f(1.000,1.000)=5.56',
994-
name: ''
995-
});
996-
})
997-
.catch(failTest)
998-
.then(done);
999-
});
1000-
1001931
it('should display correct label content with specified format - histogram2dcontour', function(done) {
1002932
Plotly.plot(gd, [{
1003933
type: 'histogram2dcontour',
@@ -1200,76 +1130,6 @@ describe('hover info', function() {
12001130
});
12011131
});
12021132

1203-
describe('histogram2d hover info', function() {
1204-
it('shows the data range when bins have multiple values', function(done) {
1205-
var gd = createGraphDiv();
1206-
1207-
Plotly.plot(gd, [{
1208-
x: [0, 2, 3, 4, 5, 6, 7],
1209-
y: [1, 3, 4, 5, 6, 7, 8],
1210-
xbins: {start: -0.5, end: 8.5, size: 3},
1211-
ybins: {start: 0.5, end: 9.5, size: 3},
1212-
type: 'histogram2d'
1213-
}], {
1214-
width: 500,
1215-
height: 400,
1216-
margin: {l: 0, t: 0, r: 0, b: 0}
1217-
})
1218-
.then(function() {
1219-
_hover(gd, 250, 200);
1220-
assertHoverLabelContent({
1221-
nums: 'x: 3 - 5\ny: 4 - 6\nz: 3'
1222-
});
1223-
})
1224-
.catch(failTest)
1225-
.then(done);
1226-
});
1227-
1228-
it('shows the data range when bins have multiple values (case 2)', function(done) {
1229-
var gd = createGraphDiv();
1230-
1231-
Plotly.plot(gd, [{
1232-
type: 'histogram2d',
1233-
x: ['a', 'b', 'c', 'a'],
1234-
y: [7, 2, 3, 7],
1235-
nbinsy: 3
1236-
}], {
1237-
width: 600,
1238-
height: 600
1239-
})
1240-
.then(function() {
1241-
_hover(gd, 250, 200);
1242-
assertHoverLabelContent({nums: ['x: b', 'y: 4 - 5', 'z: 0'].join('\n')});
1243-
})
1244-
.catch(failTest)
1245-
.then(done);
1246-
});
1247-
1248-
it('shows the exact data when bins have single values', function(done) {
1249-
var gd = createGraphDiv();
1250-
1251-
Plotly.plot(gd, [{
1252-
x: [0, 0, 3.3, 3.3, 3.3, 7, 7],
1253-
y: [2, 2, 4.2, 4.2, 4.2, 8.8, 8.8],
1254-
xbins: {start: -0.5, end: 8.5, size: 3},
1255-
ybins: {start: 0.5, end: 9.5, size: 3},
1256-
type: 'histogram2d'
1257-
}], {
1258-
width: 500,
1259-
height: 400,
1260-
margin: {l: 0, t: 0, r: 0, b: 0}
1261-
})
1262-
.then(function() {
1263-
_hover(gd, 250, 200);
1264-
assertHoverLabelContent({
1265-
nums: 'x: 3.3\ny: 4.2\nz: 3'
1266-
});
1267-
})
1268-
.catch(failTest)
1269-
.then(done);
1270-
});
1271-
});
1272-
12731133
['candlestick', 'ohlc'].forEach(function(type) {
12741134
describe(type + ' hoverinfo', function() {
12751135
var gd;

0 commit comments

Comments
 (0)