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',
|
|
|
|
//Change cursor style when hovering a node
|
|
|
|
onMouseEnter: function () {
|
2012-12-15 09:27:55 +00:00
|
|
|
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
onMouseLeave: function () {
|
2012-12-15 09:27:55 +00:00
|
|
|
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Update node positions when dragged
|
|
|
|
onDragMove: function (node, eventInfo, e) {
|
2012-12-26 03:47:02 +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) {
|
2012-12-21 04:45:44 +00:00
|
|
|
$('#item_addSynapse').val("true");
|
2012-12-21 00:24:27 +00:00
|
|
|
$('#new_item').fadeIn('fast');
|
2012-12-25 23:29:20 +00:00
|
|
|
addMetacode();
|
2012-12-21 00:24:27 +00:00
|
|
|
$('#item_name').focus();
|
|
|
|
}
|
|
|
|
else if (tempInit && tempNode2 != null) {
|
2012-12-21 04:45:44 +00:00
|
|
|
$('#item_addSynapse').val("false");
|
|
|
|
$('#synapse_item1id').val(tempNode.id);
|
|
|
|
$('#synapse_item2id').val(tempNode2.id);
|
2012-12-21 00:24:27 +00:00
|
|
|
$('#new_synapse').fadeIn('fast');
|
|
|
|
$('#synapse_desc').focus();
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDragCancel: function() {
|
2012-12-21 23:07:13 +00:00
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
|
|
|
$('#item_addSynapse').val("false");
|
|
|
|
$('#item_item1id').val(0);
|
|
|
|
$('#item_item2id').val(0);
|
|
|
|
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) {
|
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) {
|
2012-12-26 03:47:02 +00:00
|
|
|
selectEdgeOnClickHandler(node);
|
2012-12-21 00:24:27 +00:00
|
|
|
}
|
|
|
|
else if (node && !node.nodeFrom) {
|
2012-12-15 19:24:21 +00:00
|
|
|
selectNodeOnClickHandler(node);
|
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) {
|
2012-12-15 09:27:55 +00:00
|
|
|
var html =
|
|
|
|
'<div class="CardOnGraph" title="Click to Hide" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p>' +
|
|
|
|
'<img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" />' +
|
2012-12-21 23:07:13 +00:00
|
|
|
'<div class="scroll"><a href="/items/' + node.id + '" class="title">' + node.name + '</a>' +
|
2012-12-15 09:27:55 +00:00
|
|
|
'<div class="contributor">Added by: <a href="/users/' + node.getData('userid') + '">' + node.getData('username') + '</a></div>' +
|
|
|
|
'<div class="desc"><p>' + node.getData('desc') + '</p></div></div>' +
|
|
|
|
'<a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
|
|
|
var showCard = document.createElement('div');
|
|
|
|
showCard.className = 'showcard item_' + node.id;
|
|
|
|
showCard.innerHTML = html;
|
|
|
|
showCard.style.display = "none";
|
|
|
|
domElement.appendChild(showCard);
|
|
|
|
|
|
|
|
// add some events to the label
|
|
|
|
showCard.onclick = function(){
|
2012-12-16 06:12:41 +00:00
|
|
|
delete node.selected;
|
|
|
|
node.setData('dim', 25, 'current');
|
|
|
|
node.eachAdjacency(function (adj) {
|
|
|
|
adj.setDataset('end', {
|
2012-12-27 01:57:06 +00:00
|
|
|
lineWidth: 2,
|
2012-12-16 06:12:41 +00:00
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
adj.setData('showDesc', false, 'current');
|
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 500
|
|
|
|
});
|
2012-12-15 09:27:55 +00:00
|
|
|
$('.showcard.item_' + node.id).fadeOut('fast', function(){
|
|
|
|
$('.name').css('display','block');
|
|
|
|
Mconsole.plot();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a 'name' button and add it
|
2012-12-15 07:39:14 +00:00
|
|
|
// to the main node label
|
|
|
|
var nameContainer = document.createElement('span'),
|
|
|
|
style = nameContainer.style;
|
2012-12-15 09:27:55 +00:00
|
|
|
nameContainer.className = 'name item_' + node.id;
|
2012-12-15 07:39:14 +00:00
|
|
|
nameContainer.innerHTML = '<div class="label">' + node.name + '</div>';
|
|
|
|
domElement.appendChild(nameContainer);
|
|
|
|
style.fontSize = "0.9em";
|
2012-12-15 09:27:55 +00:00
|
|
|
style.color = "#222222";
|
|
|
|
|
|
|
|
// add some events to the label
|
2012-12-16 06:12:41 +00:00
|
|
|
nameContainer.onclick = function(){
|
2012-12-16 20:00:43 +00:00
|
|
|
selectNodeOnClickHandler(node)
|
2012-12-15 09:27:55 +00:00
|
|
|
}
|
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;
|
|
|
|
style.left = (left - w / 2) + 'px';
|
2012-12-16 06:12:41 +00:00
|
|
|
style.top = (top+25) + 'px';
|
2012-12-14 18:31:39 +00:00
|
|
|
style.display = '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} 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',
|
|
|
|
//Change cursor style when hovering a node
|
|
|
|
onMouseEnter: function () {
|
2012-12-16 20:00:43 +00:00
|
|
|
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
onMouseLeave: function () {
|
2012-12-16 20:00:43 +00:00
|
|
|
|
2012-12-14 18:31:39 +00:00
|
|
|
},
|
|
|
|
//Update node positions when dragged
|
|
|
|
onDragMove: function (node, eventInfo, e) {
|
2012-12-26 03:47:02 +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) {
|
|
|
|
$('#item_addSynapse').val("true");
|
|
|
|
$('#new_item').fadeIn('fast');
|
|
|
|
addMetacode();
|
|
|
|
$('#item_name').focus();
|
|
|
|
}
|
|
|
|
else if (tempInit && tempNode2 != null) {
|
2012-12-21 23:07:13 +00:00
|
|
|
$('#item_addSynapse').val("false");
|
|
|
|
$('#synapse_item1id').val(tempNode.id);
|
|
|
|
$('#synapse_item2id').val(tempNode2.id);
|
|
|
|
$('#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) {
|
2012-12-21 00:24:27 +00:00
|
|
|
//clicking on an edge, a node, or clicking on blank part of canvas?
|
2012-12-26 03:47:02 +00:00
|
|
|
if (eventInfo.getEdge() != false || node.nodeFrom) {
|
|
|
|
if (eventInfo.getEdge() != false) selectEdgeOnClickHandler(eventInfo.getEdge());
|
|
|
|
else if (node.nodeFrom) selectEdgeOnClickHandler(node);
|
2012-12-21 00:24:27 +00:00
|
|
|
}
|
|
|
|
else if (node && !node.nodeFrom) {
|
2012-12-16 20:00:43 +00:00
|
|
|
if (!Mconsole.busy) {
|
|
|
|
selectNodeOnClickHandler(node);
|
|
|
|
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) {
|
2012-12-16 20:00:43 +00:00
|
|
|
var html =
|
|
|
|
'<div class="CardOnGraph" title="Click to Hide" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p>' +
|
|
|
|
'<img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" />' +
|
2012-12-21 23:07:13 +00:00
|
|
|
'<div class="scroll"><a href="/items/' + node.id + '" class="title">' + node.name + '</a>' +
|
2012-12-16 20:00:43 +00:00
|
|
|
'<div class="contributor">Added by: <a href="/users/' + node.getData('userid') + '">' + node.getData('username') + '</a></div>' +
|
|
|
|
'<div class="desc"><p>' + node.getData('desc') + '</p></div></div>' +
|
|
|
|
'<a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
|
|
|
var showCard = document.createElement('div');
|
|
|
|
showCard.className = 'showcard item_' + node.id;
|
|
|
|
showCard.innerHTML = html;
|
|
|
|
showCard.style.display = "none";
|
|
|
|
domElement.appendChild(showCard);
|
|
|
|
|
|
|
|
// add some events to the label
|
|
|
|
showCard.onclick = function(){
|
|
|
|
if (!Mconsole.busy) {
|
|
|
|
delete node.selected;
|
|
|
|
node.setData('dim', 25, 'current');
|
|
|
|
node.eachAdjacency(function (adj) {
|
|
|
|
adj.setDataset('end', {
|
2012-12-27 01:57:06 +00:00
|
|
|
lineWidth: 2,
|
2012-12-16 20:00:43 +00:00
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
adj.setData('showDesc', false, 'current');
|
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
|
|
|
modes: ['edge-property:lineWidth:color'],
|
|
|
|
duration: 500
|
|
|
|
});
|
|
|
|
$('.showcard.item_' + node.id).fadeOut('fast', function(){
|
|
|
|
$('.name').css('display','block');
|
|
|
|
Mconsole.plot();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a 'name' button and add it
|
|
|
|
// to the main node label
|
|
|
|
var nameContainer = document.createElement('span'),
|
|
|
|
style = nameContainer.style;
|
|
|
|
nameContainer.className = 'name item_' + node.id;
|
|
|
|
nameContainer.innerHTML = '<div class="label">' + node.name + '</div>';
|
|
|
|
domElement.appendChild(nameContainer);
|
|
|
|
style.fontSize = "0.9em";
|
|
|
|
style.color = "#222222";
|
|
|
|
|
|
|
|
// add some events to the label
|
|
|
|
nameContainer.onclick = function(){
|
|
|
|
if (!Mconsole.busy) {
|
|
|
|
selectNodeOnClickHandler(node);
|
|
|
|
Mconsole.onClick(node.id, {
|
|
|
|
hideLabels: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
style.left = (left - w / 2) + 'px';
|
2012-12-16 20:00:43 +00:00
|
|
|
style.top = (top+25) + 'px';
|
2012-12-14 18:31:39 +00:00
|
|
|
style.display = '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
midPoint.x += (vect.x / 0.7);
|
|
|
|
midPoint.y += (vect.y / 0.7);
|
|
|
|
// compute the tail intersection point with the edge line
|
|
|
|
var intermediatePoint = new $jit.Complex(midPoint.x - vect.x,
|
|
|
|
midPoint.y - vect.y);
|
|
|
|
// 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));
|
|
|
|
|
2012-12-26 03:47:02 +00:00
|
|
|
//ctx.strokeStyle = 'black';
|
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);
|
|
|
|
ctx.lineTo(midPoint.x, midPoint.y);
|
|
|
|
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'),
|
|
|
|
cat = node.getData('itemcatname'),
|
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
|
2012-12-26 03:47:02 +00:00
|
|
|
var desc = adj.getData("desc") + ' (' + adj.getData("id") + ')';
|
2012-12-15 07:39:14 +00:00
|
|
|
var showDesc = adj.getData("showDesc");
|
|
|
|
if( desc != "" && showDesc ) {
|
|
|
|
//now adjust the label placement
|
|
|
|
var radius = canvas.getSize();
|
|
|
|
var x = parseInt((pos.x + posChild.x - (desc.length * 5)) /2);
|
|
|
|
var y = parseInt((pos.y + posChild.y) /2);
|
|
|
|
canvas.getCtx().fillStyle = '#000';
|
|
|
|
canvas.getCtx().font = 'bold 14px arial';
|
2012-12-21 00:24:27 +00:00
|
|
|
canvas.getCtx().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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-21 00:24:27 +00:00
|
|
|
function selectEdgeOnClickHandler(adj) {
|
|
|
|
var showDesc = adj.getData("showDesc");
|
|
|
|
if (showDesc) {
|
|
|
|
adj.setData('showDesc', false, 'current');
|
|
|
|
Mconsole.plot();
|
|
|
|
} else if (!showDesc) {
|
|
|
|
adj.setData('showDesc', true, 'current');
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
|
|
|
}//selectEdgeOnClickHandler
|
|
|
|
|
2012-12-15 19:24:21 +00:00
|
|
|
function selectNodeOnClickHandler(node) {
|
2012-12-16 06:12:41 +00:00
|
|
|
|
|
|
|
$('.showcard').css('display','none');
|
|
|
|
$('.name').css('display','block');
|
|
|
|
$('.name.item_' + node.id).css('display','none');
|
|
|
|
$('.showcard.item_' + node.id).fadeIn('fast');
|
|
|
|
|
2012-12-15 19:24:21 +00:00
|
|
|
//set final styles
|
|
|
|
Mconsole.graph.eachNode(function (n) {
|
|
|
|
if (n.id != node.id) delete n.selected;
|
2012-12-16 06:12:41 +00:00
|
|
|
n.setData('dim', 25, 'current');
|
2012-12-15 19:24:21 +00:00
|
|
|
n.eachAdjacency(function (adj) {
|
|
|
|
adj.setDataset('end', {
|
2012-12-27 01:57:06 +00:00
|
|
|
lineWidth: 2,
|
2012-12-15 19:24:21 +00:00
|
|
|
color: '#222222'
|
|
|
|
});
|
|
|
|
adj.setData('showDesc', false, 'current');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (!node.selected) {
|
|
|
|
node.selected = true;
|
2012-12-16 20:00:43 +00:00
|
|
|
node.setData('dim', 1, 'current');
|
|
|
|
|
2012-12-15 19:24:21 +00:00
|
|
|
node.eachAdjacency(function (adj) {
|
|
|
|
adj.setDataset('end', {
|
2012-12-26 03:47:02 +00:00
|
|
|
lineWidth: 4,
|
2012-12-15 19:24:21 +00:00
|
|
|
color: '#FFF'
|
|
|
|
});
|
|
|
|
adj.setData('showDesc', true, 'current');
|
|
|
|
});
|
|
|
|
} else {
|
2012-12-16 06:12:41 +00:00
|
|
|
node.setData('dim', 25, 'current');
|
2012-12-15 19:24:21 +00:00
|
|
|
delete node.selected;
|
|
|
|
}
|
|
|
|
//trigger animation to final styles
|
|
|
|
Mconsole.fx.animate({
|
2012-12-16 06:12:41 +00:00
|
|
|
modes: ['edge-property:lineWidth:color'],
|
2012-12-15 19:24:21 +00:00
|
|
|
duration: 500
|
|
|
|
});
|
|
|
|
}//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 :)
|
2012-12-16 20:00:43 +00:00
|
|
|
$('#item_grabItem').val("null");
|
2012-12-21 04:45:44 +00:00
|
|
|
$('#item_addSynapse').val("false");
|
2012-12-16 00:46:39 +00:00
|
|
|
document.getElementById('new_item').style.left = e.x + "px";
|
|
|
|
document.getElementById('new_item').style.top = e.y + "px";
|
2012-12-16 06:12:41 +00:00
|
|
|
$('#item_x').val(canvasLoc.x);
|
|
|
|
$('#item_y').val(canvasLoc.y);
|
2012-12-16 00:46:39 +00:00
|
|
|
$('#new_item').fadeIn('fast');
|
2012-12-25 23:29:20 +00:00
|
|
|
addMetacode();
|
2012-12-16 00:46:39 +00:00
|
|
|
$('#item_name').focus();
|
|
|
|
} else {
|
|
|
|
canvasDoubleClickHandlerObject.storedTime = now;
|
2012-12-26 03:47:02 +00:00
|
|
|
$('#new_item').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');
|
|
|
|
$('#new_item').fadeOut('fast');
|
|
|
|
var pos = eventInfo.getPos();
|
|
|
|
// if it's a left click, move the node
|
2012-12-25 23:29:20 +00:00
|
|
|
if (e.button == 0 && !e.altKey ) {
|
2012-12-21 23:07:13 +00:00
|
|
|
node.pos.setc(pos.x, pos.y);
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
|
|
|
// if it's a right click, start synapse creation
|
2012-12-25 23:29:20 +00:00
|
|
|
else if (e.button == 2 || (e.button == 0 && e.altKey)) {
|
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 :)
|
|
|
|
$('#item_grabItem').val("null");
|
|
|
|
var myX = e.x - 110;
|
|
|
|
var myY = e.y - 30;
|
|
|
|
document.getElementById('new_item').style.left = myX + "px";
|
|
|
|
document.getElementById('new_item').style.top = myY + "px";
|
|
|
|
document.getElementById('new_synapse').style.left = myX + "px";
|
|
|
|
document.getElementById('new_synapse').style.top = myY + "px";
|
|
|
|
$('#item_x').val(eventInfo.getPos().x);
|
|
|
|
$('#item_y').val(eventInfo.getPos().y);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|