Skip to content

Commit 591bd9e

Browse files
committed
add two bar hover cases with set 'width'
1 parent c84e2a9 commit 591bd9e

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

test/jasmine/tests/bar_test.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,9 @@ describe('bar hover', function() {
11911191
};
11921192
}
11931193

1194-
function _hover(gd, xval, yval, closest) {
1194+
function _hover(gd, xval, yval, hovermode) {
11951195
var pointData = getPointData(gd);
1196-
var pt = Bar.hoverPoints(pointData, xval, yval, closest)[0];
1196+
var pt = Bar.hoverPoints(pointData, xval, yval, hovermode)[0];
11971197

11981198
return {
11991199
style: [pt.index, pt.color, pt.xLabelVal, pt.yLabelVal],
@@ -1274,6 +1274,66 @@ describe('bar hover', function() {
12741274
});
12751275
});
12761276

1277+
describe('with special width/offset combinations', function() {
1278+
1279+
beforeEach(function() {
1280+
gd = createGraphDiv();
1281+
});
1282+
1283+
it('should return correct \'closest\' hover data (single bar, trace width)', function(done) {
1284+
Plotly.plot(gd, [{
1285+
type: 'bar',
1286+
x: [1],
1287+
y: [2],
1288+
width: 10,
1289+
marker: { color: 'red' }
1290+
}], {
1291+
xaxis: { range: [-200, 200] }
1292+
})
1293+
.then(function() {
1294+
var out = _hover(gd, 0, 0, 'closest');
1295+
1296+
expect(out.style).toEqual([0, 'red', 1, 2]);
1297+
assertPos(out.pos, [264, 278, 14, 14]);
1298+
})
1299+
.then(done);
1300+
});
1301+
1302+
it('should return correct \'closest\' hover data (two bars, array width)', function(done) {
1303+
Plotly.plot(gd, [{
1304+
type: 'bar',
1305+
x: [1, 200],
1306+
y: [2, 1],
1307+
width: [10, 20],
1308+
marker: { color: 'red' }
1309+
}, {
1310+
type: 'bar',
1311+
x: [1, 200],
1312+
y: [1, 2],
1313+
width: [20, 10],
1314+
marker: { color: 'green' }
1315+
}], {
1316+
xaxis: { range: [-200, 300] },
1317+
width: 500,
1318+
height: 500
1319+
})
1320+
.then(function() {
1321+
var out = _hover(gd, -36, 1.5, 'closest');
1322+
1323+
expect(out.style).toEqual([0, 'red', 1, 2]);
1324+
assertPos(out.pos, [99, 106, 13, 13]);
1325+
})
1326+
.then(function() {
1327+
var out = _hover(gd, 164, 0.8, 'closest');
1328+
1329+
expect(out.style).toEqual([1, 'red', 200, 1]);
1330+
assertPos(out.pos, [222, 235, 168, 168]);
1331+
})
1332+
.then(done);
1333+
});
1334+
1335+
});
1336+
12771337
});
12781338

12791339
function mockBarPlot(dataWithoutTraceType, layout) {

0 commit comments

Comments
 (0)