@baby-journey/rn-segmented-progress-bar
Version:
Animated circular progress bar with segments
36 lines (35 loc) • 964 B
JavaScript
;
export const getPathValues = (progress, max, segments) => {
if (!progress) {
return new Array(segments).fill(0);
}
const pathLengths = [];
if (progress > max) {
progress = max;
}
progress = 100 * progress / max;
let i = 0;
while (i < segments) {
const val = progress >= max / segments ? max / segments : progress;
pathLengths.push(Math.round(val * 10000) / 10000);
progress = progress - val;
i++;
}
return pathLengths;
};
export const getArcEndCoordinates = (radius, circleCircumference, cx, cy, rotation = 0) => {
if (circleCircumference == null || circleCircumference === 0 || radius == null || radius === 0 || cx == null || cy == null) {
return {
x: 0,
y: 0
};
}
const θ = circleCircumference / radius + rotation * Math.PI / 180;
const x = Math.cos(θ) * radius + cx;
const y = Math.sin(θ) * radius + cy;
return {
x,
y
};
};
//# sourceMappingURL=index.js.map