103 lines
2.3 KiB
JavaScript
103 lines
2.3 KiB
JavaScript
import Group from 'zrender/src/container/Group';
|
|
import Line from 'zrender/src/graphic/shape/Line';
|
|
import BezierCurve from 'zrender/src/graphic/shape/BezierCurve';
|
|
|
|
/** 创建区段线集合*/
|
|
export default class ELines extends Group {
|
|
constructor(model) {
|
|
super();
|
|
this.model = model;
|
|
this.zlevel = model.zlevel;
|
|
this.z = model.z;
|
|
this.create(model);
|
|
}
|
|
|
|
create(model) {
|
|
/** 创建区段*/
|
|
if (model && model.points.length > 1) {
|
|
if (model.isCurve) {
|
|
const shape = {};
|
|
for (let i = 1; i < (model.points.length - 1); i++) {
|
|
shape[`cpx${i}`] = model.points[i].x;
|
|
shape[`cpy${i}`] = model.points[i].y;
|
|
}
|
|
|
|
shape[`x1`] = model.points[0].x;
|
|
shape[`y1`] = model.points[0].y;
|
|
shape[`x2`] = model.points[model.points.length - 1].x;
|
|
shape[`y2`] = model.points[model.points.length - 1].y;
|
|
|
|
this.add(new BezierCurve({
|
|
isLine: true,
|
|
zlevel: this.zlevel,
|
|
progressive: model.progressive,
|
|
z: this.z + 1,
|
|
culling: true,
|
|
shape: shape,
|
|
style: {
|
|
lineWidth: model.style.Section.line.width,
|
|
stroke: model.style.Section.line.spareColor,
|
|
fillOpacity: 0
|
|
}
|
|
}));
|
|
} else {
|
|
for (let i = 0; i < (model.points.length - 1); i++) {
|
|
this.add(new Line({
|
|
isLine: true,
|
|
zlevel: this.zlevel,
|
|
progressive: model.progressive,
|
|
z: this.z,
|
|
shape: {
|
|
x1: model.points[i].x,
|
|
y1: model.points[i].y,
|
|
x2: model.points[i + 1].x,
|
|
y2: model.points[i + 1].y
|
|
},
|
|
style: {
|
|
lineWidth: model.style.Section.line.width,
|
|
stroke: model.style.Section.line.spareColor
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
setStyle(styles) {
|
|
this.eachChild((child) => {
|
|
if (child.setStyle && child.isLine) {
|
|
child.setStyle(styles);
|
|
}
|
|
});
|
|
}
|
|
|
|
animateStyle(loop, animates) {
|
|
if (animates && animates.length) {
|
|
this.eachChild((child) => {
|
|
if (child.animateStyle && child.isLine) {
|
|
let an = child.animateStyle(loop);
|
|
animates.forEach(elem => {
|
|
an = an.when(elem.time, elem.styles);
|
|
});
|
|
an.start();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
stopAnimation(flag) {
|
|
this.eachChild((child) => {
|
|
if (child.stopAnimation && child.isLine) {
|
|
child.stopAnimation(flag);
|
|
}
|
|
});
|
|
}
|
|
|
|
setBorderVisible(isVisible) {
|
|
this.lineBorder && this.lineBorder.hide();
|
|
if (isVisible) {
|
|
this.lineBorder && this.lineBorder.show();
|
|
}
|
|
}
|
|
}
|