var labelType, animate, useGradients, nativeTextSupport, RGraph;
(function() {
var ua = navigator.userAgent,
iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i),
typeOfCanvas = typeof HTMLCanvasElement,
nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
textSupport = nativeCanvasSupport
&& (typeof document.createElement('canvas').getContext('2d').fillText == 'function');
//I'm setting this based on the fact that ExCanvas provides text support for IE
//and that as of today iPhone/iPad current text support is lame
labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML';
nativeTextSupport = labelType == 'Native';
useGradients = nativeCanvasSupport;
animate = !(iStuff || !nativeCanvasSupport);
})();
var ontology_json;
function initAnnotationTree() {
//Log.write('Loading ontology file');
$('#annotation-tree').modal();
$('#annotation-tree').on('shown', function() {
loadOntologyJSON();
});
}
function initNodeListEvents() {
// register event handler for list of nodes that comes in the stats box.
// click on the nodes in the stats box will center them in the graph and
// update the stats box.
$('.list-nodes').unbind('click');
$('.list-nodes').click(function(event) {
var id = $(event.currentTarget).attr('id').split('-')[1];
var node = RGraph.graph.getNode(id);
centerNode(event, node);
});
}
function loadOntologyJSON() {
// if the file is already loaded, no need to load again
if(typeof ontology_json === 'object') {
drawRGraph();
return;
}
//console.log('Loading ontology file');
var url = 'static/graphs/GirijaKalyanaStory.json'
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(data) {
//console.log('Ontology JSON loaded');
ontology_json = data;
drawRGraph();
},
error: function(xhr, errtype, errtext) {
console.log('Could not load Ontology JSON!');
alert('Could not load Ontology JSON!');
console.log(errtype, ':', errtext);
}
});
}
var Log = {
elem: document.getElementById('status'),
write: function(msg) {
this.elem.innerHTML = msg;
}
};
var Stats = {
init: function() {
this.node_info = document.getElementById('node-info');
this.selected_info = document.getElementById('selected-nodes');
},
write: function(msg) {
this.node_info.innerHTML = msg;
},
appendSelectedList: function() {
var html = '
Selected:
';
if(!sweet.nodes.length) {
html += 'None';
}
else {
html += '
';
}
this.selected_info.innerHTML = html;
}
};
var removeItem = function(event) {
//console.log($(event.currentTarget));
var id = $(event.currentTarget).parent().parent().attr('id');
var node = id.split('-')[1];
$(event.currentTarget).parent().parent().remove();
sweet.remove(node);
}
// return "add node" template button creating an id for it
var addNodeTemplate = function(node) {
return '';
};
// add node to the selected list to be sweeted.
function addNode(event) {
var id = $(event.currentTarget).attr('id');
var node = id.split('-')[1];
sweet.add(node);
//Log.write('Added node ' + node);
}
//center the given node in the graph and update the stats box
function centerNode(event, node) {
if(event.stopPropagation) {
event.stopPropagation();
}
//Log.write('centering node ', node.name);
//console.log('centering node', node.name);
RGraph.onClick(node.id, {
hideLabels: false,
onComplete: function() {
//Log.write("done");
}
});
var html = '