1 | import { __assign } from "tslib";
|
2 | import Coord, { Rect, Polar } from '../coord';
|
3 | import { isString, isFunction } from '@antv/util';
|
4 | var coordMap = {
|
5 | rect: Rect,
|
6 | polar: Polar
|
7 | };
|
8 | var coordController = function () {
|
9 | function coordController() {}
|
10 | coordController.prototype.getOption = function (cfg) {
|
11 | if (isString(cfg)) {
|
12 | return {
|
13 | type: coordMap[cfg] || Rect
|
14 | };
|
15 | }
|
16 | if (isFunction(cfg)) {
|
17 | return {
|
18 | type: cfg
|
19 | };
|
20 | }
|
21 | var type = (cfg || {}).type;
|
22 | return __assign(__assign({}, cfg), {
|
23 |
|
24 | type: isFunction(type) ? type : coordMap[type] || Rect
|
25 | });
|
26 | };
|
27 | coordController.prototype.create = function (cfg) {
|
28 | var layout = this.layout;
|
29 | var option = this.getOption(cfg);
|
30 | var type = option.type;
|
31 | var coord = new type(__assign(__assign({}, option), layout));
|
32 | this.coord = coord;
|
33 | return coord;
|
34 | };
|
35 | coordController.prototype.updateLayout = function (style) {
|
36 | var coord = this.coord;
|
37 | var left = style.left,
|
38 | top = style.top,
|
39 | width = style.width,
|
40 | height = style.height,
|
41 | padding = style.padding;
|
42 | var _a = padding || [0, 0, 0, 0],
|
43 | paddingTop = _a[0],
|
44 | paddingRight = _a[1],
|
45 | paddingBottom = _a[2],
|
46 | paddingLeft = _a[3];
|
47 | this.layout = {
|
48 | left: left + paddingLeft,
|
49 | top: top + paddingTop,
|
50 | width: width - paddingLeft - paddingRight,
|
51 | height: height - paddingTop - paddingBottom
|
52 | };
|
53 | if (coord) {
|
54 | coord.update(this.layout);
|
55 | }
|
56 | };
|
57 | coordController.prototype.useLayout = function (positionLayout) {
|
58 | var coord = this.coord;
|
59 | var position = positionLayout.position,
|
60 | boxWidth = positionLayout.width,
|
61 | boxHeight = positionLayout.height;
|
62 | var left = coord.left,
|
63 | top = coord.top,
|
64 | width = coord.width,
|
65 | height = coord.height;
|
66 | switch (position) {
|
67 | case 'left':
|
68 | left += boxWidth;
|
69 | width = Math.max(0, width - boxWidth);
|
70 | break;
|
71 | case 'right':
|
72 | width = Math.max(0, width - boxWidth);
|
73 | break;
|
74 | case 'top':
|
75 | top += boxHeight;
|
76 | height = Math.max(0, height - boxHeight);
|
77 | break;
|
78 | case 'bottom':
|
79 | height = Math.max(0, height - boxHeight);
|
80 | break;
|
81 | }
|
82 | coord.update({
|
83 | left: left,
|
84 | top: top,
|
85 | width: width,
|
86 | height: height
|
87 | });
|
88 | };
|
89 | coordController.prototype.update = function () {};
|
90 | coordController.prototype.getCoord = function () {
|
91 | return this.coord;
|
92 | };
|
93 | return coordController;
|
94 | }();
|
95 | export { Coord };
|
96 | export default coordController; |
\ | No newline at end of file |