in src/Wshoot/shoot.ts [163:262]
draw(data: ChartData) {
if (!data || data.length === 0) {
return;
}
const self = this;
const { dTime } = self.config;
// 由于要保证interval时间内完成全部动画
const { interval } = self.config;
const { autoUpdate } = self.config;
const { maxFps } = self.config;
const times = (interval / dTime) >> 0;
const { keys } = self.config;
const { sCtx } = self;
const shoots: any[] = [];
const shootMap: { [key: string]: PositionPoint[] } = {};
const time = self.config.shootTime;
const l = data.length;
const getPosition = self.getPosition;
let fCo: PositionPoint;
let tCo: PositionPoint;
let s: any;
// 先清除画布
self.clear(sCtx);
for (let i = 0; i < l; i++) {
const d = data[i];
fCo = { ...d[keys.from] };
tCo = { ...d[keys.to] };
// 设置了 getPosition 函数,需要处理一遍
if (getPosition) {
const fP = getPosition(fCo);
fCo.x = fP.x;
fCo.y = fP.y;
const tP = getPosition(tCo);
tCo.x = tP.x;
tCo.y = tP.y;
}
// const fromCityName = d[keys.from];
// const toCityName = d[keys.to];
//
// if (typeof fromCityName === 'object') {
// fCo = fromCityName;
// } else {
// // 获取出发城市在画布上的坐标
// fCo = self.map.getCoord(fromCityName);
// }
//
// if (typeof toCityName === 'object') {
// tCo = toCityName;
// } else {
// // 获取到达城市在画布上的坐标
// tCo = self.map.getCoord(toCityName);
// }
if (fCo && tCo) {
const color = {};
// 如果数据带有颜色配置
if (d._color) {
Object.assign(color, d._color);
}
s = self.emit(fCo, tCo, d, color, time);
s.index = (times - 1) * Math.random();
// 判断是否是多点同时射击一个点
if (!shootMap[s.index]) {
shootMap[s.index] = [];
}
shootMap[s.index].forEach((city) => {
if (city === tCo) {
// 正在被攻击
s.shooting = true;
}
});
if (!s.shooting) {
shootMap[s.index].push(tCo);
}
shoots.push(s);
}
}
this.tween = tween(generateUniqueId(), {
duration: interval,
autoUpdate,
maxFps,
}, (t) => {
self.clear(self.sCtx);
shoots.forEach((shootFunction) => {
shootFunction(t * times - shootFunction.index);
});
});
}