UNPKG

2.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.polar = void 0;
4/* eslint-disable @typescript-eslint/no-unused-vars */
5var scale_1 = require("@antv/scale");
6var utils_1 = require("../utils");
7/**
8 * Maps normalized value to normalized polar coordinate at the center of the bounding box.
9 * It is used for Nightingale Rose Diagram.
10 * @param params [x0, x1, y0, y1]
11 * @param x x of the the bounding box of coordinate
12 * @param y y of the the bounding box of coordinate
13 * @param width width of the the bounding box of coordinate
14 * @param height height of the the bounding box of coordinate
15 * @returns transformer
16 */
17var polar = function (params, x, y, width, height) {
18 var _a = params, startAngle = _a[0], endAngle = _a[1], innerRadius = _a[2], outerRadius = _a[3];
19 var radius = new scale_1.Linear({
20 range: [innerRadius, outerRadius],
21 });
22 var angle = new scale_1.Linear({
23 range: [startAngle, endAngle],
24 });
25 var aspect = height / width;
26 var sx = aspect > 1 ? 1 : aspect;
27 var sy = aspect > 1 ? 1 / aspect : 1;
28 return {
29 transform: function (vector) {
30 var v1 = vector[0], v2 = vector[1];
31 var theta = angle.map(v1);
32 var r = radius.map(v2);
33 // 根据长宽比调整,使得极坐标系内切外接矩形
34 var x = r * Math.cos(theta) * sx;
35 var y = r * Math.sin(theta) * sy;
36 // 将坐标的原点移动到外接矩形的中心,并且将长度设置为一半
37 var dx = x * 0.5 + 0.5;
38 var dy = y * 0.5 + 0.5;
39 return [dx, dy];
40 },
41 untransform: function (vector) {
42 var dx = vector[0], dy = vector[1];
43 var x = ((dx - 0.5) * 2) / sx;
44 var y = ((dy - 0.5) * 2) / sy;
45 var r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
46 var t = Math.atan2(y, x);
47 var theta = utils_1.adjustAngle(t, startAngle, endAngle);
48 var v1 = angle.invert(theta);
49 var v2 = radius.invert(r);
50 return [v1, v2];
51 },
52 };
53};
54exports.polar = polar;
55//# sourceMappingURL=polar.js.map
\No newline at end of file