Skip to content

Commit 371d31e

Browse files
committed
use Fx.castHoverOption to setup pie loneHover args
- pie trace array hoverlabel settings were broken before this patch when pie `trace.sort = true` (the default by the way) as this reorders the calcdata items which led to fx/calc filling hoverlabel field in the wrong calcdata items. - to solve the problem, simply don't rely on calcdata for hoverlabel setting in pie traces (as we currently do for gl3d and gl2d).
1 parent 7ed8681 commit 371d31e

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/components/fx/calc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ module.exports = function calc(gd) {
2525
var cd = calcdata[i];
2626
var trace = cd[0].trace;
2727

28-
if(!trace.hoverlabel) continue;
28+
// don't include hover calc fields for pie traces
29+
// as calcdata items might be sorted by value and
30+
// won't match the data array order.
31+
if(Registry.traceIs(trace, 'pie')) continue;
2932

3033
var mergeFn = Registry.traceIs(trace, '2dMap') ? paste : Lib.mergeArray;
3134

3235
mergeFn(trace.hoverinfo, cd, 'hi', makeCoerceHoverInfo(trace));
36+
37+
if(!trace.hoverlabel) continue;
38+
3339
mergeFn(trace.hoverlabel.bgcolor, cd, 'hbg');
3440
mergeFn(trace.hoverlabel.bordercolor, cd, 'hbc');
3541
mergeFn(trace.hoverlabel.font.size, cd, 'hts');

src/traces/pie/plot.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,18 @@ module.exports = function plot(gd, cdpie) {
124124
if(hoverinfo.indexOf('value') !== -1) thisText.push(helpers.formatPieValue(pt.v, separators));
125125
if(hoverinfo.indexOf('percent') !== -1) thisText.push(helpers.formatPiePercent(pt.v / cd0.vTotal, separators));
126126

127-
var hoverLabelOpts = trace2.hoverlabel;
128-
129127
Fx.loneHover({
130128
x0: hoverCenterX - rInscribed * cd0.r,
131129
x1: hoverCenterX + rInscribed * cd0.r,
132130
y: hoverCenterY,
133131
text: thisText.join('<br>'),
134132
name: hoverinfo.indexOf('name') !== -1 ? trace2.name : undefined,
135133
idealAlign: pt.pxmid[0] < 0 ? 'left' : 'right',
136-
color: pt.hbg || hoverLabelOpts.bgcolor || pt.color,
137-
borderColor: pt.hbc || hoverLabelOpts.bordercolor,
138-
fontFamily: pt.htf || hoverLabelOpts.font.family,
139-
fontSize: pt.hts || hoverLabelOpts.font.size,
140-
fontColor: pt.htc || hoverLabelOpts.font.color
134+
color: Fx.castHoverOption(trace, pt.i, 'bgcolor') || pt.color,
135+
borderColor: Fx.castHoverOption(trace, pt.i, 'bordercolor'),
136+
fontFamily: Fx.castHoverOption(trace, pt.i, 'font.family'),
137+
fontSize: Fx.castHoverOption(trace, pt.i, 'font.size'),
138+
fontColor: Fx.castHoverOption(trace, pt.i, 'font.color')
141139
}, {
142140
container: fullLayout2._hoverlayer.node(),
143141
outerContainer: fullLayout2._paper.node()

test/jasmine/tests/hover_pie_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ describe('pie hovering', function() {
242242
assertLabel(['4', 'SUP', '5', '33.3%']);
243243

244244
return Plotly.restyle(gd, {
245-
'hoverlabel.bgcolor': [['red', 'green', 'blue']],
245+
'hoverlabel.bgcolor': [['red', 'green', 'blue', 'yellow', 'red']],
246246
'hoverlabel.bordercolor': 'yellow',
247-
'hoverlabel.font.size': [[15, 20, 30]],
247+
'hoverlabel.font.size': [[15, 20, 30, 20, 15]],
248248
'hoverlabel.font.family': 'Roboto',
249249
'hoverlabel.font.color': 'blue'
250250
});

0 commit comments

Comments
 (0)