33 * @Author : zk
44 * @Date : 2022-03-23 10:02:49
55 * @LastEditors : zk
6- * @LastEditTime : 2022-06-08 13:36:34
6+ * @LastEditTime : 2022-06-15 20:11:18
77 */
88import { AnimationUtil } from '../utils/AnimationUtil' ;
99import { easingFunc } from '../utils/Easing' ;
@@ -24,7 +24,7 @@ export default class PlotBaseAnimation {
2424 this . animationName = AnimationUtil . defineValue ( options . animationName , '' ) ;
2525 this . loop = AnimationUtil . defineValue ( options . loop , 1 ) ;
2626 this . timelineOffset = AnimationUtil . defineValue ( options . timelineOffset , 0 ) ;
27- this . featureIds = options . featureIds
27+ this . featureIds = options . featureIds ;
2828 // 动画对象
2929 this . _plotObjects = options . plotObjects || null ;
3030 // 动画状态
@@ -40,33 +40,41 @@ export default class PlotBaseAnimation {
4040 this . reset ( ) ;
4141 // 状态
4242 this . _updateGeometry = true ;
43- this . _firstRender = true ;
43+ // 允许动画作用
44+ this . _allowAnimation = false
4445 }
45- // 更新动画参数
46+ /**
47+ * @function : Module:PlotBaseAnimation.prototype.update
48+ * @description :更新动画参数
49+ * @return {* }
50+ */
4651 update ( ) {
47-
48- if ( Array . isArray ( this . _plotObjects ) && this . _plotObjects . length === 0 ) {
52+ if ( Array . isArray ( this . _plotObjects ) && this . _plotObjects . length === 0 ) {
4953 this . _plotObjects = this . featureIds
50- . split ( ',' )
51- . map ( ( t ) => {
52- const s = this . getPlotObjectById ( t ) ;
53- return s ;
54- } )
55- . filter ( ( b ) => b ) ;
54+ . split ( ',' )
55+ . map ( ( t ) => {
56+ const s = this . getPlotObjectById ( t ) ;
57+ return s ;
58+ } )
59+ . filter ( ( b ) => b ) ;
5660 }
5761 }
58- // 开始动画
62+ /**
63+ * @function : Module:PlotBaseAnimation.prototype.play
64+ * @description :开始动画
65+ * @return {* }
66+ */
5967 play ( ) {
60- if ( this . _updateGeometry ) {
61- this . _updateGeometry = false ;
62- this . update ( ) ;
63- }
64- if ( this . _firstRender ) {
65- this . _firstRender = false ;
66- this . render ( 0.00001 ) ;
67- }
68+ this . updateGeometry ( ) ;
6869 this . paused = false ;
6970 }
71+
72+ /**
73+ * @function : Module:PlotBaseAnimation.prototype.tick
74+ * @description : 步长函数
75+ * @param {number } time 时间节点
76+ * @return {* }
77+ */
7078 tick ( time ) {
7179 // 动画播放
7280 this . now = time ;
@@ -75,6 +83,12 @@ export default class PlotBaseAnimation {
7583 this . setInstanceProgress ( vTime ) ;
7684 }
7785
86+ /**
87+ * @function : Module:PlotBaseAnimation.prototype.setInstanceProgress
88+ * @description : 设置动画进度
89+ * @param {* } engineTime
90+ * @return {* }
91+ */
7892 setInstanceProgress ( engineTime ) {
7993 const insDuration = this . duration ;
8094 const insTimelineOffset = this . timelineOffset ;
@@ -88,10 +102,10 @@ export default class PlotBaseAnimation {
88102 if ( ! this . loopBegan && this . currentTime > 0 ) {
89103 this . loopBegan = true ;
90104 }
91- if ( insTime <= insDelay ) {
105+ if ( insTime <= insDelay ) {
92106 this . setAnimationsProgress ( 0 ) ;
93107 }
94- if ( ( insTime >= insEndDelay && this . currentTime !== totalDuration ) || ! insDuration ) {
108+ if ( insTime >= insEndDelay ) {
95109 this . setAnimationsProgress ( insDuration ) ;
96110 }
97111 if ( insTime > insDelay && insTime < insEndDelay ) {
@@ -112,31 +126,21 @@ export default class PlotBaseAnimation {
112126 }
113127 }
114128
115- adjustTime ( time ) {
116- const v = time - this . timelineOffset ;
117- if ( v < 0 ) {
118- return time ;
119- } else {
120- return ( this . reversed ? this . duration - v : v ) + this . timelineOffset ;
121- }
122- }
123-
124- minMax ( val , min , max ) {
125- if ( val === min ) {
126- return min ;
127- }
128- if ( val === max ) {
129- return max ;
130- }
131- return Math . min ( Math . max ( val , min ) , max ) ;
132- }
133-
134- // 暂停动画
129+ /**
130+ * @function : Module:PlotBaseAnimation.prototype.pause
131+ * @description : 暂停
132+ * @return {* }
133+ */
135134 pause ( ) {
136135 this . paused = true ;
137136 this . resetTime ( ) ;
138137 }
139- // 重置动画
138+
139+ /**
140+ * @function : Module:PlotBaseAnimation.prototype.reset
141+ * @description : 重置
142+ * @return {* }
143+ */
140144 reset ( ) {
141145 this . remaining = this . loop ;
142146 this . paused = true ;
@@ -147,70 +151,137 @@ export default class PlotBaseAnimation {
147151 this . startTime = 0 ;
148152 this . lastTime = 0 ;
149153 this . _updateGeometry = true ;
150- this . _firstRender = true ;
151154 }
152- // 复位动画
155+
156+ /**
157+ * @function : Module:PlotBaseAnimation.prototype.restore
158+ * @description : 复位
159+ * @return {* }
160+ */
153161 restore ( ) {
154162 this . reset ( ) ;
155163 }
156164
157- applyEasing ( rate ) {
158- return easingFunc ( this . easing ) ( rate ) ;
159- }
160-
165+ /**
166+ * @function : Module:PlotBaseAnimation.prototype.setAnimationsProgress
167+ * @description : 设置动画绘制进度
168+ * @param {* } time
169+ * @return {* }
170+ */
161171 setAnimationsProgress ( time ) {
162172 let rate = this . minMax ( time / this . duration , 0 , 1 ) ;
163173 rate = this . applyEasing ( rate ) ;
164- // rate=parseFloat(rate.toFixed(5))
165- // if(!rate || rate<10e-5) return;
166174 this . render ( rate ) ;
167175 }
168176
177+ /**
178+ * @function : Module:PlotBaseAnimation.prototype.countIteration
179+ * @description : 计算循环次数
180+ * @return {* }
181+ */
169182 countIteration ( ) {
170183 if ( this . remaining && this . remaining !== true ) {
171184 this . remaining -- ;
172185 }
173186 }
174187
188+ /**
189+ * @function : Module:PlotBaseAnimation.prototype.countIteration
190+ * @description : 跳转
191+ * @param {* } time
192+ * @return {* }
193+ */
175194 seek ( time ) {
176- this . currentTime = this . minMax ( time , 0 , this . timelineOffset + this . duration ) ;
195+ this . updateGeometry ( ) ;
196+ this . setInstanceProgress ( time ) ;
177197 if ( ! this . paused ) {
178198 this . resetTime ( ) ;
179199 }
180200 }
181201
202+ /**
203+ * @function : Module:PlotBaseAnimation.prototype.setSpeed
204+ * @description : 设置速率
205+ * @param {number } speed
206+ * @return {* }
207+ */
182208 setSpeed ( speed ) {
183209 this . speed = speed ;
184210 if ( ! this . paused ) {
185211 this . resetTime ( ) ;
186212 }
187213 }
188214
215+ /**
216+ * @function : Module:PlotBaseAnimation.prototype.resetTime
217+ * @description : 重置当前时间
218+ * @return {* }
219+ */
189220 resetTime ( ) {
190221 this . startTime = 0 ;
191222 this . lastTime = this . adjustTime ( this . currentTime ) * ( 1 / this . speed ) ;
192223 }
193-
194- exportOption ( ) {
195- const propertys = PlotBaseAnimation . cacheProperty . split ( ',' )
196- const object = { }
197-
198- propertys . forEach ( ( s ) => {
199- object [ s ] = this [ s ]
200- } )
201- return object
202- }
203-
204- isInAnimation ( uid ) {
205- if ( ! this . featureIds ) return false ;
206- const v = this . featureIds . split ( ',' )
207- if ( v . indexOf ( uid ) > - 1 ) {
208- return true
209- }
210- return false
224+
225+ /**
226+ * @function : Module:PlotBaseAnimation.prototype.exportOption
227+ * @description : 导出options
228+ * @return {* }
229+ */
230+ exportOption ( ) {
231+ const propertys = PlotBaseAnimation . cacheProperty . split ( ',' ) ;
232+ const object = { } ;
233+
234+ propertys . forEach ( ( s ) => {
235+ object [ s ] = this [ s ] ;
236+ } ) ;
237+ return object ;
211238 }
212239
240+ /**
241+ * @function : Module:PlotBaseAnimation.prototype.render
242+ * @description :实际绘制比率
243+ * @param {number } rate
244+ * @return {* }
245+ */
213246 render ( rate ) { }
247+
248+ /** util */
249+ adjustTime ( time ) {
250+ const v = time - this . timelineOffset ;
251+ if ( v < 0 ) {
252+ return time ;
253+ } else {
254+ return ( this . reversed ? this . duration - v : v ) + this . timelineOffset ;
255+ }
256+ }
257+ applyEasing ( rate ) {
258+ return easingFunc ( this . easing ) ( rate ) ;
259+ }
260+ minMax ( val , min , max ) {
261+ if ( val === min ) {
262+ return min ;
263+ }
264+ if ( val === max ) {
265+ return max ;
266+ }
267+ return Math . min ( Math . max ( val , min ) , max ) ;
268+ }
269+
270+ isInAnimation ( uid ) {
271+ if ( ! this . featureIds ) return false ;
272+ const v = this . featureIds . split ( ',' ) ;
273+ if ( v . indexOf ( uid ) > - 1 ) {
274+ return true ;
275+ }
276+ return false ;
277+ }
278+ updateGeometry ( ) {
279+ if ( this . _updateGeometry ) {
280+ this . _updateGeometry = false ;
281+ this . update ( ) ;
282+ this . render ( 0.00001 ) ;
283+ }
284+ }
214285}
215286
216- PlotBaseAnimation . cacheProperty = 'animationType,duration,featureIds,animationName,easing,delay,endDelay,loop,timelineOffset'
287+ PlotBaseAnimation . cacheProperty = 'animationType,duration,featureIds,animationName,easing,delay,endDelay,loop,timelineOffset' ;
0 commit comments