90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
|
import * as matrix from 'zrender/src/core/matrix';
|
||
|
|
||
|
function getTransform(zoom) {
|
||
|
let transform = matrix.create();
|
||
|
transform = matrix.scale(matrix.create(), transform, [zoom.scale, zoom.scale]);
|
||
|
transform = matrix.translate(matrix.create(), transform, [zoom.offsetX, zoom.offsetY]);
|
||
|
return transform;
|
||
|
}
|
||
|
|
||
|
class transformController {
|
||
|
constructor(painter) {
|
||
|
this.$painter = painter;
|
||
|
this.$zr = painter.$zr;
|
||
|
this.parentLevel = painter.parentLevel;
|
||
|
|
||
|
this.zoom = {scale: 1, offsetX: 0, offsetY: 0};
|
||
|
this.rect = {x:0, y:0, width: this.$zr.getWidth(), height: this.$zr.getHeight()};
|
||
|
this.transform = getTransform(this.zoom);
|
||
|
}
|
||
|
|
||
|
checkVisible(view) {
|
||
|
let rect = this.getBoundingRect();
|
||
|
let viewRect = this.getViewBoundingRect(view);
|
||
|
return viewRect.intersect(rect);
|
||
|
}
|
||
|
|
||
|
revisibleView(view) {
|
||
|
if (this.checkVisible(view)) {
|
||
|
view.show();
|
||
|
} else {
|
||
|
view.hide();
|
||
|
}
|
||
|
|
||
|
view.dirty();
|
||
|
}
|
||
|
|
||
|
transformView(view) {
|
||
|
if (view) {
|
||
|
view.transform = this.getTransform();
|
||
|
view.decomposeTransform();
|
||
|
this.revisibleView(view);
|
||
|
}
|
||
|
|
||
|
return view;
|
||
|
}
|
||
|
|
||
|
transformAll () {
|
||
|
this.parentLevel.eachChild((level) => {
|
||
|
level.eachChild((view) => {
|
||
|
this.transformView(view);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
revisibleAll() {
|
||
|
this.parentLevel.eachChild((level) => {
|
||
|
level.eachChild((view) => {
|
||
|
this.revisibleView(view);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
updateTransform(zoom) {
|
||
|
this.transform = getTransform(zoom);
|
||
|
this.transformAll();
|
||
|
}
|
||
|
|
||
|
getTransform() {
|
||
|
return this.transform;
|
||
|
}
|
||
|
|
||
|
getBoundingRect() {
|
||
|
return this.rect;
|
||
|
}
|
||
|
|
||
|
getViewBoundingRect(view) {
|
||
|
let rect = view.getBoundingRect();
|
||
|
let scale = view.scale[0];
|
||
|
let offsetX = view.position[0];
|
||
|
let offsetY = view.position[1];
|
||
|
|
||
|
rect.width = rect.width * scale;
|
||
|
rect.height = rect.height * scale;
|
||
|
rect.x = rect.x * scale + offsetX;
|
||
|
rect.y = rect.y * scale + offsetY;
|
||
|
return rect;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default transformController;
|