@baby-journey/rn-segmented-progress-bar
Version:
Animated circular progress bar with segments
42 lines (41 loc) • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPathValues = exports.getArcEndCoordinates = void 0;
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;
};
exports.getPathValues = getPathValues;
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
};
};
exports.getArcEndCoordinates = getArcEndCoordinates;
//# sourceMappingURL=index.js.map