rt-sim-training-client/src/jmap/shape/Link.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-07-03 14:29:09 +08:00
import Line from 'zrender/src/graphic/shape/Line';
import Group from 'zrender/src/container/Group';
2019-07-11 17:58:58 +08:00
// import { stat } from 'fs';
2019-07-03 14:29:09 +08:00
class Link extends Group {
2019-07-04 18:39:30 +08:00
constructor({ _code, _type, zlevel, model, state }, style, styleGlobal) {
2019-07-04 10:59:40 +08:00
super();
this._code = _code;
this._type = _type;
this.zlevel = zlevel;
this.model = model;
this.state = state;
this.style = style;
2019-07-04 18:39:30 +08:00
this.styleGlobal = styleGlobal;
2019-07-04 10:59:40 +08:00
this.create();
}
create() {
const model = this.model;
const style = this.style;
2019-07-04 18:39:30 +08:00
const styleGlobal = this.styleGlobal;
2019-07-04 10:59:40 +08:00
this.link = new Line({
zlevel: this.zlevel,
shape: {
2019-07-10 16:29:07 +08:00
x1: model.lp.x,
y1: model.lp.y,
x2: model.rp.x,
y2: model.rp.y
2019-07-04 10:59:40 +08:00
},
style: {
2019-07-04 18:39:30 +08:00
lineWidth: style.linkWidth,
stroke: style.linkColor,
2019-07-04 10:59:40 +08:00
text: model.code,
2019-07-04 18:39:30 +08:00
textDistance: style.linkWidth * 2,
2019-07-05 00:40:53 +08:00
textPosition: 'inside',
2019-07-04 10:59:40 +08:00
textAlign: 'middle',
2019-07-04 18:39:30 +08:00
fontSize: styleGlobal.textFontSize,
textFill: style.linkTextColor,
textStroke: styleGlobal.backgroundColor
2019-07-04 10:59:40 +08:00
}
});
this.add(this.link);
}
2019-07-04 18:39:30 +08:00
setState({ _code, _type, zlevel, model, state }) {
2019-07-09 19:04:45 +08:00
switch (state.status) {
2019-07-11 17:58:58 +08:00
case '01': this.link.setStyle('stroke', 'green'); break;
case '02': this.link.setStyle('stroke', 'yellow'); break;
2019-07-09 19:04:45 +08:00
}
2019-07-04 10:59:40 +08:00
}
tipBasePoint() {
return {
x: (this.link.shape.x1 + this.link.shape.x2) / 2,
y: (this.link.shape.y1 + this.link.shape.y2) / 2
};
}
2019-07-03 14:29:09 +08:00
}
2019-07-04 10:59:40 +08:00
export default Link;