Skip to content

Commit

Permalink
fix: static line if values are the same (margelo#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dynamichny authored Jul 7, 2022
1 parent df0b8b2 commit d71ca3a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/CreateGraphPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ export function createGraphPath({
Number.MAX_SAFE_INTEGER
)

const areValuesSame = minValue === maxValue

const points: SkPoint[] = []

for (let pixel = 0; pixel < width; pixel += PIXEL_RATIO) {
const index = Math.floor((pixel / width) * graphData.length)
const value = graphData[index]?.value ?? minValue

const x = (pixel / width) * (width - 2 * graphPadding) + graphPadding
const y =
height -
((value - minValue) / (maxValue - minValue)) * innerHeight -
graphPadding
const y = areValuesSame
? height / 2
: height -
((value - minValue) / (maxValue - minValue)) * innerHeight -
graphPadding

points.push({ x: x, y: y })
}
Expand Down

0 comments on commit d71ca3a

Please sign in to comment.