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

Skip to content

Commit 3829a38

Browse files
committed
Merged with master
2 parents 6e2ba19 + 6662c7a commit 3829a38

18 files changed

+3223
-154
lines changed

plotly/plotly_aux/plotly.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
offline = structargs.(f{idx});
2323
offline_given = offline;
2424
else
25-
offline = false;
25+
offline = true;
2626
offline_given = offline;
2727
end
2828

plotly/plotlyfig.m

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
obj.PlotlyDefaults.Bargap = 0;
102102
obj.PlotlyDefaults.CaptionMarginIncreaseFactor = 1.2;
103103
obj.PlotlyDefaults.MinCaptionMargin = 80;
104+
obj.PlotlyDefaults.IsLight = false;
105+
obj.PlotlyDefaults.isGeoaxis = false;
104106

105107
%-State-%
106108
obj.State.Figure = [];
@@ -514,13 +516,16 @@ function validate(obj)
514516
args.filename = obj.PlotOptions.FileName;
515517
args.fileopt = obj.PlotOptions.FileOpt;
516518
args.world_readable = obj.PlotOptions.WorldReadable;
519+
args.offline = obj.PlotOptions.Offline;
517520

518521
%layout
519522
args.layout = obj.layout;
520523

521524
if obj.PlotOptions.WriteFile
525+
522526
%send to plotly
523527
if ~obj.PlotOptions.Offline
528+
524529
response = plotly(obj.data, args);
525530

526531
%update response
@@ -624,12 +629,16 @@ function validate(obj)
624629

625630
% reverse plots
626631
nprev = length(plots) - np + 1;
627-
632+
628633
% update the plot fields
629-
obj.State.Figure.NumPlots = obj.State.Figure.NumPlots + 1;
630-
obj.State.Plot(obj.State.Figure.NumPlots).Handle = handle(plots(nprev));
631-
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
632-
obj.State.Plot(obj.State.Figure.NumPlots).Class = getGraphClass(plots(nprev));
634+
if ~strcmpi(getGraphClass(plots(nprev)), 'light')
635+
obj.State.Figure.NumPlots = obj.State.Figure.NumPlots + 1;
636+
obj.State.Plot(obj.State.Figure.NumPlots).Handle = handle(plots(nprev));
637+
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
638+
obj.State.Plot(obj.State.Figure.NumPlots).Class = getGraphClass(plots(nprev));
639+
else
640+
obj.PlotlyDefaults.IsLight = true;
641+
end
633642
end
634643

635644
% this works for pareto
@@ -716,7 +725,7 @@ function validate(obj)
716725
end
717726

718727
% update plots
719-
obj.PlotOptions.nplots = obj.State.Figure.NumPlots;
728+
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;
720729

721730
for n = 1:obj.State.Figure.NumPlots
722731
updateData(obj,n);
@@ -735,11 +744,13 @@ function validate(obj)
735744
% update annotations
736745
for n = 1:obj.State.Figure.NumTexts
737746
try
738-
if ~obj.PlotOptions.is_headmap_axis
739-
updateAnnotation(obj,n);
740-
else
747+
if obj.PlotOptions.is_headmap_axis
741748
updateHeatmapAnnotation(obj,n);
742749
obj.PlotOptions.CleanFeedTitle = false;
750+
elseif obj.PlotlyDefaults.isGeoaxis
751+
% TODO
752+
else
753+
updateAnnotation(obj,n);
743754
end
744755
catch
745756
% TODO to the future
@@ -1053,7 +1064,8 @@ function delete(obj)
10531064
|| strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ...
10541065
|| strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')...
10551066
|| strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')...
1056-
|| strcmpi(fieldname,'scatter')...
1067+
|| strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')...
1068+
|| strcmpi(fieldname,'scattergeo') ...
10571069
)
10581070
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
10591071
end

plotly/plotlyfig_aux/core/updateAxis.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,28 @@
6161
is_headmap_axis = isfield(axis_data, 'XDisplayData');
6262
obj.PlotOptions.is_headmap_axis = is_headmap_axis;
6363

64+
%-------------------------------------------------------------------------%
65+
66+
%-check if geo-axis-%
67+
isGeoaxis = isfield(axis_data, 'Type') && strcmpi(axis_data.Type, 'geoaxes');
68+
obj.PlotlyDefaults.isGeoaxis = isGeoaxis;
69+
70+
%-------------------------------------------------------------------------%
71+
6472
%-xaxis-%
65-
if ~is_headmap_axis
66-
xaxis = extractAxisData(obj,axis_data,'X');
73+
if is_headmap_axis
74+
xaxis = extractHeatmapAxisData(obj,axis_data, 'X');
6775
else
68-
xaxis = extractHeatmapAxisData(obj,axis_data,'X');
76+
xaxis = extractAxisData(obj,axis_data, 'X');
6977
end
7078

7179
%-------------------------------------------------------------------------%
7280

7381
%-yaxis-%
74-
if ~is_headmap_axis
75-
yaxis = extractAxisData(obj,axis_data,'Y');
82+
if is_headmap_axis
83+
yaxis = extractHeatmapAxisData(obj,axis_data, 'Y');
7684
else
77-
yaxis = extractHeatmapAxisData(obj,axis_data,'Y');
85+
yaxis = extractAxisData(obj,axis_data, 'Y');
7886
end
7987

8088
%-------------------------------------------------------------------------%

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,20 @@
2828
elseif strcmpi(obj.PlotOptions.TreatAs, 'bar3h')
2929
updateBar3h(obj, dataIndex);
3030
elseif strcmpi(obj.PlotOptions.TreatAs, 'surf')
31-
updateSurf(obj, dataIndex);
31+
updateSurf(obj, dataIndex);
3232
elseif strcmpi(obj.PlotOptions.TreatAs, 'comet') || strcmpi(obj.PlotOptions.TreatAs, 'comet3')
3333
updateComet(obj, dataIndex);
34+
elseif strcmpi(obj.PlotOptions.TreatAs, 'fmesh')
35+
updateFmesh(obj, dataIndex);
36+
elseif strcmpi(obj.PlotOptions.TreatAs, 'mesh')
37+
updateMesh(obj, dataIndex);
38+
elseif strcmpi(obj.PlotOptions.TreatAs, 'surfc')
39+
updateSurfc(obj, dataIndex);
40+
elseif strcmpi(obj.PlotOptions.TreatAs, 'meshc')
41+
updateSurfc(obj, dataIndex);
42+
elseif strcmpi(obj.PlotOptions.TreatAs, 'surfl')
43+
updateSurfl(obj, dataIndex);
44+
3445
% this one will be revomed
3546
elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube')
3647
updateStreamtube(obj, dataIndex);
@@ -42,7 +53,13 @@
4253

4354
switch lower(obj.State.Plot(dataIndex).Class)
4455

56+
%--GEOAXES SPECIAL CASE--%
57+
case 'geoaxes'
58+
UpdateGeoAxes(obj, dataIndex);
59+
4560
%--CORE PLOT OBJECTS--%
61+
case 'geobubble'
62+
updateGeobubble(obj, dataIndex);
4663
case 'scatterhistogram'
4764
updateScatterhistogram(obj, dataIndex);
4865
case 'wordcloud'
@@ -56,7 +73,11 @@
5673
updateImage3D(obj, dataIndex);
5774
end
5875
case 'line'
59-
updateLineseries(obj, dataIndex);
76+
if obj.PlotlyDefaults.isGeoaxis
77+
updateGeoPlot(obj, dataIndex);
78+
else
79+
updateLineseries(obj, dataIndex);
80+
end
6081
case 'categoricalhistogram'
6182
updateCategoricalHistogram(obj, dataIndex);
6283
case 'histogram'
@@ -74,7 +95,7 @@
7495
updateRectangle(obj,dataIndex);
7596
case 'surface'
7697
updateSurfaceplot(obj,dataIndex);
77-
case 'functionsurface'
98+
case {'functionsurface', 'parameterizedfunctionsurface'}
7899
updateFunctionSurface(obj,dataIndex);
79100
case 'implicitfunctionsurface'
80101
updateImplicitFunctionSurface(obj,dataIndex);
@@ -112,7 +133,9 @@
112133
updateQuivergroup(obj, dataIndex);
113134
case 'scatter'
114135
if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes')
115-
updateScatterPolar(obj, dataIndex);
136+
updateScatterPolar(obj, dataIndex);
137+
elseif obj.PlotlyDefaults.isGeoaxis
138+
updateGeoScatter(obj, dataIndex);
116139
else
117140
updateScatter(obj, dataIndex);
118141
end
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
function UpdateGeoAxes(obj, geoIndex)
2+
3+
%-AXIS INDEX-%
4+
axIndex = obj.getAxisIndex(obj.State.Plot(geoIndex).AssociatedAxis);
5+
6+
%-GET DATA STRUCTURE- %
7+
geoData = get(obj.State.Plot(geoIndex).Handle);
8+
9+
%-CHECK FOR MULTIPLE AXES-%
10+
[xsource, ysource] = findSourceAxis(obj,axIndex);
11+
12+
%-------------------------------------------------------------------------%
13+
14+
%-set domain geo plot-%
15+
xo = geoData.Position(1);
16+
yo = geoData.Position(2);
17+
w = geoData.Position(3);
18+
h = geoData.Position(4);
19+
20+
geo.domain.x = min([xo xo + w],1);
21+
geo.domain.y = min([yo yo + h],1);
22+
23+
%-------------------------------------------------------------------------%
24+
25+
%-setting projection-%
26+
geo.projection.type = 'mercator';
27+
28+
%-------------------------------------------------------------------------%
29+
30+
%-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
42+
43+
geo.showocean = true;
44+
geo.showcoastlines = false;
45+
geo.showland = true;
46+
47+
%-------------------------------------------------------------------------%
48+
49+
%-setting latitude axis-%
50+
latTick = geoData.LatitudeAxis.TickValues;
51+
52+
geo.lataxis.range = geoData.LatitudeLimits;
53+
geo.lataxis.tick0 = latTick(1);
54+
geo.lataxis.dtick = mean(diff(latTick));
55+
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);
60+
end
61+
62+
%-------------------------------------------------------------------------%
63+
64+
%-setting longitude axis-%
65+
lonTick = geoData.LongitudeAxis.TickValues;
66+
67+
geo.lonaxis.range = geoData.LongitudeLimits;
68+
geo.lonaxis.tick0 = lonTick(1);
69+
geo.lonaxis.dtick = mean(diff(lonTick));
70+
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);
75+
end
76+
77+
%-------------------------------------------------------------------------%
78+
79+
%-set map center-%
80+
geo.center.lat = geoData.MapCenter(1);
81+
geo.center.lon = geoData.MapCenter(2);
82+
83+
%-------------------------------------------------------------------------%
84+
85+
%-set better resolution-%
86+
geo.resolution = '50';
87+
88+
%-------------------------------------------------------------------------%
89+
90+
%-set geo axes to layout-%
91+
obj.layout = setfield(obj.layout, sprintf('geo%d', xsource+1), geo);
92+
93+
%-------------------------------------------------------------------------%
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
135+
end

0 commit comments

Comments
 (0)