2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
import {createTransform, createBoundingRect} from './utils/parser';
|
|
|
|
|
|
|
|
class TransformHandle {
|
|
|
|
constructor(painter) {
|
|
|
|
this.$painter = painter;
|
|
|
|
|
|
|
|
this.parentLevel = painter.getParentLevel();
|
|
|
|
|
|
|
|
this.rect = { x: 0, y: 0, width: 0, height: 0 };
|
|
|
|
|
|
|
|
this.transform = createTransform({ scaleRate: 1, offsetX: 0, offsetY: 0 });
|
|
|
|
}
|
|
|
|
|
|
|
|
checkVisible(view) {
|
2019-12-05 10:25:07 +08:00
|
|
|
return createBoundingRect(view).intersect(this.rect);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
revisibleView(view) {
|
|
|
|
if (this.checkVisible(view)) {
|
|
|
|
view.show();
|
|
|
|
} else {
|
|
|
|
view.hide();
|
2020-07-23 10:32:58 +08:00
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-07-23 10:32:58 +08:00
|
|
|
view.dirty();
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 视图进行缩放/平移
|
|
|
|
transformView(view) {
|
|
|
|
if (view) {
|
|
|
|
view.transform = this.transform;
|
|
|
|
view.decomposeTransform();
|
|
|
|
this.revisibleView(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理所有视图缩放/平移
|
|
|
|
transformAll() {
|
|
|
|
this.traverse(this.transformView, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重新计算显示图形
|
|
|
|
revisibleAll() {
|
|
|
|
this.traverse(this.revisibleView, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新偏移量
|
|
|
|
updateTransform(opts) {
|
|
|
|
this.transform = createTransform(opts);
|
|
|
|
this.transformAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新画布尺寸
|
|
|
|
updateZrSize(opts) {
|
|
|
|
this.rect = { x: 0, y: 0, width: opts.width, height: opts.height };
|
|
|
|
this.revisibleAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 遍历group执行回调
|
|
|
|
traverse(cb, context) {
|
|
|
|
this.parentLevel.eachChild(level => {
|
|
|
|
level.eachChild((view) => {
|
|
|
|
cb.call(context, view);
|
|
|
|
}, context);
|
|
|
|
}, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TransformHandle;
|