1 | import { __extends } from "tslib";
|
2 | import { jsx } from '@antv/f-engine';
|
3 | import { deepMix, isFunction, isNil, mix } from '@antv/util';
|
4 | import Geometry from '../geometry';
|
5 | import * as LabelViews from './label';
|
6 | export default (function (Views) {
|
7 | return 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 |
|
39 | var count = values.length;
|
40 | var ratio;
|
41 | if (coord.isPolar) {
|
42 | if (coord.transposed && count > 1) {
|
43 | ratio = defaultWithRatio.multiplePie;
|
44 | } else {
|
45 | ratio = defaultWithRatio.rose;
|
46 | }
|
47 | } else {
|
48 | ratio = defaultWithRatio.column;
|
49 | }
|
50 | var size = 1 / values.length * ratio;
|
51 |
|
52 | if (adjust && adjust.type === 'dodge') {
|
53 | return size / records.length;
|
54 | }
|
55 | return size;
|
56 | };
|
57 | Interval.prototype.mapping = function () {
|
58 | var _a;
|
59 | var records = _super.prototype.mapping.call(this);
|
60 | var props = this.props;
|
61 | var coord = props.coord,
|
62 | sizeZoom = props.sizeZoom;
|
63 | var y0 = this.getY0Value();
|
64 | var defaultSize = this.getDefaultSize();
|
65 | for (var i = 0, len = records.length; i < len; i++) {
|
66 | var record = records[i];
|
67 | var children = record.children;
|
68 | for (var j = 0, len_1 = children.length; j < len_1; j++) {
|
69 | var child = children[j];
|
70 | var normalized = child.normalized,
|
71 | mappedSize = child.size,
|
72 | origin_1 = child.origin;
|
73 |
|
74 | if (isNil(mappedSize)) {
|
75 | var x = normalized.x,
|
76 | y = normalized.y,
|
77 | _b = normalized.size,
|
78 | size = _b === void 0 ? defaultSize : _b;
|
79 | var zoomRatio = (_a = isFunction(sizeZoom) ? sizeZoom(origin_1) : sizeZoom) !== null && _a !== void 0 ? _a : 1;
|
80 | mix(child, coord.convertRect({
|
81 | x: x,
|
82 | y: y,
|
83 | y0: y0,
|
84 | size: size * zoomRatio
|
85 | }));
|
86 | } else {
|
87 | var x = child.x,
|
88 | y = child.y;
|
89 | var rect = {
|
90 | size: mappedSize,
|
91 | x: x,
|
92 | y: y,
|
93 | y0: y0
|
94 | };
|
95 | mix(child, coord.transformToRect(rect));
|
96 | }
|
97 | mix(child.shape, this.getSelectionStyle(child));
|
98 | }
|
99 | }
|
100 | return records;
|
101 | };
|
102 |
|
103 | Interval.prototype.getPointY0 = function () {
|
104 | var props = this.props;
|
105 | var coord = props.coord;
|
106 | var y0 = this.getY0Value();
|
107 | var y0Point = coord.convertPoint({
|
108 | y: y0,
|
109 | x: 0
|
110 | });
|
111 | return y0Point === null || y0Point === void 0 ? void 0 : y0Point.y;
|
112 | };
|
113 | Interval.prototype.render = function () {
|
114 | var _a = this,
|
115 | props = _a.props,
|
116 | state = _a.state;
|
117 | var coord = props.coord,
|
118 | _b = props.shape,
|
119 | shape = _b === void 0 ? 'rect' : _b,
|
120 | animation = props.animation,
|
121 | showLabel = props.showLabel,
|
122 | customLabelCfg = props.labelCfg;
|
123 | var View = isFunction(Views) ? Views : Views[shape];
|
124 | var LabelView = LabelViews[shape];
|
125 | var labelCfg = deepMix({
|
126 | label: null,
|
127 | offsetX: 0,
|
128 | offsetY: 0
|
129 | }, customLabelCfg);
|
130 | if (!View) return null;
|
131 | var selected = state.selected;
|
132 | var records = this.mapping();
|
133 | var pointY0 = this.getPointY0();
|
134 | var clip = this.getClip();
|
135 | return jsx(View, {
|
136 | coord: coord,
|
137 | records: records,
|
138 | selected: selected,
|
139 | shape: shape,
|
140 | animation: animation,
|
141 | showLabel: showLabel,
|
142 | labelCfg: labelCfg,
|
143 | LabelView: LabelView,
|
144 | y0: pointY0,
|
145 | clip: clip
|
146 | });
|
147 | };
|
148 | return Interval;
|
149 | }(Geometry);
|
150 | }); |
\ | No newline at end of file |