Question

I'm using the Chap Links Timeline Library http://almende.github.io/chap-links-library/js/timeline/doc/ and find it very useful. However I need to stack the events in a special order.

I tried to use the customStackOrder() function without any success so far. How can I access custom data fields in this function?

My data elements look like:

data.push({
  start: new Date( msg.timestamp ),  
  content: msg.text,
  stackOrder: msg.level
});

and

function customStackOrder(A,B) {
  return A.stackOrder - B.stackOrder
}

But A.stackOrder and B.stackOrder is undefined.

Was it helpful?

Solution

How can I access custom data fields in this function?

The Timeline does just ignores custom fields, and there is no easy way to access them. Usable item properties in the function customStackOrder are the actual position and size (left, right, width, height) and timestamps (start and optionally end).

If you really want to do this, you will have to apply an inefficient hack. This is not officially supported and I don't recommend it:

  • From the items passed to the sorting function you will have to determine their table index: var indexA = mytimeline.items.indexOf(itemA)
  • Read the data of this item from your original data table: var dataA = data[indexA].
  • Read your custom field from this: var stackOrderA = dataA.stackOrder

Edit:

Another trick could be: if you don't use the field className, you could misuse this to hold the value of your stackOrder field. Just ensure the values cannot collide with some actual css.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top