Skip to content

Commit 0a546d0

Browse files
committed
fix: Add smoothing values as props & Fix inaccurate linear value points
1 parent e0fa6a3 commit 0a546d0

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/AnimatedLineGraph.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const ReanimatedView = Reanimated.View as any
5656
export function AnimatedLineGraph({
5757
points,
5858
color,
59+
smoothing = 0.2,
5960
gradientFillColors,
6061
lineThickness = 3,
6162
range,
@@ -190,6 +191,7 @@ export function AnimatedLineGraph({
190191
const createGraphPathProps = {
191192
points: points,
192193
range: pathRange,
194+
smoothing: smoothing,
193195
horizontalPadding: horizontalPadding,
194196
verticalPadding: verticalPadding,
195197
canvasHeight: height,

src/CreateGraphPath.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ function createGraphPathBase({
161161
const actualWidth = width - 2 * horizontalPadding
162162
const actualHeight = height - 2 * verticalPadding
163163

164+
const areSameValues = range.y.min === range.y.max;
165+
164166
const getGraphPoint = (point: GraphPoint): Vector => {
165167
const x =
166168
actualWidth * pixelFactorX(point.date, range.x.min, range.x.max) +
167169
horizontalPadding
168-
const y =
170+
const y = areSameValues ? actualHeight / 2 + verticalPadding :
169171
actualHeight -
170172
actualHeight * pixelFactorY(point.value, range.y.min, range.y.max) +
171173
verticalPadding

src/LineGraphProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ interface BaseLineGraphProps extends ViewProps {
3333
* Color of the graph line (path)
3434
*/
3535
color: string
36+
/**
37+
* Smoothing value of the graph (Radius of the edge points)
38+
*/
39+
smoothing: number
3640
/**
3741
* (Optional) Colors for the fill gradient below the graph line
3842
*/

0 commit comments

Comments
 (0)