Skip to content

Commit

Permalink
fix: Remove incorrect delta from pixel factor calculation (#56)
Browse files Browse the repository at this point in the history
* fix: Remove incorrect delta from pixel factor calculation

* fix: Drawing factor calculation

Co-authored-by: Christoph Pader <christoph@margelo.io>
  • Loading branch information
thomas-coldwell and chrispader committed Jan 23, 2023
1 parent ed74ff4 commit e327c9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 3 additions & 1 deletion example/src/data/GraphData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function generateRandomGraphData(length: number): GraphPoint[] {
return Array<number>(length)
.fill(0)
.map((_, index) => ({
date: new Date(index),
date: new Date(
new Date(2000, 0, 1).getTime() + 1000 * 60 * 60 * 24 * index
),
value: weightedRandom(10, Math.pow(index + 1, 2)),
}))
}
Expand Down
8 changes: 3 additions & 5 deletions src/CreateGraphPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@ function createGraphPathBase({

// Calculates how many points between two points must be
// calculated and drawn onto the canvas
const drawingFactor = pixelFactorX(
new Date(point.date.getTime() - prev.date.getTime()),
range.x.min,
range.x.max
)
const spanX = range.x.max.getTime() - range.x.min.getTime()
const deltaX = point.date.getTime() - prev.date.getTime()
const drawingFactor = deltaX / spanX
const drawingPixels = actualWidth * drawingFactor + horizontalPadding
const numberOfDrawingPoints = Math.floor(drawingPixels / PIXEL_RATIO)

Expand Down

0 comments on commit e327c9d

Please sign in to comment.