set value boundaries in CircularProgressbar, instead of in Path

This commit is contained in:
Kevin Qi 2019-05-11 14:55:21 -07:00
parent 397e623a2a
commit af4775625e
3 changed files with 4 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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(