@antv/f2
Version:
Charts for mobile visualization.
149 lines • 4.63 kB
JavaScript
import { __extends } from "tslib";
import { jsx } from '@antv/f-engine';
import { deepMix, isFunction, isNil, mix } from '@antv/util';
import Geometry from '../geometry';
import * as LabelViews from './label';
export default (function (Views) {
return /** @class */function (_super) {
__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 (isNil(mappedSize)) {
var x = normalized.x,
y = normalized.y,
_b = normalized.size,
size = _b === void 0 ? defaultSize : _b;
var zoomRatio = (_a = isFunction(sizeZoom) ? sizeZoom(origin_1) : sizeZoom) !== null && _a !== void 0 ? _a : 1;
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
};
mix(child, coord.transformToRect(rect));
}
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 = isFunction(Views) ? Views : Views[shape];
var LabelView = LabelViews[shape];
var labelCfg = 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 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);
});