source: node_modules/recharts/es6/util/CartesianUtils.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[a762898]1export var rectWithPoints = (_ref, _ref2) => {
2 var {
3 x: x1,
4 y: y1
5 } = _ref;
6 var {
7 x: x2,
8 y: y2
9 } = _ref2;
10 return {
11 x: Math.min(x1, x2),
12 y: Math.min(y1, y2),
13 width: Math.abs(x2 - x1),
14 height: Math.abs(y2 - y1)
15 };
16};
17
18/**
19 * Compute the x, y, width, and height of a box from two reference points.
20 * @param {Object} coords x1, x2, y1, and y2
21 * @return {Object} object
22 */
23export var rectWithCoords = _ref3 => {
24 var {
25 x1,
26 y1,
27 x2,
28 y2
29 } = _ref3;
30 return rectWithPoints({
31 x: x1,
32 y: y1
33 }, {
34 x: x2,
35 y: y2
36 });
37};
38
39/** Normalizes the angle so that 0 <= angle < 180.
40 * @param {number} angle Angle in degrees.
41 * @return {number} the normalized angle with a value of at least 0 and never greater or equal to 180. */
42export function normalizeAngle(angle) {
43 return (angle % 180 + 180) % 180;
44}
45
46/** Calculates the width of the largest horizontal line that fits inside a rectangle that is displayed at an angle.
47 * @param {Object} size Width and height of the text in a horizontal position.
48 * @param {number} angle Angle in degrees in which the text is displayed.
49 * @return {number} The width of the largest horizontal line that fits inside a rectangle that is displayed at an angle.
50 */
51export var getAngledRectangleWidth = function getAngledRectangleWidth(_ref4) {
52 var {
53 width,
54 height
55 } = _ref4;
56 var angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
57 // Ensure angle is >= 0 && < 180
58 var normalizedAngle = normalizeAngle(angle);
59 var angleRadians = normalizedAngle * Math.PI / 180;
60
61 /* Depending on the height and width of the rectangle, we may need to use different formulas to calculate the angled
62 * width. This threshold defines when each formula should kick in. */
63 var angleThreshold = Math.atan(height / width);
64 var angledWidth = angleRadians > angleThreshold && angleRadians < Math.PI - angleThreshold ? height / Math.sin(angleRadians) : width / Math.cos(angleRadians);
65 return Math.abs(angledWidth);
66};
Note: See TracBrowser for help on using the repository browser.