UNPKG

@antv/f2

Version:

Charts for mobile visualization.

109 lines (108 loc) 3.64 kB
"use strict"; var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "Coord", { enumerable: true, get: function get() { return _coord.default; } }); exports.default = void 0; var _tslib = require("tslib"); var _coord = _interopRequireWildcard(require("../coord")); var _util = require("@antv/util"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var coordMap = { rect: _coord.Rect, polar: _coord.Polar }; var coordController = /** @class */function () { function coordController() {} coordController.prototype.getOption = function (cfg) { if ((0, _util.isString)(cfg)) { return { type: coordMap[cfg] || _coord.Rect }; } if ((0, _util.isFunction)(cfg)) { return { type: cfg }; } var type = (cfg || {}).type; return (0, _tslib.__assign)((0, _tslib.__assign)({}, cfg), { // 默认直角坐标系 type: (0, _util.isFunction)(type) ? type : coordMap[type] || _coord.Rect }); }; coordController.prototype.create = function (cfg) { var layout = this.layout; var option = this.getOption(cfg); var type = option.type; var coord = new type((0, _tslib.__assign)((0, _tslib.__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; }(); var _default = exports.default = coordController;