Skip to content

Commit 6ae8a00

Browse files
committed
fix #4194 - stringify locations[i] for hover pointData
- so the rest of Fx.hover can properly handle it, the bug currently only happens for number locations[i] that make it part of the <extra></extra> hover label content.
1 parent 19c0683 commit 6ae8a00

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/traces/choropleth/hover.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function makeHoverInfo(pointData, trace, pt) {
5858
if(trace.hovertemplate) return;
5959

6060
var hoverinfo = pt.hi || trace.hoverinfo;
61+
var loc = String(pt.loc);
6162

6263
var parts = (hoverinfo === 'all') ?
6364
attributes.hoverinfo.flags :
@@ -72,10 +73,10 @@ function makeHoverInfo(pointData, trace, pt) {
7273
var text = [];
7374

7475
if(hasIdAsNameLabel) {
75-
pointData.nameOverride = pt.loc;
76+
pointData.nameOverride = loc;
7677
} else {
7778
if(hasName) pointData.nameOverride = trace.name;
78-
if(hasLocation) text.push(pt.loc);
79+
if(hasLocation) text.push(loc);
7980
}
8081

8182
if(hasZ) {

test/jasmine/tests/choroplethmapbox_test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,44 @@ describe('@noCI Test choroplethmapbox hover:', function() {
589589
nums: '10.000',
590590
name: 'PROP::New York',
591591
evtPts: [{location: 'NY', z: 10, pointNumber: 0, curveNumber: 0, properties: {name: 'New York'}}]
592+
}, {
593+
desc: 'with "typeof number" locations[i] and feature id (in *name* label case)',
594+
patch: function() {
595+
var fig = Lib.extendDeep({}, require('@mocks/mapbox_choropleth-raw-geojson.json'));
596+
fig.data.shift();
597+
fig.data[0].locations = [100];
598+
fig.data[0].geojson.id = 100;
599+
return fig;
600+
},
601+
nums: '10',
602+
name: '100',
603+
evtPts: [{location: 100, z: 10, pointNumber: 0, curveNumber: 0}]
604+
}, {
605+
desc: 'with "typeof number" locations[i] and feature id (in *nums* label case)',
606+
patch: function() {
607+
var fig = Lib.extendDeep({}, require('@mocks/mapbox_choropleth-raw-geojson.json'));
608+
fig.data.shift();
609+
fig.data[0].locations = [100];
610+
fig.data[0].geojson.id = 100;
611+
fig.data[0].hoverinfo = 'location+name';
612+
return fig;
613+
},
614+
nums: '100',
615+
name: 'trace 0',
616+
evtPts: [{location: 100, z: 10, pointNumber: 0, curveNumber: 0}]
617+
}, {
618+
desc: 'with "typeof number" locations[i] and feature id (hovertemplate case)',
619+
patch: function() {
620+
var fig = Lib.extendDeep({}, require('@mocks/mapbox_choropleth-raw-geojson.json'));
621+
fig.data.shift();
622+
fig.data[0].locations = [100];
623+
fig.data[0].geojson.id = 100;
624+
fig.data[0].hovertemplate = '### %{location}<extra>%{location} ###</extra>';
625+
return fig;
626+
},
627+
nums: '### 100',
628+
name: '100 ###',
629+
evtPts: [{location: 100, z: 10, pointNumber: 0, curveNumber: 0}]
592630
}];
593631

594632
specs.forEach(function(s) {

0 commit comments

Comments
 (0)