Skip to content

Fixed hover behaviour for multicategory plots #6360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
@@ -888,7 +888,17 @@ function createHoverText(hoverData, opts) {
var xa = c0.xa;
var ya = c0.ya;
var axLetter = hovermode.charAt(0);
var t0 = c0[axLetter + 'Label'];
var axLabel = axLetter + 'Label';
var t0 = c0[axLabel];

// search in array for the label
if(t0 === undefined && xa.type === 'multicategory') {
for(var q = 0; q < hoverData.length; q++) {
t0 = hoverData[q][axLabel];
if(t0 !== undefined) break;
}
}

var outerContainerBB = getBoundingClientRect(gd, outerContainer);
var outerTop = outerContainerBB.top;
var outerWidth = outerContainerBB.width;
@@ -2067,7 +2077,7 @@ function getCoord(axLetter, winningPoint, fullLayout) {

var cd0 = winningPoint.cd[0];

if(ax.type === 'category') val = ax._categoriesMap[val];
if(ax.type === 'category' || ax.type === 'multicategory') val = ax._categoriesMap[val];
else if(ax.type === 'date') {
var periodalignment = winningPoint.trace[axLetter + 'periodalignment'];
if(periodalignment) {
Binary file added test/image/baselines/zz-multicategory_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
923 changes: 923 additions & 0 deletions test/image/mocks/zz-multicategory_series.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
@@ -2640,6 +2640,32 @@ describe('Hover on multicategory axes', function() {
})
.then(done, done.fail);
});

it('should work with series', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/zz-multicategory_series.json'));
fig.data = [fig.data[0]];
fig.layout.width = 500;
fig.layout.height = 500;

Plotly.newPlot(gd, fig)
.then(function() {
gd.on('plotly_hover', function(d) {
eventData = d.points[0];
});
})
.then(function() { _hover(200, 200); })
.then(function() {
expect(eventData.x).toEqual(['High', 4]);
})
.then(function() {
return Plotly.restyle(gd, 'hovertemplate', '%{z} @ %{x} | %{y}');
})
.then(function() { _hover(200, 200); })
.then(function() {
expect(eventData.x).toEqual(['High', 4]);
})
.then(done, done.fail);
});
});

describe('hover on traces with (x|y)period positioning', function() {