UNPKG

@antv/f2

Version:

Charts for mobile visualization.

96 lines 2.61 kB
import { __assign } from "tslib"; import Coord, { Rect, Polar } from '../coord'; import { isString, isFunction } from '@antv/util'; var coordMap = { rect: Rect, polar: Polar }; var coordController = /** @class */function () { function coordController() {} coordController.prototype.getOption = function (cfg) { if (isString(cfg)) { return { type: coordMap[cfg] || Rect }; } if (isFunction(cfg)) { return { type: cfg }; } var type = (cfg || {}).type; return __assign(__assign({}, cfg), { // 默认直角坐标系 type: isFunction(type) ? type : coordMap[type] || Rect }); }; coordController.prototype.create = function (cfg) { var layout = this.layout; var option = this.getOption(cfg); var type = option.type; var coord = new type(__assign(__assign({}, option), layout)); this.coord = coord; return coord; }; coordController.prototype.updateLayout = function (style) { var coord = this.coord; var left = style.left, top = style.top, width = style.width, height = style.height, padding = style.padding; var _a = padding || [0, 0, 0, 0], paddingTop = _a[0], paddingRight = _a[1], paddingBottom = _a[2], paddingLeft = _a[3]; this.layout = { left: left + paddingLeft, top: top + paddingTop, width: width - paddingLeft - paddingRight, height: height - paddingTop - paddingBottom }; if (coord) { coord.update(this.layout); } }; coordController.prototype.useLayout = function (positionLayout) { var coord = this.coord; var position = positionLayout.position, boxWidth = positionLayout.width, boxHeight = positionLayout.height; var left = coord.left, top = coord.top, width = coord.width, height = coord.height; switch (position) { case 'left': left += boxWidth; width = Math.max(0, width - boxWidth); break; case 'right': width = Math.max(0, width - boxWidth); break; case 'top': top += boxHeight; height = Math.max(0, height - boxHeight); break; case 'bottom': height = Math.max(0, height - boxHeight); break; } coord.update({ left: left, top: top, width: width, height: height }); }; coordController.prototype.update = function () {}; coordController.prototype.getCoord = function () { return this.coord; }; return coordController; }(); export { Coord }; export default coordController;