NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/@antv/g2/lib/geom/polygon.js
2023-09-14 14:47:11 +08:00

80 lines
2.2 KiB
Java

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
/**
* @fileOverview 多边形
* @author dxq613@gmail.com
*/
var GeomBase = require('./base');
var Util = require('../util');
require('./shape/polygon');
var Polygon = /*#__PURE__*/function (_GeomBase) {
_inheritsLoose(Polygon, _GeomBase);
function Polygon() {
return _GeomBase.apply(this, arguments) || this;
}
var _proto = Polygon.prototype;
/**
* 获取默认的配置属性
* @protected
* @return {Object} 默认属性
*/
_proto.getDefaultCfg = function getDefaultCfg() {
var cfg = _GeomBase.prototype.getDefaultCfg.call(this);
cfg.type = 'polygon';
cfg.shapeType = 'polygon';
cfg.generatePoints = true;
return cfg;
};
_proto.createShapePointsCfg = function createShapePointsCfg(obj) {
var cfg = _GeomBase.prototype.createShapePointsCfg.call(this, obj);
var self = this;
var x = cfg.x;
var y = cfg.y;
var temp;
if (!(Util.isArray(x) && Util.isArray(y))) {
// x y 都是数组时,不做处理
var xScale = self.getXScale();
var yScale = self.getYScale();
var xCount = xScale.values ? xScale.values.length : xScale.ticks.length;
var yCount = yScale.values ? yScale.values.length : yScale.ticks.length;
var xOffset = 0.5 * 1 / xCount;
var yOffset = 0.5 * 1 / yCount;
if (xScale.isCategory && yScale.isCategory) {
// 如果x,y都是分类
x = [x - xOffset, x - xOffset, x + xOffset, x + xOffset];
y = [y - yOffset, y + yOffset, y + yOffset, y - yOffset];
} else if (Util.isArray(x)) {
// x 是数组
temp = x;
x = [temp[0], temp[0], temp[1], temp[1]];
y = [y - yOffset / 2, y + yOffset / 2, y + yOffset / 2, y - yOffset / 2];
} else if (Util.isArray(y)) {
// y 是数组
temp = y;
y = [temp[0], temp[1], temp[1], temp[0]];
x = [x - xOffset / 2, x - xOffset / 2, x + xOffset / 2, x + xOffset / 2];
}
cfg.x = x;
cfg.y = y;
}
return cfg;
};
return Polygon;
}(GeomBase);
GeomBase.Polygon = Polygon;
module.exports = Polygon;