Hi,
I’m trying to sort events in the timeline view.
For a specified section, I would like to have some events in the 1rst row, other in the 2nd row, and the last in the 3rd.
I use the sort:function(a,b) {} to sort them, but something go wrong, and I don’t know why
In the part you compare priority values, conditions does not covers all possible scenarios. Why don’t you simply use ‘lesser’ or ‘greater’ for comparing numeric values:
}[/code]Also, please note that sort order defines only mutual position of events, i.e. which one will be displayed top-most, which right below it, etc.
This function can’t make event be displayed in 2nd row, leaving the 1st row empty
Hi,
thanks you for your answer
I used the " (quote sign) to indicate that my ‘priority’ values are strings, I changed them here to simplify, but in fact, they are URL (so they are not ‘sortable’)
As I only have 3 URL possible (let says “http://case1.com”, “http://case2.com” and “http://case3.com” ) , I thought that with 6 elseif cases ( + equality ) , it will be OK ? Did I miss one case ?
I’ll try to change my system to add a integer (instead of strings) to be compared, to test it.
Concerning the “mutual positions” it’s not an issue if the second row go in the 1rst row, if there is no 1rst row. But, maybe my intial issue is related to this ?
Sorry, it’s my mistake, it really gives six combinations.
Probably the more readable and maintainable way for specifying the order of urls (in case you’ll have to add fourth or fifth url at some point) would be to assign some ‘weight’ value to each url, and use these values for sorting. E.g.:
Events in ‘David Miller’ section are expected to be displayed in the same row, even if they would have different sorting order.
Order could be applied only for stacked events, like first three tasks in ‘James Smith’ section.
Is this a scenario you describe?
Sorry, I wasn’t able to reproduce the issue, as all data that I want to be displayed are grabbed dynamically form other sources.
I’ll try to take a snapshot of these data, when the bug will occurs. (data may/will change every hours)
Hi,
it’s hard to tell for sure, but probably the sorting function is causing the problem.
At least if I reinitialize timeline from a console without specifying sort function, events do not overlap:[code]scheduler.createTimelineView({
name: “timeline”,
x_unit: “minute”,
x_date: “%H:%i”,
x_step: 60,
x_size: 24,
x_start: 6,
x_length: 2,
y_unit: init_sections(),
y_property: “section_id”,
render:“bar”,
section_autoheight: false,
dy:40,
dx:60
});
scheduler.setCurrentView(new Date(2014, 4, 18));[/code]
Try to rewrite sort function in a more readable way, and probably the issue will be fixed. Currently due to the amount of if-else with different order of ‘a’ and ‘b’ parameters, it’s hard to tell what function will return in every particular case. Maybe there is a combination of inputs when function behaves incorrectly
I still got the issue, randomly
Here is an exemple (date and data are permanant, for debugging purpose):
Calendar : potato.renaud-goud.fr/day.php
Datas : potato.renaud-goud.fr/includes/events2.php
So, there are 4 events to display, but the Timeline put the 4th one over the 2nd one, makeing the 2nd one invisible whereas they got different idTV
Hi! We have just bought a commercial license and have a similar problem. The goal is to sort by ‘order’ if within same timespan. My main question is why is never event 02 and 05 compared?
See the output from this logging
sort: function (a, b) {
console.log('a: ’ + a.order + ’ - ’ + 'b: ’ + b.order);
Look at the attached image how it looks here.
As long as they are never compared my sorting logic will never be used.
It is always event number 2 and higher in “column 2” which overlap neighbor event in “column 1” in stead of pushing them down and squeeze between
Hope for some help in understanding this. Thanks!
Regards,
Oddvin
For reference I paste the entire sorting function:
sort: function (a, b) {
console.log('a: ’ + a.order + ’ - ’ + 'b: ’ + b.order);
var aa = new Date(a.start_date);
var bb = new Date(b.start_date);
var as = a.start_date.valueOf(); // event a start_date
var ae = a.end_date.valueOf(); // event a end_date
var ao = parseInt(a.order); // event a order
var bs = b.start_date.valueOf(); // event b start_date
var be = b.end_date.valueOf(); // event b end_date
var bo = parseInt(b.order); // event b order
if (aa.setHours(0, 0, 0, 0) == bb.setHours(0, 0, 0, 0)) { // on same day
if (
(as > be && as < be && ao > bo) || // Don't ask :wink:
(bs > as && bs < ae && bo > ao) ||
(as == bs || ae == be) ||
(as < bs && ae > bs && ao < bo) ||
(bs < as && be > as && bo < ao) ||
(as < bs && ae > be) ||
(bs < as && be > ae) ||
(as < bs && ae < be && ae > bs) ||
(bs < as && be < ae && be > as)
) {
return ao > bo ? 1 : -1;
}
}
return as > bs ? 1 : -1;
}
});
My main question is why is never event 02 and 05 compared?
This is up to the sorting algorithm that is used for array.sort in browser, not all of them compare everything-to-everything.
What timeline does, is sorts an array or events providing your function as a compare function developer.mozilla.org/en-US/doc … Array/sort
What happens in there and in which order elements are compared is out of our control.
The problem may occur, if your compare function is not transitive - by transitivity here i mean that
if:
a > b
and:
b > c
then following should be also true:
a > c