UNPKG

5.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getCoordinateBBox = exports.getCoordinateClipCfg = exports.getAngleByPoint = exports.isPointInCoordinate = exports.getDistanceToCenter = exports.isFullCircle = exports.getXDimensionLength = void 0;
4var graphics_1 = require("./graphics");
5var helper_1 = require("./helper");
6var bbox_1 = require("./bbox");
7/**
8 * @ignore
9 * Gets x dimension length
10 * @param coordinate
11 * @returns x dimension length
12 */
13function getXDimensionLength(coordinate) {
14 if (coordinate.isPolar && !coordinate.isTransposed) {
15 // 极坐标系下 width 为弧长
16 return (coordinate.endAngle - coordinate.startAngle) * coordinate.getRadius();
17 }
18 // 直角坐标系
19 var start = coordinate.convert({ x: 0, y: 0 });
20 var end = coordinate.convert({ x: 1, y: 0 });
21 // 坐标系有可能发生 transpose 等变换,所有通过两点之间的距离进行计算
22 return Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
23}
24exports.getXDimensionLength = getXDimensionLength;
25/**
26 * @ignore
27 * Determines whether full circle is
28 * @param coordinate
29 * @returns true if full circle
30 */
31function isFullCircle(coordinate) {
32 if (coordinate.isPolar) {
33 var startAngle = coordinate.startAngle, endAngle = coordinate.endAngle;
34 return endAngle - startAngle === Math.PI * 2;
35 }
36 return false;
37}
38exports.isFullCircle = isFullCircle;
39/**
40 * @ignore
41 * 获取当前点到坐标系圆心的距离
42 * @param coordinate 坐标系
43 * @param point 当前点
44 * @returns distance to center
45 */
46function getDistanceToCenter(coordinate, point) {
47 var center = coordinate.getCenter();
48 return Math.sqrt(Math.pow((point.x - center.x), 2) + Math.pow((point.y - center.y), 2));
49}
50exports.getDistanceToCenter = getDistanceToCenter;
51/**
52 * @ignore
53 * 坐标点是否在坐标系中
54 * @param coordinate
55 * @param point
56 */
57function isPointInCoordinate(coordinate, point) {
58 var result = false;
59 if (coordinate) {
60 if (coordinate.type === 'theta') {
61 var start = coordinate.start, end = coordinate.end;
62 result = (0, helper_1.isBetween)(point.x, start.x, end.x) && (0, helper_1.isBetween)(point.y, start.y, end.y);
63 }
64 else {
65 var invertPoint = coordinate.invert(point);
66 result = (0, helper_1.isBetween)(invertPoint.x, 0, 1) && (0, helper_1.isBetween)(invertPoint.y, 0, 1);
67 }
68 }
69 return result;
70}
71exports.isPointInCoordinate = isPointInCoordinate;
72/**
73 * @ignore
74 * 获取点到圆心的连线与水平方向的夹角
75 */
76function getAngleByPoint(coordinate, point) {
77 var center = coordinate.getCenter();
78 return Math.atan2(point.y - center.y, point.x - center.x);
79}
80exports.getAngleByPoint = getAngleByPoint;
81/**
82 * @ignore
83 * 获取同坐标系范围相同的剪切区域
84 * @param coordinate
85 * @returns
86 */
87function getCoordinateClipCfg(coordinate, margin) {
88 if (margin === void 0) { margin = 0; }
89 var start = coordinate.start, end = coordinate.end;
90 var width = coordinate.getWidth();
91 var height = coordinate.getHeight();
92 if (coordinate.isPolar) {
93 var startAngle_1 = coordinate.startAngle, endAngle_1 = coordinate.endAngle;
94 var center_1 = coordinate.getCenter();
95 var radius_1 = coordinate.getRadius();
96 return {
97 type: 'path',
98 startState: {
99 path: (0, graphics_1.getSectorPath)(center_1.x, center_1.y, radius_1 + margin, startAngle_1, startAngle_1),
100 },
101 endState: function (ratio) {
102 var diff = (endAngle_1 - startAngle_1) * ratio + startAngle_1;
103 var path = (0, graphics_1.getSectorPath)(center_1.x, center_1.y, radius_1 + margin, startAngle_1, diff);
104 return {
105 path: path,
106 };
107 },
108 attrs: {
109 path: (0, graphics_1.getSectorPath)(center_1.x, center_1.y, radius_1 + margin, startAngle_1, endAngle_1),
110 },
111 };
112 }
113 var endState;
114 if (coordinate.isTransposed) {
115 endState = {
116 height: height + margin * 2,
117 };
118 }
119 else {
120 endState = {
121 width: width + margin * 2,
122 };
123 }
124 return {
125 type: 'rect',
126 startState: {
127 x: start.x - margin,
128 y: end.y - margin,
129 width: coordinate.isTransposed ? width + margin * 2 : 0,
130 height: coordinate.isTransposed ? 0 : height + margin * 2,
131 },
132 endState: endState,
133 attrs: {
134 x: start.x - margin,
135 y: end.y - margin,
136 width: width + margin * 2,
137 height: height + margin * 2,
138 },
139 };
140}
141exports.getCoordinateClipCfg = getCoordinateClipCfg;
142/**
143 * 获取坐标系范围的 BBox
144 * @param coordinate
145 * @param margin
146 */
147function getCoordinateBBox(coordinate, margin) {
148 if (margin === void 0) { margin = 0; }
149 var start = coordinate.start, end = coordinate.end;
150 var width = coordinate.getWidth();
151 var height = coordinate.getHeight();
152 var minX = Math.min(start.x, end.x);
153 var minY = Math.min(start.y, end.y);
154 return bbox_1.BBox.fromRange(minX - margin, minY - margin, minX + width + margin, minY + height + margin);
155}
156exports.getCoordinateBBox = getCoordinateBBox;
157//# sourceMappingURL=coordinate.js.map
\No newline at end of file