Skip to content

Commit 7d93cd1

Browse files
authored
Merge pull request #936 from LudvigHz/buffer-redraw
2 parents 853d2dc + e3b4dec commit 7d93cd1

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
@@ -673,7 +673,7 @@ export function getItemWithInteractions<
673673
export function getCanvasBoundariesFromVisibleTime(visibleTimeStart: number, visibleTimeEnd: number, buffer: number) {
674674
const zoom = visibleTimeEnd - visibleTimeStart
675675
// buffer - 1 (1 is visible area) divided by 2 (2 is the buffer split on the right and left of the timeline)
676-
const canvasTimeStart = visibleTimeStart - (zoom * (buffer - 1)) / 2
676+
const canvasTimeStart = visibleTimeStart - zoom * (buffer - 1) / 2
677677
const canvasTimeEnd = canvasTimeStart + zoom * buffer
678678
return [canvasTimeStart, canvasTimeEnd]
679679
}
@@ -713,15 +713,16 @@ export function calculateScrollCanvas<
713713
visibleTimeEnd,
714714
}
715715

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

0 commit comments

Comments
 (0)