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

65 lines
1.5 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-04 10:59:40 +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
let textPosition = 'insideBottom';
if (model.beg.x !== model.end.x && model.beg.y !== model.end.y) {
textPosition = model.beg.y > model.end.y ? 'insideLeft' : 'insideRight';
}
this.link = new Line({
zlevel: this.zlevel,
shape: {
x1: model.beg.x,
y1: model.beg.y,
x2: model.end.x,
y2: model.end.y
},
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-04 10:59:40 +08:00
textPosition: textPosition,
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 }) {
this.link.setStyle('stroke', 'green');
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;