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-%
5454axIndex = obj .getAxisIndex(obj .State .Plot(plotIndex ).AssociatedAxis);
5555
56- animLine = obj .State .Plot(plotIndex ).AssociatedAxis.Children(plotIndex );
57-
5856% -PLOT DATA STRUCTURE- %
5957plot_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-%
9298obj.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-%
127118obj.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)
189178obj.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 = ' ▶' ;
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
221243end
222-
223244end
0 commit comments