Search code examples
javascriptjquerytimelinesimile

Add overlays in Simile Timeline


I've got a problem I would like to add two overlays on both side of a timeline. The idea is to make it look like this mock-up : https://lh4.googleusercontent.com/-EUgq5L-gFgc/TsEgpPpyJ1I/AAAAAAAACEA/vbByi9CTIhk/s592/Capture%252520du%2525202011-11-14%25252014%25253A55%25253A14-m.png

But the more important is that it will have several tracks in the timeline (one per person represented in the app) and I need to add data on both side of each track. I can have the data in any convenient form I want, but I just can't find how to implement it. If someone can help it will help me a lot. Thanks !


Solution

  • I respond to my own question and here is the code if someone else have the same issue :

    var timeline;
    function onLoad() {
    if (typeof(timelineJsonObject)=='undefined' || timelineJsonObject===null) 
    {
        return;
    }
    
    var overviewEvents = new Timeline.DefaultEventSource();
    var events = new Array(timelineJsonObject.length);
    
    var theme = Timeline.ClassicTheme.create();
        theme.event.tape.height = 24;
    
    var overviewTheme = Timeline.ClassicTheme.create();
        overviewTheme.event.tape.height = 8;
    
    var bandInfos = new Array(timelineJsonObject.length+1);
    bandInfos[0] = Timeline.createBandInfo
        ({
            theme:          overviewTheme,
            layout:         'overview',
            eventSource:    overviewEvents,
            width:          "96px",
            intervalUnit:   Timeline.DateTime.MONTH, 
            intervalPixels: 32
        });
    
    $($("td",  $($("#timelineTable tbody tr")[0]))[1]).attr("rowspan", timelineJsonObject.length+1);
    
    $("#timeline").height((timelineJsonObject.length+1) * 96);
    
    var cssClassMod = new Array(2);
    cssClassMod[0] = "even";
    cssClassMod[1] = "odd";
    
    tableBody = $("#timelineTable tbody");
    
    for (i = 0; i < timelineJsonObject.length; i++)
    {
        events[i] = new Timeline.DefaultEventSource();
    
        bandInfos[i+1] = Timeline.createBandInfo
            ({
                theme:          theme,
                layout:         'original',
                eventSource:    events[i],
                width:          "96px",
                intervalUnit:   Timeline.DateTime.MONTH, 
                intervalPixels: 128
            });
        bandInfos[i+1].syncWith = i;
        bandInfos[i+1].highlight = true;
    
        events[i].loadJSON(timelineJsonObject[i][2], document.location.href);
        overviewEvents.loadJSON(timelineJsonObject[i][2], document.location.href);
    
        tableBody.append('<tr><td>' + timelineJsonObject[i][0] + '</td><td>' + timelineJsonObject[i][1] + '</td></tr>');
        $("tr", tablebody).last().addClass(cssClassMod[i%2]);
    }
    
    timeline = Timeline.create(document.getElementById("timeline"), bandInfos);
    
    timeline.finishedEventLoading();
    }