I'm using the fullCalendar jquery plugin.
I'm trying to make my events in the agendaDay view show up from left to right ordered by start time.
Essentially, I want to remove the stacking of events, so an event from 9-11 would show up next to an event from 12-4 instead of above it.
It looks like there are a few functions that are associated with the sorting of events.
function segCmp(a, b) {
var tryCmp = (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
if (tryCmp == 0)
return (a.event.rowId - b.event.rowId);
return tryCmp;
}
function segsCollide(seg1, seg2) {
return seg1.end > seg2.start && seg1.start < seg2.end;
}
// event rendering utilities
function sliceSegs(events, visEventEnds, start, end) {
var segs = [],
i, len=events.length, event,
eventStart, eventEnd,
segStart, segEnd,
isStart, isEnd;
for (i=0; i<len; i++) {
event = events[i];
eventStart = event.start;
eventEnd = visEventEnds[i];
if (eventEnd > start && eventStart < end) {
if (eventStart < start) {
segStart = cloneDate(start);
isStart = false;
}else{
segStart = eventStart;
isStart = true;
}
if (eventEnd > end) {
segEnd = cloneDate(end);
isEnd = false;
}else{
segEnd = eventEnd;
isEnd = true;
}
segs.push({
event: event,
start: segStart,
end: segEnd,
isStart: isStart,
isEnd: isEnd,
msLength: segEnd - segStart
});
}
}
return segs.sort(segCmp);
}
// event rendering calculation utilities
function stackSegs(segs) {
var levels = [],
i, len = segs.length, seg,
j, collide, k;
for (i=0; i<len; i++) {
seg = segs[i];
j = 0; // the level index where seg should belong
while (true) {
collide = false;
if (levels[j]) {
for (k=0; k<levels[j].length; k++) {
if (segsCollide(levels[j][k], seg)) {
collide = true;
break;
}
}
}
if (collide) {
j++;
}else{
break;
}
}
if (levels[j]) {
levels[j].push(seg);
}else{
levels[j] = [seg];
}
}
return levels;
}
Any thoughts?
The orientation of time slots in the calendar is from top to bottom not left to right. I don't believe it is possible to change that orientation.
There is an option you can pass to fullCalendar()
that will disable the overlapping of events in agendaDay and agendaWeek view it's slotEventOverlap: false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With