2012-12-14 18:31:39 +00:00
|
|
|
(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);
|
|
|
|
})();
|
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
// init custom node type
|
|
|
|
$jit.ForceDirected.Plot.NodeTypes.implement(nodeSettings);
|
|
|
|
//implement an edge type
|
|
|
|
$jit.ForceDirected.Plot.EdgeTypes.implement(edgeSettings);
|
2013-02-19 14:44:43 +00:00
|
|
|
$jit.ForceDirected.Plot.EdgeTypes.implement(edgeSettingsEmbed);
|
2012-12-23 06:12:56 +00:00
|
|
|
// end
|
2012-12-15 07:39:14 +00:00
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
// init custom node type
|
|
|
|
$jit.RGraph.Plot.NodeTypes.implement(nodeSettings);
|
|
|
|
//implement an edge type
|
|
|
|
$jit.RGraph.Plot.EdgeTypes.implement(edgeSettings);
|
|
|
|
// end
|
|
|
|
|
2013-02-19 14:44:43 +00:00
|
|
|
function initialize(type, loadLater, embed){
|
2012-12-23 06:12:56 +00:00
|
|
|
|
|
|
|
if (loadLater == null) {
|
|
|
|
loadlater = false;
|
|
|
|
}
|
2013-02-19 14:44:43 +00:00
|
|
|
if (embed == null) {
|
|
|
|
embed = false;
|
|
|
|
}
|
2012-12-15 07:39:14 +00:00
|
|
|
|
|
|
|
viewMode = "graph";
|
2012-12-14 18:31:39 +00:00
|
|
|
gType = type;
|
|
|
|
|
|
|
|
if ( type == "centered") {
|
2012-12-15 07:39:14 +00:00
|
|
|
// init Rgraph
|
|
|
|
Mconsole = new $jit.RGraph(graphSettings(type));
|
2012-12-14 18:31:39 +00:00
|
|
|
}
|
|
|
|
else if ( type == "arranged" || type == "chaotic" ) {
|
|
|
|
// init ForceDirected
|
2013-02-19 14:44:43 +00:00
|
|
|
Mconsole = new $jit.ForceDirected(graphSettings(type, embed));
|
2012-12-14 18:31:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert("You didn't specify a type!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// load JSON data.
|
2012-12-23 06:12:56 +00:00
|
|
|
if (!loadLater) {
|
2013-01-24 03:05:24 +00:00
|
|
|
Mconsole.busy = true;
|
2012-12-23 06:12:56 +00:00
|
|
|
Mconsole.loadJSON(json);
|
2012-12-14 18:31:39 +00:00
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
// choose how to plot and animate the data onto the screen
|
|
|
|
var chooseAnimate;
|
2012-12-14 18:31:39 +00:00
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
if ( type == "centered") {
|
|
|
|
// compute positions incrementally and animate.
|
|
|
|
//trigger small animation
|
|
|
|
Mconsole.graph.eachNode(function(n) {
|
|
|
|
var pos = n.getPos();
|
|
|
|
pos.setc(-200, -200);
|
|
|
|
});
|
|
|
|
Mconsole.compute('end');
|
|
|
|
|
|
|
|
chooseAnimate = {
|
|
|
|
modes:['polar'],
|
2013-01-24 03:05:24 +00:00
|
|
|
duration: 2000,
|
|
|
|
onComplete: function() {
|
|
|
|
Mconsole.busy = false;
|
|
|
|
}
|
2012-12-23 06:12:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else if ( type == "arranged" ) {
|
|
|
|
// compute positions incrementally and animate.
|
|
|
|
Mconsole.graph.eachNode(function(n) {
|
|
|
|
var pos = n.getPos();
|
|
|
|
pos.setc(0, 0);
|
|
|
|
var newPos = new $jit.Complex();
|
|
|
|
newPos.x = n.data.$xloc;
|
|
|
|
newPos.y = n.data.$yloc;
|
|
|
|
n.setPos(newPos, 'end');
|
|
|
|
});
|
|
|
|
|
|
|
|
chooseAnimate = {
|
|
|
|
modes: ['linear'],
|
|
|
|
transition: $jit.Trans.Quad.easeInOut,
|
2013-01-24 03:05:24 +00:00
|
|
|
duration: 2500,
|
|
|
|
onComplete: function() {
|
|
|
|
Mconsole.busy = false;
|
|
|
|
}
|
2012-12-23 06:12:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else if ( type == "chaotic" ) {
|
|
|
|
// compute positions incrementally and animate.
|
|
|
|
Mconsole.compute();
|
|
|
|
|
|
|
|
chooseAnimate = {
|
|
|
|
modes: ['linear'],
|
|
|
|
transition: $jit.Trans.Elastic.easeOut,
|
2013-01-24 03:05:24 +00:00
|
|
|
duration: 2500,
|
|
|
|
onComplete: function() {
|
|
|
|
Mconsole.busy = false;
|
|
|
|
}
|
2012-12-23 06:12:56 +00:00
|
|
|
};
|
|
|
|
}
|
2012-12-14 18:31:39 +00:00
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
if ( type == "centered") {
|
|
|
|
Mconsole.fx.animate(chooseAnimate);
|
|
|
|
}
|
|
|
|
else if ( type == "arranged" || type == "chaotic") {
|
|
|
|
Mconsole.animate(chooseAnimate);
|
|
|
|
}
|
2013-03-17 06:29:17 +00:00
|
|
|
|
|
|
|
// prevent touch events on the canvas from default behaviour
|
|
|
|
$("#infovis-canvas").bind('touchstart', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
Mconsole.events.touched = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// prevent touch events on the canvas from default behaviour
|
|
|
|
$("#infovis-canvas").bind('touchmove', function(event) {
|
|
|
|
//touchPanZoomHandler(event);
|
|
|
|
});
|
|
|
|
|
|
|
|
// prevent touch events on the canvas from default behaviour
|
|
|
|
$("#infovis-canvas").bind('touchend touchcancel', function(event) {
|
|
|
|
lastDist = 0;
|
|
|
|
if (!Mconsole.events.touchMoved && !touchDragNode) hideCurrentCard();
|
|
|
|
Mconsole.events.touched = Mconsole.events.touchMoved = false;
|
|
|
|
touchDragNode = false;
|
|
|
|
});
|
2012-12-23 06:12:56 +00:00
|
|
|
});
|
|
|
|
// end
|
|
|
|
}// if not loadLater
|
2012-12-14 18:31:39 +00:00
|
|
|
}
|