2012-12-14 18:31:39 +00:00
|
|
|
function graphSettings(type) {
|
|
|
|
var t;
|
|
|
|
|
|
|
|
if (type == "arranged" || type == "chaotic") {
|
|
|
|
t = {
|
|
|
|
//id of the visualization container
|
|
|
|
injectInto: 'infovis',
|
|
|
|
//Enable zooming and panning
|
|
|
|
//by scrolling and DnD
|
|
|
|
Navigation: {
|
|
|
|
enable: true,
|
|
|
|
type: 'HTML',
|
|
|
|
//Enable panning events only if we're dragging the empty
|
|
|
|
//canvas (and not a node).
|
|
|
|
panning: 'avoid nodes',
|
2012-12-27 01:57:06 +00:00
|
|
|
zooming: 15 //zoom speed. higher is more sensible
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
// Change node and edge styles such as
|
|
|
|
// color and width.
|
|
|
|
// These properties are also set per node
|
|
|
|
// with dollar prefixed data-properties in the
|
|
|
|
// JSON structure.
|
|
|
|
Node: {
|
|
|
|
overridable: true,
|
|
|
|
color: '#2D6A5D',
|
|
|
|
type: 'customNode',
|
|
|
|
dim: 25
|
|
|
|
},
|
|
|
|
Edge: {
|
|
|
|
overridable: true,
|
|
|
|
color: '#222222',
|
|
|
|
type: 'customEdge',
|
2012-12-27 01:57:06 +00:00
|
|
|
lineWidth: 2
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Native canvas text styling
|
|
|
|
Label: {
|
|
|
|
type: 'HTML', //Native or HTML
|
|
|
|
size: 20,
|
|
|
|
//style: 'bold'
|
|
|
|
},
|
|
|
|
//Add Tips
|
|
|
|
Tips: {
|
2012-12-15 07:39:14 +00:00
|
|
|
enable: false,
|
2012-12-16 20:00:43 +00:00
|
|
|
onShow: function (tip, node) {}
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
// Add node events
|
|
|
|
Events: {
|
|
|
|
enable: true,
|
2012-12-21 00:24:27 +00:00
|
|
|
enableForEdges: true,
|
2012-12-14 18:31:39 +00:00
|
|
|
type: 'HTML',
|
2013-01-05 21:28:04 +00:00
|
|
|
onMouseMove: function(node, eventInfo, e) {
|
|
|
|
onMouseMoveHandler(node, eventInfo, e);
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Update node positions when dragged
|
|
|
|
onDragMove: function (node, eventInfo, e) {
|
2013-01-05 21:21:11 +00:00
|
|
|
clickDragOnTopic(node, eventInfo, e);
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
2012-12-21 00:24:27 +00:00
|
|
|
onDragEnd: function() {
|
|
|
|
if (tempInit && tempNode2 == null) {
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_addSynapse').val("true");
|
|
|
|
$('#new_topic').fadeIn('fast');
|
2012-12-25 23:29:20 +00:00
|
|
|
addMetacode();
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_name').focus();
|
2012-12-21 00:24:27 +00:00
|
|
|
}
|
|
|
|
else if (tempInit && tempNode2 != null) {
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_addSynapse').val("false");
|
|
|
|
$('#synapse_topic1id').val(tempNode.id);
|
2013-01-03 23:21:46 +00:00
|
|
|
$('#synapse_topic2id').val(tempNode2.id);
|
2012-12-21 00:24:27 +00:00
|
|
|
$('#new_synapse').fadeIn('fast');
|
|
|
|
$('#synapse_desc').focus();
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
|
|
|
}
|
2013-01-05 17:50:19 +00:00
|
|
|
else if (dragged != 0 && goRealtime) { saveLayout(dragged); }
|
2012-12-21 00:24:27 +00:00
|
|
|
},
|
|
|
|
onDragCancel: function() {
|
2012-12-21 23:07:13 +00:00
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_addSynapse').val("false");
|
|
|
|
$('#topic_topic1id').val(0);
|
|
|
|
$('#topic_topic2id').val(0);
|
2012-12-21 23:07:13 +00:00
|
|
|
Mconsole.plot();
|
2012-12-21 00:24:27 +00:00
|
|
|
},
|
2012-12-14 18:31:39 +00:00
|
|
|
//Implement the same handler for touchscreens
|
|
|
|
onTouchMove: function (node, eventInfo, e) {
|
|
|
|
$jit.util.event.stop(e); //stop default touchmove event
|
|
|
|
this.onDragMove(node, eventInfo, e);
|
|
|
|
},
|
|
|
|
//Add also a click handler to nodes
|
2012-12-15 19:47:04 +00:00
|
|
|
onClick: function (node, eventInfo, e) {
|
2013-01-05 17:50:19 +00:00
|
|
|
if (e.target.id != "infovis-canvas") return false;
|
2012-12-15 19:24:21 +00:00
|
|
|
//clicking on a node, or clicking on blank part of canvas?
|
2012-12-21 00:24:27 +00:00
|
|
|
if (node.nodeFrom) {
|
2013-01-06 03:40:31 +00:00
|
|
|
selectEdgeOnClickHandler(node, e);
|
2012-12-21 00:24:27 +00:00
|
|
|
}
|
|
|
|
else if (node && !node.nodeFrom) {
|
2013-01-06 23:40:48 +00:00
|
|
|
selectNodeOnClickHandler(node, e);
|
2012-12-14 18:31:39 +00:00
|
|
|
} else {
|
2012-12-16 06:12:41 +00:00
|
|
|
canvasDoubleClickHandler(eventInfo.getPos(), e);
|
2012-12-15 19:24:21 +00:00
|
|
|
}//if
|
|
|
|
}//onClick
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Number of iterations for the FD algorithm
|
|
|
|
iterations: 200,
|
|
|
|
//Edge length
|
|
|
|
levelDistance: 200,
|
|
|
|
// Add text to the labels. This method is only triggered
|
|
|
|
// on label creation and only for DOM labels (not native canvas ones).
|
|
|
|
onCreateLabel: function (domElement, node) {
|
2013-01-03 01:37:49 +00:00
|
|
|
onCreateLabelHandler(domElement, node);
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
// Change node styles when DOM labels are placed
|
|
|
|
// or moved.
|
|
|
|
onPlaceLabel: function (domElement, node) {
|
|
|
|
var style = domElement.style;
|
|
|
|
var left = parseInt(style.left);
|
|
|
|
var top = parseInt(style.top);
|
|
|
|
var w = domElement.offsetWidth;
|
2013-01-05 17:50:19 +00:00
|
|
|
style.left = (left - w / 2 + 107) + 'px';
|
|
|
|
//style.left = (left - w / 2) + 'px';
|
|
|
|
style.top = (top-165) + 'px';
|
2012-12-14 18:31:39 +00:00
|
|
|
style.display = '';
|
2013-01-05 17:50:19 +00:00
|
|
|
var label = document.getElementById('topic_' + node.id + '_label');
|
|
|
|
w = label.offsetWidth;
|
|
|
|
style = label.style;
|
|
|
|
style.left = (-(w / 2 + 106)) + 'px';
|
2012-12-14 18:31:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} else if (type = "centered") {
|
|
|
|
t = {
|
|
|
|
//id of the visualization container
|
|
|
|
injectInto: 'infovis',
|
|
|
|
//Optional: create a background canvas that plots
|
|
|
|
//concentric circles.
|
|
|
|
background: {
|
|
|
|
CanvasStyles: {
|
|
|
|
strokeStyle: '#333',
|
|
|
|
lineWidth: 1.5
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//Enable zooming and panning
|
|
|
|
//by scrolling and DnD
|
|
|
|
Navigation: {
|
|
|
|
enable: true,
|
|
|
|
type: 'HTML',
|
|
|
|
//Enable panning events only if we're dragging the empty
|
|
|
|
//canvas (and not a node).
|
|
|
|
panning: 'avoid nodes',
|
2012-12-27 01:57:06 +00:00
|
|
|
zooming: 15 //zoom speed. higher is more sensible
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
// Change node and edge styles such as
|
|
|
|
// color and width.
|
|
|
|
// These properties are also set per node
|
|
|
|
// with dollar prefixed data-properties in the
|
|
|
|
// JSON structure.
|
|
|
|
Node: {
|
|
|
|
overridable: true,
|
|
|
|
color: '#2D6A5D',
|
|
|
|
type: 'customNode',
|
|
|
|
dim: 25
|
|
|
|
},
|
|
|
|
Edge: {
|
|
|
|
overridable: true,
|
|
|
|
color: '#222222',
|
|
|
|
type: 'customEdge',
|
2012-12-27 01:57:06 +00:00
|
|
|
lineWidth: 2
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Native canvas text styling
|
|
|
|
Label: {
|
|
|
|
type: 'HTML', //Native or HTML
|
|
|
|
size: 20,
|
|
|
|
//style: 'bold'
|
|
|
|
},
|
|
|
|
//Add Tips
|
|
|
|
Tips: {
|
2012-12-16 20:00:43 +00:00
|
|
|
enable: false,
|
|
|
|
onShow: function (tip, node) {}
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
// Add node events
|
|
|
|
Events: {
|
|
|
|
enable: true,
|
|
|
|
type: 'HTML',
|
2013-01-05 21:28:04 +00:00
|
|
|
onMouseMove: function(node, eventInfo, e) {
|
|
|
|
onMouseMoveHandler(node, eventInfo, e);
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Update node positions when dragged
|
|
|
|
onDragMove: function (node, eventInfo, e) {
|
2013-01-05 21:21:11 +00:00
|
|
|
clickDragOnTopic(node, eventInfo, e);
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
2012-12-21 23:07:13 +00:00
|
|
|
onDragEnd: function() {
|
2012-12-26 03:47:02 +00:00
|
|
|
if (tempInit && tempNode2 == null) {
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_addSynapse').val("true");
|
|
|
|
$('#new_topic').fadeIn('fast');
|
2012-12-26 03:47:02 +00:00
|
|
|
addMetacode();
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_name').focus();
|
2012-12-26 03:47:02 +00:00
|
|
|
}
|
|
|
|
else if (tempInit && tempNode2 != null) {
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_addSynapse').val("false");
|
|
|
|
$('#synapse_topic1id').val(tempNode.id);
|
|
|
|
$('#synapse_topic2id').val(tempNode2.id);
|
2012-12-21 23:07:13 +00:00
|
|
|
$('#new_synapse').fadeIn('fast');
|
|
|
|
$('#synapse_desc').focus();
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDragCancel: function() {
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
|
|
|
Mconsole.plot();
|
|
|
|
},
|
2012-12-14 18:31:39 +00:00
|
|
|
//Implement the same handler for touchscreens
|
|
|
|
onTouchMove: function (node, eventInfo, e) {
|
|
|
|
$jit.util.event.stop(e); //stop default touchmove event
|
|
|
|
this.onDragMove(node, eventInfo, e);
|
|
|
|
},
|
2012-12-26 03:47:02 +00:00
|
|
|
//Add also a click handler to nodes
|
2012-12-16 20:00:43 +00:00
|
|
|
onClick: function (node, eventInfo, e) {
|
2013-01-05 17:50:19 +00:00
|
|
|
if (e.target.id != "infovis-canvas") return false;
|
2012-12-21 00:24:27 +00:00
|
|
|
//clicking on an edge, a node, or clicking on blank part of canvas?
|
2013-01-06 04:12:32 +00:00
|
|
|
if (eventInfo.getNode() == false) {
|
2013-01-06 03:40:31 +00:00
|
|
|
if (eventInfo.getEdge() != false) selectEdgeOnClickHandler(eventInfo.getEdge(), e);
|
|
|
|
else if (node.nodeFrom) selectEdgeOnClickHandler(node, e);
|
2012-12-21 00:24:27 +00:00
|
|
|
}
|
|
|
|
else if (node && !node.nodeFrom) {
|
2012-12-16 20:00:43 +00:00
|
|
|
if (!Mconsole.busy) {
|
2013-01-06 23:40:48 +00:00
|
|
|
selectNodeOnClickHandler(node, e);
|
2012-12-16 20:00:43 +00:00
|
|
|
Mconsole.onClick(node.id, {
|
|
|
|
hideLabels: false
|
|
|
|
});
|
|
|
|
}
|
2012-12-21 23:07:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-12-16 20:00:43 +00:00
|
|
|
canvasDoubleClickHandler(eventInfo.getPos(), e);
|
|
|
|
}//if
|
|
|
|
}//onClick
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
2012-12-16 20:00:43 +00:00
|
|
|
//Number of iterations for the FD algorithm
|
2012-12-14 18:31:39 +00:00
|
|
|
iterations: 200,
|
|
|
|
//Edge length
|
|
|
|
levelDistance: 200,
|
|
|
|
// Add text to the labels. This method is only triggered
|
|
|
|
// on label creation and only for DOM labels (not native canvas ones).
|
|
|
|
onCreateLabel: function (domElement, node) {
|
2013-01-03 01:37:49 +00:00
|
|
|
onCreateLabelHandler(domElement, node);
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
// Change node styles when DOM labels are placed
|
|
|
|
// or moved.
|
|
|
|
onPlaceLabel: function (domElement, node) {
|
|
|
|
var style = domElement.style;
|
|
|
|
var left = parseInt(style.left);
|
|
|
|
var top = parseInt(style.top);
|
|
|
|
var w = domElement.offsetWidth;
|
2013-01-05 17:50:19 +00:00
|
|
|
style.left = (left - w / 2 + 107) + 'px';
|
|
|
|
//style.left = (left - w / 2) + 'px';
|
|
|
|
style.top = (top-165) + 'px';
|
2012-12-14 18:31:39 +00:00
|
|
|
style.display = '';
|
2013-01-05 17:50:19 +00:00
|
|
|
var label = document.getElementById('topic_' + node.id + '_label');
|
|
|
|
w = label.offsetWidth;
|
|
|
|
style = label.style;
|
|
|
|
style.left = (-(w / 2 + 106)) + 'px';
|
2012-12-14 18:31:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-01-06 23:40:48 +00:00
|
|
|
/*$('body').keypress(function(e) {
|
2013-01-06 03:40:31 +00:00
|
|
|
console.log(e);
|
|
|
|
switch(e.keyCode) {
|
|
|
|
case 114: case 82:
|
|
|
|
removeSelectedEdges();
|
|
|
|
break;
|
|
|
|
case 100: case 68:
|
|
|
|
deleteSelectedEdges();
|
|
|
|
break;
|
|
|
|
}//switch
|
2013-01-06 23:40:48 +00:00
|
|
|
});*/
|
2013-01-06 03:40:31 +00:00
|
|
|
|
2012-12-14 18:31:39 +00:00
|
|
|
return t;
|
2012-12-15 07:39:14 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
// defining code to draw edges with arrows pointing in the middle of them
|
|
|
|
var renderMidArrow = function(from, to, dim, swap, canvas){
|
|
|
|
var ctx = canvas.getCtx();
|
|
|
|
// invert edge direction
|
|
|
|
if (swap) {
|
|
|
|
var tmp = from;
|
|
|
|
from = to;
|
|
|
|
to = tmp;
|
|
|
|
}
|
|
|
|
// vect represents a line from tip to tail of the arrow
|
|
|
|
var vect = new $jit.Complex(to.x - from.x, to.y - from.y);
|
|
|
|
// scale it
|
|
|
|
vect.$scale(dim / vect.norm());
|
|
|
|
// compute the midpoint of the edge line
|
|
|
|
var midPoint = new $jit.Complex((to.x + from.x) / 2, (to.y + from.y) / 2);
|
|
|
|
// move midpoint by half the "length" of the arrow so the arrow is centered on the midpoint
|
2013-01-05 22:31:38 +00:00
|
|
|
var arrowPoint = new $jit.Complex((vect.x / 0.7) + midPoint.x, (vect.y / 0.7) + midPoint.y);
|
2012-12-23 06:12:56 +00:00
|
|
|
// compute the tail intersection point with the edge line
|
2013-01-05 22:31:38 +00:00
|
|
|
var intermediatePoint = new $jit.Complex(arrowPoint.x - vect.x,
|
|
|
|
arrowPoint.y - vect.y);
|
2012-12-23 06:12:56 +00:00
|
|
|
// vector perpendicular to vect
|
|
|
|
var normal = new $jit.Complex(-vect.y / 2, vect.x / 2);
|
|
|
|
var v1 = intermediatePoint.add(normal);
|
|
|
|
var v2 = intermediatePoint.$add(normal.$scale(-1));
|
|
|
|
|
2013-01-05 22:31:38 +00:00
|
|
|
//ctx.strokeStyle = "#222222";
|
2012-12-23 06:12:56 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(from.x, from.y);
|
|
|
|
ctx.lineTo(to.x, to.y);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(v1.x, v1.y);
|
2013-01-05 22:31:38 +00:00
|
|
|
ctx.lineTo(arrowPoint.x, arrowPoint.y);
|
2012-12-23 06:12:56 +00:00
|
|
|
ctx.lineTo(v2.x, v2.y);
|
|
|
|
ctx.stroke();
|
|
|
|
};
|
2012-12-15 07:39:14 +00:00
|
|
|
|
|
|
|
// defining custom node type
|
2012-12-16 00:46:39 +00:00
|
|
|
var nodeSettings = {
|
2012-12-15 07:39:14 +00:00
|
|
|
'customNode': {
|
|
|
|
'render': function (node, canvas) {
|
|
|
|
var pos = node.pos.getc(true),
|
|
|
|
dim = node.getData('dim'),
|
2013-01-01 22:45:35 +00:00
|
|
|
cat = node.getData('metacode'),
|
2012-12-25 23:29:20 +00:00
|
|
|
inCommons = node.getData('inCommons'),
|
|
|
|
onCanvas = node.getData('onCanvas'),
|
2012-12-15 07:39:14 +00:00
|
|
|
ctx = canvas.getCtx();
|
2012-12-22 19:52:16 +00:00
|
|
|
|
2012-12-25 23:29:20 +00:00
|
|
|
// if the topic is from the Commons draw a green circle around it
|
|
|
|
if (inCommons) {
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(pos.x, pos.y, dim+3, 0, 2 * Math.PI, false);
|
|
|
|
ctx.strokeStyle = '#67be5f'; // green
|
|
|
|
ctx.lineWidth = 2;
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
// if the topic is on the Canvas draw a white circle around it
|
|
|
|
if (onCanvas) {
|
2012-12-22 19:52:16 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(pos.x, pos.y, dim+3, 0, 2 * Math.PI, false);
|
2012-12-23 06:12:56 +00:00
|
|
|
ctx.strokeStyle = 'white';
|
|
|
|
ctx.lineWidth = 2;
|
|
|
|
ctx.stroke();
|
2012-12-22 19:52:16 +00:00
|
|
|
}
|
2012-12-15 07:39:14 +00:00
|
|
|
ctx.drawImage(imgArray[cat], pos.x - dim, pos.y - dim, dim*2, dim*2);
|
|
|
|
|
|
|
|
},
|
|
|
|
'contains': function(node, pos) {
|
|
|
|
var npos = node.pos.getc(true),
|
|
|
|
dim = node.getData('dim');
|
|
|
|
return this.nodeHelper.circle.contains(npos, pos, dim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// defining custom edges
|
|
|
|
var edgeSettings = {
|
|
|
|
'customEdge': {
|
|
|
|
'render': function(adj, canvas) {
|
|
|
|
//get nodes cartesian coordinates
|
|
|
|
var pos = adj.nodeFrom.pos.getc(true);
|
|
|
|
var posChild = adj.nodeTo.pos.getc(true);
|
|
|
|
|
|
|
|
var directionCat = adj.getData("category");
|
|
|
|
//label placement on edges
|
|
|
|
//plot arrow edge
|
|
|
|
if (directionCat == "none") {
|
|
|
|
this.edgeHelper.line.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, canvas);
|
|
|
|
}
|
|
|
|
else if (directionCat == "both") {
|
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, true, canvas);
|
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, false, canvas);
|
|
|
|
}
|
|
|
|
else if (directionCat == "from-to") {
|
|
|
|
var direction = adj.data.$direction;
|
|
|
|
var inv = (direction && direction.length>1 && direction[0] != adj.nodeFrom.id);
|
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, inv, canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
//check for edge label in data
|
2013-01-03 08:53:25 +00:00
|
|
|
var desc = adj.getData("desc");
|
2012-12-15 07:39:14 +00:00
|
|
|
var showDesc = adj.getData("showDesc");
|
|
|
|
if( desc != "" && showDesc ) {
|
2013-01-08 01:34:47 +00:00
|
|
|
//now adjust the label placement
|
|
|
|
var ctx = canvas.getCtx();
|
2012-12-15 07:39:14 +00:00
|
|
|
var radius = canvas.getSize();
|
|
|
|
var x = parseInt((pos.x + posChild.x - (desc.length * 5)) /2);
|
|
|
|
var y = parseInt((pos.y + posChild.y) /2);
|
2013-01-08 01:34:47 +00:00
|
|
|
ctx.font = 'bold 14px arial';
|
|
|
|
|
|
|
|
//render background
|
|
|
|
ctx.fillStyle = '#FFF';
|
|
|
|
var margin = 5;
|
|
|
|
var height = 14 + margin; //font size + margin
|
|
|
|
var CURVE = height / 2; //offset for curvy corners
|
|
|
|
var width = ctx.measureText(desc).width + 2 * margin - 2 * CURVE
|
|
|
|
var labelX = x - margin + CURVE;
|
|
|
|
var labelY = y - height + margin;
|
|
|
|
ctx.fillRect(labelX, labelY, width, height);
|
|
|
|
|
|
|
|
//curvy corners woo - circles in place of last CURVE pixels of rect
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(labelX, labelY + CURVE, CURVE, 0, 2 * Math.PI, false);
|
|
|
|
ctx.arc(labelX + width, labelY + CURVE, CURVE, 0, 2 * Math.PI, false);
|
|
|
|
ctx.fill();
|
|
|
|
|
|
|
|
//render text
|
|
|
|
ctx.fillStyle = '#000';
|
|
|
|
ctx.fillText(desc, x, y);
|
2012-12-15 07:39:14 +00:00
|
|
|
}
|
|
|
|
}, 'contains' : function(adj, pos) {
|
|
|
|
var from = adj.nodeFrom.pos.getc(true),
|
2012-12-26 03:47:02 +00:00
|
|
|
to = adj.nodeTo.pos.getc(true);
|
2012-12-21 00:24:27 +00:00
|
|
|
return this.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon);
|
2012-12-15 07:39:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-06 03:40:31 +00:00
|
|
|
|
2013-01-08 00:43:12 +00:00
|
|
|
function editEdge(edge, e) {
|
2013-01-08 03:06:24 +00:00
|
|
|
//reset so we don't interfere with other edges
|
|
|
|
$('#edit_synapse').remove();
|
2013-01-08 00:43:12 +00:00
|
|
|
|
2013-01-08 03:06:24 +00:00
|
|
|
deselectEdge(edge); //so the label is missing while editing
|
|
|
|
var edit_div = document.createElement('div');
|
|
|
|
edit_div.setAttribute('id', 'edit_synapse');
|
|
|
|
$('.main .wrapper').append(edit_div);
|
|
|
|
$('#edit_synapse').attr('class', 'best_in_place best_in_place_desc');
|
|
|
|
$('#edit_synapse').attr('data-object', 'synapse');
|
|
|
|
$('#edit_synapse').attr('data-attribute', 'desc');
|
|
|
|
$('#edit_synapse').attr('data-type', 'input');
|
|
|
|
//TODO how to get blank data-nil
|
|
|
|
$('#edit_synapse').attr('data-nil', ' ');
|
2013-01-08 00:43:12 +00:00
|
|
|
$('#edit_synapse').attr('data-url', '/synapses/' + edge.getData("id"));
|
|
|
|
$('#edit_synapse').html(edge.getData("desc"));
|
2013-01-08 03:06:24 +00:00
|
|
|
|
2013-01-08 00:43:12 +00:00
|
|
|
$('#edit_synapse').css('position', 'absolute');
|
|
|
|
$('#edit_synapse').css('left', e.clientX);
|
|
|
|
$('#edit_synapse').css('top', e.clientY);
|
|
|
|
|
|
|
|
$('#edit_synapse').bind("ajax:success", function() {
|
|
|
|
var desc = $(this).html();
|
|
|
|
edge.setData("desc", desc);
|
|
|
|
selectEdge(edge);
|
|
|
|
Mconsole.plot();
|
2013-01-08 03:06:24 +00:00
|
|
|
$('#edit_synapse').remove();
|
2013-01-08 00:43:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#edit_synapse').focusout(function() {
|
2013-01-08 03:06:24 +00:00
|
|
|
//in case they cancel
|
2013-01-08 04:40:58 +00:00
|
|
|
$('#edit_synapse').hide();
|
2013-01-08 00:43:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//css stuff above moves it, this activates it
|
|
|
|
$('#edit_synapse').click();
|
2013-01-08 03:06:24 +00:00
|
|
|
$('#edit_synapse form').submit(function() {
|
|
|
|
//hide it once form submits.
|
|
|
|
//If you don't do this, and data is unchanged, it'll show up on canvas
|
|
|
|
$('#edit_synapse').hide();
|
|
|
|
});
|
2013-01-08 00:43:12 +00:00
|
|
|
$('#edit_synapse input').focus();
|
|
|
|
$('#edit_synapse').show();
|
|
|
|
}
|
|
|
|
|
2013-01-06 03:40:31 +00:00
|
|
|
function selectEdgeOnClickHandler(adj, e) {
|
2013-01-08 00:43:12 +00:00
|
|
|
//editing overrides everything else
|
|
|
|
if (e.altKey) {
|
|
|
|
editEdge(adj, e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-07 05:17:39 +00:00
|
|
|
var showDesc = adj.getData("showDesc");
|
2013-01-08 00:43:12 +00:00
|
|
|
if (showDesc && e.shiftKey) {
|
|
|
|
//deselecting an edge with shift
|
2013-01-07 05:17:39 +00:00
|
|
|
deselectEdge(adj);
|
2013-01-08 00:43:12 +00:00
|
|
|
} else if (!showDesc && e.shiftKey) {
|
|
|
|
//selecting an edge with shift
|
|
|
|
selectEdge(adj);
|
|
|
|
} else if (showDesc && !e.shiftKey) {
|
|
|
|
//deselecting an edge without shift - unselect all
|
|
|
|
deselectAllEdges();
|
|
|
|
} else if (!showDesc && !e.shiftKey) {
|
|
|
|
//selecting an edge without shift - unselect all but new one
|
|
|
|
deselectAllEdges();
|
2013-01-06 03:40:31 +00:00
|
|
|
selectEdge(adj);
|
|
|
|
}
|
2013-01-08 00:43:12 +00:00
|
|
|
|
|
|
|
Mconsole.plot();
|
2012-12-21 00:24:27 +00:00
|
|
|
}//selectEdgeOnClickHandler
|
|
|
|
|
2013-01-08 00:43:12 +00:00
|
|
|
function deselectAllEdges() {
|
|
|
|
for (var i = 0; i < selectedEdges.length; i += 1) {
|
|
|
|
var edge = selectedEdges[i];
|
|
|
|
deselectEdge(edge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-06 23:40:48 +00:00
|
|
|
function selectNodeOnClickHandler(node, e) {
|
|
|
|
//set final styles
|
|
|
|
if (!e.shiftKey) {
|
|
|
|
Mconsole.graph.eachNode(function (n) {
|
|
|
|
if (n.id != node.id) {
|
|
|
|
delete n.selected;
|
|
|
|
n.setData('onCanvas',false);
|
|
|
|
}
|
|
|
|
|
|
|
|
n.setData('dim', 25, 'current');
|
|
|
|
n.eachAdjacency(function (adj) {
|
|
|
|
deselectEdge(adj);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2013-01-06 03:40:31 +00:00
|
|
|
if (!node.selected) {
|
|
|
|
node.selected = true;
|
2013-01-06 23:40:48 +00:00
|
|
|
node.setData('dim', 30, 'current');
|
|
|
|
node.setData('onCanvas',true);
|
2013-01-06 03:40:31 +00:00
|
|
|
node.eachAdjacency(function (adj) {
|
|
|
|
selectEdge(adj);
|
|
|
|
});
|
|
|
|
Mconsole.plot();
|
|
|
|
} else {
|
|
|
|
node.setData('dim', 25, 'current');
|
|
|
|
delete node.selected;
|
2013-01-06 23:40:48 +00:00
|
|
|
node.setData('onCanvas',false);
|
2013-01-06 03:40:31 +00:00
|
|
|
}
|
|
|
|
//trigger animation to final styles
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 500
|
|
|
|
});
|
|
|
|
Mconsole.plot();
|
2012-12-15 19:24:21 +00:00
|
|
|
}//selectNodeOnClickHandler
|
2012-12-15 07:39:14 +00:00
|
|
|
|
2012-12-15 19:47:04 +00:00
|
|
|
//for the canvasDoubleClickHandler function
|
|
|
|
var canvasDoubleClickHandlerObject = new Object();
|
2012-12-16 00:46:39 +00:00
|
|
|
canvasDoubleClickHandlerObject.storedTime = 0;
|
2012-12-15 19:47:04 +00:00
|
|
|
|
2012-12-16 06:12:41 +00:00
|
|
|
function canvasDoubleClickHandler(canvasLoc,e) {
|
2012-12-16 00:46:39 +00:00
|
|
|
var TOLERANCE = 300; //0.3 seconds
|
2012-12-15 19:47:04 +00:00
|
|
|
|
2012-12-16 00:46:39 +00:00
|
|
|
//grab the location and timestamp of the click
|
|
|
|
var storedTime = canvasDoubleClickHandlerObject.storedTime;
|
|
|
|
var now = Date.now(); //not compatible with IE8 FYI
|
2012-12-15 19:47:04 +00:00
|
|
|
|
2012-12-26 03:47:02 +00:00
|
|
|
if (now - storedTime < TOLERANCE) {
|
2012-12-16 00:46:39 +00:00
|
|
|
//pop up node creation :)
|
2013-01-03 23:21:46 +00:00
|
|
|
$('#topic_grabTopic').val("null");
|
|
|
|
$('#topic_addSynapse').val("false");
|
|
|
|
$('#new_topic').css('left',e.clientX + "px");
|
|
|
|
$('#new_topic').css('top',e.clientY + "px");
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_x').val(canvasLoc.x);
|
|
|
|
$('#topic_y').val(canvasLoc.y);
|
|
|
|
$('#new_topic').fadeIn('fast');
|
2012-12-25 23:29:20 +00:00
|
|
|
addMetacode();
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_name').focus();
|
2012-12-16 00:46:39 +00:00
|
|
|
} else {
|
|
|
|
canvasDoubleClickHandlerObject.storedTime = now;
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#new_topic').fadeOut('fast');
|
2012-12-21 04:45:44 +00:00
|
|
|
$('#new_synapse').fadeOut('fast');
|
|
|
|
tempInit = false;
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
Mconsole.plot();
|
2012-12-16 00:46:39 +00:00
|
|
|
}
|
2012-12-15 19:47:04 +00:00
|
|
|
}//canvasDoubleClickHandler
|
2012-12-21 23:07:13 +00:00
|
|
|
|
|
|
|
// ForceDirected Mode: for the creation of new topics and synapses through clicking and draggin with right clicks off of topics
|
2012-12-26 03:47:02 +00:00
|
|
|
function clickDragOnTopic(node, eventInfo, e) {
|
2012-12-21 23:07:13 +00:00
|
|
|
if (node && !node.nodeFrom) {
|
|
|
|
$('#new_synapse').fadeOut('fast');
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#new_topic').fadeOut('fast');
|
2012-12-21 23:07:13 +00:00
|
|
|
var pos = eventInfo.getPos();
|
|
|
|
// if it's a left click, move the node
|
2013-01-03 23:21:46 +00:00
|
|
|
if (e.button == 0 && !e.altKey && (e.buttons == 0 || e.buttons == 1 || e.buttons == undefined)) {
|
2013-01-04 21:51:37 +00:00
|
|
|
dragged = node.id;
|
|
|
|
node.pos.setc(pos.x, pos.y);
|
|
|
|
node.data.$xloc = pos.x;
|
|
|
|
node.data.$yloc = pos.y;
|
2012-12-21 23:07:13 +00:00
|
|
|
Mconsole.plot();
|
|
|
|
}
|
2013-01-03 23:21:46 +00:00
|
|
|
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox
|
2013-01-06 23:40:48 +00:00
|
|
|
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && userid != null) {
|
2012-12-21 23:07:13 +00:00
|
|
|
if (tempInit == false) {
|
|
|
|
tempNode = node;
|
|
|
|
tempInit = true;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
temp = eventInfo.getNode();
|
|
|
|
if (temp != false && temp.id != node.id) { // this means a Node has been returned
|
|
|
|
tempNode2 = temp;
|
|
|
|
Mconsole.plot();
|
2012-12-26 03:47:02 +00:00
|
|
|
renderMidArrow({ x: tempNode.pos.getc().x, y: tempNode.pos.getc().y }, { x: temp.pos.getc().x, y: temp.pos.getc().y }, 13, false, Mconsole.canvas);
|
2012-12-21 23:07:13 +00:00
|
|
|
// before making the highlighted one bigger, make sure all the others are regular size
|
|
|
|
Mconsole.graph.eachNode(function (n) {
|
|
|
|
n.setData('dim', 25, 'current');
|
|
|
|
});
|
|
|
|
temp.setData('dim',35,'current');
|
|
|
|
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
|
|
|
Mconsole.fx.plotNode(temp, Mconsole.canvas);
|
|
|
|
} else if (!temp) {
|
2012-12-23 06:12:56 +00:00
|
|
|
tempNode2 = null;
|
2012-12-21 23:07:13 +00:00
|
|
|
Mconsole.graph.eachNode(function (n) {
|
|
|
|
n.setData('dim', 25, 'current');
|
|
|
|
});
|
|
|
|
//pop up node creation :)
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_grabTopic').val("null");
|
2013-01-03 23:21:46 +00:00
|
|
|
var myX = e.clientX - 110;
|
|
|
|
var myY = e.clientY - 30;
|
|
|
|
$('#new_topic').css('left',myX + "px");
|
2013-01-06 23:40:48 +00:00
|
|
|
$('#new_topic').css('top',myY + "px");
|
|
|
|
$('#new_synapse').css('left',myX + "px");
|
|
|
|
$('#new_synapse').css('top',myY + "px");
|
2013-01-01 22:45:35 +00:00
|
|
|
$('#topic_x').val(eventInfo.getPos().x);
|
|
|
|
$('#topic_y').val(eventInfo.getPos().y);
|
2012-12-21 23:07:13 +00:00
|
|
|
Mconsole.plot();
|
|
|
|
renderMidArrow({ x: tempNode.pos.getc().x, y: tempNode.pos.getc().y }, { x: pos.x, y: pos.y }, 13, false, Mconsole.canvas);
|
|
|
|
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-02 04:57:32 +00:00
|
|
|
}
|
2013-01-03 01:37:49 +00:00
|
|
|
|
|
|
|
function onCreateLabelHandler(domElement, node) {
|
|
|
|
var html = ' \
|
|
|
|
<div class="CardOnGraph" \
|
|
|
|
id="topic_$_id_$"> \
|
2013-01-03 08:53:25 +00:00
|
|
|
<p class="type best_in_place best_in_place_metacode" \
|
2013-01-03 01:37:49 +00:00
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-collection=$_metacode_choices_$ \
|
|
|
|
data-attribute="metacode" \
|
|
|
|
data-type="select">$_metacode_$</p> \
|
2013-01-03 02:49:00 +00:00
|
|
|
<img alt="$_metacode_$" \
|
|
|
|
class="icon" \
|
2013-01-05 02:39:16 +00:00
|
|
|
title="Click to hide card" \
|
2013-01-03 02:49:00 +00:00
|
|
|
height="50" \
|
|
|
|
width="50" \
|
2013-01-03 01:37:49 +00:00
|
|
|
src="$_imgsrc_$" /> \
|
2013-01-03 02:49:00 +00:00
|
|
|
<span class="title"> \
|
2013-01-03 08:53:25 +00:00
|
|
|
<span class="best_in_place best_in_place_name" \
|
2013-01-03 02:49:00 +00:00
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-attribute="name" \
|
2013-01-03 04:01:38 +00:00
|
|
|
data-type="input">$_name_$</span> \
|
2013-01-03 08:53:25 +00:00
|
|
|
<a href="/topics/$_id_$" class="topic-go-arrow" target="_blank"> \
|
2013-01-03 02:49:00 +00:00
|
|
|
<img class="topic-go-arrow" \
|
2013-01-05 02:39:16 +00:00
|
|
|
title="Explore Topic" \
|
2013-01-03 02:49:00 +00:00
|
|
|
src="/assets/go-arrow.png" /> \
|
|
|
|
</a> \
|
2013-01-03 08:53:25 +00:00
|
|
|
<div class="clearfloat"></div> \
|
2013-01-03 02:49:00 +00:00
|
|
|
</span> \
|
2013-01-03 01:37:49 +00:00
|
|
|
<div class="contributor"> \
|
2013-01-03 09:01:18 +00:00
|
|
|
Added by: <a href="/users/$_userid_$" target="_blank">$_username_$ \
|
|
|
|
</a> \
|
2013-01-03 01:37:49 +00:00
|
|
|
</div> \
|
2013-01-05 21:21:11 +00:00
|
|
|
<div class="scroll"> \
|
2013-01-03 01:37:49 +00:00
|
|
|
<div class="desc"> \
|
2013-01-03 08:53:25 +00:00
|
|
|
<span class="best_in_place best_in_place_desc" \
|
2013-01-03 02:02:41 +00:00
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
2013-01-03 04:01:38 +00:00
|
|
|
data-nil="$_desc_nil_$" \
|
2013-01-03 02:02:41 +00:00
|
|
|
data-attribute="desc" \
|
2013-01-05 17:50:19 +00:00
|
|
|
data-ok-button="Save" \
|
|
|
|
data-cancel-button="Discard" \
|
2013-01-03 02:02:41 +00:00
|
|
|
data-type="textarea">$_desc_$</span> \
|
2013-01-05 17:50:19 +00:00
|
|
|
<div class="clearfloat"></div> \
|
2013-01-03 01:37:49 +00:00
|
|
|
</div> \
|
2013-01-05 02:39:16 +00:00
|
|
|
</div> \
|
2013-01-06 23:40:48 +00:00
|
|
|
<div class="link"> \
|
2013-01-05 17:45:02 +00:00
|
|
|
$_go_link_$ \
|
|
|
|
$_a_tag_$<span class="best_in_place best_in_place_link" \
|
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-attribute="link" \
|
|
|
|
data-type="input">$_link_$</span>$_close_a_tag_$ \
|
2013-01-06 23:40:48 +00:00
|
|
|
</div> \
|
2013-01-05 21:21:11 +00:00
|
|
|
<div class="clearfloat"></div> \
|
2013-01-03 01:37:49 +00:00
|
|
|
</div>';
|
|
|
|
|
2013-01-05 17:45:02 +00:00
|
|
|
//link is rendered differently if user is logged out or in
|
|
|
|
var go_link, a_tag, close_a_tag;
|
|
|
|
if (userid == null) {
|
2013-01-05 17:56:44 +00:00
|
|
|
go_link = '';
|
2013-01-06 23:40:48 +00:00
|
|
|
if (node.getData("link") != "") {
|
|
|
|
a_tag = '<a href="' + node.getData("link") + '">';
|
|
|
|
close_a_tag = '</a>';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a_tag = '';
|
|
|
|
close_a_tag = '';
|
|
|
|
}
|
2013-01-05 17:45:02 +00:00
|
|
|
} else {
|
|
|
|
go_link = '<a href="' + node.getData("link") + '" ' +
|
|
|
|
' class="go-link" target="_blank">[go]</a>';
|
|
|
|
a_tag = '';
|
|
|
|
close_a_tag = '';
|
|
|
|
}
|
|
|
|
|
2013-01-03 01:37:49 +00:00
|
|
|
//create metacode_choices array from imgArray
|
2013-01-03 02:55:47 +00:00
|
|
|
var metacodes = new Array();
|
2013-01-03 01:37:49 +00:00
|
|
|
for (var key in imgArray) {
|
|
|
|
if (imgArray.hasOwnProperty(key)) {
|
2013-01-03 02:55:47 +00:00
|
|
|
if (key != node.getData("metacode")) {
|
|
|
|
metacodes.push(key);
|
|
|
|
}
|
2013-01-03 01:37:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-03 02:55:47 +00:00
|
|
|
|
|
|
|
//Arrange it how we want it
|
|
|
|
metacodes.sort();
|
|
|
|
metacodes.unshift(node.getData("metacode"));
|
|
|
|
|
|
|
|
var metacode_choices = "'[";
|
|
|
|
for (var i in metacodes) {
|
|
|
|
metacode_choices += '["' + metacodes[i] + '","' + metacodes[i] + '"],';
|
|
|
|
}
|
2013-01-03 01:37:49 +00:00
|
|
|
//remove trailing comma and add ]
|
|
|
|
metacode_choices = metacode_choices.slice(0, -1);
|
|
|
|
metacode_choices += "]'";
|
|
|
|
|
2013-01-05 17:45:02 +00:00
|
|
|
var desc_nil = "<span class='gray'>Click to add description.</span>";
|
2013-01-05 17:56:44 +00:00
|
|
|
var link_nil = "<span class='gray'>Click to add link.</span>";
|
2013-01-05 17:45:02 +00:00
|
|
|
|
2013-01-03 01:37:49 +00:00
|
|
|
html = html.replace(/\$_id_\$/g, node.id);
|
|
|
|
html = html.replace(/\$_metacode_\$/g, node.getData("metacode"));
|
|
|
|
html = html.replace(/\$_imgsrc_\$/g, imgArray[node.getData("metacode")].src);
|
|
|
|
html = html.replace(/\$_name_\$/g, node.name);
|
|
|
|
html = html.replace(/\$_userid_\$/g, node.getData("userid"));
|
|
|
|
html = html.replace(/\$_username_\$/g, node.getData("username"));
|
2013-01-05 16:57:25 +00:00
|
|
|
html = html.replace(/\$_metacode_choices_\$/g, metacode_choices);
|
2013-01-05 17:45:02 +00:00
|
|
|
html = html.replace(/\$_go_link_\$/g, go_link);
|
|
|
|
html = html.replace(/\$_a_tag_\$/g, a_tag);
|
|
|
|
html = html.replace(/\$_close_a_tag_\$/g, close_a_tag);
|
2013-01-06 23:40:48 +00:00
|
|
|
if (node.getData("link") == "" && userid != null) {
|
2013-01-05 17:56:44 +00:00
|
|
|
html = html.replace(/\$_link_\$/g, link_nil);
|
|
|
|
} else {
|
|
|
|
html = html.replace(/\$_link_\$/g, node.getData("link"));
|
|
|
|
}
|
2013-01-03 04:01:38 +00:00
|
|
|
|
|
|
|
html = html.replace(/\$_desc_nil_\$/g, desc_nil);
|
2013-01-03 08:53:25 +00:00
|
|
|
if (node.getData("desc") == "" && userid != null) {
|
2013-01-05 16:57:25 +00:00
|
|
|
//logged in but desc isn't there so it's invisible
|
2013-01-03 04:01:38 +00:00
|
|
|
html = html.replace(/\$_desc_\$/g, desc_nil);
|
2013-01-03 02:02:41 +00:00
|
|
|
} else {
|
|
|
|
html = html.replace(/\$_desc_\$/g, node.getData("desc"));
|
|
|
|
}
|
2013-01-03 04:01:38 +00:00
|
|
|
|
2013-01-03 01:37:49 +00:00
|
|
|
var showCard = document.createElement('div');
|
|
|
|
showCard.className = 'showcard topic_' + node.id;
|
|
|
|
showCard.innerHTML = html;
|
|
|
|
showCard.style.display = "none";
|
|
|
|
domElement.appendChild(showCard);
|
|
|
|
|
|
|
|
// add some events to the label
|
2013-01-05 02:39:16 +00:00
|
|
|
$(showCard).find('img.icon').click(function(){
|
2013-01-08 01:34:47 +00:00
|
|
|
hideCard(node);
|
2013-01-03 03:39:10 +00:00
|
|
|
});
|
2013-01-03 23:21:46 +00:00
|
|
|
|
2013-01-05 16:57:25 +00:00
|
|
|
$(showCard).find('.scroll').mCustomScrollbar();
|
2013-01-03 01:37:49 +00:00
|
|
|
|
|
|
|
// Create a 'name' button and add it to the main node label
|
|
|
|
var nameContainer = document.createElement('span'),
|
2013-01-05 17:50:19 +00:00
|
|
|
style = nameContainer.style;
|
2013-01-03 01:37:49 +00:00
|
|
|
nameContainer.className = 'name topic_' + node.id;
|
2013-01-05 17:50:19 +00:00
|
|
|
nameContainer.id = 'topic_' + node.id + '_label';
|
|
|
|
|
2013-01-05 02:39:16 +00:00
|
|
|
var littleHTML = ' \
|
|
|
|
<div class="label">$_name_$</div> \
|
|
|
|
<div class="nodeOptions">';
|
2013-01-07 05:17:39 +00:00
|
|
|
if ((userid == null || mapid == null) && node.id != Mconsole.root) {
|
2013-01-05 02:39:16 +00:00
|
|
|
littleHTML += ' \
|
|
|
|
<span class="removeFromCanvas" \
|
|
|
|
onclick="removeFromCanvas($_id_$)" \
|
|
|
|
title="Click to remove topic from canvas"> \
|
|
|
|
</span>';
|
|
|
|
}
|
2013-01-06 23:40:48 +00:00
|
|
|
else if (mapid != null && userid != null && node.id != Mconsole.root) {
|
2013-01-05 02:39:16 +00:00
|
|
|
littleHTML += ' \
|
2013-01-06 23:40:48 +00:00
|
|
|
<span class="removeFromCanvas" \
|
|
|
|
onclick="removeFromCanvas($_id_$)" \
|
|
|
|
title="Click to remove topic from canvas"> \
|
|
|
|
</span> \
|
2013-01-07 05:17:39 +00:00
|
|
|
<a href="/topics/$_mapid_$/$_id_$/removefrommap" \
|
2013-01-05 02:39:16 +00:00
|
|
|
title="Click to remove topic from map" \
|
2013-01-06 23:40:48 +00:00
|
|
|
class="removeFromMap" \
|
2013-01-07 05:17:39 +00:00
|
|
|
data-method="post" \
|
2013-01-05 02:39:16 +00:00
|
|
|
data-remote="true" \
|
|
|
|
rel="nofollow"> \
|
|
|
|
</a>';
|
|
|
|
}
|
2013-01-06 23:40:48 +00:00
|
|
|
if (userid != null && node.id != Mconsole.root) {
|
2013-01-05 02:39:16 +00:00
|
|
|
littleHTML += ' \
|
|
|
|
<a href="/topics/$_id_$" \
|
|
|
|
title="Click to delete this topic" \
|
|
|
|
class="deleteTopic" \
|
|
|
|
data-confirm="Delete this topic and all synapses linking to it?" \
|
|
|
|
data-method="delete" \
|
|
|
|
data-remote="true" \
|
|
|
|
rel="nofollow"> \
|
|
|
|
</a>';
|
|
|
|
}
|
|
|
|
littleHTML += '</div>';
|
|
|
|
littleHTML = littleHTML.replace(/\$_id_\$/g, node.id);
|
|
|
|
littleHTML = littleHTML.replace(/\$_mapid_\$/g, mapid);
|
|
|
|
littleHTML = littleHTML.replace(/\$_name_\$/g, node.name);
|
|
|
|
nameContainer.innerHTML = littleHTML;
|
2013-01-03 01:37:49 +00:00
|
|
|
domElement.appendChild(nameContainer);
|
|
|
|
style.fontSize = "0.9em";
|
|
|
|
style.color = "#222222";
|
|
|
|
|
|
|
|
// add some events to the label
|
2013-01-06 23:40:48 +00:00
|
|
|
$(nameContainer).find('.label').click(function(e){
|
|
|
|
$('.showcard').css('display','none');
|
|
|
|
$('.name').css('display','block');
|
|
|
|
$('.name.topic_' + node.id).css('display','none');
|
|
|
|
$('.showcard.topic_' + node.id).fadeIn('fast');
|
|
|
|
selectNodeOnClickHandler(node,e);
|
|
|
|
node.setData('dim', 1, 'current');
|
2013-01-05 02:39:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
nameContainer.onmouseover = function(){
|
|
|
|
$('.name.topic_' + node.id + ' .nodeOptions').css('display','block');
|
|
|
|
}
|
|
|
|
|
|
|
|
nameContainer.onmouseout = function(){
|
|
|
|
$('.name.topic_' + node.id + ' .nodeOptions').css('display','none');
|
2013-01-03 01:37:49 +00:00
|
|
|
}
|
2013-01-03 03:39:10 +00:00
|
|
|
|
2013-01-05 16:57:25 +00:00
|
|
|
//jQuery selector for the card thing at the top of a topic view
|
|
|
|
//only works if we're editing the topic whose page we are on
|
|
|
|
//e.g. on /topics/1 you only need to update .focus.topic_1
|
|
|
|
var topcard = '.focus.topic_' + node.id;
|
|
|
|
|
|
|
|
//bind best_in_place ajax callbacks
|
|
|
|
$(showCard).find('.best_in_place_metacode')
|
|
|
|
.bind("ajax:success", function() {
|
2013-01-03 03:39:10 +00:00
|
|
|
var metacode = $(this).html();
|
2013-01-05 16:57:25 +00:00
|
|
|
//changing img alt, img src for top card (topic view page)
|
|
|
|
//and on-canvas card. Also changing image of node
|
2013-01-03 03:39:10 +00:00
|
|
|
$(showCard).find('img.icon').attr('alt', metacode);
|
|
|
|
$(showCard).find('img.icon').attr('src', imgArray[metacode].src);
|
2013-01-05 16:57:25 +00:00
|
|
|
$(topcard + ' img').attr('alt', metacode);
|
|
|
|
$(topcard + ' img').attr('src', imgArray[metacode].src);
|
|
|
|
$(topcard + ' .focusleft p').html(metacode);
|
2013-01-03 03:39:10 +00:00
|
|
|
node.setData("metacode", metacode);
|
|
|
|
Mconsole.plot();
|
|
|
|
});
|
2013-01-04 05:20:43 +00:00
|
|
|
|
|
|
|
$(showCard).find('.best_in_place_name').bind("ajax:success", function() {
|
|
|
|
var name = $(this).html();
|
|
|
|
$(nameContainer).find('.label').html(name);
|
2013-01-05 16:57:25 +00:00
|
|
|
$(topcard + ' .focusmiddle .title-text').html(name);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(showCard).find('.best_in_place_desc').bind("ajax:success", function() {
|
|
|
|
var desc = $(this).html();
|
|
|
|
$(topcard + ' .focusmiddle p').html(desc);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(showCard).find('.best_in_place_link').bind("ajax:success", function() {
|
|
|
|
var link = $(this).html();
|
|
|
|
$(topcard + ' .focusright a').html(link);
|
|
|
|
$(topcard + ' .focusright a').attr('href', link);
|
2013-01-05 17:56:44 +00:00
|
|
|
$(showCard).find('.go-link').attr('href', link);
|
2013-01-04 05:20:43 +00:00
|
|
|
});
|
2013-01-03 04:25:33 +00:00
|
|
|
|
2013-01-03 01:37:49 +00:00
|
|
|
}//onCreateLabelHandler
|
2013-01-05 21:28:04 +00:00
|
|
|
|
2013-01-08 01:34:47 +00:00
|
|
|
function hideCard(node) {
|
|
|
|
var card = '.showcard';
|
|
|
|
if (node != null) {
|
|
|
|
card += '.topic_' + node.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(card).fadeOut('fast', function(){
|
|
|
|
node.setData('dim', 25, 'current');
|
|
|
|
$('.name').show();
|
|
|
|
Mconsole.plot();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-06 04:12:32 +00:00
|
|
|
//edge that the mouse is currently hovering over
|
2013-01-06 03:40:31 +00:00
|
|
|
var edgeHover = false;
|
2013-01-05 22:31:38 +00:00
|
|
|
|
2013-01-05 21:28:04 +00:00
|
|
|
function onMouseMoveHandler(node, eventInfo, e) {
|
2013-01-05 22:31:38 +00:00
|
|
|
var edge = eventInfo.getEdge();
|
2013-01-06 04:12:32 +00:00
|
|
|
var node = eventInfo.getNode();
|
2013-01-05 22:31:38 +00:00
|
|
|
|
2013-01-06 04:12:32 +00:00
|
|
|
//if we're on top of a node object, act like there aren't edges under it
|
|
|
|
if (node != false) {
|
|
|
|
if (edgeHover) {
|
|
|
|
onMouseLeave(edgeHover);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-06 03:40:31 +00:00
|
|
|
if (edge == false && edgeHover != false) {
|
2013-01-05 22:31:38 +00:00
|
|
|
//mouse not on an edge, but we were on an edge previously
|
2013-01-06 03:40:31 +00:00
|
|
|
onMouseLeave(edgeHover);
|
|
|
|
} else if (edge != false && edgeHover == false) {
|
2013-01-05 22:31:38 +00:00
|
|
|
//mouse is on an edge, but there isn't a stored edge
|
|
|
|
onMouseEnter(edge);
|
2013-01-06 03:40:31 +00:00
|
|
|
} else if (edge != false && edgeHover != edge) {
|
2013-01-05 22:31:38 +00:00
|
|
|
//mouse is on an edge, but a different edge is stored
|
2013-01-06 03:40:31 +00:00
|
|
|
onMouseLeave(edgeHover)
|
|
|
|
onMouseEnter(edge);
|
2013-01-05 21:28:04 +00:00
|
|
|
}
|
2013-01-06 03:40:31 +00:00
|
|
|
edgeHover = edge;
|
2013-01-05 22:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseEnter(edge) {
|
|
|
|
$('canvas').css('cursor', 'pointer');
|
2013-01-06 03:40:31 +00:00
|
|
|
var showDesc = edge.getData("showDesc");
|
|
|
|
if (!showDesc) {
|
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 4,
|
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 100
|
|
|
|
});
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
2013-01-05 22:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseLeave(edge) {
|
|
|
|
$('canvas').css('cursor', 'default');
|
2013-01-06 03:40:31 +00:00
|
|
|
var showDesc = edge.getData("showDesc");
|
|
|
|
if (!showDesc) {
|
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 2,
|
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 100
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is for hiding one topic from your canvas
|
|
|
|
function removeEdge(edge) {
|
|
|
|
var id = edge.getData("id");
|
|
|
|
$.ajax({
|
|
|
|
type: "DELETE",
|
|
|
|
url: "/synapses/" + id,
|
|
|
|
success: function(){
|
|
|
|
hideEdge(edge);
|
|
|
|
},
|
2013-01-05 22:31:38 +00:00
|
|
|
});
|
2013-01-06 03:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideEdge(edge) {
|
|
|
|
var from = edge.nodeFrom.id;
|
|
|
|
var to = edge.nodeTo.id;
|
|
|
|
edge.setData('alpha', 0, 'end');
|
2013-01-05 22:31:38 +00:00
|
|
|
Mconsole.fx.animate({
|
2013-01-06 03:40:31 +00:00
|
|
|
modes: ['edge-property:alpha'],
|
|
|
|
duration: 1000
|
2013-01-05 22:31:38 +00:00
|
|
|
});
|
2013-01-06 03:40:31 +00:00
|
|
|
Mconsole.graph.removeAdjacence(from, to);
|
2013-01-05 22:31:38 +00:00
|
|
|
Mconsole.plot();
|
2013-01-05 21:28:04 +00:00
|
|
|
}
|
2013-01-06 03:40:31 +00:00
|
|
|
|
2013-01-06 23:40:48 +00:00
|
|
|
function hideSelectedEdges() {
|
|
|
|
for (var i = 0; i < selectedEdges.length; i += 1) {
|
|
|
|
var edge = selectedEdges[i];
|
|
|
|
hideEdge(edge);
|
|
|
|
}
|
|
|
|
selectedEdges = new Array();
|
|
|
|
}
|
|
|
|
|
2013-01-06 03:40:31 +00:00
|
|
|
function removeSelectedEdges() {
|
2013-01-06 04:37:24 +00:00
|
|
|
for (var i = 0; i < selectedEdges.length; i += 1) {
|
|
|
|
if (mapid != null) {
|
|
|
|
var edge = selectedEdges[i];
|
|
|
|
var id = edge.getData("id");
|
|
|
|
//delete mapping of id mapid
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2013-01-07 05:17:39 +00:00
|
|
|
url: "/synapses/" + mapid + "/" + id + "/removefrommap",
|
2013-01-06 04:37:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
hideEdge(edge);
|
|
|
|
}
|
|
|
|
selectedEdges = new Array();
|
2013-01-06 03:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSelectedEdges() {
|
|
|
|
for (var i = 0; i < selectedEdges.length; i += 1) {
|
|
|
|
var edge = selectedEdges[i];
|
|
|
|
var id = edge.getData("id");
|
|
|
|
$.ajax({
|
|
|
|
type: "DELETE",
|
|
|
|
url: "/synapses/" + id,
|
|
|
|
});
|
|
|
|
hideEdge(edge);
|
|
|
|
}
|
|
|
|
selectedEdges = new Array();
|
|
|
|
}
|
|
|
|
|
|
|
|
//keeps track of all selected edges globally
|
|
|
|
var selectedEdges = new Array();
|
|
|
|
|
|
|
|
function selectEdge(edge) {
|
|
|
|
var showDesc = edge.getData("showDesc");
|
|
|
|
if (! showDesc) {
|
|
|
|
edge.setData('showDesc', true, 'current');
|
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 4,
|
|
|
|
color: '#FFFFFF'
|
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 100
|
|
|
|
});
|
|
|
|
}
|
|
|
|
selectedEdges.push(edge);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deselectEdge(edge) {
|
|
|
|
var showDesc = edge.getData("showDesc");
|
|
|
|
if (showDesc) {
|
|
|
|
edge.setData('showDesc', false, 'current');
|
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 2,
|
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (edgeHover == edge) {
|
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 4,
|
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 100
|
|
|
|
});
|
|
|
|
}
|
|
|
|
selectedEdges.splice(selectedEdges.indexOf(edge), 1);
|
|
|
|
}
|
2013-01-07 05:17:39 +00:00
|
|
|
|
|
|
|
function hideSelectedNodes() {
|
|
|
|
Mconsole.graph.eachNode( function (n) {
|
|
|
|
if (n.data.$onCanvas == true && n.id != Mconsole.root) {
|
|
|
|
removeFromCanvas(n.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeSelectedNodes() {
|
|
|
|
Mconsole.graph.eachNode( function (n) {
|
|
|
|
if (n.data.$onCanvas == true && n.id != Mconsole.root) {
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "/topics/" + mapid + "/" + n.id + "/removefrommap",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSelectedNodes() {
|
|
|
|
Mconsole.graph.eachNode( function (n) {
|
|
|
|
if (n.data.$onCanvas == true && n.id != Mconsole.root) {
|
|
|
|
$.ajax({
|
|
|
|
type: "DELETE",
|
|
|
|
url: "/topics/" + n.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|