Skip to content

Commit

Permalink
fix minimum start difference for same row computation (jquense#886) (j…
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice Gelineau committed Jul 20, 2018
1 parent d1dfa3e commit 6510361
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ class DayColumn extends React.Component {
rtl: isRtl,
selected,
startAccessor,
step,
titleAccessor,
timeslots,
tooltipAccessor,
} = this.props

Expand All @@ -174,6 +176,7 @@ class DayColumn extends React.Component {
startAccessor,
endAccessor,
slotMetrics: this.slotMetrics,
minimumStartDifference: Math.ceil((step * timeslots) / 2),
})

return styledEvents.map(({ event, style }, idx) => {
Expand Down
14 changes: 8 additions & 6 deletions src/utils/DayEventLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class Event {
/**
* Return true if event a and b is considered to be on the same row.
*/
function onSameRow(a, b) {
function onSameRow(a, b, minimumStartDifference) {
return (
// Occupies the same start slot.
Math.abs(b.start - a.start) <= 30 ||
Math.abs(b.start - a.start) < minimumStartDifference ||
// A's start slot overlaps with b's end slot.
(a.start > b.start && a.start < b.end)
(b.start > a.start && b.start < a.end)
)
}

Expand Down Expand Up @@ -129,7 +129,7 @@ function sortByRender(events) {
return sorted
}

function getStyledEvents({ events, ...props }) {
function getStyledEvents({ events, minimumStartDifference, ...props }) {
// Create proxy events and order them so that we don't have
// to fiddle with z-indexes.
const proxies = events.map(event => new Event(event, props))
Expand All @@ -144,7 +144,9 @@ function getStyledEvents({ events, ...props }) {

// Check if this event can go into a container event.
const container = containerEvents.find(
c => c.end > event.start || Math.abs(event.start - c.start) < 30
c =>
c.end > event.start ||
Math.abs(event.start - c.start) < minimumStartDifference
)

// Couldn't find a container — that means this event is a container.
Expand All @@ -161,7 +163,7 @@ function getStyledEvents({ events, ...props }) {
// Start looking from behind.
let row = null
for (let j = container.rows.length - 1; !row && j >= 0; j--) {
if (onSameRow(container.rows[j], event)) {
if (onSameRow(container.rows[j], event, minimumStartDifference)) {
row = container.rows[j]
}
}
Expand Down

0 comments on commit 6510361

Please sign in to comment.