Skip to content

Commit 5aead69

Browse files
committed
Restructured code
1 parent 5d4743e commit 5aead69

File tree

3 files changed

+252
-29
lines changed

3 files changed

+252
-29
lines changed

plotly/plotly_offline_aux/plotlyoffline.m

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
link_text = '';
4040
end
4141

42-
% check if an animation
43-
if ~isempty(plotlyfig.frames)
44-
isAnimation = true;
45-
else
46-
isAnimation = false;
47-
end
48-
4942
% format the data and layout
5043
jdata = m2json(plotlyfig.data);
5144
jlayout = m2json(plotlyfig.layout);
@@ -63,19 +56,11 @@
6356
'</script>'], plotly_domain, link_text);
6457

6558
% template Plotly.plot
66-
if isAnimation
67-
script = sprintf(['\n Plotly.plot("%s", {\n"data": %s,\n"layout": %s,\n"frames": %s\n}).then(function(){'...
68-
'\n $(".%s.loading").remove();' ...
69-
'\n $(".link--embedview").text("%s");'...
70-
'\n });'], id, clean_jdata, clean_jlayout, clean_jframes,...
71-
id, link_text);
72-
else
73-
script = sprintf(['\n Plotly.plot("%s", %s, %s).then(function(){'...
74-
'\n $(".%s.loading").remove();' ...
75-
'\n $(".link--embedview").text("%s");'...
76-
'\n });'], id, clean_jdata, clean_jlayout, ...
77-
id, link_text);
78-
end
59+
script = sprintf(['\n Plotly.plot("%s", {\n"data": %s,\n"layout": %s,\n"frames": %s\n}).then(function(){'...
60+
'\n $(".%s.loading").remove();' ...
61+
'\n $(".link--embedview").text("%s");'...
62+
'\n });'], id, clean_jdata, clean_jlayout, clean_jframes,...
63+
id, link_text);
7964

8065
plotly_script = sprintf(['\n<div id="%s" style="height: %s;',...
8166
'width: %s;" class="plotly-graph-div">' ...

plotly/plotlyfig_aux/handlegraphics/updateAnimatedLine.m

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function updateAnimatedLine(obj,plotIndex)
5353
%-AXIS INDEX-%
5454
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
5555

56-
animLine = obj.State.Plot(plotIndex).AssociatedAxis.Children;
56+
animLine = obj.State.Plot(plotIndex).AssociatedAxis.Children(plotIndex);
5757

5858
%-PLOT DATA STRUCTURE- %
5959
plot_data = get(obj.State.Plot(plotIndex).Handle);
@@ -189,20 +189,35 @@ function updateAnimatedLine(obj,plotIndex)
189189
obj.data{plotIndex}.showlegend = showleg;
190190

191191
%-------------------------------------------------------------------------%
192-
% Play Button
193-
args = {NaN,struct('frame',struct('duration',0,'redraw',false),'mode','immediate','transition',struct('duration',0))};
194-
c{1} = struct('label','&#9654;','method','animate','args',{args});
192+
%- Play Button Options-%
195193

196-
% Stop/Pause Button
197-
% c{2} = struct('label','&#9724;','method','animate','args',{args2});
194+
opts{1} = nan;
195+
opts{2}.frame.duration = 0;
196+
opts{2}.frame.redraw = false;
197+
opts{2}.mode = 'immediate';
198+
opts{2}.transition.duration = 0;
199+
200+
button{1}.label = '&#9654;';
201+
button{1}.method = 'animate';
202+
button{1}.args = opts;
203+
204+
obj.layout.updatemenus{1}.type = 'buttons';
205+
obj.layout.updatemenus{1}.buttons = button;
206+
obj.layout.updatemenus{1}.pad.r = 70;
207+
obj.layout.updatemenus{1}.pad.t = 10;
208+
obj.layout.updatemenus{1}.direction = 'left';
209+
obj.layout.updatemenus{1}.showactive = true;
210+
obj.layout.updatemenus{1}.x = 0.01;
211+
obj.layout.updatemenus{1}.y = 0.01;
212+
obj.layout.updatemenus{1}.xanchor = 'left';
213+
obj.layout.updatemenus{1}.yanchor = 'top';
198214

199-
obj.layout.updatemenus={struct('buttons',{c},'type','buttons','pad',struct('r',70,'t',10),...
200-
'direction','left','showactive',true,'x',0.01,'xanchor','left','y',0.01,'yanchor','middle')};
201215
DD{plotIndex} = obj.data{plotIndex};
202216

203-
for i = 1:1:length(x)
217+
for i = 1:length(x)
204218
DD{plotIndex}.x=x(1:i);
205219
DD{plotIndex}.y=y(1:i);
206220
obj.frames{end+1} = struct('name',['f',num2str(i)],'data',{DD});
207221
end
222+
208223
end
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
function updateAnimatedLine(obj,plotIndex)
2+
3+
%----SCATTER FIELDS----%
4+
5+
% x - [DONE]
6+
% y - [DONE]
7+
% r - [HANDLED BY SCATTER]
8+
% t - [HANDLED BY SCATTER]
9+
% mode - [DONE]
10+
% name - [NOT SUPPORTED IN MATLAB]
11+
% text - [DONE]
12+
% error_y - [HANDLED BY ERRORBAR]
13+
% error_x - [NOT SUPPORTED IN MATLAB]
14+
% connectgaps - [NOT SUPPORTED IN MATLAB]
15+
% fill - [HANDLED BY AREA]
16+
% fillcolor - [HANDLED BY AREA]
17+
% opacity --- [TODO]
18+
% textfont - [NOT SUPPORTED IN MATLAB]
19+
% textposition - [NOT SUPPORTED IN MATLAB]
20+
% xaxis [DONE]
21+
% yaxis [DONE]
22+
% showlegend [DONE]
23+
% stream - [HANDLED BY PLOTLYSTREAM]
24+
% visible [DONE]
25+
% type [DONE]
26+
27+
% MARKER
28+
% marler.color - [DONE]
29+
% marker.size - [DONE]
30+
% marker.line.color - [DONE]
31+
% marker.line.width - [DONE]
32+
% marker.line.dash - [NOT SUPPORTED IN MATLAB]
33+
% marker.line.opacity - [NOT SUPPORTED IN MATLAB]
34+
% marker.line.smoothing - [NOT SUPPORTED IN MATLAB]
35+
% marker.line.shape - [NOT SUPPORTED IN MATLAB]
36+
% marker.opacity --- [TODO]
37+
% marker.colorscale - [NOT SUPPORTED IN MATLAB]
38+
% marker.sizemode - [NOT SUPPORTED IN MATLAB]
39+
% marker.sizeref - [NOT SUPPORTED IN MATLAB]
40+
% marker.maxdisplayed - [NOT SUPPORTED IN MATLAB]
41+
42+
% LINE
43+
44+
% line.color - [DONE]
45+
% line.width - [DONE]
46+
% line.dash - [DONE]
47+
% line.opacity --- [TODO]
48+
% line.smoothing - [NOT SUPPORTED IN MATLAB]
49+
% line.shape - [NOT SUPPORTED IN MATLAB]
50+
51+
%-------------------------------------------------------------------------%
52+
53+
%-AXIS INDEX-%
54+
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
55+
56+
animLine = obj.State.Plot(plotIndex).AssociatedAxis.Children(plotIndex);
57+
58+
%-PLOT DATA STRUCTURE- %
59+
plot_data = get(obj.State.Plot(plotIndex).Handle);
60+
61+
%-CHECK FOR MULTIPLE AXES-%
62+
[xsource, ysource] = findSourceAxis(obj,axIndex);
63+
64+
%-AXIS DATA-%
65+
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
66+
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
67+
68+
%-------------------------------------------------------------------------%
69+
70+
%-if polar plot or not-%
71+
treatas = obj.PlotOptions.TreatAs;
72+
ispolar = strcmpi(treatas, 'compass') || strcmpi(treatas, 'ezpolar');
73+
74+
%-------------------------------------------------------------------------%
75+
76+
%-getting data-%
77+
[x,y] = getpoints(animLine);
78+
79+
%-------------------------------------------------------------------------%
80+
81+
%-scatter xaxis-%
82+
obj.data{plotIndex}.xaxis = ['x' num2str(xsource)];
83+
84+
%-------------------------------------------------------------------------%
85+
86+
%-scatter yaxis-%
87+
obj.data{plotIndex}.yaxis = ['y' num2str(ysource)];
88+
89+
%-------------------------------------------------------------------------%
90+
91+
%-scatter type-%
92+
obj.data{plotIndex}.type = 'scatter';
93+
94+
if ispolar
95+
obj.data{plotIndex}.type = 'scatterpolar';
96+
end
97+
98+
%-------------------------------------------------------------------------%
99+
100+
%-scatter visible-%
101+
obj.data{plotIndex}.visible = strcmp(plot_data.Visible,'on');
102+
103+
%-------------------------------------------------------------------------%
104+
105+
%-scatter x-%
106+
107+
if ispolar
108+
r = sqrt(x.^2 + y.^2);
109+
obj.data{plotIndex}.r = r;
110+
else
111+
obj.data{plotIndex}.x = x(1);
112+
end
113+
114+
%-------------------------------------------------------------------------%
115+
116+
%-scatter y-%
117+
if ispolar
118+
theta = atan2(x,y);
119+
obj.data{plotIndex}.theta = -(rad2deg(theta) - 90);
120+
else
121+
obj.data{plotIndex}.y = y(1);
122+
end
123+
124+
%-------------------------------------------------------------------------%
125+
126+
%-Fro 3D plots-%
127+
obj.PlotOptions.is3d = false; % by default
128+
129+
if isfield(plot_data,'ZData')
130+
131+
numbset = unique(plot_data.ZData);
132+
133+
if any(plot_data.ZData) && length(numbset)>1
134+
%-scatter z-%
135+
obj.data{plotIndex}.z = plot_data.ZData;
136+
137+
%-overwrite type-%
138+
obj.data{plotIndex}.type = 'scatter3d';
139+
140+
%-flag to manage 3d plots-%
141+
obj.PlotOptions.is3d = true;
142+
end
143+
end
144+
145+
%-------------------------------------------------------------------------%
146+
147+
%-scatter name-%
148+
obj.data{plotIndex}.name = plot_data.DisplayName;
149+
150+
%-------------------------------------------------------------------------%
151+
152+
%-scatter mode-%
153+
if ~strcmpi('none', plot_data.Marker) ...
154+
&& ~strcmpi('none', plot_data.LineStyle)
155+
mode = 'lines+markers';
156+
elseif ~strcmpi('none', plot_data.Marker)
157+
mode = 'markers';
158+
elseif ~strcmpi('none', plot_data.LineStyle)
159+
mode = 'lines';
160+
else
161+
mode = 'none';
162+
end
163+
164+
obj.data{plotIndex}.mode = mode;
165+
166+
%-------------------------------------------------------------------------%
167+
168+
%-scatter line-%
169+
obj.data{plotIndex}.line = extractLineLine(plot_data);
170+
171+
%-------------------------------------------------------------------------%
172+
173+
%-scatter marker-%
174+
obj.data{plotIndex}.marker = extractLineMarker(plot_data);
175+
176+
%-------------------------------------------------------------------------%
177+
178+
%-scatter showlegend-%
179+
leg = get(plot_data.Annotation);
180+
legInfo = get(leg.LegendInformation);
181+
182+
switch legInfo.IconDisplayStyle
183+
case 'on'
184+
showleg = true;
185+
case 'off'
186+
showleg = false;
187+
end
188+
189+
obj.data{plotIndex}.showlegend = showleg;
190+
191+
%-------------------------------------------------------------------------%
192+
%- Play Button Options-%
193+
194+
opts{1} = nan;
195+
opts{2}.frame.duration = 0;
196+
opts{2}.frame.redraw = false;
197+
opts{2}.mode = 'immediate';
198+
opts{2}.transition.duration = 0;
199+
200+
button{1}.label = '&#9654;';
201+
button{1}.method = 'animate';
202+
button{1}.args = opts;
203+
204+
obj.layout.updatemenus{1}.type = 'buttons';
205+
obj.layout.updatemenus{1}.buttons = button;
206+
obj.layout.updatemenus{1}.pad.r = 70;
207+
obj.layout.updatemenus{1}.pad.t = 10;
208+
obj.layout.updatemenus{1}.direction = 'left';
209+
obj.layout.updatemenus{1}.showactive = true;
210+
obj.layout.updatemenus{1}.x = 0.01;
211+
obj.layout.updatemenus{1}.y = 0.01;
212+
obj.layout.updatemenus{1}.xanchor = 'left';
213+
obj.layout.updatemenus{1}.yanchor = 'top';
214+
215+
DD{plotIndex} = obj.data{plotIndex};
216+
217+
for i = 1:length(x)
218+
DD{plotIndex}.x=x(1:i);
219+
DD{plotIndex}.y=y(1:i);
220+
obj.frames{end+1} = struct('name',['f',num2str(i)],'data',{DD});
221+
end
222+
223+
end

0 commit comments

Comments
 (0)