Skip to content

Commit b9c2819

Browse files
committed
Use buffer prop to calculate when to redraw canvas
Previously, when to redraw was statically set to 0.5x the displayed interval. Most likely this is a bug as it should redraw when only half of the configured buffer size remains outside the viewport.
1 parent 35b7334 commit b9c2819

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ and this project adheres (more or less) to [Semantic Versioning](http://semver.o
77

88
## Unreleased
99

10+
* Fix issue where the redraw mechanism was not based on the `buffer` prop.
11+
1012
## 0.30.0 (beta)
1113
Huge update made by @Remco4EF and @remcoblumink
12-
* full rewrite to typescript
14+
* full rewrite to typescript
1315
* uses Vite as bundler
1416
* Updates dependencies to latest versions
1517
* Updates react usage to 18+

src/lib/utility/calendar.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ export function getItemWithInteractions<
670670
export function getCanvasBoundariesFromVisibleTime(visibleTimeStart: number, visibleTimeEnd: number, buffer: number) {
671671
const zoom = visibleTimeEnd - visibleTimeStart
672672
// buffer - 1 (1 is visible area) divided by 2 (2 is the buffer split on the right and left of the timeline)
673-
const canvasTimeStart = visibleTimeStart - (zoom * (buffer - 1)) / 2
673+
const canvasTimeStart = visibleTimeStart - zoom * (buffer - 1) / 2
674674
const canvasTimeEnd = canvasTimeStart + zoom * buffer
675675
return [canvasTimeStart, canvasTimeEnd]
676676
}
@@ -710,15 +710,16 @@ export function calculateScrollCanvas<
710710
visibleTimeEnd,
711711
}
712712

713+
// Calculate half of the buffer size on each side = 1/4 of the (buffer - viewport)
714+
const halfBuffer = oldZoom * (buffer! - 1) * 0.25
715+
713716
// Check if the current canvas covers the new times
714-
const canKeepCanvas =
715-
newZoom === oldZoom &&
716-
visibleTimeStart >= oldCanvasTimeStart + oldZoom * 0.5 &&
717-
visibleTimeStart <= oldCanvasTimeEnd - oldZoom * 1.5 &&
718-
visibleTimeEnd >= oldCanvasTimeStart + oldZoom * 1.5 &&
719-
visibleTimeEnd <= oldCanvasTimeEnd - oldZoom * 0.5
720-
721-
if (!canKeepCanvas || forceUpdateDimensions) {
717+
const shouldCreateNewCanvas =
718+
newZoom !== oldZoom ||
719+
visibleTimeStart <= oldCanvasTimeStart + halfBuffer ||
720+
visibleTimeEnd >= oldCanvasTimeEnd - halfBuffer
721+
722+
if (shouldCreateNewCanvas || forceUpdateDimensions) {
722723
const [canvasTimeStart, canvasTimeEnd] = getCanvasBoundariesFromVisibleTime(
723724
visibleTimeStart,
724725
visibleTimeEnd,

0 commit comments

Comments
 (0)