Skip to content

Commit 2f0d56e

Browse files
authored
Merge pull request #3040 from plotly/polar-hover-text-fix
Polar 'text' in hover labels fixes
2 parents 8c3580f + 74bd9b2 commit 2f0d56e

File tree

6 files changed

+76
-6
lines changed

6 files changed

+76
-6
lines changed

src/traces/barpolar/hover.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var Fx = require('../../components/fx');
1212
var Lib = require('../../lib');
1313
var getTraceColor = require('../bar/hover').getTraceColor;
14+
var fillHoverText = require('../scatter/fill_hover_text');
1415
var makeHoverPointText = require('../scatterpolar/hover').makeHoverPointText;
1516
var isPtInsidePolygon = require('../../plots/polar/helpers').isPtInsidePolygon;
1617

@@ -58,7 +59,8 @@ module.exports = function hoverPoints(pointData, xval, yval) {
5859
pointData.y0 = pointData.y1 = cdi.ct[1];
5960

6061
var _cdi = Lib.extendFlat({}, cdi, {r: cdi.s, theta: cdi.p});
61-
pointData.extraText = makeHoverPointText(_cdi, trace, subplot);
62+
fillHoverText(cdi, trace, pointData);
63+
makeHoverPointText(_cdi, trace, subplot, pointData);
6264
pointData.color = getTraceColor(trace, cdi);
6365
pointData.xLabelVal = pointData.yLabelVal = undefined;
6466

src/traces/scatterpolar/hover.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ function hoverPoints(pointData, xval, yval, hovermode) {
3131

3232
newPointData.xLabelVal = undefined;
3333
newPointData.yLabelVal = undefined;
34-
newPointData.extraText = makeHoverPointText(cdi, trace, subplot);
34+
makeHoverPointText(cdi, trace, subplot, newPointData);
3535

3636
return scatterPointData;
3737
}
3838

39-
function makeHoverPointText(cdi, trace, subplot) {
39+
function makeHoverPointText(cdi, trace, subplot, pointData) {
4040
var radialAxis = subplot.radialAxis;
4141
var angularAxis = subplot.angularAxis;
4242
var hoverinfo = cdi.hi || trace.hoverinfo;
@@ -50,7 +50,7 @@ function makeHoverPointText(cdi, trace, subplot) {
5050
text.push(ax._hovertitle + ': ' + Axes.tickText(ax, val, 'hover').text);
5151
}
5252

53-
if(parts.indexOf('all') !== -1) parts = ['r', 'theta'];
53+
if(parts.indexOf('all') !== -1) parts = ['r', 'theta', 'text'];
5454
if(parts.indexOf('r') !== -1) {
5555
textPart(radialAxis, radialAxis.c2l(cdi.r));
5656
}
@@ -61,8 +61,12 @@ function makeHoverPointText(cdi, trace, subplot) {
6161
angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(theta) : theta
6262
);
6363
}
64+
if(parts.indexOf('text') !== -1 && pointData.text) {
65+
text.push(pointData.text);
66+
delete pointData.text;
67+
}
6468

65-
return text.join('<br>');
69+
pointData.extraText = text.join('<br>');
6670
}
6771

6872
module.exports = {

src/traces/scatterpolargl/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function hoverPoints(pointData, xval, yval, hovermode) {
165165

166166
newPointData.xLabelVal = undefined;
167167
newPointData.yLabelVal = undefined;
168-
newPointData.extraText = makeHoverPointText(cdi, trace, subplot);
168+
makeHoverPointText(cdi, trace, subplot, newPointData);
169169

170170
return scatterPointData;
171171
}

test/jasmine/tests/barpolar_test.js

+32
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,38 @@ describe('Test barpolar hover:', function() {
115115
extraText: 'r: 1<br>θ: 0°',
116116
color: '#1f77b4'
117117
}
118+
}, {
119+
desc: 'with custom text scalar',
120+
traces: [{
121+
r: [1, 2, 3],
122+
theta: [0, 90, 180],
123+
text: 'TEXT'
124+
}],
125+
xval: 1,
126+
yval: 0,
127+
exp: {
128+
index: 0,
129+
x: 263.33,
130+
y: 200,
131+
extraText: 'r: 1<br>θ: 0°<br>TEXT',
132+
color: '#1f77b4'
133+
}
134+
}, {
135+
desc: 'with custom text array',
136+
traces: [{
137+
r: [1, 2, 3],
138+
theta: [0, 90, 180],
139+
text: ['A', 'B', 'C']
140+
}],
141+
xval: 1,
142+
yval: 0,
143+
exp: {
144+
index: 0,
145+
x: 263.33,
146+
y: 200,
147+
extraText: 'r: 1<br>θ: 0°<br>A',
148+
color: '#1f77b4'
149+
}
118150
}, {
119151
desc: 'works with bars with offsets',
120152
traces: [{

test/jasmine/tests/scatterpolar_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ describe('Test scatterpolar hover:', function() {
158158
},
159159
nums: 'r: 1.108937\nθ: 115.4969°',
160160
name: 'Trial 3'
161+
}, {
162+
desc: 'with custom text scalar',
163+
patch: function(fig) {
164+
fig.data.forEach(function(t) { t.text = 'a'; });
165+
return fig;
166+
},
167+
nums: 'r: 4.022892\nθ: 128.342°\na',
168+
name: 'Trial 3'
169+
}, {
170+
desc: 'with custom text array',
171+
patch: function(fig) {
172+
fig.data.forEach(function(t) { t.text = t.r.map(String); });
173+
return fig;
174+
},
175+
nums: 'r: 4.022892\nθ: 128.342°\n4.02289202968',
176+
name: 'Trial 3'
161177
}]
162178
.forEach(function(specs) {
163179
it('should generate correct hover labels ' + specs.desc, function(done) {

test/jasmine/tests/scatterpolargl_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ describe('Test scatterpolargl hover:', function() {
7979
pos: [470, 80],
8080
nums: 'r: 4\nθ: d',
8181
name: 'angular cate...'
82+
}, {
83+
desc: 'with custom text scalar',
84+
patch: function(fig) {
85+
fig.data.forEach(function(t) { t.text = 'a'; });
86+
return fig;
87+
},
88+
nums: 'r: 3.886013\nθ: 125.2822°\na',
89+
name: 'Trial 3'
90+
}, {
91+
desc: 'with custom text array',
92+
patch: function(fig) {
93+
fig.data.forEach(function(t) { t.text = t.r.map(String); });
94+
return fig;
95+
},
96+
nums: 'r: 3.886013\nθ: 125.2822°\n3.88601339194',
97+
name: 'Trial 3'
8298
}]
8399
.forEach(function(specs) {
84100
it('should generate correct hover labels ' + specs.desc, function(done) {

0 commit comments

Comments
 (0)