Skip to content

Commit 53c5714

Browse files
committed
unified hoverlabel: rank points based on trace's index
1 parent 06ad9a7 commit 53c5714

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/components/fx/hover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ function createHoverText(hoverData, opts, gd) {
980980

981981
legendOpts.entries.push([pt]);
982982
}
983+
legendOpts.entries.sort(function(a, b) { return a[0].trace.index - b[0].trace.index;});
983984
legendOpts.layer = container;
984985

985986
// Draw unified hover label

test/jasmine/tests/hover_label_test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,11 +3779,11 @@ describe('hovermode: (x|y)unified', function() {
37793779

37803780
assertLabel({title: '3', items: [
37813781
'trace 0 : 2',
3782-
'trace 3 : 2',
37833782
'trace 1 : median: 1',
3784-
'trace 4 : 1',
3783+
'trace 3 : 2',
37853784
'trace 2 : 2',
3786-
'trace 5 : 2'
3785+
'trace 5 : 2',
3786+
'trace 4 : 1'
37873787
]});
37883788
})
37893789
.catch(failTest)
@@ -3812,7 +3812,7 @@ describe('hovermode: (x|y)unified', function() {
38123812
.then(done);
38133813
});
38143814

3815-
it('should order items in the same way as the legend', function(done) {
3815+
it('should have the same traceorder as the legend', function(done) {
38163816
var mock = require('@mocks/stacked_area.json');
38173817
var mockCopy = Lib.extendDeep({}, mock);
38183818
mockCopy.layout.hovermode = 'x unified';
@@ -3833,6 +3833,25 @@ describe('hovermode: (x|y)unified', function() {
38333833
.then(done);
38343834
});
38353835

3836+
it('should order items based on trace index as in the legend', function(done) {
3837+
var mock = require('@mocks/29.json');
3838+
var mockCopy = Lib.extendDeep({}, mock);
3839+
mockCopy.layout.hovermode = 'x unified';
3840+
Plotly.newPlot(gd, mockCopy)
3841+
.then(function(gd) {
3842+
_hover(gd, {xpx: 400, ypx: 400});
3843+
3844+
assertLabel({title: 'Apr 13, 2014, 09:51:36', items: [
3845+
'Outdoor (wun... : 63',
3846+
'1st Floor (N... : (Apr 13, 2014, 09:51:34, 69.5)',
3847+
'2nd Floor (R... : (Apr 13, 2014, 09:51:33, 69.125)',
3848+
'Attic (Ardui... : (Apr 13, 2014, 09:51:37, 68.68)'
3849+
]});
3850+
})
3851+
.catch(failTest)
3852+
.then(done);
3853+
});
3854+
38363855
it('should work for finance traces', function(done) {
38373856
var mockOhlc = require('@mocks/finance_multicategory.json');
38383857
var mockCopy = Lib.extendDeep({}, mockOhlc);

0 commit comments

Comments
 (0)