mirror of
https://github.com/kevinsqi/react-circular-progressbar.git
synced 2025-12-08 20:25:50 +00:00
set value boundaries in CircularProgressbar, instead of in Path
This commit is contained in:
parent
397e623a2a
commit
af4775625e
@ -71,7 +71,8 @@ class CircularProgressbar extends React.Component<CircularProgressbarProps> {
|
||||
} = this.props;
|
||||
|
||||
const pathRadius = this.getPathRadius();
|
||||
const pathRatio = value / (maxValue - minValue);
|
||||
const boundedValue = Math.min(Math.max(value, minValue), maxValue);
|
||||
const pathRatio = boundedValue / (maxValue - minValue);
|
||||
|
||||
return (
|
||||
<svg
|
||||
|
||||
@ -63,10 +63,7 @@ function getDashStyle({
|
||||
pathRadius: number;
|
||||
}) {
|
||||
const diameter = Math.PI * 2 * pathRadius;
|
||||
|
||||
// Keep dashRatio between [0, 1]
|
||||
const boundedDashRatio = Math.min(Math.max(dashRatio, 0), 1);
|
||||
const gapLength = (1 - boundedDashRatio) * diameter;
|
||||
const gapLength = (1 - dashRatio) * diameter;
|
||||
|
||||
return {
|
||||
// Have dash be full diameter, and gap be full diameter
|
||||
|
||||
@ -44,7 +44,7 @@ describe('<CircularProgressbar />', () => {
|
||||
expect(wrapper.find('.CircularProgressbar-text').text()).toEqual('50%');
|
||||
});
|
||||
});
|
||||
describe('props.percentage', () => {
|
||||
describe('props.value', () => {
|
||||
test('Renders correct path', () => {
|
||||
const percentage = 30;
|
||||
const wrapper = mount(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user