Skip to content

Commit b44b57e

Browse files
author
zhaokai
committed
优化时间轴方法 打包问题
1 parent bfd6371 commit b44b57e

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

src/service/PlotBase/Animation/AnimationTypes/PlotExtendAnimation/PlotGrowAnimation/PlotGrowAnimation.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2022-03-23 10:02:49
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-15 20:47:28
6+
* @LastEditTime: 2022-06-16 11:37:25
77
*/
88
import Point from '../../../../../PlotUtilBase/Geometry/Point';
99
import Spline from '../../../../../PlotUtilBase/Geometry/Spline';
@@ -14,8 +14,8 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
1414
constructor(options) {
1515
super(options);
1616
}
17-
_initBaseAttributes(options){
18-
super._initBaseAttributes(options)
17+
_initBaseAttributes(options) {
18+
super._initBaseAttributes(options);
1919
// animation type
2020
this.animationType = 'grow-animation';
2121
// init options
@@ -31,7 +31,11 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
3131
// 1.spline
3232
if (mode === 'spline') {
3333
this.splines = polysArr.map((s) => {
34-
return new Spline(s,{});
34+
if (s.length >= 2) {
35+
return new Spline(s, {});
36+
} else {
37+
return null;
38+
}
3539
});
3640
} else if (mode === 'center') {
3741
this.modeFunArr = [];
@@ -40,6 +44,10 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
4044
const len = polys.length;
4145
const v = [];
4246
let center;
47+
if (len <= 1) {
48+
v.push(null);
49+
continue;
50+
}
4351
if (len === 2) {
4452
center = [(polys[1].x - polys[0].x) / 2 + polys[0].x, (polys[1].y - polys[0].y) / 2 + polys[0].y];
4553
} else {
@@ -69,6 +77,7 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
6977
const splines = this.splines;
7078
const trueRate = this._calcTrueRate(rate);
7179
splines.forEach((t, index) => {
80+
if (!t) return;
7281
const animationPoly = this._animationPolys[index];
7382
const animationObject = this._plotObjects[index];
7483
if (animationPoly.length > 0) {
@@ -92,25 +101,25 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
92101
_centerAction(rate) {
93102
const trueRate = this._calcTrueRate(rate);
94103
this._plotObjects.forEach((plotObject, i) => {
95-
const tPolys = this.modeFunArr[i].map((s) => {
104+
if (!this.modeFunArr || !this.modeFunArr[i]) return;
105+
const tPolys = this.modeFunArr[i].map((s) => {
96106
const p = s(trueRate);
97-
107+
98108
return new Point(p[0], p[1]);
99109
});
100110
this._setPnts(plotObject, tPolys);
101111
});
102112
}
103113

104-
exportOption(){
105-
const object = super.exportOption()
106-
const propertys= PlotGrowAnimation.cacheProperty.split(',')
107-
propertys.forEach((s)=>{
108-
object[s]=this[s]
109-
})
110-
return object
114+
exportOption() {
115+
const object = super.exportOption();
116+
const propertys = PlotGrowAnimation.cacheProperty.split(',');
117+
propertys.forEach((s) => {
118+
object[s] = this[s];
119+
});
120+
return object;
111121
}
112122

113-
114123
_render(rate) {
115124
const mode = this.growMode;
116125
if (mode === 'spline') {
@@ -124,4 +133,4 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
124133
}
125134
}
126135

127-
PlotGrowAnimation.cacheProperty='startRate,endRate,growMode'
136+
PlotGrowAnimation.cacheProperty = 'startRate,endRate,growMode';

src/service/PlotBase/Animation/TimeLine/TimeLine.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2022-03-23 11:53:45
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-15 20:52:13
6+
* @LastEditTime: 2022-06-16 10:42:15
77
*/
88

99
import { AnimationReg } from '../AnimationTypes';
@@ -15,13 +15,15 @@ export default class TimeLine {
1515
this._animationArr = [];
1616
// 初始化图层组方法
1717
this.initLayerGroupFunction(layerGroup);
18-
//-- 时间轴选项 --
18+
//-- 时间轴选项 -
1919
// 反转
2020
this.invert = false;
2121
// 速率
2222
this.speed = 1;
2323
// 请求raf
2424
this.raf = null;
25+
// 是否重新刷新动画队列
26+
// this._refreshAnimationList = false;
2527
}
2628

2729
/**
@@ -88,13 +90,23 @@ export default class TimeLine {
8890
this.resetTime();
8991
this.animationAction((t) => t.play())();
9092
this.handleRender();
91-
const activeInstances = this._animationArr.concat([]);
93+
let activeInstances = this._animationArr.concat([]);
9294
const that = this;
9395
const engine = (function () {
9496
function start() {
9597
that.raf = requestAnimationFrame(step);
9698
}
9799
function step(t) {
100+
101+
// 重新刷新动画队列
102+
// if (that._refreshAnimationList) {
103+
// activeInstances = that._animationArr.concat([]);
104+
// activeInstances.forEach((ani) => {
105+
// ani.play();
106+
// });
107+
// that._refreshAnimationList = false;
108+
// }
109+
98110
let activeInstancesLength = activeInstances.length;
99111
if (activeInstancesLength) {
100112
let i = 0;
@@ -227,10 +239,12 @@ export default class TimeLine {
227239
* @return {*}
228240
*/
229241
seek(time) {
242+
this.pause()
230243
this.animationAction((s) => {
231244
s.seek(time);
232245
})();
233246
this.handleRender();
247+
this._refreshAnimationList = true;
234248
}
235249

236250
/**

src/service/PlotBase/SvgLoader/element/StyleElement.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
* @Author: zk
55
* @Date: 2022-06-14 13:54:55
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-06-14 14:47:59
7+
* @LastEditTime: 2022-06-16 11:37:48
88
*/
99

1010
import Element from './Element';
1111
import StringUtil from '../../../PlotUtilBase/Util/StringUtil'
1212
import Property from './Property';
1313
export default class StyleElement extends Element {
1414

15-
type = 'style';
15+
1616
constructor(
1717
node
1818
) {
1919
super(node);
2020
const that=this
21+
this.type = 'style';
2122
this._styles={}
2223
const css = StringUtil.compressSpaces(
2324
Array.from(node.childNodes)

0 commit comments

Comments
 (0)