@antv/f2
Version:
Charts for mobile visualization.
159 lines (158 loc) • 5.85 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _tslib = require("tslib");
var _fEngine = require("@antv/f-engine");
var _util = require("@antv/util");
var _geometry = _interopRequireDefault(require("../geometry"));
var LabelViews = _interopRequireWildcard(require("./label"));
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 _default = exports.default = function _default(Views) {
return /** @class */function (_super) {
(0, _tslib.__extends)(Interval, _super);
function Interval() {
return _super !== null && _super.apply(this, arguments) || this;
}
Interval.prototype.getDefaultCfg = function () {
return {
geomType: 'interval',
justifyContent: true,
startOnZero: true
};
};
Interval.prototype.getDefaultSize = function () {
var _a = this,
attrs = _a.attrs,
props = _a.props,
adjust = _a.adjust,
records = _a.records;
var coord = props.coord,
sizeRatio = props.sizeRatio;
var x = attrs.x;
var scale = x.scale;
var values = scale.values;
if (sizeRatio) {
return 1 / values.length * sizeRatio;
}
var defaultWithRatio = {
column: 1 / 2,
rose: 0.999999,
multiplePie: 3 / 4 // 多饼图
};
var count = values.length;
var ratio;
if (coord.isPolar) {
if (coord.transposed && count > 1) {
ratio = defaultWithRatio.multiplePie;
} else {
ratio = defaultWithRatio.rose;
}
} else {
ratio = defaultWithRatio.column;
}
var size = 1 / values.length * ratio;
// 分组时size要除以类别个数
if (adjust && adjust.type === 'dodge') {
return size / records.length;
}
return size;
};
Interval.prototype.mapping = function () {
var _a;
var records = _super.prototype.mapping.call(this);
var props = this.props;
var coord = props.coord,
sizeZoom = props.sizeZoom;
var y0 = this.getY0Value();
var defaultSize = this.getDefaultSize();
for (var i = 0, len = records.length; i < len; i++) {
var record = records[i];
var children = record.children;
for (var j = 0, len_1 = children.length; j < len_1; j++) {
var child = children[j];
var normalized = child.normalized,
mappedSize = child.size,
origin_1 = child.origin;
// 没有指定size,则根据数据来计算默认size
if ((0, _util.isNil)(mappedSize)) {
var x = normalized.x,
y = normalized.y,
_b = normalized.size,
size = _b === void 0 ? defaultSize : _b;
var zoomRatio = (_a = (0, _util.isFunction)(sizeZoom) ? sizeZoom(origin_1) : sizeZoom) !== null && _a !== void 0 ? _a : 1;
(0, _util.mix)(child, coord.convertRect({
x: x,
y: y,
y0: y0,
size: size * zoomRatio
}));
} else {
var x = child.x,
y = child.y;
var rect = {
size: mappedSize,
x: x,
y: y,
y0: y0
};
(0, _util.mix)(child, coord.transformToRect(rect));
}
(0, _util.mix)(child.shape, this.getSelectionStyle(child));
}
}
return records;
};
// 获取Y轴坐标零点的画布位置
Interval.prototype.getPointY0 = function () {
var props = this.props;
var coord = props.coord;
var y0 = this.getY0Value();
var y0Point = coord.convertPoint({
y: y0,
x: 0
});
return y0Point === null || y0Point === void 0 ? void 0 : y0Point.y;
};
Interval.prototype.render = function () {
var _a = this,
props = _a.props,
state = _a.state;
var coord = props.coord,
_b = props.shape,
shape = _b === void 0 ? 'rect' : _b,
animation = props.animation,
showLabel = props.showLabel,
customLabelCfg = props.labelCfg;
var View = (0, _util.isFunction)(Views) ? Views : Views[shape];
var LabelView = LabelViews[shape];
var labelCfg = (0, _util.deepMix)({
label: null,
offsetX: 0,
offsetY: 0
}, customLabelCfg);
if (!View) return null;
var selected = state.selected;
var records = this.mapping();
var pointY0 = this.getPointY0();
var clip = this.getClip();
return (0, _fEngine.jsx)(View, {
coord: coord,
records: records,
selected: selected,
shape: shape,
animation: animation,
showLabel: showLabel,
labelCfg: labelCfg,
LabelView: LabelView,
y0: pointY0,
clip: clip
});
};
return Interval;
}(_geometry.default);
};
;