@antv/f2
Version:
Charts for mobile visualization.
110 lines (109 loc) • 3.81 kB
JavaScript
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 _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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;
;