Skip to content

Commit 7acaaf9

Browse files
add geoplot functionality in fig2plotly
1 parent 49ce2b2 commit 7acaaf9

File tree

7 files changed

+345
-9
lines changed

7 files changed

+345
-9
lines changed

plotly/plotly_aux/plotly.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
offline_given = true;
5858
end
5959

60-
if ~offline_given
60+
if offline_given
6161
obj = plotlyfig(args, structargs);
6262
obj.layout.width = 840;
6363
obj.layout.height = 630;

plotly/plotlyfig.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,13 @@ function validate(obj)
742742
% update annotations
743743
for n = 1:obj.State.Figure.NumTexts
744744
try
745-
if ~obj.PlotOptions.is_headmap_axis
746-
updateAnnotation(obj,n);
747-
else
745+
if obj.PlotOptions.is_headmap_axis
748746
updateHeatmapAnnotation(obj,n);
749747
obj.PlotOptions.CleanFeedTitle = false;
748+
elseif obj.PlotlyDefaults.isGeoaxis
749+
% TODO
750+
else
751+
updateAnnotation(obj,n);
750752
end
751753
catch
752754
% TODO to the future

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@
6969
updateImage3D(obj, dataIndex);
7070
end
7171
case 'line'
72-
updateLineseries(obj, dataIndex);
72+
if obj.PlotlyDefaults.isGeoaxis
73+
updateGeoPlot(obj, dataIndex);
74+
else
75+
updateLineseries(obj, dataIndex);
76+
end
7377
case 'categoricalhistogram'
7478
updateCategoricalHistogram(obj, dataIndex);
7579
case 'histogram'

plotly/plotlyfig_aux/handlegraphics/UpdateGeoAxes.m

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function UpdateGeoAxes(obj, geoIndex)
4646

4747
%-------------------------------------------------------------------------%
4848

49-
%-setting latitude axis
49+
%-setting latitude axis-%
5050
latTick = geoData.LatitudeAxis.TickValues;
5151

5252
geo.lataxis.range = geoData.LatitudeLimits;
@@ -61,7 +61,7 @@ function UpdateGeoAxes(obj, geoIndex)
6161

6262
%-------------------------------------------------------------------------%
6363

64-
%-setting longitude axis
64+
%-setting longitude axis-%
6565
lonTick = geoData.LongitudeAxis.TickValues;
6666

6767
geo.lonaxis.range = geoData.LongitudeLimits;
@@ -75,10 +75,61 @@ function UpdateGeoAxes(obj, geoIndex)
7575
end
7676

7777
%-------------------------------------------------------------------------%
78+
79+
%-set map center-%
80+
geo.center.lat = geoData.MapCenter(1);
81+
geo.center.lon = geoData.MapCenter(2);
7882

79-
%-set geo axes to layout-%
83+
%-------------------------------------------------------------------------%
84+
85+
%-set better resolution-%
86+
geo.resolution = '50';
87+
88+
%-------------------------------------------------------------------------%
8089

90+
%-set geo axes to layout-%
8191
obj.layout = setfield(obj.layout, sprintf('geo%d', xsource+1), geo);
8292

8393
%-------------------------------------------------------------------------%
94+
95+
%-TEXT STTINGS-%
96+
isText = false;
97+
child = geoData.Children;
98+
t = 1;
99+
100+
for n=1:length(child)
101+
if strcmpi(child(n).Type, 'text')
102+
isText = true;
103+
texts{t} = child(t).String;
104+
lats(t) = child(t).Position(1);
105+
lons(t) = child(t).Position(2);
106+
sizes(t) = child(t).FontSize;
107+
families{t} = matlab2plotlyfont(child(t).FontName);
108+
colors{t} = sprintf('rgb(%f,%f,%f)', child(t).Color);
109+
110+
if strcmpi(child(t).HorizontalAlignment, 'left')
111+
pos{t} = 'right';
112+
elseif strcmpi(child(t).HorizontalAlignment, 'right')
113+
pos{t} = 'left';
114+
else
115+
pos{t} = child(t).HorizontalAlignment;
116+
end
117+
118+
t = t + 1;
119+
end
120+
end
121+
122+
if isText
123+
obj.data{geoIndex}.type = 'scattergeo';
124+
obj.data{geoIndex}.mode = 'text';
125+
obj.data{geoIndex}.text = texts;
126+
obj.data{geoIndex}.lat = lats;
127+
obj.data{geoIndex}.lon = lons;
128+
obj.data{geoIndex}.geo = obj.data{geoIndex-1}.geo;
129+
130+
obj.data{geoIndex}.textfont.size = sizes;
131+
obj.data{geoIndex}.textfont.color = colors;
132+
obj.data{geoIndex}.textfont.family = families;
133+
obj.data{geoIndex}.textposition = pos;
134+
end
84135
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function updateGeoPlot(obj,geoIndex)
2+
3+
%-AXIS INDEX-%
4+
axIndex = obj.getAxisIndex(obj.State.Plot(geoIndex).AssociatedAxis);
5+
6+
%-GET STRUCTURES-%
7+
geoData = get(obj.State.Plot(geoIndex).Handle);
8+
axisData = geoData.Parent;
9+
figureData = get(obj.State.Figure.Handle);
10+
11+
%-CHECK FOR MULTIPLE AXES-%
12+
[xsource, ysource] = findSourceAxis(obj,axIndex);
13+
14+
%-ASSOCIATE GEO-AXES LAYOUT-%
15+
obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1);
16+
17+
%-------------------------------------------------------------------------%
18+
19+
%-set scattergeo type-%
20+
obj.data{geoIndex}.type = 'scattergeo';
21+
22+
%-------------------------------------------------------------------------%
23+
24+
%-set scattergeo mode-%
25+
obj.data{geoIndex}.mode = 'lines+markers';
26+
27+
%-------------------------------------------------------------------------%
28+
29+
%-set plot data-%
30+
obj.data{geoIndex}.lat = geoData.LatitudeData;
31+
obj.data{geoIndex}.lon = geoData.LongitudeData;
32+
33+
%-------------------------------------------------------------------------%
34+
35+
%-get marker setting-%
36+
[marker, linee] = extractGeoLinePlusMarker(geoData, axisData);
37+
38+
%-------------------------------------------------------------------------%
39+
40+
%-set marker field-%
41+
obj.data{geoIndex}.marker = marker;
42+
43+
if strcmpi(geoData.Marker, 'none')
44+
obj.data{geoIndex}.mode = 'lines';
45+
end
46+
47+
%-------------------------------------------------------------------------%
48+
49+
%-set line field-%
50+
obj.data{geoIndex}.line = linee;
51+
52+
%-------------------------------------------------------------------------%
53+
end

plotly/plotlyfig_aux/handlegraphics/updateWordcloud.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function updateWordcloud(obj,scatterIndex)
123123
%-------------------------------------------------------------------------%
124124

125125
%-det font family-%
126-
obj.data{scatterIndex}.textfont.family = matlab2plotlyfont(scatter_data.FontName);;
126+
obj.data{scatterIndex}.textfont.family = matlab2plotlyfont(scatter_data.FontName);
127127

128128
%-------------------------------------------------------------------------%
129129

0 commit comments

Comments
 (0)