Skip to content

Commit e672fb9

Browse files
committed
fix scatterpolar[gl] hover 'text' placement
- before this commit 'text' values were shown first i.e. above r and theta values in the hover labels.
1 parent 8c3580f commit e672fb9

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/traces/scatterpolar/hover.js

Lines changed: 8 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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/scatterpolar_test.js

Lines changed: 16 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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)