@antv/f2
Version:
Charts for mobile visualization.
174 lines (172 loc) • 7.08 kB
JavaScript
"use strict";
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var _util = require("@antv/util");
var _jsx = require("../../jsx");
var _geometry = _interopRequireDefault(require("../geometry"));
var LabelViews = _interopRequireWildcard(require("./label"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var _default = function _default(Views) {
return /*#__PURE__*/function (_Geometry) {
(0, _inherits2.default)(Interval, _Geometry);
var _super = (0, _createSuper2.default)(Interval);
function Interval() {
(0, _classCallCheck2.default)(this, Interval);
return _super.apply(this, arguments);
}
(0, _createClass2.default)(Interval, [{
key: "getDefaultCfg",
value: function getDefaultCfg() {
return {
geomType: 'interval',
justifyContent: true,
startOnZero: true
};
}
}, {
key: "getDefaultSize",
value: function getDefaultSize() {
var attrs = this.attrs,
props = this.props,
adjust = this.adjust,
records = this.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;
}
}, {
key: "mapping",
value: function mapping() {
var records = (0, _get2.default)((0, _getPrototypeOf2.default)(Interval.prototype), "mapping", this).call(this);
var props = this.props;
var coord = props.coord;
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 = children.length; j < _len; j++) {
var child = children[j];
var normalized = child.normalized,
mappedSize = child.size;
// 没有指定size,则根据数据来计算默认size
if ((0, _util.isNil)(mappedSize)) {
var x = normalized.x,
y = normalized.y,
_normalized$size = normalized.size,
size = _normalized$size === void 0 ? defaultSize : _normalized$size;
(0, _util.mix)(child, coord.convertRect({
x: x,
y: y,
y0: y0,
size: size
}));
} 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轴坐标零点的画布位置
}, {
key: "getPointY0",
value: function getPointY0() {
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;
}
}, {
key: "render",
value: function render() {
var props = this.props,
state = this.state,
container = this.container;
var coord = props.coord,
_props$shape = props.shape,
shape = _props$shape === void 0 ? 'rect' : _props$shape,
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, _jsx.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);
};
exports.default = _default;