1
0
Fork 0
forked from 0x2620/oxjs

speed up rendering of the calendar (only compute event positions once)

This commit is contained in:
rolux 2011-05-27 21:42:01 +02:00
commit b99679ffe1
2 changed files with 96 additions and 11 deletions

View file

@ -98,6 +98,7 @@ Ox.Calendar = function(options, self) {
event.rangeText = event.rangeText.split(' - ').shift() + ' - ...';
}
});
self.lineEvents = getLineEvents();
self.maxZoom = 32;
self.minLabelWidth = 80;
@ -318,6 +319,7 @@ Ox.Calendar = function(options, self) {
self.options.showTypes = data.selected.map(function(type) {
return type.id;
});
self.lineEvents = getLineEvents();
renderCalendar();
}
})
@ -823,18 +825,15 @@ Ox.Calendar = function(options, self) {
});
}
function renderEvents() {
var calendarEvent = getCalendarEvent(),
height,
lineEvents = [];
//types = ['date', 'place', 'person', 'other'];
function getLineEvents() {
var lineEvents = [];
self.options.events.filter(function(event) {
// filter out events with types not shown
// and events outside the visible area <-- commented out to keep layout from changing
return self.options.showTypes.indexOf(event.type) > -1
/*&& overlaps(event, calendarEvent)*/;
}).sort(function(a, b) {
// sort events
// sort events (dates first, people last, longer before shorter)
if (a.type == 'date' && b.type != 'date') {
return -1;
} else if (a.type != 'date' && b.type == 'date') {
@ -843,7 +842,6 @@ Ox.Calendar = function(options, self) {
return 1;
} else if (a.type != 'person' && b.type == 'person') {
return -1;
///*
} else if ((b.endTime - b.startTime) != (a.endTime - a.startTime)) {
return (b.endTime - b.startTime) - (a.endTime - a.startTime);
} else /*if (a.startTime < b.startTime || a.startTime > b.startTime)*/ {
@ -872,11 +870,18 @@ Ox.Calendar = function(options, self) {
}
lineEvents[line].push(event);
});
return lineEvents;
}
function renderEvents() {
var calendarEvent = getCalendarEvent(),
height;
//types = ['date', 'place', 'person', 'other'];
self.$content.find('.OxLine').remove();
height = Math.max(lineEvents.length * 16, self.$container.height());
height = Math.max(self.lineEvents.length * 16, self.$container.height());
self.$background.$element.children().css({height: height + 'px'});
self.$content.css({height: height + 'px'});
lineEvents.forEach(function(events, line) {
self.lineEvents.forEach(function(events, line) {
var $line = new Ox.Element()
.addClass('OxLine')
.css({