Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f6fcc7

Browse files
committed
add support for 'connectgaps'
1 parent 197db01 commit 9f6fcc7

File tree

5 files changed

+103
-18
lines changed

5 files changed

+103
-18
lines changed

src/traces/scattermapbox/attributes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var scatterGeoAttrs = require('../scattergeo/attributes');
12+
var scatterAttrs = require('../scatter/attributes');
1213
var plotAttrs = require('../../plots/attributes');
1314
var extendFlat = require('../../lib/extend').extendFlat;
1415

@@ -42,7 +43,7 @@ module.exports = {
4243
dash: lineAttrs.dash // TODO
4344
},
4445

45-
//connectgaps
46+
connectgaps: scatterAttrs.connectgaps,
4647

4748
marker: {
4849
symbol: {

src/traces/scattermapbox/convert.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,37 @@ function makeBlankGeoJSON() {
8484
}
8585

8686
function makeLineGeoJSON(trace) {
87+
var len = getCoordLen(trace),
88+
connectgaps = trace.connectgaps;
89+
90+
var coords = [],
91+
lineString = [];
92+
93+
for(var i = 0; i < len; i++) {
94+
var lon = trace.lon[i],
95+
lat = trace.lat[i];
96+
97+
if(checkLonLat(lon, lat)) {
98+
lineString.push([+lon, +lat]);
99+
}
100+
else if(!connectgaps && lineString.length > 0) {
101+
coords.push(lineString);
102+
lineString = [];
103+
}
104+
}
105+
106+
coords.push(lineString);
107+
87108
return {
88109
type: 'MultiLineString',
89-
coordinates: [calcCoords(trace)]
110+
coordinates: coords
90111
};
91112
}
92113

93114
// N.B. `hash` is mutated here
94115
function makeMarkerGeoJSON(trace, hash) {
95116
var marker = trace.marker,
96-
len = trace.lon.length,
117+
len = getCoordLen(trace),
97118
hasColorArray = Array.isArray(marker.color),
98119
hasSizeArray = Array.isArray(marker.size);
99120

@@ -117,7 +138,7 @@ function makeMarkerGeoJSON(trace, hash) {
117138
if(hasColorArray) translate(props, COLOR_PROP, marker.color, i);
118139
if(hasSizeArray) translate(props, SIZE_PROP, marker.size, i);
119140

120-
if(isNumeric(lon) && isNumeric(lat)) {
141+
if(checkLonLat(lon, lat)) {
121142
features.push({
122143
type: 'Feature',
123144
geometry: {
@@ -199,19 +220,11 @@ function calcMarkerSize(trace, hash) {
199220
return out;
200221
}
201222

223+
function checkLonLat(lon, lat) {
224+
return isNumeric(lon) && isNumeric(lat);
225+
}
202226

203-
function calcCoords(trace) {
204-
var len = trace.lon.length;
205-
var coordinates = [];
206-
207-
for(var i = 0; i < len; i++) {
208-
var lon = trace.lon[i],
209-
lat = trace.lat[i];
210-
211-
if(isNumeric(lon) && isNumeric(lat)) {
212-
coordinates.push([+lon, +lat]);
213-
}
214-
}
215-
216-
return coordinates;
227+
// lon and lat have the same length after the defaults step
228+
function getCoordLen(trace) {
229+
return trace.lon.length;
217230
}

src/traces/scattermapbox/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4343

4444
if(subTypes.hasLines(traceOut)) {
4545
handleLineDefaults(traceIn, traceOut, defaultColor, coerce);
46+
coerce('connectgaps');
4647
}
4748

4849
if(subTypes.hasMarkers(traceOut)) {
103 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scattermapbox",
5+
"mode": "lines",
6+
"lon": [
7+
10,
8+
20,
9+
30,
10+
null,
11+
20,
12+
30,
13+
40
14+
],
15+
"lat": [
16+
10,
17+
20,
18+
30,
19+
null,
20+
10,
21+
20,
22+
30
23+
],
24+
"line": {
25+
"width": 5
26+
},
27+
"name": "connectgaps false"
28+
},
29+
{
30+
"type": "scattermapbox",
31+
"mode": "lines",
32+
"lon": [
33+
10,
34+
20,
35+
30,
36+
null,
37+
20,
38+
30,
39+
40
40+
],
41+
"lat": [
42+
-10,
43+
-20,
44+
-30,
45+
null,
46+
-10,
47+
-20,
48+
-30
49+
],
50+
"line": {
51+
"width": 10
52+
},
53+
"connectgaps": true,
54+
"name": "connectgaps true"
55+
}
56+
],
57+
"layout": {
58+
"mapbox": {
59+
"style": "streets",
60+
"zoom": 1.5,
61+
"center": {
62+
"lon": 56,
63+
"lat": 1
64+
}
65+
},
66+
"height": 450,
67+
"width": 1100,
68+
"autosize": true
69+
}
70+
}

0 commit comments

Comments
 (0)