Skip to content

Commit 5552c77

Browse files
committed
test hoveron=fills label position and text
1 parent c7a9dd5 commit 5552c77

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/jasmine/tests/hover_label_test.js

+39
Original file line numberDiff line numberDiff line change
@@ -652,3 +652,42 @@ describe('hover after resizing', function() {
652652
}).then(done);
653653
});
654654
});
655+
656+
describe('hover on fill', function() {
657+
'use strict';
658+
659+
afterEach(destroyGraphDiv);
660+
661+
function assertLabelsCorrect(mousePos, labelPos, labelText) {
662+
return new Promise(function(resolve) {
663+
mouseEvent('mousemove', mousePos[0], mousePos[1]);
664+
665+
setTimeout(function() {
666+
var hoverText = d3.selectAll('g.hovertext');
667+
expect(hoverText.size()).toEqual(1);
668+
expect(hoverText.text()).toEqual(labelText);
669+
670+
var transformParts = hoverText.attr('transform').split('(');
671+
expect(transformParts[0]).toEqual('translate');
672+
var transformCoords = transformParts[1].split(')')[0].split(',');
673+
expect(+transformCoords[0]).toBeCloseTo(labelPos[0], 0, labelText + ':x');
674+
expect(+transformCoords[1]).toBeCloseTo(labelPos[1], 0, labelText + ':y');
675+
676+
resolve();
677+
}, constants.HOVERMINTIME);
678+
});
679+
}
680+
681+
it('should always show one label in the right place', function(done) {
682+
var mock = require('@mocks/scatter_fill_self_next.json');
683+
mock.data.forEach(function(trace) { trace.hoveron = 'fills'; });
684+
685+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() {
686+
return assertLabelsCorrect([250, 150], [252.575, 133.8], 'trace 2');
687+
}).then(function() {
688+
return assertLabelsCorrect([250, 300], [234.125, 210], 'trace 1');
689+
}).then(function() {
690+
return assertLabelsCorrect([155, 260], [160.325, 248.1], 'trace 0');
691+
}).then(done);
692+
});
693+
});

0 commit comments

Comments
 (0)