question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overlap's algorithm fails with custom timeslots and steps

See original GitHub issue

Do you want to request a feature or report a bug?

Report a bug

What’s the current behavior?

Hi,

When trying to show dates by slots of 15 minutes, I noticed some strange behavior: two slots next to each others overlap instead of taking each one a container.

image

The first slot is from 05:00 to 05:15 and the second one from 05:15 to 05:30.

They should look like this : image

This bug can be seen in the following sandbox: https://codesandbox.io/s/react-big-calendar-issue-q8bdq?fontsize=14&hidenavigation=1&theme=dark

What’s the expected behavior?

It should work the same way as a 30-minute step does : https://codesandbox.io/s/react-big-calendar-issue-yet7e?fontsize=14&hidenavigation=1&theme=dark

Food for though

I did a little digging in the source and found out that this is the formula that put the two events on the same line: https://github.com/intljusticemission/react-big-calendar/blob/77004e2a51dfa466341e14d2dab35466822d0efb/src/utils/layout-algorithms/overlap.js#L155

In my case, it evals to

 Math.abs(195 - 180) < 30

If I’m not wrong, it should be 15 instead of 30, as my timeslots are 15 minutes long. Therefore I would set minimumStartDifference = step here and call it a day.

https://github.com/intljusticemission/react-big-calendar/blob/77004e2a51dfa466341e14d2dab35466822d0efb/src/DayColumn.js#L197

Workaround

Create a new WorkWeek vue (as seen in the example) and force the dayLayoutAlgorithm to 'no-overlap'

<TimeGrid
      {...rest}
      date={date}
      range={range}
      dayLayoutAlgorithm="no-overlap"
    />

Thanks !

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
FidelisClaytoncommented, Jun 11, 2020

I managed to do it by using the dayLayoutAlgorithm:

import overlap from 'react-big-calendar/lib/utils/layout-algorithms/overlap'

// rest of code
     <BigCalendar
        dayLayoutAlgorithm={(params) => {
          return overlap({ ...params, minimumStartDifference: 15 })
        }}
        // rest of props
     />
3reactions
coder-guy22296commented, Jan 14, 2020

We have the same issue where two 15min slots right next to each other with step=5 and timeslots=12 , the bottom one is offset. we traced it down to the same variable: minimumStartDifference. https://codesandbox.io/s/react-big-calendar-issue-m6bew

https://github.com/intljusticemission/react-big-calendar/issues/1192 https://github.com/intljusticemission/react-big-calendar/issues/1440 https://github.com/intljusticemission/react-big-calendar/issues/886

There are multiple GitHub issues that want to tweak this behavior of how close two events start before indenting the second one. We should offer some way to allow users to tweak this behavior. currently, we are patching react big calendar with the following:

-      minimumStartDifference: Math.ceil((step * timeslots) / 2),
+      minimumStartDifference: Math.ceil((step * timeslots) / 4),

would be nicer if we could expose minimumStartDifference as a prop to react big calendar. What do you think @jquense ?

I’m willing to submit a pull request

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overlap's algorithm fails with custom timeslots and steps
What's the current behavior? Hi,. When trying to show dates by slots of 15 minutes, I noticed some strange behavior: two slots next...
Read more >
Checking for overlap between time spans - python
First we sort the list by the start time. Then we loop over it checking if the next start time is lower then...
Read more >
DOORDASH: Available Time Problem - LeetCode Discuss
So an intrepid engineer has decided to roll their own implementation. Unfortunately one major missing feature is the ability to find out what...
Read more >
MINIMIZING OVERHEAD IN PARALLEL ALGORITHMS ... - DTIC
munication processor and overlapping communication/computation do exist. ... L2 cache with a custom cache controller/bus interface at the next level of ...
Read more >
Populating time slots between reservations in a list
where it is possible without overlapping with any booking. I tried looping the lists but ended up with CPU time limit error (System....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found