UNPKG

3.57 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getTransformOptions = exports.angleOf = exports.radiusOf = exports.getRadius = exports.isNonCartesian = exports.isTheta = exports.isCircular = exports.isRadar = exports.isFisheye = exports.isParallel = exports.isHelix = exports.isRadial = exports.isPolar = exports.isTranspose = void 0;
4function isTranspose(coordinate) {
5 const { transformations } = coordinate.getOptions();
6 const transposes = transformations
7 .map(([type]) => type)
8 .filter((type) => type === 'transpose');
9 return transposes.length % 2 !== 0;
10}
11exports.isTranspose = isTranspose;
12function isPolar(coordinate) {
13 const { transformations } = coordinate.getOptions();
14 return transformations.some(([type]) => type === 'polar');
15}
16exports.isPolar = isPolar;
17function isRadial(coordinate) {
18 const { transformations } = coordinate.getOptions();
19 return (
20 // distinguish radial from theta.
21 transformations.some(([type]) => type === 'reflect') &&
22 transformations.some(([type]) => type.startsWith('transpose')));
23}
24exports.isRadial = isRadial;
25function isHelix(coordinate) {
26 const { transformations } = coordinate.getOptions();
27 return transformations.some(([type]) => type === 'helix');
28}
29exports.isHelix = isHelix;
30function isParallel(coordinate) {
31 const { transformations } = coordinate.getOptions();
32 return transformations.some(([type]) => type === 'parallel');
33}
34exports.isParallel = isParallel;
35function isFisheye(coordinate) {
36 const { transformations } = coordinate.getOptions();
37 return transformations.some(([type]) => type === 'fisheye');
38}
39exports.isFisheye = isFisheye;
40function isRadar(coordinate) {
41 return isParallel(coordinate) && isPolar(coordinate);
42}
43exports.isRadar = isRadar;
44function isCircular(coordinate) {
45 return isHelix(coordinate) || isPolar(coordinate);
46}
47exports.isCircular = isCircular;
48function isTheta(coordinate) {
49 return isPolar(coordinate) && isTranspose(coordinate);
50}
51exports.isTheta = isTheta;
52function isNonCartesian(coordinate) {
53 return (isPolar(coordinate) ||
54 isParallel(coordinate) ||
55 isRadial(coordinate) ||
56 isTheta(coordinate));
57}
58exports.isNonCartesian = isNonCartesian;
59function getRadius(coordinate) {
60 if (isCircular(coordinate)) {
61 const [width, height] = coordinate.getSize();
62 const polar = coordinate
63 .getOptions()
64 .transformations.find((t) => t[0] === 'polar');
65 // coordinate.size * outerRadius.
66 if (polar)
67 return (Math.max(width, height) / 2) * polar[4];
68 }
69 return 0;
70}
71exports.getRadius = getRadius;
72function radiusOf(coordinate) {
73 const { transformations } = coordinate.getOptions();
74 const [, , , innerRadius, outerRadius] = transformations.find((d) => d[0] === 'polar');
75 return [+innerRadius, +outerRadius];
76}
77exports.radiusOf = radiusOf;
78function angleOf(coordinate, isRadius = true) {
79 const { transformations } = coordinate.getOptions();
80 const [, startAngle, endAngle] = transformations.find((d) => d[0] === 'polar');
81 return isRadius
82 ? [(+startAngle * 180) / Math.PI, (+endAngle * 180) / Math.PI]
83 : [startAngle, endAngle];
84}
85exports.angleOf = angleOf;
86function getTransformOptions(coordinate, type) {
87 const { transformations } = coordinate.getOptions();
88 const [, ...args] = transformations.find((d) => d[0] === type);
89 return args;
90}
91exports.getTransformOptions = getTransformOptions;
92//# sourceMappingURL=coordinate.js.map
\No newline at end of file