import {computed} from "mobx/lib/mobx"; import {ReportRootDesigner} from "../designer/ReportRootDesigner"; import {BehaviorService} from "./BehaviorService"; import {SnapInfo} from "./SnapInfo"; export class SnapGridService { private _designer: ReportRootDesigner; private _behaviorService: BehaviorService; constructor(designer:ReportRootDesigner, behaviorService:BehaviorService) { this._designer = designer; this._behaviorService = behaviorService; } get gridSize():number { return this.calculateGridSize(); } get designer():ReportRootDesigner { return this._designer; } get behaviorService():BehaviorService { return this._behaviorService; } @computed get snapGridInfo(): SnapInfo { const snapInfo = new SnapInfo(); const dx = this.calculateGridSize(); const rc = {left: 0, top: 0}; const i = -Math.floor((rc.left / dx + 1)); snapInfo.x = rc.left + i * dx; snapInfo.startIndexX = i; const j = -Math.floor((rc.top / dx + 1)); snapInfo.y = rc.top + j * dx; snapInfo.startIndexY = j; snapInfo.gridSize = dx; snapInfo.width = this._designer.viewPortSize.width; snapInfo.height = this._designer.viewPortSize.height; return snapInfo; } private calculateGridSize():number { const zoom = this._behaviorService.zoom; let dx = this._behaviorService.snapGridSize.fPixels * zoom; while (dx < 3.0) { dx *= 5.0; if (dx < 3.0) { dx *= 2.0; } } return Math.floor(dx); } }