{I"
class:EFI"ProcessedAsset; FI"logical_path; FI"
graph.js; FI"
pathname; FI"*$root/app/assets/javascripts/graph.js; FI"content_type; FI"application/javascript; FI"
mtime; Fl+zł±SI"length; Fiy-I"digest; F"%fd3b08f73b7aaf5703df1831c0ffe95cI"source; FI"y-
var graphXOffset = 50;
var graphYOffset = 30;
var graphXDistance = 150;
var graphYDistance = 60;
var nodeWidth = 80;
var nodeHeight = 20;
//var graphEngine = "wireit";
var graphEngine = "jsPlumb";
/**
* Provide a JSON document of the following form:
*
* {
* "nodes" : [
* { "ID" : "n1", "name" : "Node 1" },
* { "ID" : "n2", "name" : "Node 2" },
* { "ID" : "n3", "name" : "Node 3" }
* ],
*
* "edges" : [
* { "from" : "n1", "to" : "n2", "label" : "Edge 1", "short_label" : "e1", "href" : "http://..." },
* { "from" : "n1", "to" : "n3", "label" : "Edge 2", "short_label" : "e2", "href" : "http://..." }
* ]
* }
*
*/
function loadGraph(graphJSON) {
if(!graphJSON)
return;
var nodes = Array();
var nodeIDs = Array();
var wires = Array();
var errors = Array();
var i = 0;
var nodesJSON = graphJSON["nodes"];
if(typeof(nodesJSON) == "undefined" || !nodesJSON) {
throw "The graph does not contain any nodes. Probably the generation was aborted because the graph would have grown too big for rendering in the Web browser.";
}
for(i = 0; i < nodesJSON.length; i++) {
var node = nodesJSON[i];
var id = node["ID"];
nodeIDs.push(id);
nodes[id] = new Object();
nodes[id]["name"] = node["name"];
nodes[id]["from"] = new Array();
nodes[id]["to"] = new Array();
nodes[id]["content"] = node["content"].replace(/\n/g,"\n
");
nodes[id]["column"] = node["column"];
nodes[id]["row"] = 0;
}
if(nodesJSON.length > 50) {
if(!confirm("Graph contains " + nodesJSON.length + " nodes, do you want to start rendering?")) {
return;
}
}
var edgesJSON = graphJSON["edges"];
for(i = 0; i < edgesJSON.length; i++) {
var edge = edgesJSON[i];
var from = edge["from"];
var to = edge["to"];
var label_short = edge["label_short"];
var label = edge["label"];
var href = edge["href"];
// TODO: better construct object instead of Array..
var wire = new Array(from, to, label_short, label, href);
nodes[from]["to"].push(to);
nodes[to]["from"].push(from);
wires.push(wire);
}
getNodePositions(nodes, nodeIDs);
if(graphEngine == "wireit") {
drawGraphWireit(nodeIDs, nodes, wires);
} else if(graphEngine == "jsPlumb") {
cont = $("#graphContainer");
drawGraphJSPlumb(cont, nodeIDs, nodes, wires);
}
}
function drawGraphJSPlumb(container, nodeIDs, nodes, wires) {
var color = "gray";
jsPlumb.importDefaults({
// notice the 'curviness' argument to this Bezier curve. the curves on this page are far smoother
// than the curves on the first demo, which use the default curviness value.
//Connector : [ "Bezier", { curviness: 20 } ],
DragOptions : { cursor: "pointer", zIndex:2000 },
PaintStyle : { strokeStyle:color, lineWidth:2 },
EndpointStyle : { radius:0, fillStyle:color },
HoverPaintStyle : {strokeStyle:"#ec9f2e" },
EndpointHoverStyle : {fillStyle:"#ec9f2e" }
});
var connector = {
connector: [ "Bezier", { curviness: 20 } ],
endpoint: "Blank",
anchor: "AutoDefault"
};
for(var i = 0; i < nodeIDs.length ; i++) {
var id = nodeIDs[i];
var node = nodes[id];
node["containerId"] = i;
var x = graphXOffset + (graphXDistance * (node["column"] - 1));
var y = graphYOffset + (graphYDistance * (node["row"] - 1));
if(id == "__start__") {
container.append("