Skip to content

Commit 6739f29

Browse files
Merge pull request #400 from plotly/add_geoRenderType_optional_paramter_to_geoscatter_geoplot_and_geobubble_functionalities
add geoRenderType optional paramter to geoscatter geoplot and geobubble functionalities
2 parents 6662c7a + 4748b85 commit 6739f29

File tree

5 files changed

+217
-89
lines changed

5 files changed

+217
-89
lines changed

plotly/plotlyfig.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
obj.PlotOptions.is_headmap_axis = false;
6161
obj.PlotOptions.Quality = -1;
6262
obj.PlotOptions.Zmin = [];
63+
obj.PlotOptions.geoRenderType = 'geo';
6364

6465
% offline options
6566
obj.PlotOptions.Offline = true;
@@ -251,6 +252,9 @@
251252
if(strcmpi(varargin{a},'Zmin'))
252253
obj.PlotOptions.Zmin = varargin{a+1};
253254
end
255+
if(strcmpi(varargin{a},'geoRenderType'))
256+
obj.PlotOptions.geoRenderType = varargin{a+1};
257+
end
254258
end
255259
end
256260

@@ -1063,7 +1067,7 @@ function delete(obj)
10631067
|| strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')...
10641068
|| strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')...
10651069
|| strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')...
1066-
|| strcmpi(fieldname,'scattergeo') ...
1070+
|| strcmpi(fieldname,'scattergeo') || strcmpi(fieldname,'scattermapbox')...
10671071
)
10681072
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
10691073
end

plotly/plotlyfig_aux/handlegraphics/UpdateGeoAxes.m

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,78 +17,96 @@ function UpdateGeoAxes(obj, geoIndex)
1717
w = geoData.Position(3);
1818
h = geoData.Position(4);
1919

20-
geo.domain.x = min([xo xo + w],1);
21-
geo.domain.y = min([yo yo + h],1);
20+
geoaxes.domain.x = min([xo xo + w],1);
21+
geoaxes.domain.y = min([yo yo + h],1);
2222

2323
%-------------------------------------------------------------------------%
2424

2525
%-setting projection-%
26-
geo.projection.type = 'mercator';
26+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
27+
geoaxes.projection.type = 'mercator';
28+
end
2729

2830
%-------------------------------------------------------------------------%
2931

3032
%-setting basemap-%
31-
geo.framecolor = 'rgb(120,120,120)';
32-
33-
if strcmpi(geoData.Basemap, 'streets-light')
34-
geo.oceancolor = 'rgba(20,220,220,1)';
35-
geo.landcolor = 'rgba(20,220,220,0.2)';
36-
elseif strcmpi(geoData.Basemap, 'colorterrain')
37-
geo.oceancolor = 'rgba(118,165,225,0.6)';
38-
geo.landcolor = 'rgba(190,180,170,1)';
39-
geo.showcountries = true;
40-
geo.showlakes = true;
41-
end
33+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
34+
geoaxes.framecolor = 'rgb(120,120,120)';
35+
36+
if strcmpi(geoData.Basemap, 'streets-light')
37+
geoaxes.oceancolor = 'rgba(20,220,220,1)';
38+
geoaxes.landcolor = 'rgba(20,220,220,0.2)';
39+
elseif strcmpi(geoData.Basemap, 'colorterrain')
40+
geoaxes.oceancolor = 'rgba(118,165,225,0.6)';
41+
geoaxes.landcolor = 'rgba(190,180,170,1)';
42+
geoaxes.showcountries = true;
43+
geoaxes.showlakes = true;
44+
end
4245

43-
geo.showocean = true;
44-
geo.showcoastlines = false;
45-
geo.showland = true;
46+
geoaxes.showocean = true;
47+
geoaxes.showcoastlines = false;
48+
geoaxes.showland = true;
49+
end
4650

4751
%-------------------------------------------------------------------------%
4852

4953
%-setting latitude axis-%
50-
latTick = geoData.LatitudeAxis.TickValues;
54+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
55+
latTick = geoData.LatitudeAxis.TickValues;
5156

52-
geo.lataxis.range = geoData.LatitudeLimits;
53-
geo.lataxis.tick0 = latTick(1);
54-
geo.lataxis.dtick = mean(diff(latTick));
57+
geoaxes.lataxis.range = geoData.LatitudeLimits;
58+
geoaxes.lataxis.tick0 = latTick(1);
59+
geoaxes.lataxis.dtick = mean(diff(latTick));
5560

56-
if strcmpi(geoData.Grid, 'on')
57-
geo.lataxis.showgrid = true;
58-
geo.lataxis.gridwidth = geoData.LineWidth;
59-
geo.lataxis.gridcolor = sprintf('rgba(%f,%f,%f,%f)', 255*geoData.GridColor, geoData.GridAlpha);
61+
if strcmpi(geoData.Grid, 'on')
62+
geoaxes.lataxis.showgrid = true;
63+
geoaxes.lataxis.gridwidth = geoData.LineWidth;
64+
geoaxes.lataxis.gridcolor = sprintf('rgba(%f,%f,%f,%f)', 255*geoData.GridColor, geoData.GridAlpha);
65+
end
6066
end
6167

6268
%-------------------------------------------------------------------------%
6369

6470
%-setting longitude axis-%
65-
lonTick = geoData.LongitudeAxis.TickValues;
71+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
72+
lonTick = geoData.LongitudeAxis.TickValues;
6673

67-
geo.lonaxis.range = geoData.LongitudeLimits;
68-
geo.lonaxis.tick0 = lonTick(1);
69-
geo.lonaxis.dtick = mean(diff(lonTick));
74+
geoaxes.lonaxis.range = geoData.LongitudeLimits;
75+
geoaxes.lonaxis.tick0 = lonTick(1);
76+
geoaxes.lonaxis.dtick = mean(diff(lonTick));
7077

71-
if strcmpi(geoData.Grid, 'on')
72-
geo.lonaxis.showgrid = true;
73-
geo.lonaxis.gridwidth = geoData.LineWidth;
74-
geo.lonaxis.gridcolor = sprintf('rgba(%f,%f,%f,%f)', 255*geoData.GridColor, geoData.GridAlpha);
78+
if strcmpi(geoData.Grid, 'on')
79+
geoaxes.lonaxis.showgrid = true;
80+
geoaxes.lonaxis.gridwidth = geoData.LineWidth;
81+
geoaxes.lonaxis.gridcolor = sprintf('rgba(%f,%f,%f,%f)', 255*geoData.GridColor, geoData.GridAlpha);
82+
end
7583
end
7684

7785
%-------------------------------------------------------------------------%
7886

7987
%-set map center-%
80-
geo.center.lat = geoData.MapCenter(1);
81-
geo.center.lon = geoData.MapCenter(2);
88+
geoaxes.center.lat = geoData.MapCenter(1);
89+
geoaxes.center.lon = geoData.MapCenter(2);
8290

8391
%-------------------------------------------------------------------------%
8492

8593
%-set better resolution-%
86-
geo.resolution = '50';
94+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
95+
geoaxes.resolution = '50';
96+
end
8797

88-
%-------------------------------------------------------------------------%
98+
%-----------------------------------------------------------------------------%
8999

90-
%-set geo axes to layout-%
91-
obj.layout = setfield(obj.layout, sprintf('geo%d', xsource+1), geo);
100+
%-set mapbox style-%
101+
if strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
102+
geoaxes.zoom = geoData.ZoomLevel - 1.4;
103+
104+
if strcmpi(geoData.Basemap, 'streets-light')
105+
geoaxes.style = 'carto-positron';
106+
elseif strcmpi(geoData.Basemap, 'colorterrain')
107+
geoaxes.style = 'stamen-terrain';
108+
end
109+
end
92110

93111
%-------------------------------------------------------------------------%
94112

@@ -120,16 +138,38 @@ function UpdateGeoAxes(obj, geoIndex)
120138
end
121139

122140
if isText
123-
obj.data{geoIndex}.type = 'scattergeo';
141+
142+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
143+
obj.data{geoIndex}.type = 'scattergeo';
144+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
145+
obj.data{geoIndex}.type = 'scattermapbox';
146+
end
147+
124148
obj.data{geoIndex}.mode = 'text';
125149
obj.data{geoIndex}.text = texts;
126150
obj.data{geoIndex}.lat = lats;
127151
obj.data{geoIndex}.lon = lons;
128-
obj.data{geoIndex}.geo = obj.data{geoIndex-1}.geo;
129152

130153
obj.data{geoIndex}.textfont.size = sizes;
131154
obj.data{geoIndex}.textfont.color = colors;
132155
obj.data{geoIndex}.textfont.family = families;
133156
obj.data{geoIndex}.textposition = pos;
157+
158+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
159+
obj.data{geoIndex}.geo = obj.data{geoIndex-1}.geo;
160+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
161+
obj.data{geoIndex}.subplot = obj.data{geoIndex-1}.subplot;
162+
end
163+
end
164+
165+
%-------------------------------------------------------------------------%
166+
167+
%-set geo axes to layout-%
168+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
169+
obj.layout = setfield(obj.layout, sprintf('geo%d', xsource+1), geoaxes);
170+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
171+
obj.layout = setfield(obj.layout, sprintf('mapbox%d', xsource+1), geoaxes);
134172
end
173+
174+
%-------------------------------------------------------------------------%
135175
end

plotly/plotlyfig_aux/handlegraphics/updateGeoPlot.m

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ function updateGeoPlot(obj,geoIndex)
1212
[xsource, ysource] = findSourceAxis(obj,axIndex);
1313

1414
%-ASSOCIATE GEO-AXES LAYOUT-%
15-
obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1);
15+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
16+
obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1);
17+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
18+
obj.data{geoIndex}.subplot = sprintf('mapbox%d', xsource+1);
19+
end
1620

1721
%-------------------------------------------------------------------------%
1822

1923
%-set scattergeo type-%
20-
obj.data{geoIndex}.type = 'scattergeo';
24+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
25+
obj.data{geoIndex}.type = 'scattergeo';
26+
27+
%-set scattermapbox type-%
28+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
29+
obj.data{geoIndex}.type = 'scattermapbox';
30+
end
2131

2232
%-------------------------------------------------------------------------%
2333

@@ -37,15 +47,27 @@ function updateGeoPlot(obj,geoIndex)
3747

3848
%-------------------------------------------------------------------------%
3949

40-
%-set marker field-%
41-
obj.data{geoIndex}.marker = marker;
42-
50+
%-corrections-%
4351
if strcmpi(geoData.Marker, 'none')
4452
obj.data{geoIndex}.mode = 'lines';
53+
else
54+
if strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
55+
marker.allowoverlap = true;
56+
marker = rmfield(marker, 'symbol');
57+
58+
if strcmp(marker.color, 'rgba(0,0,0,0)') && isfield(marker, 'line')
59+
marker.color = marker.line.color;
60+
end
61+
end
4562
end
4663

4764
%-------------------------------------------------------------------------%
4865

66+
%-set marker field-%
67+
obj.data{geoIndex}.marker = marker;
68+
69+
%-------------------------------------------------------------------------%
70+
4971
%-set line field-%
5072
obj.data{geoIndex}.line = linee;
5173

plotly/plotlyfig_aux/handlegraphics/updateGeoScatter.m

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@ function updateGeoScatter(obj,geoIndex)
1212
[xsource, ysource] = findSourceAxis(obj,axIndex);
1313

1414
%-ASSOCIATE GEO-AXES LAYOUT-%
15-
obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1);
15+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
16+
obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1);
17+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
18+
obj.data{geoIndex}.subplot = sprintf('mapbox%d', xsource+1);
19+
end
1620

1721
%-------------------------------------------------------------------------%
1822

1923
%-set scattergeo type-%
20-
obj.data{geoIndex}.type = 'scattergeo';
24+
if strcmpi(obj.PlotOptions.geoRenderType, 'geo')
25+
obj.data{geoIndex}.type = 'scattergeo';
26+
27+
%-set scattermapbox type-%
28+
elseif strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
29+
obj.data{geoIndex}.type = 'scattermapbox';
30+
end
2131

2232
%-------------------------------------------------------------------------%
2333

2434
%-set scattergeo mode-%
25-
obj.data{geoIndex}.mode = 'markers';
35+
obj.data{geoIndex}.mode = 'markers+text';
2636

2737
%-------------------------------------------------------------------------%
2838

@@ -35,10 +45,19 @@ function updateGeoScatter(obj,geoIndex)
3545
%-get marker setting-%
3646
marker = extractGeoMarker(geoData, axisData);
3747

48+
if strcmpi(obj.PlotOptions.geoRenderType, 'mapbox')
49+
marker.allowoverlap = true;
50+
marker = rmfield(marker, 'symbol');
51+
52+
if strcmp(marker.color, 'rgba(0,0,0,0)') && isfield(marker, 'line')
53+
marker.color = marker.line.color;
54+
end
55+
end
56+
3857
%-------------------------------------------------------------------------%
3958

4059
%-set marker field-%
41-
obj.data{geoIndex}.marker = marker;
60+
obj.data{geoIndex}.marker = marker;
4261

4362
%-------------------------------------------------------------------------%
4463
end

0 commit comments

Comments
 (0)