Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use arc calculations to render range values #86

Merged
merged 10 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,27 @@ Try this example yourself [here](./example).

# 📖 Props

| Name | Type | Default | Description |
| --------------------------- | --------------------------------------------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| fillValue | number (0-100) | 0 | Current progress value |
| segments | Array of { scale: number, filledColor: string, emptyColor: string, data: object } | [] | Segments of the arc. Here, scale is a percentage value out of 100%, filledColor for filled part of a segment, and emptyColor is background color for an empty segment, data could be any object that you'd want to receive back for a segment. See example above. |
| filledArcWidth | number | 8 | Thickness of progress line |
| emptyArcWidth | number | 8 | Thickness of background line |
| spaceBetweenSegments | number | 2 | Space between segments |
| arcDegree | number | 180 | Degree of arc |
| radius | number | 100 | Arc radius |
| isAnimated | bool | true | Enable/disable progress animation |
| animationDuration | number | 1000 | Progress animation duration |
| animationDelay | number | 0 | Progress animation delay |
| ranges | Array of strings | [] | Arc ranges (segments) display values |
| rangesTextColor | string | '#000000' | Color of ranges text |
| rangesTextStyle | object | { fontSize: 12 } | Ranges text styling |
| showArcRanges | bool | false | Show/hide arc ranges |
| middleContentContainerStyle | object | {} | Extra styling for the middle content container |
| capInnerColor | string | '#28E037' | Cap's inner color |
| capOuterColor | string | '#FFFFFF' | Cap's outer color |
| children | function | | Pass a function as a child. It receives metaData with the last filled segment's data as an argument. From there you can extract data object. See example above. |
| |
| Name | Type | Default | Description |
| --------------------------- | --------------------------------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| fillValue | number (0-100) | 0 | Current progress value |
| segments | Array of { scale: number, filledColor: string, emptyColor: string, data: object } | [] | Segments of the arc. Here, scale is a percentage value out of 100%, filledColor for filled part of a segment, and emptyColor is background color for an empty segment, data could be any object that you'd want to receive back for a segment. See example above. |
| filledArcWidth | number | 8 | Thickness of progress line |
| emptyArcWidth | number | 8 | Thickness of background line |
| spaceBetweenSegments | number | 2 | Space between segments |
| arcDegree | number | 180 | Degree of arc |
| radius | number | 100 | Arc radius |
| isAnimated | bool | true | Enable/disable progress animation |
| animationDuration | number | 1000 | Progress animation duration |
| animationDelay | number | 0 | Progress animation delay |
| ranges | Array of strings | [] | Arc ranges (segments) display values |
| rangesTextColor | string | '#000000' | Color of ranges text |
| rangesTextStyle | object | { fontSize: 12 } | Ranges text styling |
| showArcRanges | bool | false | Show/hide arc ranges |
| middleContentContainerStyle | object | {} | Extra styling for the middle content container |
| capInnerColor | string | '#28E037' | Cap's inner color |
| capOuterColor | string | '#FFFFFF' | Cap's outer color |
| children | function | | Pass a function as a child. It receives metaData with the last filled segment's data as an argument. From there you can extract data object. See example above. |
| alignRangesWithSegments | bool | true | This might be useful when using segment[].arcDegreeScale values to customize the size of individual segments. If you'd like the range display to align with the edge of each segment, pass this prop as `true`. Otherwise, range displays will be distributed evenly across the arc. |

## 📋 Attributions

Expand Down
8 changes: 6 additions & 2 deletions src/SegmentedArc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const SegmentedArc = ({
rangesTextStyle = styles.rangeTextStyle,
capInnerColor = '#28E037',
capOuterColor = '#FFFFFF',
alignRangesWithSegments = true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true as the default is a good idea. It was a bit confusing before why we would want to default to false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a 50/50 shot of getting it right 😉

children
}) => {
const [arcAnimatedValue] = useState(new Animated.Value(0));
Expand Down Expand Up @@ -147,6 +148,7 @@ export const SegmentedArc = ({
<Svg width={svgWidth} height={svgHeight}>
<SegmentedArcContext.Provider
value={{
arcs,
margin,
center,
filledArcWidth,
Expand All @@ -164,7 +166,8 @@ export const SegmentedArc = ({
rangesTextColor,
rangesTextStyle,
capInnerColor,
capOuterColor
capOuterColor,
alignRangesWithSegments
}}
>
{arcs.map((arc, index) => (
Expand Down Expand Up @@ -216,7 +219,8 @@ SegmentedArc.propTypes = {
rangesTextColor: PropTypes.string,
rangesTextStyle: PropTypes.object,
capInnerColor: PropTypes.string,
capOuterColor: PropTypes.string
capOuterColor: PropTypes.string,
alignRangesWithSegments: PropTypes.bool
};
export { SegmentedArcContext };
export default SegmentedArc;
Loading
Loading