source: node_modules/recharts/lib/util/CartesianUtils.js

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

Added visualizations

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