Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2acf548

Browse files
committed
rm obsolete gd.data.length -> pointData.name logic in Fx.hover
- which is now handled during defaults, where one-trace graphs have no `'name'` hoverinfo flag by default - this fixes the set `hoverinfo: 'all'` + 1 trace graph hover labels, the name label is now properly displayed.
1 parent aab3366 commit 2acf548

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/fx/hover.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,11 @@ function _hover(gd, evt, subplot) {
354354
trace: trace,
355355
xa: xaArray[subploti],
356356
ya: yaArray[subploti],
357-
name: (gd.data.length > 1 || trace.hoverinfo.indexOf('name') !== -1) ? trace.name : undefined,
358357
// point properties - override all of these
359358
index: false, // point index in trace - only used by plotly.js hoverdata consumers
360359
distance: Math.min(distance, constants.MAXDIST), // pixel distance or pseudo-distance
361360
color: Color.defaultLine, // trace color
361+
name: trace.name,
362362
x0: undefined,
363363
x1: undefined,
364364
y0: undefined,
@@ -724,7 +724,9 @@ function createHoverText(hoverData, opts) {
724724
else if(d.yLabel === undefined) text = d.xLabel;
725725
else text = '(' + d.xLabel + ', ' + d.yLabel + ')';
726726

727-
if(d.text && !Array.isArray(d.text)) text += (text ? '<br>' : '') + d.text;
727+
if(d.text && !Array.isArray(d.text)) {
728+
text += (text ? '<br>' : '') + d.text;
729+
}
728730

729731
// if 'text' is empty at this point,
730732
// put 'name' in main label and don't show secondary label

test/jasmine/tests/hover_label_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('hover info', function() {
154154
expect(d3.selectAll('g.axistext').size()).toEqual(1);
155155
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
156156
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388');
157-
expect(d3.selectAll('g.hovertext').select('text').selectAll('tspan').size()).toEqual(2);
157+
expect(d3.selectAll('g.hovertext').select('text.nums').selectAll('tspan').size()).toEqual(2);
158158
expect(d3.selectAll('g.hovertext').selectAll('tspan')[0][0].innerHTML).toEqual('1');
159159
expect(d3.selectAll('g.hovertext').selectAll('tspan')[0][1].innerHTML).toEqual('hover text');
160160
});

0 commit comments

Comments
 (0)