Skip to content

Commit c483e63

Browse files
committed
Added support for comet
1 parent b73a0a2 commit c483e63

File tree

4 files changed

+152
-102
lines changed

4 files changed

+152
-102
lines changed

plotly/plotlyfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ function validate(obj)
534534
web(response.url, '-browser');
535535
end
536536
else
537-
obj.url = plotlyoffline(obj);
537+
obj.url = plotlyoffline(obj);
538538
if obj.PlotOptions.OpenURL
539539
web(obj.url, '-browser');
540540
end

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
updateBar3h(obj, dataIndex);
3030
elseif strcmpi(obj.PlotOptions.TreatAs, 'surf')
3131
updateSurf(obj, dataIndex);
32-
32+
elseif strcmpi(obj.PlotOptions.TreatAs, 'comet')
33+
updateComet(obj, dataIndex);
3334
% this one will be revomed
3435
elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube')
3536
updateStreamtube(obj, dataIndex);
@@ -191,4 +192,33 @@
191192

192193
%-------------------------------------------------------------------------%
193194

195+
try
196+
if obj.layout.isAnimation
197+
%- Play Button Options-%
198+
opts{1} = nan;
199+
opts{2}.frame.duration = 5;
200+
opts{2}.frame.redraw = false;
201+
opts{2}.mode = 'immediate';
202+
opts{2}.transition.duration = 5;
203+
204+
button{1}.label = '▶';
205+
button{1}.method = 'animate';
206+
button{1}.args = opts;
207+
208+
obj.layout.updatemenus{1}.type = 'buttons';
209+
obj.layout.updatemenus{1}.buttons = button;
210+
obj.layout.updatemenus{1}.pad.r = 70;
211+
obj.layout.updatemenus{1}.pad.t = 10;
212+
obj.layout.updatemenus{1}.direction = 'left';
213+
obj.layout.updatemenus{1}.showactive = true;
214+
obj.layout.updatemenus{1}.x = 0.01;
215+
obj.layout.updatemenus{1}.y = 0.01;
216+
obj.layout.updatemenus{1}.xanchor = 'left';
217+
obj.layout.updatemenus{1}.yanchor = 'top';
218+
219+
obj.layout = rmfield(obj.layout,'isAnimation');
220+
end
221+
catch
222+
end
223+
194224
end

plotly/plotlyfig_aux/handlegraphics/updateAnimatedLine.m

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ 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(plotIndex);
57-
5856
%-PLOT DATA STRUCTURE- %
5957
plot_data = get(obj.State.Plot(plotIndex).Handle);
6058

59+
animObjs = obj.State.Plot(plotIndex).AssociatedAxis.Children;
60+
61+
for i=1:numel(animObjs)
62+
if isequaln(get(animObjs(i)),plot_data)
63+
animObj = animObjs(i);
64+
end
65+
end
66+
6167
%-CHECK FOR MULTIPLE AXES-%
6268
[xsource, ysource] = findSourceAxis(obj,axIndex);
6369

@@ -74,7 +80,13 @@ function updateAnimatedLine(obj,plotIndex)
7480
%-------------------------------------------------------------------------%
7581

7682
%-getting data-%
77-
[x,y] = getpoints(animLine);
83+
try
84+
[x,y,z] = getpoints(animObj);
85+
catch
86+
x=plot_data.XData;
87+
y=plot_data.YData;
88+
z=plot_data.ZData;
89+
end
7890

7991
%-------------------------------------------------------------------------%
8092

@@ -108,7 +120,7 @@ function updateAnimatedLine(obj,plotIndex)
108120
r = sqrt(x.^2 + y.^2);
109121
obj.data{plotIndex}.r = r;
110122
else
111-
obj.data{plotIndex}.x = x(1);
123+
obj.data{plotIndex}.x = [x(1) x(1)];
112124
end
113125

114126
%-------------------------------------------------------------------------%
@@ -118,21 +130,19 @@ function updateAnimatedLine(obj,plotIndex)
118130
theta = atan2(x,y);
119131
obj.data{plotIndex}.theta = -(rad2deg(theta) - 90);
120132
else
121-
obj.data{plotIndex}.y = y(1);
133+
obj.data{plotIndex}.y = [y(1) y(1)];
122134
end
123135

124136
%-------------------------------------------------------------------------%
125137

126-
%-Fro 3D plots-%
138+
%-For 3D plots-%
127139
obj.PlotOptions.is3d = false; % by default
128140

129-
if isfield(plot_data,'ZData')
130-
131-
numbset = unique(plot_data.ZData);
132-
133-
if any(plot_data.ZData) && length(numbset)>1
141+
numbset = unique(z);
142+
if numel(numbset)>1
143+
if any(z)
134144
%-scatter z-%
135-
obj.data{plotIndex}.z = plot_data.ZData;
145+
obj.data{plotIndex}.z = [z(1) z(1)];
136146

137147
%-overwrite type-%
138148
obj.data{plotIndex}.type = 'scatter3d';
@@ -189,35 +199,24 @@ function updateAnimatedLine(obj,plotIndex)
189199
obj.data{plotIndex}.showlegend = showleg;
190200

191201
%-------------------------------------------------------------------------%
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;
199202

200-
button{1}.label = '▶';
201-
button{1}.method = 'animate';
202-
button{1}.args = opts;
203+
%-Add a temporary tag-%
204+
obj.layout.isAnimation = true;
203205

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';
206+
%-------------------------------------------------------------------------%
214207

215-
DD{plotIndex} = obj.data{plotIndex};
208+
%-Create Frames-%
209+
DD = obj.data{plotIndex};
216210

217211
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});
212+
sIdx = i - plot_data.MaximumNumPoints;
213+
if sIdx < 0
214+
sIdx=0;
215+
end
216+
DD.x=x(sIdx+1:i);
217+
DD.y=y(sIdx+1:i);
218+
obj.frames{i}.name = ['f',num2str(i)];
219+
obj.frames{i}.data{plotIndex} = DD;
221220
end
222221

223222
end

plotly/plotlyfig_aux/handlegraphics/updateComet.m

Lines changed: 85 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function updateAnimatedLine(obj,plotIndex)
1+
function updateComet(obj,plotIndex)
22

33
%----SCATTER FIELDS----%
44

@@ -53,11 +53,23 @@ 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(plotIndex);
57-
5856
%-PLOT DATA STRUCTURE- %
5957
plot_data = get(obj.State.Plot(plotIndex).Handle);
6058

59+
animObjs = obj.State.Plot(plotIndex).AssociatedAxis.Children;
60+
61+
for i=1:numel(animObjs)
62+
if isequaln(get(animObjs(i)),plot_data)
63+
animObj = animObjs(i);
64+
end
65+
if strcmpi(animObjs(i).Tag,'tail')
66+
tail = animObjs(i);
67+
end
68+
if strcmpi(animObjs(i).Tag,'body')
69+
body = animObjs(i);
70+
end
71+
end
72+
6173
%-CHECK FOR MULTIPLE AXES-%
6274
[xsource, ysource] = findSourceAxis(obj,axIndex);
6375

@@ -67,14 +79,8 @@ function updateAnimatedLine(obj,plotIndex)
6779

6880
%-------------------------------------------------------------------------%
6981

70-
%-if polar plot or not-%
71-
treatas = obj.PlotOptions.TreatAs;
72-
ispolar = strcmpi(treatas, 'compass') || strcmpi(treatas, 'ezpolar');
73-
74-
%-------------------------------------------------------------------------%
75-
7682
%-getting data-%
77-
[x,y] = getpoints(animLine);
83+
[x,y,z] = getpoints(tail);
7884

7985
%-------------------------------------------------------------------------%
8086

@@ -91,10 +97,6 @@ function updateAnimatedLine(obj,plotIndex)
9197
%-scatter type-%
9298
obj.data{plotIndex}.type = 'scatter';
9399

94-
if ispolar
95-
obj.data{plotIndex}.type = 'scatterpolar';
96-
end
97-
98100
%-------------------------------------------------------------------------%
99101

100102
%-scatter visible-%
@@ -103,36 +105,23 @@ function updateAnimatedLine(obj,plotIndex)
103105
%-------------------------------------------------------------------------%
104106

105107
%-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
108+
obj.data{plotIndex}.x = x(1);
113109

114110
%-------------------------------------------------------------------------%
115111

116112
%-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
113+
obj.data{plotIndex}.y = y(1);
123114

124115
%-------------------------------------------------------------------------%
125116

126-
%-Fro 3D plots-%
117+
%-For 3D plots-%
127118
obj.PlotOptions.is3d = false; % by default
128119

129-
if isfield(plot_data,'ZData')
130-
131-
numbset = unique(plot_data.ZData);
132-
133-
if any(plot_data.ZData) && length(numbset)>1
120+
numbset = unique(z);
121+
if numel(numbset)>1
122+
if any(z)
134123
%-scatter z-%
135-
obj.data{plotIndex}.z = plot_data.ZData;
124+
obj.data{plotIndex}.z = z(1);
136125

137126
%-overwrite type-%
138127
obj.data{plotIndex}.type = 'scatter3d';
@@ -145,7 +134,7 @@ function updateAnimatedLine(obj,plotIndex)
145134
%-------------------------------------------------------------------------%
146135

147136
%-scatter name-%
148-
obj.data{plotIndex}.name = plot_data.DisplayName;
137+
obj.data{plotIndex}.name = plot_data.Tag;
149138

150139
%-------------------------------------------------------------------------%
151140

@@ -189,35 +178,67 @@ function updateAnimatedLine(obj,plotIndex)
189178
obj.data{plotIndex}.showlegend = showleg;
190179

191180
%-------------------------------------------------------------------------%
192-
%- Play Button Options-%
193181

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});
182+
%-Add a temporary tag-%
183+
obj.layout.isAnimation = true;
184+
185+
%-------------------------------------------------------------------------%
186+
187+
%-Create Frames-%
188+
DD = obj.data{plotIndex};
189+
190+
switch(plot_data.Tag)
191+
case 'head'
192+
for i = 1:length(x)
193+
DD.x=[x(i) x(i)];
194+
DD.y=[y(i) y(i)];
195+
if obj.PlotOptions.is3d
196+
DD.z=[z(i) z(i)];
197+
end
198+
obj.frames{i}.data{plotIndex} = DD;
199+
obj.frames{i}.name=['f',num2str(i)];
200+
end
201+
case 'body'
202+
for i = 1:length(x)
203+
sIdx = i-animObj.MaximumNumPoints;
204+
if sIdx < 0
205+
sIdx=0;
206+
end
207+
DD.x=x(sIdx+1:i);
208+
DD.y=y(sIdx+1:i);
209+
if obj.PlotOptions.is3d
210+
DD.z=z(sIdx+1:i);
211+
end
212+
if i==length(x)
213+
DD.x=nan;
214+
DD.y=nan;
215+
if obj.PlotOptions.is3d
216+
DD.z=nan;
217+
end
218+
end
219+
obj.frames{i}.data{plotIndex} = DD;
220+
end
221+
case 'tail'
222+
for i = 1:length(x)
223+
DD.x=x(1:i);
224+
DD.y=y(1:i);
225+
if obj.PlotOptions.is3d
226+
DD.z=z(1:i);
227+
end
228+
if i < body.MaximumNumPoints
229+
rIdx = i;
230+
else
231+
rIdx = body.MaximumNumPoints;
232+
end
233+
if i ~= length(x)
234+
val = nan(rIdx,1);
235+
DD.x(end-rIdx+1:end)=val;
236+
DD.y(end-rIdx+1:end)=val;
237+
if obj.PlotOptions.is3d
238+
DD.z(end-rIdx+1:end)=val;
239+
end
240+
end
241+
obj.frames{i}.data{plotIndex} = DD;
242+
end
221243
end
222-
223244
end

0 commit comments

Comments
 (0)