Created
January 8, 2025 10:04
-
-
Save renzified/913af621088bdda1ef0cbf1b5c0f49b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun fillRemainingGap( | |
| maxEventCount: Int, | |
| startDate: LocalDate, | |
| endDate: LocalDate, | |
| remainingEvents: MutableList<Event>, | |
| topAnchorMapping: MutableMap<LocalDate, Int>, | |
| rowCountMapping: MutableMap<LocalDate, Int>, | |
| initialAnchors: List<Int> | |
| ) { | |
| var dateCursor = startDate | |
| while (dateCursor.isBefore(endDate.plusDays(1))) { | |
| var shouldDie = false | |
| val date = dateCursor | |
| val frozenEvents = remainingEvents.toList() | |
| for (i in frozenEvents.indices) { | |
| val item = frozenEvents[i] | |
| if (item.start == date) { | |
| // we cant fit this anymore | |
| if (rowCountMapping[item.start] == maxEventCount) { | |
| shouldDie = true | |
| break | |
| } | |
| // draw then break the loop of lowest row count so we | |
| // get the latest lowest row count | |
| drawEvents( | |
| maxEventCount = maxEventCount, | |
| events = listOf(item), | |
| remainingEvents = mutableListOf(), | |
| topAnchorMapping = topAnchorMapping, | |
| rowCountMapping = rowCountMapping, | |
| initialAnchors = initialAnchors | |
| ) | |
| remainingEvents.removeAt(i) | |
| // if it filled up the whole gap then we are done | |
| if (item.end.isEqual(this.endDate)) { | |
| shouldDie = true | |
| break | |
| } | |
| } | |
| } | |
| // we cant fit anymore | |
| if (shouldDie) break | |
| dateCursor = dateCursor.plusDays(1) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment