Skip to content

Commit 0822b93

Browse files
committed
unified hoverlabel: inherit traceorder from the the legend
1 parent ec8c373 commit 0822b93

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/components/fx/hover.js

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ function createHoverText(hoverData, opts, gd) {
940940
bgcolor: fullLayout.paper_bgcolor,
941941
borderwidth: 1,
942942
tracegroupgap: 7,
943+
traceorder: fullLayout.legend ? fullLayout.legend.traceorder : undefined,
943944
orientation: 'v'
944945
}
945946
};

test/jasmine/tests/hover_label_test.js

+21
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,27 @@ describe('hovermode: (x|y)unified', function() {
37883788
.then(done);
37893789
});
37903790

3791+
it('should order items in the same way as the legend', function(done) {
3792+
var mock = require('@mocks/stacked_area.json');
3793+
var mockCopy = Lib.extendDeep({}, mock);
3794+
mockCopy.layout.hovermode = 'x unified';
3795+
var expectation = ['top : 1', 'middle : 6', 'bottom : 0'];
3796+
Plotly.newPlot(gd, mockCopy)
3797+
.then(function(gd) {
3798+
_hover(gd, { xval: 3 });
3799+
3800+
assertLabel({title: '3', items: expectation});
3801+
return Plotly.relayout(gd, 'legend.traceorder', 'normal');
3802+
})
3803+
.then(function(gd) {
3804+
_hover(gd, { xval: 3 });
3805+
3806+
assertLabel({title: '3', items: expectation.reverse()});
3807+
})
3808+
.catch(failTest)
3809+
.then(done);
3810+
});
3811+
37913812
it('should work for finance traces', function(done) {
37923813
var mockOhlc = require('@mocks/finance_multicategory.json');
37933814
var mockCopy = Lib.extendDeep({}, mockOhlc);

0 commit comments

Comments
 (0)