UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

68 lines (61 loc) 4.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerRotatePlugin = exports.RotatePlugin = void 0; const base_plugin_1 = require("../../base/base-plugin"), register_1 = require("../register"), vrender_core_1 = require("@visactor/vrender-core"); class RotatePlugin extends base_plugin_1.BasePlugin { constructor() { super(RotatePlugin.type), this.type = "rotatePlugin", this.rotate90WithTransform = rotateDom => { this.rotateDegree = 90; const rotateCenter = rotateDom.clientWidth < rotateDom.clientHeight ? Math.max(rotateDom.clientWidth, rotateDom.clientHeight) / 2 : Math.min(rotateDom.clientWidth, rotateDom.clientHeight) / 2, domRect = this._vchart.getContainer().getBoundingClientRect(), x1 = domRect.left, y1 = domRect.top, x2 = domRect.right, y2 = domRect.bottom; rotateDom.style.transform = "rotate(90deg)", rotateDom.style.transformOrigin = `${rotateCenter}px ${rotateCenter}px`; const getRect = () => ({ x1: x1, y1: y1, x2: x2, y2: y2 }), getMatrix = () => { const viewPortWidth = ("undefined" != typeof window ? { width: window.innerWidth || document.documentElement.clientWidth, height: window.innerHeight || document.documentElement.clientHeight } : vrender_core_1.vglobal && "getViewportSize" in vrender_core_1.vglobal && vrender_core_1.vglobal.getViewportSize ? vrender_core_1.vglobal.getViewportSize() : rotateDom.getBoundingClientRect()).width, domRect = this._vchart.getContainer().getBoundingClientRect(), x1 = domRect.top, y1 = viewPortWidth - domRect.right, matrix = vrender_core_1.matrixAllocate.allocate(1, 0, 0, 1, 0, 0); matrix.translate(x1, y1); const centerX = rotateCenter - x1, centerY = rotateCenter - y1; return matrix.translate(centerX, centerY), matrix.rotate(Math.PI / 2), matrix.translate(-centerX, -centerY), this.matrix = matrix, matrix; }; (0, vrender_core_1.registerGlobalEventTransformer)(vrender_core_1.vglobal, this._vchart.getContainer(), getMatrix, getRect, vrender_core_1.transformPointForCanvas), (0, vrender_core_1.registerWindowEventTransformer)(this._vchart.getStage().window, this._vchart.getContainer(), getMatrix, getRect, vrender_core_1.transformPointForCanvas), this.vglobal_mapToCanvasPoint = vrender_core_1.vglobal.mapToCanvasPoint, vrender_core_1.vglobal.mapToCanvasPoint = vrender_core_1.mapToCanvasPointForCanvas; }, this.cancelTransform = rotateDom => { this.rotateDegree = 0, rotateDom.style.transform = "none", rotateDom.style.transformOrigin = "none"; const domRect = this._vchart.getContainer().getBoundingClientRect(), x1 = domRect.left, y1 = domRect.top, x2 = domRect.right, y2 = domRect.bottom, getRect = () => ({ x1: x1, y1: y1, x2: x2, y2: y2 }), getMatrix = () => { const matrix = vrender_core_1.matrixAllocate.allocate(1, 0, 0, 1, 0, 0); return matrix.translate(x1, y1), matrix; }; (0, vrender_core_1.registerGlobalEventTransformer)(vrender_core_1.vglobal, this._vchart.getContainer(), getMatrix, getRect, vrender_core_1.transformPointForCanvas), (0, vrender_core_1.registerWindowEventTransformer)(this._vchart.getStage().window, this._vchart.getContainer(), getMatrix, getRect, vrender_core_1.transformPointForCanvas), vrender_core_1.vglobal.mapToCanvasPoint = this.vglobal_mapToCanvasPoint; }; } onInit(service) { const {globalInstance: vchart} = service; vchart && (this._vchart = vchart, vchart.rotate90WithTransform = this.rotate90WithTransform, vchart.cancelTransform = this.cancelTransform); } release() { this._vchart = null, this.vglobal_mapToCanvasPoint = null, this.matrix = null, super.release(); } } exports.RotatePlugin = RotatePlugin, RotatePlugin.pluginType = "vchart", RotatePlugin.specKey = "rotate", RotatePlugin.type = "rotatePlugin"; const registerRotatePlugin = () => { (0, register_1.registerVChartPlugin)(RotatePlugin); }; exports.registerRotatePlugin = registerRotatePlugin; //# sourceMappingURL=rotate.js.map