1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getDefaultSize = void 0;
|
4 | var util_1 = require("@antv/util");
|
5 | var coordinate_1 = require("../../util/coordinate");
|
6 |
|
7 | function findMinDistance(arr, scale) {
|
8 | var count = arr.length;
|
9 | var sourceArr = arr;
|
10 | if ((0, util_1.isString)(sourceArr[0])) {
|
11 |
|
12 | sourceArr = arr.map(function (v) {
|
13 | return scale.translate(v);
|
14 | });
|
15 | }
|
16 | var distance = sourceArr[1] - sourceArr[0];
|
17 | for (var i = 2; i < count; i++) {
|
18 | var tmp = sourceArr[i] - sourceArr[i - 1];
|
19 | if (distance > tmp) {
|
20 | distance = tmp;
|
21 | }
|
22 | }
|
23 | return distance;
|
24 | }
|
25 | function getDodgeCount(dataArray, dodgeBy) {
|
26 | if (dodgeBy) {
|
27 | var mergeData = (0, util_1.flatten)(dataArray);
|
28 | var values = (0, util_1.valuesOfKey)(mergeData, dodgeBy);
|
29 | return values.length;
|
30 | }
|
31 | return dataArray.length;
|
32 | }
|
33 |
|
34 | function getDefaultSize(geometry) {
|
35 | var theme = geometry.theme;
|
36 | var coordinate = geometry.coordinate;
|
37 | var xScale = geometry.getXScale();
|
38 | var xValues = xScale.values;
|
39 | var dataArray = geometry.beforeMappingData;
|
40 | var count = xValues.length;
|
41 | var xDimensionLength = (0, coordinate_1.getXDimensionLength)(geometry.coordinate);
|
42 |
|
43 | var intervalPadding = geometry.intervalPadding, dodgePadding = geometry.dodgePadding;
|
44 |
|
45 | var maxColumnWidth = geometry.maxColumnWidth || theme.maxColumnWidth;
|
46 | var minColumnWidth = geometry.minColumnWidth || theme.minColumnWidth;
|
47 | var columnWidthRatio = geometry.columnWidthRatio || theme.columnWidthRatio;
|
48 | var multiplePieWidthRatio = geometry.multiplePieWidthRatio || theme.multiplePieWidthRatio;
|
49 | var roseWidthRatio = geometry.roseWidthRatio || theme.roseWidthRatio;
|
50 |
|
51 | if (xScale.isLinear && xValues.length > 1) {
|
52 |
|
53 | xValues.sort();
|
54 | var interval = findMinDistance(xValues, xScale);
|
55 | count = (xScale.max - xScale.min) / interval;
|
56 | if (xValues.length > count) {
|
57 | count = xValues.length;
|
58 | }
|
59 | }
|
60 | var range = xScale.range;
|
61 | var normalizedSize = 1 / count;
|
62 | var wr = 1;
|
63 | if (coordinate.isPolar) {
|
64 |
|
65 | if (coordinate.isTransposed && count > 1) {
|
66 |
|
67 | wr = multiplePieWidthRatio;
|
68 | }
|
69 | else {
|
70 | wr = roseWidthRatio;
|
71 | }
|
72 | }
|
73 | else {
|
74 |
|
75 | if (xScale.isLinear) {
|
76 | normalizedSize *= range[1] - range[0];
|
77 | }
|
78 | wr = columnWidthRatio;
|
79 | }
|
80 |
|
81 | if (!(0, util_1.isNil)(intervalPadding) && intervalPadding >= 0) {
|
82 |
|
83 | var normalizedIntervalPadding = intervalPadding / xDimensionLength;
|
84 | normalizedSize = (1 - (count - 1) * normalizedIntervalPadding) / count;
|
85 | }
|
86 | else {
|
87 |
|
88 | normalizedSize *= wr;
|
89 | }
|
90 |
|
91 | if (geometry.getAdjust('dodge')) {
|
92 | var dodgeAdjust = geometry.getAdjust('dodge');
|
93 | var dodgeBy = dodgeAdjust.dodgeBy;
|
94 | var dodgeCount = getDodgeCount(dataArray, dodgeBy);
|
95 | if (!(0, util_1.isNil)(dodgePadding) && dodgePadding >= 0) {
|
96 |
|
97 | var normalizedDodgePadding = dodgePadding / xDimensionLength;
|
98 | normalizedSize = (normalizedSize - normalizedDodgePadding * (dodgeCount - 1)) / dodgeCount;
|
99 | }
|
100 | else if (!(0, util_1.isNil)(intervalPadding) && intervalPadding >= 0) {
|
101 |
|
102 | normalizedSize *= wr;
|
103 | normalizedSize = normalizedSize / dodgeCount;
|
104 | }
|
105 | else {
|
106 |
|
107 | normalizedSize = normalizedSize / dodgeCount;
|
108 | }
|
109 | normalizedSize = normalizedSize >= 0 ? normalizedSize : 0;
|
110 | }
|
111 |
|
112 | if (!(0, util_1.isNil)(maxColumnWidth) && maxColumnWidth >= 0) {
|
113 | var normalizedMaxColumnWidth = maxColumnWidth / xDimensionLength;
|
114 | if (normalizedSize > normalizedMaxColumnWidth) {
|
115 | normalizedSize = normalizedMaxColumnWidth;
|
116 | }
|
117 | }
|
118 |
|
119 | if (!(0, util_1.isNil)(minColumnWidth) && minColumnWidth >= 0) {
|
120 | var normalizedMinColumnWidth = minColumnWidth / xDimensionLength;
|
121 | if (normalizedSize < normalizedMinColumnWidth) {
|
122 | normalizedSize = normalizedMinColumnWidth;
|
123 | }
|
124 | }
|
125 | return normalizedSize;
|
126 | }
|
127 | exports.getDefaultSize = getDefaultSize;
|
128 |
|
\ | No newline at end of file |