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

fix: Add smoothing values as props & Fix inaccurate linear value points #55

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: Add smoothing values as props & Fix inaccurate linear value points
  • Loading branch information
bored-yuns committed Dec 6, 2022
commit 0a546d0d4c20258383752ad5ea10e02fe4d76278
2 changes: 2 additions & 0 deletions src/AnimatedLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const ReanimatedView = Reanimated.View as any
export function AnimatedLineGraph({
points,
color,
smoothing = 0.2,
gradientFillColors,
lineThickness = 3,
range,
Expand Down Expand Up @@ -190,6 +191,7 @@ export function AnimatedLineGraph({
const createGraphPathProps = {
points: points,
range: pathRange,
smoothing: smoothing,
horizontalPadding: horizontalPadding,
verticalPadding: verticalPadding,
canvasHeight: height,
Expand Down
4 changes: 3 additions & 1 deletion src/CreateGraphPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ function createGraphPathBase({
const actualWidth = width - 2 * horizontalPadding
const actualHeight = height - 2 * verticalPadding

const areSameValues = range.y.min === range.y.max;

const getGraphPoint = (point: GraphPoint): Vector => {
const x =
actualWidth * pixelFactorX(point.date, range.x.min, range.x.max) +
horizontalPadding
const y =
const y = areSameValues ? actualHeight / 2 + verticalPadding :
actualHeight -
actualHeight * pixelFactorY(point.value, range.y.min, range.y.max) +
verticalPadding
Expand Down
4 changes: 4 additions & 0 deletions src/LineGraphProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ interface BaseLineGraphProps extends ViewProps {
* Color of the graph line (path)
*/
color: string
/**
* Smoothing value of the graph (Radius of the edge points)
*/
smoothing: number
/**
* (Optional) Colors for the fill gradient below the graph line
*/
Expand Down