Skip to content

Commit 5854f6f

Browse files
committed
fix handling of locations[i] 0
... in choropleth and scattergeo traces
1 parent 98079a1 commit 5854f6f

File tree

4 files changed

+195
-2
lines changed

4 files changed

+195
-2
lines changed

src/lib/geo_location_utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ function extractTraceFeature(calcTrace) {
213213

214214
for(i = 0; i < trace._length; i++) {
215215
var cdi = calcTrace[i];
216-
if(cdi.loc) lookup[cdi.loc] = cdi;
216+
if(cdi.loc || cdi.loc === 0) {
217+
lookup[cdi.loc] = cdi;
218+
}
217219
}
218220

219221
function appendFeature(fIn) {

src/traces/scattergeo/calc.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,28 @@ var calcSelection = require('../scatter/calc_selection');
1818

1919
var _ = require('../../lib')._;
2020

21+
function isNonBlankString(v) {
22+
return v && typeof v === 'string';
23+
}
24+
2125
module.exports = function calc(gd, trace) {
2226
var hasLocationData = Array.isArray(trace.locations);
2327
var len = hasLocationData ? trace.locations.length : trace._length;
2428
var calcTrace = new Array(len);
2529

30+
var isValidLoc;
31+
if(trace.geojson) {
32+
isValidLoc = function(v) { return isNonBlankString(v) || isNumeric(v); };
33+
} else {
34+
isValidLoc = isNonBlankString;
35+
}
36+
2637
for(var i = 0; i < len; i++) {
2738
var calcPt = calcTrace[i] = {};
2839

2940
if(hasLocationData) {
3041
var loc = trace.locations[i];
31-
calcPt.loc = typeof loc === 'string' ? loc : null;
42+
calcPt.loc = isValidLoc(loc) ? loc : null;
3243
} else {
3344
var lon = trace.lon[i];
3445
var lat = trace.lat[i];
25.5 KB
Loading
+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"data": [{
3+
"type": "choropleth",
4+
"locations": [0],
5+
"z": [10],
6+
"showscale": false,
7+
"geojson": {
8+
"type": "FeatureCollection",
9+
"features": [{
10+
"type": "Feature",
11+
"id": 0,
12+
"geometry": {
13+
"type": "Polygon",
14+
"coordinates": [[
15+
[-87.359296, 35.00118], [-85.606675, 34.984749], [-85.431413, 34.124869], [-85.184951, 32.859696],
16+
[-85.069935, 32.580372], [-84.960397, 32.421541], [-85.004212, 32.322956], [-84.889196, 32.262709],
17+
[-85.058981, 32.13674], [-85.053504, 32.01077], [-85.141136, 31.840985], [-85.042551, 31.539753],
18+
[-85.113751, 31.27686], [-85.004212, 31.003013], [-85.497137, 30.997536], [-87.600282, 30.997536],
19+
[-87.633143, 30.86609], [-87.408589, 30.674397], [-87.446927, 30.510088], [-87.37025, 30.427934],
20+
[-87.518128, 30.280057], [-87.655051, 30.247195], [-87.90699, 30.411504], [-87.934375, 30.657966],
21+
[-88.011052, 30.685351], [-88.10416, 30.499135], [-88.137022, 30.318396], [-88.394438, 30.367688],
22+
[-88.471115, 31.895754], [-88.241084, 33.796253], [-88.098683, 34.891641], [-88.202745, 34.995703],
23+
[-87.359296, 35.00118]
24+
]]
25+
}
26+
}, {
27+
"type": "Feature",
28+
"id": 1,
29+
"geometry": {
30+
"type": "Polygon",
31+
"coordinates": [[[-83.109191,35.00118],[-83.322791,34.787579],[-83.339222,34.683517],[-83.005129,34.469916],[-82.901067,34.486347],[-82.747713,34.26727],[-82.714851,34.152254],[-82.55602,33.94413],[-82.325988,33.81816],[-82.194542,33.631944],[-81.926172,33.462159],[-81.937125,33.347144],[-81.761863,33.160928],[-81.493493,33.007573],[-81.42777,32.843265],[-81.416816,32.629664],[-81.279893,32.558464],[-81.121061,32.290094],[-81.115584,32.120309],[-80.885553,32.032678],[-81.132015,31.693108],[-81.175831,31.517845],[-81.279893,31.364491],[-81.290846,31.20566],[-81.400385,31.13446],[-81.444201,30.707258],[-81.718048,30.745597],[-81.948079,30.827751],[-82.041187,30.751074],[-82.002849,30.564858],[-82.046664,30.362211],[-82.167157,30.356734],[-82.216449,30.570335],[-83.498053,30.647012],[-84.867289,30.712735],[-85.004212,31.003013],[-85.113751,31.27686],[-85.042551,31.539753],[-85.141136,31.840985],[-85.053504,32.01077],[-85.058981,32.13674],[-84.889196,32.262709],[-85.004212,32.322956],[-84.960397,32.421541],[-85.069935,32.580372],[-85.184951,32.859696],[-85.431413,34.124869],[-85.606675,34.984749],[-84.319594,34.990226],[-83.618546,34.984749],[-83.109191,35.00118]]]
32+
}
33+
}]
34+
}
35+
}, {
36+
"type": "scattergeo",
37+
"locations": [0],
38+
"marker": {"size": 40},
39+
"geo": "geo2",
40+
"geojson": {
41+
"type": "FeatureCollection",
42+
"features": [{
43+
"type": "Feature",
44+
"id": 0,
45+
"geometry": {
46+
"type": "Polygon",
47+
"coordinates": [[
48+
[-87.359296, 35.00118], [-85.606675, 34.984749], [-85.431413, 34.124869], [-85.184951, 32.859696],
49+
[-85.069935, 32.580372], [-84.960397, 32.421541], [-85.004212, 32.322956], [-84.889196, 32.262709],
50+
[-85.058981, 32.13674], [-85.053504, 32.01077], [-85.141136, 31.840985], [-85.042551, 31.539753],
51+
[-85.113751, 31.27686], [-85.004212, 31.003013], [-85.497137, 30.997536], [-87.600282, 30.997536],
52+
[-87.633143, 30.86609], [-87.408589, 30.674397], [-87.446927, 30.510088], [-87.37025, 30.427934],
53+
[-87.518128, 30.280057], [-87.655051, 30.247195], [-87.90699, 30.411504], [-87.934375, 30.657966],
54+
[-88.011052, 30.685351], [-88.10416, 30.499135], [-88.137022, 30.318396], [-88.394438, 30.367688],
55+
[-88.471115, 31.895754], [-88.241084, 33.796253], [-88.098683, 34.891641], [-88.202745, 34.995703],
56+
[-87.359296, 35.00118]
57+
]]
58+
}
59+
}, {
60+
"type": "Feature",
61+
"id": 1,
62+
"geometry": {
63+
"type": "Polygon",
64+
"coordinates": [[[-83.109191,35.00118],[-83.322791,34.787579],[-83.339222,34.683517],[-83.005129,34.469916],[-82.901067,34.486347],[-82.747713,34.26727],[-82.714851,34.152254],[-82.55602,33.94413],[-82.325988,33.81816],[-82.194542,33.631944],[-81.926172,33.462159],[-81.937125,33.347144],[-81.761863,33.160928],[-81.493493,33.007573],[-81.42777,32.843265],[-81.416816,32.629664],[-81.279893,32.558464],[-81.121061,32.290094],[-81.115584,32.120309],[-80.885553,32.032678],[-81.132015,31.693108],[-81.175831,31.517845],[-81.279893,31.364491],[-81.290846,31.20566],[-81.400385,31.13446],[-81.444201,30.707258],[-81.718048,30.745597],[-81.948079,30.827751],[-82.041187,30.751074],[-82.002849,30.564858],[-82.046664,30.362211],[-82.167157,30.356734],[-82.216449,30.570335],[-83.498053,30.647012],[-84.867289,30.712735],[-85.004212,31.003013],[-85.113751,31.27686],[-85.042551,31.539753],[-85.141136,31.840985],[-85.053504,32.01077],[-85.058981,32.13674],[-84.889196,32.262709],[-85.004212,32.322956],[-84.960397,32.421541],[-85.069935,32.580372],[-85.184951,32.859696],[-85.431413,34.124869],[-85.606675,34.984749],[-84.319594,34.990226],[-83.618546,34.984749],[-83.109191,35.00118]]]
65+
}
66+
}]
67+
}
68+
}, {
69+
"type": "choropleth",
70+
"locations": [0],
71+
"z": [10],
72+
"showscale": false,
73+
"geo": "geo3",
74+
"geojson": {
75+
"type": "FeatureCollection",
76+
"features": [{
77+
"type": "Feature",
78+
"id": 0,
79+
"geometry": {
80+
"type": "Polygon",
81+
"coordinates": [[
82+
[-87.359296, 35.00118], [-85.606675, 34.984749], [-85.431413, 34.124869], [-85.184951, 32.859696],
83+
[-85.069935, 32.580372], [-84.960397, 32.421541], [-85.004212, 32.322956], [-84.889196, 32.262709],
84+
[-85.058981, 32.13674], [-85.053504, 32.01077], [-85.141136, 31.840985], [-85.042551, 31.539753],
85+
[-85.113751, 31.27686], [-85.004212, 31.003013], [-85.497137, 30.997536], [-87.600282, 30.997536],
86+
[-87.633143, 30.86609], [-87.408589, 30.674397], [-87.446927, 30.510088], [-87.37025, 30.427934],
87+
[-87.518128, 30.280057], [-87.655051, 30.247195], [-87.90699, 30.411504], [-87.934375, 30.657966],
88+
[-88.011052, 30.685351], [-88.10416, 30.499135], [-88.137022, 30.318396], [-88.394438, 30.367688],
89+
[-88.471115, 31.895754], [-88.241084, 33.796253], [-88.098683, 34.891641], [-88.202745, 34.995703],
90+
[-87.359296, 35.00118]
91+
]]
92+
}
93+
}, {
94+
"type": "Feature",
95+
"id": 1,
96+
"geometry": {
97+
"type": "Polygon",
98+
"coordinates": [[[-83.109191,35.00118],[-83.322791,34.787579],[-83.339222,34.683517],[-83.005129,34.469916],[-82.901067,34.486347],[-82.747713,34.26727],[-82.714851,34.152254],[-82.55602,33.94413],[-82.325988,33.81816],[-82.194542,33.631944],[-81.926172,33.462159],[-81.937125,33.347144],[-81.761863,33.160928],[-81.493493,33.007573],[-81.42777,32.843265],[-81.416816,32.629664],[-81.279893,32.558464],[-81.121061,32.290094],[-81.115584,32.120309],[-80.885553,32.032678],[-81.132015,31.693108],[-81.175831,31.517845],[-81.279893,31.364491],[-81.290846,31.20566],[-81.400385,31.13446],[-81.444201,30.707258],[-81.718048,30.745597],[-81.948079,30.827751],[-82.041187,30.751074],[-82.002849,30.564858],[-82.046664,30.362211],[-82.167157,30.356734],[-82.216449,30.570335],[-83.498053,30.647012],[-84.867289,30.712735],[-85.004212,31.003013],[-85.113751,31.27686],[-85.042551,31.539753],[-85.141136,31.840985],[-85.053504,32.01077],[-85.058981,32.13674],[-84.889196,32.262709],[-85.004212,32.322956],[-84.960397,32.421541],[-85.069935,32.580372],[-85.184951,32.859696],[-85.431413,34.124869],[-85.606675,34.984749],[-84.319594,34.990226],[-83.618546,34.984749],[-83.109191,35.00118]]]
99+
}
100+
}]
101+
}
102+
}, {
103+
"type": "scattergeo",
104+
"locations": [0],
105+
"marker": {"size": 40},
106+
"geo": "geo4",
107+
"geojson": {
108+
"type": "FeatureCollection",
109+
"features": [{
110+
"type": "Feature",
111+
"id": 0,
112+
"geometry": {
113+
"type": "Polygon",
114+
"coordinates": [[
115+
[-87.359296, 35.00118], [-85.606675, 34.984749], [-85.431413, 34.124869], [-85.184951, 32.859696],
116+
[-85.069935, 32.580372], [-84.960397, 32.421541], [-85.004212, 32.322956], [-84.889196, 32.262709],
117+
[-85.058981, 32.13674], [-85.053504, 32.01077], [-85.141136, 31.840985], [-85.042551, 31.539753],
118+
[-85.113751, 31.27686], [-85.004212, 31.003013], [-85.497137, 30.997536], [-87.600282, 30.997536],
119+
[-87.633143, 30.86609], [-87.408589, 30.674397], [-87.446927, 30.510088], [-87.37025, 30.427934],
120+
[-87.518128, 30.280057], [-87.655051, 30.247195], [-87.90699, 30.411504], [-87.934375, 30.657966],
121+
[-88.011052, 30.685351], [-88.10416, 30.499135], [-88.137022, 30.318396], [-88.394438, 30.367688],
122+
[-88.471115, 31.895754], [-88.241084, 33.796253], [-88.098683, 34.891641], [-88.202745, 34.995703],
123+
[-87.359296, 35.00118]
124+
]]
125+
}
126+
}, {
127+
"type": "Feature",
128+
"id": 1,
129+
"geometry": {
130+
"type": "Polygon",
131+
"coordinates": [[[-83.109191,35.00118],[-83.322791,34.787579],[-83.339222,34.683517],[-83.005129,34.469916],[-82.901067,34.486347],[-82.747713,34.26727],[-82.714851,34.152254],[-82.55602,33.94413],[-82.325988,33.81816],[-82.194542,33.631944],[-81.926172,33.462159],[-81.937125,33.347144],[-81.761863,33.160928],[-81.493493,33.007573],[-81.42777,32.843265],[-81.416816,32.629664],[-81.279893,32.558464],[-81.121061,32.290094],[-81.115584,32.120309],[-80.885553,32.032678],[-81.132015,31.693108],[-81.175831,31.517845],[-81.279893,31.364491],[-81.290846,31.20566],[-81.400385,31.13446],[-81.444201,30.707258],[-81.718048,30.745597],[-81.948079,30.827751],[-82.041187,30.751074],[-82.002849,30.564858],[-82.046664,30.362211],[-82.167157,30.356734],[-82.216449,30.570335],[-83.498053,30.647012],[-84.867289,30.712735],[-85.004212,31.003013],[-85.113751,31.27686],[-85.042551,31.539753],[-85.141136,31.840985],[-85.053504,32.01077],[-85.058981,32.13674],[-84.889196,32.262709],[-85.004212,32.322956],[-84.960397,32.421541],[-85.069935,32.580372],[-85.184951,32.859696],[-85.431413,34.124869],[-85.606675,34.984749],[-84.319594,34.990226],[-83.618546,34.984749],[-83.109191,35.00118]]]
132+
}
133+
}]
134+
}
135+
}],
136+
"layout": {
137+
"width": 600,
138+
"height": 400,
139+
"showlegend": false,
140+
"grid": {"rows": 2, "columns": 2},
141+
"geo": {
142+
"domain": {"row": 0, "column": 0},
143+
"fitbounds": "geojson"
144+
},
145+
"geo2": {
146+
"domain": {"row": 1, "column": 0},
147+
"fitbounds": "geojson"
148+
},
149+
"geo3": {
150+
"domain": {"row": 0, "column": 1},
151+
"fitbounds": "locations"
152+
},
153+
"geo4": {
154+
"domain": {"row": 1, "column": 1},
155+
"fitbounds": "locations"
156+
},
157+
"annotations": [{
158+
"text": "fitbounds: 'geojson'",
159+
"font": {"size": 20},
160+
"showarrow": false,
161+
"xref": "paper",
162+
"x": 0,
163+
"xanchor": "left",
164+
"yref": "paper",
165+
"y": 1.02,
166+
"yanchor": "bottom"
167+
}, {
168+
"text": "fitbounds: 'locations'",
169+
"font": {"size": 20},
170+
"showarrow": false,
171+
"xref": "paper",
172+
"x": 1,
173+
"xanchor": "right",
174+
"yref": "paper",
175+
"y": 1.02,
176+
"yanchor": "bottom"
177+
}],
178+
"margin": {"l": 20, "r": 20, "b": 20, "t": 40}
179+
}
180+
}

0 commit comments

Comments
 (0)