Skip to content

Commit 9ee8877

Browse files
committed
add tests for custom hover labels cartesian, geo, mapbox & ternary
1 parent a8cc8b0 commit 9ee8877

File tree

4 files changed

+134
-1
lines changed

4 files changed

+134
-1
lines changed

test/jasmine/tests/geo_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,21 @@ describe('Test geo interactions', function() {
502502
})
503503
.then(done);
504504
});
505+
506+
it('should show custom \`hoverlabel\' settings', function(done) {
507+
Plotly.restyle(gd, {
508+
'hoverlabel.bgcolor': 'red',
509+
'hoverlabel.bordercolor': [['blue', 'black', 'green']]
510+
})
511+
.then(function() {
512+
mouseEventScatterGeo('mousemove');
513+
514+
var path = d3.selectAll('g.hovertext').select('path');
515+
expect(path.style('fill')).toEqual('rgb(255, 0, 0)', 'bgcolor');
516+
expect(path.style('stroke')).toEqual('rgb(0, 0, 255)', 'bordecolor[0]');
517+
})
518+
.then(done);
519+
});
505520
});
506521

507522
describe('scattergeo hover events', function() {

test/jasmine/tests/hover_label_test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,3 +984,89 @@ describe('hover updates', function() {
984984

985985
});
986986
});
987+
988+
describe('Test hover label custom styling:', function() {
989+
afterEach(destroyGraphDiv);
990+
991+
function assertLabel(className, expectation) {
992+
var g = d3.select('g.' + className);
993+
994+
var path = g.select('path');
995+
expect(path.style('fill')).toEqual(expectation.path[0], 'bgcolor');
996+
expect(path.style('stroke')).toEqual(expectation.path[1], 'bordercolor');
997+
998+
var text = g.select('text');
999+
expect(parseInt(text.style('font-size'))).toEqual(expectation.text[0], 'font.size');
1000+
expect(text.style('font-family').split(',')[0]).toEqual(expectation.text[1], 'font.family');
1001+
expect(text.style('fill')).toEqual(expectation.text[2], 'font.color');
1002+
}
1003+
1004+
function assertPtLabel(expectation) {
1005+
assertLabel('hovertext', expectation);
1006+
}
1007+
1008+
function assertCommonLabel(expectation) {
1009+
assertLabel('axistext', expectation);
1010+
}
1011+
1012+
function _hover(gd, opts) {
1013+
Fx.hover(gd, opts);
1014+
delete gd._lastHoverTime;
1015+
}
1016+
1017+
it('should work for x/y cartesian traces', function(done) {
1018+
var gd = createGraphDiv();
1019+
1020+
Plotly.plot(gd, [{
1021+
x: [1, 2, 3],
1022+
y: [1, 2, 1],
1023+
hoverlabel: {
1024+
font: {
1025+
color: ['red', 'green', 'blue'],
1026+
size: 20
1027+
}
1028+
}
1029+
}], {
1030+
hovermode: 'x',
1031+
hoverlabel: { bgcolor: 'white' }
1032+
})
1033+
.then(function() {
1034+
_hover(gd, { xval: gd._fullData[0].x[0] });
1035+
1036+
assertPtLabel({
1037+
path: ['rgb(255, 255, 255)', 'rgb(68, 68, 68)'],
1038+
text: [20, 'Arial', 'rgb(255, 0, 0)']
1039+
});
1040+
assertCommonLabel({
1041+
path: ['rgb(255, 255, 255)', 'rgb(255, 255, 255)'],
1042+
text: [13, 'Arial', 'rgb(255, 255, 255)']
1043+
});
1044+
})
1045+
.then(function() {
1046+
_hover(gd, { xval: gd._fullData[0].x[1] });
1047+
1048+
assertPtLabel({
1049+
path: ['rgb(255, 255, 255)', 'rgb(68, 68, 68)'],
1050+
text: [20, 'Arial', 'rgb(0, 128, 0)']
1051+
});
1052+
assertCommonLabel({
1053+
path: ['rgb(255, 255, 255)', 'rgb(255, 255, 255)'],
1054+
text: [13, 'Arial', 'rgb(255, 255, 255)']
1055+
});
1056+
})
1057+
.then(function() {
1058+
_hover(gd, { xval: gd._fullData[0].x[2] });
1059+
1060+
assertPtLabel({
1061+
path: ['rgb(255, 255, 255)', 'rgb(68, 68, 68)'],
1062+
text: [20, 'Arial', 'rgb(0, 0, 255)']
1063+
});
1064+
assertCommonLabel({
1065+
path: ['rgb(255, 255, 255)', 'rgb(255, 255, 255)'],
1066+
text: [13, 'Arial', 'rgb(255, 255, 255)']
1067+
});
1068+
})
1069+
.catch(fail)
1070+
.then(done);
1071+
});
1072+
});

test/jasmine/tests/mapbox_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,22 @@ describe('@noCI, mapbox plots', function() {
709709
assertMouseMove(blankPos, 0).then(function() {
710710
return assertMouseMove(pointPos, 1);
711711
})
712+
.then(function() {
713+
return Plotly.restyle(gd, {
714+
'hoverlabel.bgcolor': 'yellow',
715+
'hoverlabel.font.size': [[20, 10, 30]]
716+
});
717+
})
718+
.then(function() {
719+
return assertMouseMove(pointPos, 1);
720+
})
721+
.then(function() {
722+
var path = d3.select('g.hovertext').select('path');
723+
var text = d3.select('g.hovertext').select('text');
724+
725+
expect(path.style('fill')).toEqual('rgb(255, 255, 0)', 'bgcolor');
726+
expect(text.style('font-size')).toEqual('20px', 'font.size[0]');
727+
})
712728
.catch(failTest)
713729
.then(done);
714730
}, LONG_TIMEOUT_INTERVAL);

test/jasmine/tests/ternary_test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('ternary plots', function() {
106106
}).then(done);
107107
});
108108

109-
it('should display to hover labels', function() {
109+
it('should display to hover labels', function(done) {
110110
var hoverLabels;
111111

112112
mouseEvent('mousemove', blankPos[0], blankPos[1]);
@@ -121,6 +121,22 @@ describe('ternary plots', function() {
121121
expect(rows[0][0].innerHTML).toEqual('Component A: 0.5', 'with correct text');
122122
expect(rows[0][1].innerHTML).toEqual('B: 0.25', 'with correct text');
123123
expect(rows[0][2].innerHTML).toEqual('Component C: 0.25', 'with correct text');
124+
125+
Plotly.restyle(gd, {
126+
'hoverlabel.bordercolor': 'blue',
127+
'hoverlabel.font.family': [['Gravitas', 'Arial', 'Roboto']]
128+
})
129+
.then(function() {
130+
delete gd._lastHoverTime;
131+
mouseEvent('mousemove', pointPos[0], pointPos[1]);
132+
133+
var path = d3.select('g.hovertext').select('path');
134+
var text = d3.select('g.hovertext').select('text');
135+
136+
expect(path.style('stroke')).toEqual('rgb(0, 0, 255)', 'bordercolor');
137+
expect(text.style('font-family')).toEqual('Gravitas', 'font.family[0]');
138+
})
139+
.then(done);
124140
});
125141

126142
it('should respond to hover interactions by', function() {

0 commit comments

Comments
 (0)