bc518174
王天杨
提交两个项目文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import isNil from 'lodash/isNil';
import { isValidElement } from 'react';
import isFunction from 'lodash/isFunction';
import { getPercentValue } from './DataUtils';
import { parseScale, checkDomainOfScale, getTicksOfScale } from './ChartUtils';
export var RADIAN = Math.PI / 180;
export var degreeToRadian = function degreeToRadian(angle) {
return angle * Math.PI / 180;
};
export var radianToDegree = function radianToDegree(angleInRadian) {
return angleInRadian * 180 / Math.PI;
};
export var polarToCartesian = function polarToCartesian(cx, cy, radius, angle) {
return {
x: cx + Math.cos(-RADIAN * angle) * radius,
y: cy + Math.sin(-RADIAN * angle) * radius
};
};
export var getMaxRadius = function getMaxRadius(width, height) {
var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
top: 0,
right: 0,
bottom: 0,
left: 0
};
return Math.min(Math.abs(width - (offset.left || 0) - (offset.right || 0)), Math.abs(height - (offset.top || 0) - (offset.bottom || 0))) / 2;
};
/**
* Calculate the scale function, position, width, height of axes
* @param {Object} props Latest props
* @param {Object} axisMap The configuration of axes
* @param {Object} offset The offset of main part in the svg element
* @param {Object} axisType The type of axes, radius-axis or angle-axis
* @param {String} chartName The name of chart
* @return {Object} Configuration
*/
export var formatAxisMap = function formatAxisMap(props, axisMap, offset, axisType, chartName) {
var width = props.width,
height = props.height;
var startAngle = props.startAngle,
endAngle = props.endAngle;
var cx = getPercentValue(props.cx, width, width / 2);
var cy = getPercentValue(props.cy, height, height / 2);
var maxRadius = getMaxRadius(width, height, offset);
var innerRadius = getPercentValue(props.innerRadius, maxRadius, 0);
var outerRadius = getPercentValue(props.outerRadius, maxRadius, maxRadius * 0.8);
var ids = Object.keys(axisMap);
return ids.reduce(function (result, id) {
var axis = axisMap[id];
var domain = axis.domain,
reversed = axis.reversed;
var range;
if (isNil(axis.range)) {
if (axisType === 'angleAxis') {
range = [startAngle, endAngle];
} else if (axisType === 'radiusAxis') {
range = [innerRadius, outerRadius];
}
if (reversed) {
range = [range[1], range[0]];
}
} else {
range = axis.range;
var _range = range;
var _range2 = _slicedToArray(_range, 2);
startAngle = _range2[0];
endAngle = _range2[1];
}
var _parseScale = parseScale(axis, chartName),
realScaleType = _parseScale.realScaleType,
scale = _parseScale.scale;
scale.domain(domain).range(range);
checkDomainOfScale(scale);
var ticks = getTicksOfScale(scale, _objectSpread(_objectSpread({}, axis), {}, {
realScaleType: realScaleType
}));
var finalAxis = _objectSpread(_objectSpread(_objectSpread({}, axis), ticks), {}, {
range: range,
radius: outerRadius,
realScaleType: realScaleType,
scale: scale,
cx: cx,
cy: cy,
innerRadius: innerRadius,
outerRadius: outerRadius,
startAngle: startAngle,
endAngle: endAngle
});
return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, id, finalAxis));
}, {});
};
export var distanceBetweenPoints = function distanceBetweenPoints(point, anotherPoint) {
var x1 = point.x,
y1 = point.y;
var x2 = anotherPoint.x,
y2 = anotherPoint.y;
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
};
export var getAngleOfPoint = function getAngleOfPoint(_ref, _ref2) {
var x = _ref.x,
y = _ref.y;
var cx = _ref2.cx,
cy = _ref2.cy;
var radius = distanceBetweenPoints({
x: x,
y: y
}, {
x: cx,
y: cy
});
if (radius <= 0) {
return {
radius: radius
};
}
var cos = (x - cx) / radius;
var angleInRadian = Math.acos(cos);
if (y > cy) {
angleInRadian = 2 * Math.PI - angleInRadian;
}
return {
radius: radius,
angle: radianToDegree(angleInRadian),
angleInRadian: angleInRadian
};
};
export var formatAngleOfSector = function formatAngleOfSector(_ref3) {
var startAngle = _ref3.startAngle,
endAngle = _ref3.endAngle;
var startCnt = Math.floor(startAngle / 360);
var endCnt = Math.floor(endAngle / 360);
var min = Math.min(startCnt, endCnt);
return {
startAngle: startAngle - min * 360,
endAngle: endAngle - min * 360
};
};
var reverseFormatAngleOfSetor = function reverseFormatAngleOfSetor(angle, _ref4) {
var startAngle = _ref4.startAngle,
endAngle = _ref4.endAngle;
var startCnt = Math.floor(startAngle / 360);
var endCnt = Math.floor(endAngle / 360);
var min = Math.min(startCnt, endCnt);
return angle + min * 360;
};
export var inRangeOfSector = function inRangeOfSector(_ref5, sector) {
var x = _ref5.x,
y = _ref5.y;
var _getAngleOfPoint = getAngleOfPoint({
x: x,
y: y
}, sector),
radius = _getAngleOfPoint.radius,
angle = _getAngleOfPoint.angle;
var innerRadius = sector.innerRadius,
outerRadius = sector.outerRadius;
if (radius < innerRadius || radius > outerRadius) {
return false;
}
if (radius === 0) {
return true;
}
var _formatAngleOfSector = formatAngleOfSector(sector),
startAngle = _formatAngleOfSector.startAngle,
endAngle = _formatAngleOfSector.endAngle;
var formatAngle = angle;
var inRange;
if (startAngle <= endAngle) {
while (formatAngle > endAngle) {
formatAngle -= 360;
}
while (formatAngle < startAngle) {
formatAngle += 360;
}
inRange = formatAngle >= startAngle && formatAngle <= endAngle;
} else {
while (formatAngle > startAngle) {
formatAngle -= 360;
}
while (formatAngle < endAngle) {
formatAngle += 360;
}
inRange = formatAngle >= endAngle && formatAngle <= startAngle;
}
if (inRange) {
return _objectSpread(_objectSpread({}, sector), {}, {
radius: radius,
angle: reverseFormatAngleOfSetor(formatAngle, sector)
});
}
return null;
};
export var getTickClassName = function getTickClassName(tick) {
return ! /*#__PURE__*/isValidElement(tick) && !isFunction(tick) && typeof tick !== 'boolean' ? tick.className : '';
};
|