$( document ).
ready(function() {
$('#code').keyup(function()
{
parse();
});
});
function init()
{
data = new [Link]();
[Link]('datetime', 'start');
[Link]('datetime', 'end');
[Link]('string', 'content');
[Link]('string', 'className');
[Link]('string', 'group');
// specify options
var options = {
width: "100%",
height: "100%",
top: "0px",
editable: true,
layout: "box",
style: "box",
animateZoom: false,
'zoomMax': 2000 * 60 * 60 * 24 * 365 * 10000, // milliseconds
animate: false,
max: new Date(650),
min: new Date(0),
snapEvents: false,
showCustomTime: true,
customStackOrder: orderEvents
};
// Instantiate our timeline object.
vis = new [Link]([Link]('mytimeline'));
[Link](vis, 'select', onSelect);
// Draw our timeline with the created data and options
[Link]([new Date(0), new Date([Link]), "", "", ""]);
[Link](data, options);
[Link](new Date( 570))
createColorClasses(100);
parse();
$('#modality').click(function()
{
toggleModality();
});
$('#player .next').click(function()
{
nextCollision();
});
$('#player .prev').click(function()
{
prevCollision();
});
}
function orderEvents(item1, item2)
{
function get_random_color()
{
var letters = 'ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ )
color += letters[[Link]([Link]() * 5)];
return color;
}
function createColorClasses(num)
{
var style = [Link]('style');
[Link] = 'text/css';
for(i=0; i< num; i++)
{
[Link] += ".color"+i+" { background-color: "+get_random_color()
+" !important; }";
}
[Link]('head')[0].appendChild(style);
}
function parse()
{
var codeArr = $("#code").val().split("\n");
var detectSubActions = false;
for( var i=0; i < [Link]; i++)
{
var currLine = codeArr[i];
currLine = [Link](/\t/g, " ").replace(/\s+/g," ");
if ([Link]("#define") > -1)
{
var lineArr = [Link](" ");
if([Link] > 2)
{
action = lineArr[1];
time = lineArr[2];
mainAction = [Link]([Link]("_")+1);
if(action != undefined && time != undefined)
{
if([Link]().indexOf("START") > -1)
{
myActions[mainAction] = {name:
mainAction,start: parseInt(time), duration: "", subActions: new Object()};
}
else if([Link]().indexOf("DURATION") > -
1)
{
myActions[mainAction].duration =
parseInt(time);
}
}
}
}
else
{
if([Link]("{") > -1)
{
detectSubActions = true;
numSubAction = 0;
}
else if([Link]("}") > -1)
{
detectSubActions = false;
}
else //inside actions
{
if(detectSubActions && [Link]("//|") > -1)
{
currLine = [Link]("//| ", "").replace("//|", "");
timing = [Link](0, [Link](" "));
nameSubAction = [Link]([Link](" ")+1)
if([Link](",") > -1)
{
timingArr = [Link](",");
startSubAction = timingArr[0];
durationSubAction = timingArr[1];
var subaction = {name: nameSubAction, device:
[Link](0, [Link](" ")), start:
parseInt(startSubAction)/*parseInt(startSubAction)+myActions[mainAction].start*/,
duration: parseInt(durationSubAction)};
myActions[mainAction].subActions[numSubAction] = subaction;
if(!isBlackList(mainAction))
{
checkDeviceCollisions([Link](), {name: mainAction,
start: myActions[mainAction].start + [Link], duration:
[Link]});
}
numSubAction++;
}
}
}
}
}
drawVisualization();
drawCollisionPlayer();
}
function checkDeviceCollisions(device, action)
{
if(myDevices[device] == undefined)
{
myDevices[device] = {collisions: new Array()};
}
for(var i = 0; i < myDevices[device].[Link]; ++i)
{
var collision = myDevices[device].collisions[i];
var inBounds1 = [Link] >= [Link] && [Link] <
[Link] + [Link];
var inBounds2 = [Link] >= [Link] && [Link] <
[Link] + [Link];
if( isCompatible([Link], [Link]) && (inBounds1 ||
inBounds2))
{
myActions[[Link]].collision = true;
myActions[[Link]].collision = true;
var text = (device + " collision between " + [Link] + "[" +
[Link] + ":" + [Link] + "] and " + [Link] + "[" +
[Link] + ":" + [Link] + "]");
[Link]({tick: new Date(inBounds1 ? [Link] :
[Link]), action1: [Link], action2: [Link], text: text});
}
}
myDevices[device].[Link](action);
}
function isCompatible(action1, action2)
{
if(action1 == action2)
{
return false;
}
else
{
for (var i in myIncompatibles)
{
if(myIncompatibles[i].indexOf(action1) > -1 &&
myIncompatibles[i].indexOf(action2) > -1)
{
return false;
}
}
}
return true;
}
function isBlackList(actionName)
{
return [Link](actionName) > -1;
}
// Called when the Visualization API is loaded.
function drawVisualization()
{
[Link](0, [Link]());
var t = new Date();
var numAction = 0;
if($("#modality").html() == "Expanded")
{
if([Link]() == 5)
[Link](4);
for(var index in myActions)
{
action = myActions[index];
[Link]([new Date( parseInt([Link])), new
Date( parseInt([Link]) + parseInt([Link])), [Link],
[Link] != undefined ? "collision" : "color"+numAction]);
numAction++;
}
}
else
{
if([Link]() == 4)
[Link]("string", "group");
for(var index in myActions)
{
action = myActions[index];
for(var index2 in [Link])
{
action2 = [Link][index2];
[Link]([new Date( parseInt([Link])), new
Date( parseInt([Link]) + parseInt([Link])), [Link], "",
""+[Link]]);
}
numAction++;
}
}
[Link]();
}
function drawCollisionPlayer()
{
if([Link] > 0)
{
$("#player").show();
$("[Link]-customtime").addClass("collisionTimeline");
nextCollision();
}
}
function nextCollision()
{
if(currentCollision < [Link] - 1)
{
currentCollision++;
updateCollision();
}
}
function prevCollision()
{
if(currentCollision > 0)
{
currentCollision--;
updateCollision();
}
}
function updateCollision()
{
[Link](myCollisions[currentCollision].tick);
$("#player .error").html(myCollisions[currentCollision].text);
$(".collision").removeClass("current");
$(".collision").each(function()
{
if($(this).children().text() == myCollisions[currentCollision].action1
|| $(this).children().text() == myCollisions[currentCollision].action2)
{
$(this).addClass("current");
}
});
if(currentCollision + 1 >= [Link])
{
$("#player .next").hide();
}
else
{
$("#player .next").show();
}
if(currentCollision <= 0)
{
$("#player .prev").hide();
}
else
{
$("#player .prev").show();
}
$("#player .status").html((currentCollision + 1) + " / " +
[Link]);
}
function onSelect()
{
var sel = [Link]();
if ([Link])
{
if (sel[0].row != undefined)
{
showSubActions(sel[0].row);
//$("#code").val().indexOf([Link](sel[0].row, 2))
// $("#code").setCursorPosition($
("#code").val().indexOf([Link](sel[0].row, 2)));
//[Link]("Go to pos "+ $
("#code").val().indexOf([Link](sel[0].row, 2)))
}
}
}
function closeTimeline2()
{
delete data2;
delete vis2;
$("#mytimeline2").hide();
$("#closeTimeline").hide();
[Link]([]);
}
function showSubActions(numRow)
{
var element = $("."+[Link](numRow, 3));
if(data2 != undefined)
{
delete data2;
delete vis2;
}
data2 = new [Link]();
[Link]('datetime', 'start');
[Link]('datetime', 'end');
[Link]('string', 'content');
[Link]('string', 'className');
$("#mytimeline2").show();
$("#closeTimeline").show();
$("#closeTimeline").click(function(){
closeTimeline2();
});
// Instantiate our timeline object.
vis2 = new [Link]([Link]('mytimeline2'));
index = [Link](numRow, 2);
var action = myActions[index];
var maxEnd = 0;
for(var index2 in [Link])
{
action2 = [Link][index2];
end = parseInt([Link]) + parseInt([Link]);
[Link]([Link]);
[Link]([new Date([Link]), new Date(end), [Link], ""]);
if(end > maxEnd)
{
maxEnd = end;
}
}
// specify options
var options = {
width: $("#code").width()/*[Link]()*/,
height: $("#code").height(),
top: "0px",
editable: true,
layout: "box",
style: "box",
min: new Date(0),
max: new Date(maxEnd+50)
};
[Link](data2, options);
var offset = $("#code").offset();
// [Link] += 12;
// var offset = [Link]();
// [Link] += 30;
// [Link] = $("#code").top();
// [Link] = 0;
var offset2 = $("#code").offset();
[Link] += 5;
[Link] += 5;
// var offset2 = $("#code").offset();
// [Link] += 4;
// [Link] += [Link]() - $("#closeTimeline").width();
$("#closeTimeline").offset(offset2);
$("#mytimeline2").offset(offset);
$("#mytimeline2").width($("#code").width());
$("#mytimeline2").height($("#code").height());
}
$.[Link] = function(pos) {
[Link](function(index, elem) {
if ([Link]) {
[Link](pos, pos);
} else if ([Link]) {
var range = [Link]();
[Link](true);
[Link]('character', pos);
[Link]('character', pos);
[Link]();
}
});
return this;
};
function toggleModality()
{
if($("#modality").html() == "Expanded")
{
$("#modality").html("Grouped");
closeTimeline2();
}
else
{
$("#modality").html("Expanded");
}
drawVisualization();
}