Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit caf887c

Browse filesBrowse files
committed
add finance trace hover tests
1 parent fe2d8d7 commit caf887c
Copy full SHA for caf887c

File tree

1 file changed

+100
-0
lines changed
Filter options

1 file changed

+100
-0
lines changed

‎test/jasmine/tests/finance_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/finance_test.js
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,5 +1046,105 @@ describe('finance charts *special* handlers:', function() {
10461046
.catch(failTest)
10471047
.then(done);
10481048
});
1049+
});
1050+
1051+
describe('finance trace hover:', function() {
1052+
var gd;
1053+
1054+
afterEach(destroyGraphDiv);
1055+
1056+
function run(specs) {
1057+
gd = createGraphDiv();
1058+
1059+
var data = specs.traces.map(function(t) {
1060+
return Lib.extendFlat({
1061+
type: specs.type,
1062+
open: [1, 2],
1063+
close: [2, 3],
1064+
high: [3, 4],
1065+
low: [0, 5]
1066+
}, t);
1067+
});
1068+
1069+
var layout = Lib.extendFlat({
1070+
showlegend: false,
1071+
width: 400,
1072+
height: 400,
1073+
margin: {t: 0, b: 0, l: 0, r: 0, pad: 0}
1074+
}, specs.layout || {});
1075+
1076+
var xval = 'xval' in specs ? specs.xvals : 0;
1077+
var yval = 'yval' in specs ? specs.yvals : 1;
1078+
var hovermode = layout.hovermode || 'x';
1079+
1080+
return Plotly.plot(gd, data, layout).then(function() {
1081+
var results = gd.calcdata.map(function(cd) {
1082+
var trace = cd[0].trace;
1083+
var pointData = {
1084+
index: false,
1085+
distance: 20,
1086+
cd: cd,
1087+
trace: trace,
1088+
xa: gd._fullLayout.xaxis,
1089+
ya: gd._fullLayout.yaxis,
1090+
maxHoverDistance: 20
1091+
};
1092+
var pts = trace._module.hoverPoints(pointData, xval, yval, hovermode);
1093+
return pts ? pts[0] : {distance: Infinity};
1094+
});
1095+
1096+
var actual = results[0];
1097+
var exp = specs.exp;
1098+
1099+
1100+
for(var k in exp) {
1101+
var msg = '- key ' + k;
1102+
expect(actual[k]).toBe(exp[k], msg);
1103+
}
1104+
});
1105+
}
10491106

1107+
['ohlc', 'candlestick'].forEach(function(type) {
1108+
[{
1109+
type: type,
1110+
desc: 'basic',
1111+
traces: [{}],
1112+
exp: {
1113+
extraText: 'open: 1<br>high: 3<br>low: 0<br>close: 2 ▲'
1114+
}
1115+
}, {
1116+
type: type,
1117+
desc: 'with scalar text',
1118+
traces: [{text: 'SCALAR'}],
1119+
exp: {
1120+
extraText: 'open: 1<br>high: 3<br>low: 0<br>close: 2 ▲<br>SCALAR'
1121+
}
1122+
}, {
1123+
type: type,
1124+
desc: 'with array text',
1125+
traces: [{text: ['A', 'B']}],
1126+
exp: {
1127+
extraText: 'open: 1<br>high: 3<br>low: 0<br>close: 2 ▲<br>A'
1128+
}
1129+
}, {
1130+
type: type,
1131+
desc: 'just scalar text',
1132+
traces: [{hoverinfo: 'text', text: 'SCALAR'}],
1133+
exp: {
1134+
extraText: 'SCALAR'
1135+
}
1136+
}, {
1137+
type: type,
1138+
desc: 'just array text',
1139+
traces: [{hoverinfo: 'text', text: ['A', 'B']}],
1140+
exp: {
1141+
extraText: 'A'
1142+
}
1143+
}]
1144+
.forEach(function(specs) {
1145+
it('should generate correct hover labels ' + type + ' - ' + specs.desc, function(done) {
1146+
run(specs).catch(failTest).then(done);
1147+
});
1148+
});
1149+
});
10501150
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.