UNPKG

4.63 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import { jsx } from '@antv/f-engine';
3import { deepMix, isFunction, isNil, mix } from '@antv/util';
4import Geometry from '../geometry';
5import * as LabelViews from './label';
6export default (function (Views) {
7 return /** @class */function (_super) {
8 __extends(Interval, _super);
9 function Interval() {
10 return _super !== null && _super.apply(this, arguments) || this;
11 }
12 Interval.prototype.getDefaultCfg = function () {
13 return {
14 geomType: 'interval',
15 justifyContent: true,
16 startOnZero: true
17 };
18 };
19 Interval.prototype.getDefaultSize = function () {
20 var _a = this,
21 attrs = _a.attrs,
22 props = _a.props,
23 adjust = _a.adjust,
24 records = _a.records;
25 var coord = props.coord,
26 sizeRatio = props.sizeRatio;
27 var x = attrs.x;
28 var scale = x.scale;
29 var values = scale.values;
30 if (sizeRatio) {
31 return 1 / values.length * sizeRatio;
32 }
33 var defaultWithRatio = {
34 column: 1 / 2,
35 rose: 0.999999,
36 multiplePie: 3 / 4 // 多饼图
37 };
38 var count = values.length;
39 var ratio;
40 if (coord.isPolar) {
41 if (coord.transposed && count > 1) {
42 ratio = defaultWithRatio.multiplePie;
43 } else {
44 ratio = defaultWithRatio.rose;
45 }
46 } else {
47 ratio = defaultWithRatio.column;
48 }
49 var size = 1 / values.length * ratio;
50 // 分组时size要除以类别个数
51 if (adjust && adjust.type === 'dodge') {
52 return size / records.length;
53 }
54 return size;
55 };
56 Interval.prototype.mapping = function () {
57 var _a;
58 var records = _super.prototype.mapping.call(this);
59 var props = this.props;
60 var coord = props.coord,
61 sizeZoom = props.sizeZoom;
62 var y0 = this.getY0Value();
63 var defaultSize = this.getDefaultSize();
64 for (var i = 0, len = records.length; i < len; i++) {
65 var record = records[i];
66 var children = record.children;
67 for (var j = 0, len_1 = children.length; j < len_1; j++) {
68 var child = children[j];
69 var normalized = child.normalized,
70 mappedSize = child.size,
71 origin_1 = child.origin;
72 // 没有指定size,则根据数据来计算默认size
73 if (isNil(mappedSize)) {
74 var x = normalized.x,
75 y = normalized.y,
76 _b = normalized.size,
77 size = _b === void 0 ? defaultSize : _b;
78 var zoomRatio = (_a = isFunction(sizeZoom) ? sizeZoom(origin_1) : sizeZoom) !== null && _a !== void 0 ? _a : 1;
79 mix(child, coord.convertRect({
80 x: x,
81 y: y,
82 y0: y0,
83 size: size * zoomRatio
84 }));
85 } else {
86 var x = child.x,
87 y = child.y;
88 var rect = {
89 size: mappedSize,
90 x: x,
91 y: y,
92 y0: y0
93 };
94 mix(child, coord.transformToRect(rect));
95 }
96 mix(child.shape, this.getSelectionStyle(child));
97 }
98 }
99 return records;
100 };
101 // 获取Y轴坐标零点的画布位置
102 Interval.prototype.getPointY0 = function () {
103 var props = this.props;
104 var coord = props.coord;
105 var y0 = this.getY0Value();
106 var y0Point = coord.convertPoint({
107 y: y0,
108 x: 0
109 });
110 return y0Point === null || y0Point === void 0 ? void 0 : y0Point.y;
111 };
112 Interval.prototype.render = function () {
113 var _a = this,
114 props = _a.props,
115 state = _a.state;
116 var coord = props.coord,
117 _b = props.shape,
118 shape = _b === void 0 ? 'rect' : _b,
119 animation = props.animation,
120 showLabel = props.showLabel,
121 customLabelCfg = props.labelCfg;
122 var View = isFunction(Views) ? Views : Views[shape];
123 var LabelView = LabelViews[shape];
124 var labelCfg = deepMix({
125 label: null,
126 offsetX: 0,
127 offsetY: 0
128 }, customLabelCfg);
129 if (!View) return null;
130 var selected = state.selected;
131 var records = this.mapping();
132 var pointY0 = this.getPointY0();
133 var clip = this.getClip();
134 return jsx(View, {
135 coord: coord,
136 records: records,
137 selected: selected,
138 shape: shape,
139 animation: animation,
140 showLabel: showLabel,
141 labelCfg: labelCfg,
142 LabelView: LabelView,
143 y0: pointY0,
144 clip: clip
145 });
146 };
147 return Interval;
148 }(Geometry);
149});
\No newline at end of file