@carbon/charts
Version:
Carbon charting components
80 lines • 2.51 kB
JavaScript
import { TextAnchor, DominantBaseline } from '../interfaces/enums';
export function radialLabelPlacement(angleRadians) {
var angle = mod(radToDeg(angleRadians), 360);
if (isInRange(angle, [0, 10]) || isInRange(angle, [350, 0])) {
return {
textAnchor: TextAnchor.START,
dominantBaseline: DominantBaseline.MIDDLE,
};
}
else if (isInRange(angle, [10, 80])) {
return {
textAnchor: TextAnchor.START,
dominantBaseline: DominantBaseline.HANGING,
};
}
else if (isInRange(angle, [80, 100])) {
return {
textAnchor: TextAnchor.MIDDLE,
dominantBaseline: DominantBaseline.HANGING,
};
}
else if (isInRange(angle, [100, 170])) {
return {
textAnchor: TextAnchor.END,
dominantBaseline: DominantBaseline.HANGING,
};
}
else if (isInRange(angle, [170, 190])) {
return {
textAnchor: TextAnchor.END,
dominantBaseline: DominantBaseline.MIDDLE,
};
}
else if (isInRange(angle, [190, 260])) {
return {
textAnchor: TextAnchor.END,
dominantBaseline: DominantBaseline.BASELINE,
};
}
else if (isInRange(angle, [260, 280])) {
return {
textAnchor: TextAnchor.MIDDLE,
dominantBaseline: DominantBaseline.BASELINE,
};
}
else {
// 280 - 350
return {
textAnchor: TextAnchor.START,
dominantBaseline: DominantBaseline.BASELINE,
};
}
}
function mod(n, m) {
return ((n % m) + m) % m;
}
function isInRange(x, _a) {
var min = _a[0], max = _a[1];
return x >= min && x <= max;
}
export function radToDeg(rad) {
return rad * (180 / Math.PI);
}
export function degToRad(deg) {
return deg * (Math.PI / 180);
}
export function polarToCartesianCoords(a, r, t) {
if (t === void 0) { t = { x: 0, y: 0 }; }
var x = r * Math.cos(a) + t.x;
var y = r * Math.sin(a) + t.y;
return { x: x, y: y };
}
// Return the distance between a point (described with polar coordinates)
// on a circumference and the vertical diameter.
// If the point is on the left if the diameter, its distance is positive,
// if it is on the right of the diameter, its distance is negative.
export function distanceBetweenPointOnCircAndVerticalDiameter(a, r) {
return r * Math.sin(a - Math.PI / 2);
}
//# sourceMappingURL=../../src/services/angle-utils.js.map