import Group from 'zrender/src/container/Group'; import Polygon from 'zrender/src/graphic/shape/Polygon'; /** 创建三角形*/ export default class ETriangle extends Group { constructor(model) { super(); this.model = model; this.zlevel = model.zlevel; this.z = model.z; this.create(model); } create(model) { if (model && model.point) { const right = model.right == 1 ? 1 : -1; this.angle = new Polygon({ zlevel: model.zlevel, z: model.z, shape: { points:[[model.point.x + 10 * right, model.point.y], [model.point.x, model.point.y - 6], [model.point.x, model.point.y + 6]] }, style: { stroke:'#00FF00', lineWidth: 0.5, fill: '#00FF00' } }); this.add(this.angle); } } updateTriangle(model, right) { const trainRight = right == 1 ? 1 : -1; const data = [[model.x + 10 * trainRight, model.y], [model.x, model.y - 6], [model.x, model.y + 6]]; // this.angle.shape.points.push([model.x + 10 * trainRight, model.y]); // this.angle.attr('shape', { points: this.angle.shape.points }); this.angle.attr({ shape: { points:data } }); this.angle.animateTo({ shape: { points:data } }, 10, 0, 'elasticOut', function () { }); this.dirty(); } }