2013-01-11 03:01:24 +00:00
|
|
|
/*
|
|
|
|
* @file
|
|
|
|
* This function defines all settings and event callbacks for the JIT graph. Some are found in other files
|
|
|
|
* First is the common settings (the same as arranged or chaotic)
|
|
|
|
* Then if it's a centred graph additional settings are added.
|
|
|
|
*/
|
2012-12-14 18:31:39 +00:00
|
|
|
|
2013-02-19 14:44:43 +00:00
|
|
|
function graphSettings(type, embed) {
|
2013-01-11 03:01:24 +00:00
|
|
|
var t = {
|
|
|
|
//id of the visualization container
|
|
|
|
injectInto: 'infovis',
|
|
|
|
//Enable zooming and panning
|
|
|
|
//by scrolling and DnD
|
|
|
|
Navigation: {
|
|
|
|
enable: true,
|
|
|
|
//Enable panning events only if we're dragging the empty
|
|
|
|
//canvas (and not a node).
|
|
|
|
panning: 'avoid nodes',
|
2013-04-26 04:07:29 +00:00
|
|
|
zooming: 28 //zoom speed. higher is more sensible
|
2013-01-11 03:01:24 +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',
|
2013-01-24 04:40:06 +00:00
|
|
|
lineWidth: 2,
|
|
|
|
alpha: 0.4
|
2013-01-11 03:01:24 +00:00
|
|
|
},
|
|
|
|
//Native canvas text styling
|
|
|
|
Label: {
|
2014-01-29 03:46:58 +00:00
|
|
|
type: 'Native', //Native or HTML
|
2013-01-11 03:01:24 +00:00
|
|
|
size: 20,
|
2014-01-31 00:32:15 +00:00
|
|
|
family: 'arial',
|
2014-01-29 03:46:58 +00:00
|
|
|
textBaseline: 'hanging',
|
2014-02-04 01:43:31 +00:00
|
|
|
color:'#DDD'
|
2013-01-11 03:01:24 +00:00
|
|
|
//style: 'bold'
|
|
|
|
},
|
|
|
|
//Add Tips
|
|
|
|
Tips: {
|
|
|
|
enable: false,
|
|
|
|
onShow: function (tip, node) {}
|
|
|
|
},
|
|
|
|
// Add node events
|
|
|
|
Events: {
|
|
|
|
enable: true,
|
|
|
|
enableForEdges: true,
|
|
|
|
onMouseMove: function(node, eventInfo, e) {
|
|
|
|
onMouseMoveHandler(node, eventInfo, e);
|
|
|
|
},
|
|
|
|
//Update node positions when dragged
|
|
|
|
onDragMove: function (node, eventInfo, e) {
|
2013-03-17 06:29:17 +00:00
|
|
|
onDragMoveTopicHandler(node, eventInfo, e);
|
2013-01-11 03:01:24 +00:00
|
|
|
},
|
|
|
|
onDragEnd: function(node, eventInfo, e) {
|
|
|
|
onDragEndTopicHandler(node, eventInfo, e, false);
|
|
|
|
},
|
|
|
|
onDragCancel: function(node, eventInfo, e) {
|
|
|
|
onDragCancelHandler(node, eventInfo, e, false);
|
|
|
|
},
|
|
|
|
//Implement the same handler for touchscreens
|
2013-03-17 06:29:17 +00:00
|
|
|
onTouchStart: function (node, eventInfo, e) {
|
|
|
|
//$jit.util.event.stop(e); //stop default touchmove event
|
|
|
|
//Mconsole.events.onMouseDown(e, null, eventInfo);
|
|
|
|
Mconsole.events.touched = true;
|
|
|
|
touchPos = eventInfo.getPos();
|
|
|
|
var canvas = Mconsole.canvas,
|
|
|
|
ox = canvas.translateOffsetX;
|
|
|
|
oy = canvas.translateOffsetY,
|
|
|
|
sx = canvas.scaleOffsetX,
|
|
|
|
sy = canvas.scaleOffsetY;
|
|
|
|
touchPos.x *= sx;
|
|
|
|
touchPos.y *= sy;
|
|
|
|
touchPos.x += ox;
|
|
|
|
touchPos.y += oy;
|
|
|
|
|
|
|
|
touchDragNode = node;
|
|
|
|
},
|
|
|
|
//Implement the same handler for touchscreens
|
2013-01-11 03:01:24 +00:00
|
|
|
onTouchMove: function (node, eventInfo, e) {
|
2013-03-17 06:29:17 +00:00
|
|
|
if (touchDragNode) onDragMoveTopicHandler(touchDragNode, eventInfo, e);
|
|
|
|
else {
|
|
|
|
touchPanZoomHandler(eventInfo, e);
|
2013-03-17 09:18:30 +00:00
|
|
|
Mconsole.labels.hideLabel(Mconsole.graph.getNode(MetamapsModel.showcardInUse));
|
2013-03-17 06:29:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
//Implement the same handler for touchscreens
|
|
|
|
onTouchEnd: function (node, eventInfo, e) {
|
2013-03-17 09:18:30 +00:00
|
|
|
|
2013-03-17 06:29:17 +00:00
|
|
|
},
|
|
|
|
//Implement the same handler for touchscreens
|
|
|
|
onTouchCancel: function (node, eventInfo, e) {
|
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
},
|
|
|
|
//Add also a click handler to nodes
|
|
|
|
onClick: function (node, eventInfo, e) {
|
2013-03-29 06:38:13 +00:00
|
|
|
if (MetamapsModel.boxStartCoordinates) {
|
|
|
|
Mconsole.busy = false;
|
|
|
|
MetamapsModel.boxEndCoordinates = eventInfo.getPos();
|
|
|
|
selectNodesWithBox();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
if (e.target.id != "infovis-canvas") return false;
|
2013-01-30 23:58:27 +00:00
|
|
|
|
2013-03-29 06:38:13 +00:00
|
|
|
//clicking on a edge, node, or clicking on blank part of canvas?
|
2013-01-11 03:01:24 +00:00
|
|
|
if (node.nodeFrom) {
|
|
|
|
selectEdgeOnClickHandler(node, e);
|
|
|
|
} else if (node && !node.nodeFrom) {
|
|
|
|
selectNodeOnClickHandler(node, e);
|
|
|
|
} else {
|
2013-03-17 06:29:17 +00:00
|
|
|
//topic and synapse editing cards
|
2013-04-26 04:07:29 +00:00
|
|
|
if (!MetamapsModel.didPan) {
|
|
|
|
hideCards();
|
|
|
|
}
|
2013-01-11 03:01:24 +00:00
|
|
|
canvasDoubleClickHandler(eventInfo.getPos(), e);
|
|
|
|
}//if
|
2014-01-29 03:46:58 +00:00
|
|
|
},
|
|
|
|
onRightClick: function (node, eventInfo, e) {
|
2014-01-31 02:28:10 +00:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
if (node && !node.nodeFrom) {
|
2014-01-31 00:32:15 +00:00
|
|
|
selectNodeOnRightClickHandler(node, e);
|
2014-01-29 03:46:58 +00:00
|
|
|
}
|
|
|
|
else if (node && node.nodeFrom) { // the variable 'node' is actually an edge/adjacency
|
|
|
|
// open right click menu
|
2014-02-21 01:22:13 +00:00
|
|
|
selectEdgeOnRightClickHandler(node, e);
|
2014-01-29 03:46:58 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// right click on open canvas, options here?
|
|
|
|
}
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|
2013-01-11 03:19:44 +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).
|
2014-01-29 03:46:58 +00:00
|
|
|
//onCreateLabel: function (domElement, node) {
|
|
|
|
// onCreateLabelHandler(type, domElement, node);
|
|
|
|
//},
|
2013-01-11 03:19:44 +00:00
|
|
|
// Change node styles when DOM labels are placed or moved.
|
2014-01-29 03:46:58 +00:00
|
|
|
//onPlaceLabel: function (domElement, node) {
|
|
|
|
// onPlaceLabelHandler(domElement, node);
|
|
|
|
//}
|
2013-01-11 03:01:24 +00:00
|
|
|
};
|
|
|
|
|
2013-02-19 14:44:43 +00:00
|
|
|
if (embed) {
|
|
|
|
t.Edge.type = 'customEdgeEmbed';
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
if (type == "centered") {
|
|
|
|
t.background = {
|
|
|
|
CanvasStyles: {
|
|
|
|
strokeStyle: '#333',
|
|
|
|
lineWidth: 1.5
|
|
|
|
}
|
|
|
|
};
|
2014-03-03 00:36:18 +00:00
|
|
|
t.levelDistance = 280;
|
2013-01-11 03:01:24 +00:00
|
|
|
t.Events.enableForEdges = true;
|
|
|
|
t.Events.onDragEnd = function(node, eventInfo, e) {
|
|
|
|
//different because we can't go realtime
|
|
|
|
onDragEndTopicHandler(node, eventInfo, e, false);
|
|
|
|
};
|
|
|
|
t.Events.onDragCancel = function(node, eventInfo, e) {
|
|
|
|
//different because we're centred
|
|
|
|
onDragCancelHandler(node, eventInfo, e, true);
|
|
|
|
};
|
2013-11-14 17:28:31 +00:00
|
|
|
/*t.Events.onClick = function(node, eventInfo, e) {
|
2013-01-11 03:01:24 +00:00
|
|
|
//this is handled mostly differently than in arranged/chaotic
|
|
|
|
if (e.target.id != "infovis-canvas") return false;
|
2013-02-15 02:08:58 +00:00
|
|
|
|
2013-02-15 03:23:14 +00:00
|
|
|
//hide synapse and topic editing dialog
|
|
|
|
hideCards();
|
2013-02-15 02:08:58 +00:00
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
//clicking on an edge, a node, or clicking on blank part of canvas?
|
|
|
|
if (node.nodeFrom) {
|
|
|
|
selectEdgeOnClickHandler(node, e);
|
|
|
|
} else if (node && !node.nodeFrom) {
|
|
|
|
//node is actually a node :)
|
2013-11-14 17:28:31 +00:00
|
|
|
selectNodeOnClickHandler(node, e);
|
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
} else {
|
|
|
|
canvasDoubleClickHandler(eventInfo.getPos(), e);
|
|
|
|
}
|
2013-11-14 17:28:31 +00:00
|
|
|
};*/
|
2013-01-11 03:01:24 +00:00
|
|
|
}//if
|
2013-01-06 03:40:31 +00:00
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
return t;
|
|
|
|
}//graphSettings
|
2012-12-15 07:39:14 +00:00
|
|
|
|
2013-02-15 03:23:14 +00:00
|
|
|
function hideCards() {
|
|
|
|
$('#edit_synapse').hide();
|
2013-04-26 04:07:29 +00:00
|
|
|
MetamapsModel.edgecardInUse = null;
|
2013-02-15 03:23:14 +00:00
|
|
|
hideCurrentCard();
|
2014-01-31 02:28:10 +00:00
|
|
|
// delete right click menu
|
|
|
|
$('.rightclickmenu').remove();
|
2013-02-15 03:23:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 05:47:32 +00:00
|
|
|
// defining code to draw edges with arrows pointing in one direction
|
2014-01-29 03:46:58 +00:00
|
|
|
var renderMidArrow = function(from, to, dim, swap, canvas, placement, newSynapse){
|
2012-12-23 06:12:56 +00:00
|
|
|
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
|
2014-01-29 03:46:58 +00:00
|
|
|
var newX = (to.x - from.x) * placement + from.x;
|
|
|
|
var newY = (to.y - from.y) * placement + from.y;
|
|
|
|
var midPoint = new $jit.Complex(newX, newY);
|
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
// 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-27 22:21:19 +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));
|
2014-01-29 03:46:58 +00:00
|
|
|
|
|
|
|
if (newSynapse) {
|
|
|
|
ctx.strokeStyle = "#222222";
|
|
|
|
ctx.lineWidth = 2;
|
|
|
|
ctx.globalAlpha = 0.4;
|
|
|
|
}
|
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'),
|
2013-03-15 00:53:01 +00:00
|
|
|
greenCircle = node.getData('greenCircle'),
|
|
|
|
whiteCircle = node.getData('whiteCircle'),
|
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
|
2013-03-15 00:53:01 +00:00
|
|
|
if (greenCircle) {
|
2012-12-25 23:29:20 +00:00
|
|
|
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
|
2013-03-15 00:53:01 +00:00
|
|
|
if (whiteCircle) {
|
2012-12-22 19:52:16 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(pos.x, pos.y, dim+3, 0, 2 * Math.PI, false);
|
2013-02-19 14:44:43 +00:00
|
|
|
if (! MetamapsModel.embed) ctx.strokeStyle = 'white';
|
|
|
|
if (MetamapsModel.embed) ctx.strokeStyle = '#999';
|
2012-12-23 06:12:56 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 22:21:19 +00:00
|
|
|
var renderEdgeArrows = function(edgeHelper, adj) {
|
|
|
|
var canvas = Mconsole.canvas;
|
|
|
|
var directionCat = adj.getData('category');
|
|
|
|
var direction = adj.getData('direction');
|
|
|
|
var pos = adj.nodeFrom.pos.getc(true);
|
|
|
|
var posChild = adj.nodeTo.pos.getc(true);
|
|
|
|
|
|
|
|
//plot arrow edge
|
|
|
|
if (directionCat == "none") {
|
2013-01-27 22:58:43 +00:00
|
|
|
edgeHelper.line.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, canvas);
|
2013-01-27 22:21:19 +00:00
|
|
|
}
|
|
|
|
else if (directionCat == "both") {
|
2014-01-29 03:46:58 +00:00
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, true, canvas, 0.7);
|
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, false, canvas, 0.7);
|
2013-01-27 22:21:19 +00:00
|
|
|
}
|
|
|
|
else if (directionCat == "from-to") {
|
|
|
|
var direction = adj.data.$direction;
|
|
|
|
var inv = (direction && direction.length > 1 && direction[0] != adj.nodeFrom.id);
|
2014-01-29 03:46:58 +00:00
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, inv, canvas, 0.7);
|
|
|
|
renderMidArrow({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 13, inv, canvas, 0.3);
|
2013-01-27 22:21:19 +00:00
|
|
|
}
|
|
|
|
}//renderEdgeArrow
|
|
|
|
|
2012-12-15 07:39:14 +00:00
|
|
|
// 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
|
2013-01-27 22:21:19 +00:00
|
|
|
renderEdgeArrows(this.edgeHelper, adj);
|
2012-12-15 07:39:14 +00:00
|
|
|
|
|
|
|
//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-02-16 22:32:50 +00:00
|
|
|
// '&' to '&'
|
|
|
|
desc = decodeEntities(desc);
|
|
|
|
|
2013-01-08 01:34:47 +00:00
|
|
|
//now adjust the label placement
|
|
|
|
var ctx = canvas.getCtx();
|
2014-03-02 03:02:27 +00:00
|
|
|
ctx.font = '14px arial';
|
|
|
|
ctx.fillStyle = '#222222';
|
|
|
|
ctx.textBaseline = 'hanging';
|
|
|
|
|
|
|
|
// helper function to determine how many lines are needed
|
|
|
|
// Line Splitter Function
|
|
|
|
// copyright Stephen Chapman, 19th April 2006
|
|
|
|
// you may copy this code but please keep the copyright notice as well
|
|
|
|
function splitLine(st,n) {var b = ''; var s = st;while (s.length > n) {var c = s.substring(0,n);var d = c.lastIndexOf(' ');var e =c.lastIndexOf('\n');if (e != -1) d = e; if (d == -1) d = n; b += c.substring(0,d) + '\n';s = s.substring(d+1);}return b+s;}
|
|
|
|
var arrayOfLabelLines = splitLine(desc,30).split('\n');
|
|
|
|
var index, lineWidths = [];
|
|
|
|
for (index = 0; index < arrayOfLabelLines.length; ++index) {
|
|
|
|
lineWidths.push( ctx.measureText( arrayOfLabelLines[index] ).width )
|
|
|
|
}
|
|
|
|
var width = Math.max.apply(null, lineWidths) + 8;
|
|
|
|
var height = (16 * arrayOfLabelLines.length) + 8;
|
|
|
|
|
|
|
|
var x = (pos.x + posChild.x - width)/2;
|
|
|
|
var y = ((pos.y + posChild.y) /2) - height/2;
|
|
|
|
var radius = 5;
|
2013-01-08 01:34:47 +00:00
|
|
|
|
|
|
|
//render background
|
|
|
|
ctx.beginPath();
|
2014-03-02 03:02:27 +00:00
|
|
|
ctx.moveTo(x + radius, y);
|
|
|
|
ctx.lineTo(x + width - radius, y);
|
|
|
|
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
|
|
ctx.lineTo(x + width, y + height - radius);
|
|
|
|
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
|
|
ctx.lineTo(x + radius, y + height);
|
|
|
|
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
|
|
ctx.lineTo(x, y + radius);
|
|
|
|
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
|
|
ctx.closePath();
|
2013-02-19 14:44:43 +00:00
|
|
|
ctx.fill();
|
|
|
|
|
|
|
|
//render text
|
2014-03-02 03:02:27 +00:00
|
|
|
ctx.fillStyle = '#FFF';
|
|
|
|
ctx.textAlign = 'center';
|
|
|
|
for (index = 0; index < arrayOfLabelLines.length; ++index) {
|
|
|
|
ctx.fillText(arrayOfLabelLines[index], x + (width/2), y + 5 + (16*index));
|
|
|
|
}
|
2013-02-19 14:44:43 +00:00
|
|
|
}
|
|
|
|
}, 'contains' : function(adj, pos) {
|
|
|
|
var from = adj.nodeFrom.pos.getc(true),
|
|
|
|
to = adj.nodeTo.pos.getc(true);
|
|
|
|
return this.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var edgeSettingsEmbed = {
|
|
|
|
'customEdgeEmbed': {
|
|
|
|
'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
|
|
|
|
renderEdgeArrows(this.edgeHelper, adj);
|
|
|
|
|
|
|
|
//check for edge label in data
|
|
|
|
var desc = adj.getData("desc");
|
|
|
|
var showDesc = adj.getData("showDesc");
|
|
|
|
if( desc != "" && showDesc ) {
|
|
|
|
// '&' to '&'
|
|
|
|
desc = decodeEntities(desc);
|
|
|
|
|
|
|
|
//now adjust the label placement
|
|
|
|
var ctx = canvas.getCtx();
|
|
|
|
var radius = canvas.getSize();
|
|
|
|
var x = parseInt((pos.x + posChild.x - (desc.length * 5)) /2);
|
|
|
|
var y = parseInt((pos.y + posChild.y) /2);
|
|
|
|
ctx.font = 'bold 14px arial';
|
|
|
|
|
|
|
|
//render background
|
|
|
|
ctx.fillStyle = '#999';
|
|
|
|
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);
|
2013-01-08 01:34:47 +00:00
|
|
|
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-03-22 06:37:56 +00:00
|
|
|
function drawSelectBox(eventInfo, e) {
|
2013-03-29 06:38:13 +00:00
|
|
|
Mconsole.plot();
|
2013-03-22 06:37:56 +00:00
|
|
|
var ctx=Mconsole.canvas.getCtx();
|
|
|
|
|
|
|
|
var startX = MetamapsModel.boxStartCoordinates.x,
|
|
|
|
startY = MetamapsModel.boxStartCoordinates.y,
|
|
|
|
currX = eventInfo.getPos().x,
|
|
|
|
currY = eventInfo.getPos().y;
|
|
|
|
|
|
|
|
Mconsole.plot();
|
2013-07-11 15:13:27 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(startX, startY);
|
|
|
|
ctx.lineTo(startX, currY);
|
|
|
|
ctx.lineTo(currX, currY);
|
|
|
|
ctx.lineTo(currX, startY);
|
|
|
|
ctx.lineTo(startX, startY);
|
|
|
|
ctx.strokeStyle = "black";
|
2013-03-22 06:37:56 +00:00
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectNodesWithBox() {
|
|
|
|
|
|
|
|
var sX = MetamapsModel.boxStartCoordinates.x,
|
|
|
|
sY = MetamapsModel.boxStartCoordinates.y,
|
|
|
|
eX = MetamapsModel.boxEndCoordinates.x,
|
|
|
|
eY = MetamapsModel.boxEndCoordinates.y;
|
|
|
|
|
|
|
|
|
|
|
|
Mconsole.graph.eachNode(function (n) {
|
2013-11-14 17:28:31 +00:00
|
|
|
var x = gType == "centered" ? n.pos.toComplex().x : n.pos.x,
|
|
|
|
y = gType == "centered" ? n.pos.toComplex().y : n.pos.y;
|
2013-03-22 06:37:56 +00:00
|
|
|
|
|
|
|
if ((sX < x && x < eX && sY < y && y < eY) || (sX > x && x > eX && sY > y && y > eY) || (sX > x && x > eX && sY < y && y < eY) || (sX < x && x < eX && sY > y && y > eY)) {
|
2013-04-26 04:07:29 +00:00
|
|
|
var nodeIsSelected = MetamapsModel.selectedNodes.indexOf(n);
|
|
|
|
if (nodeIsSelected == -1) selectNode(n); // the node is not selected, so select it
|
|
|
|
else if (nodeIsSelected != -1) deselectNode(n); // the node is selected, so deselect it
|
|
|
|
|
2013-03-22 06:37:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
MetamapsModel.boxStartCoordinates = false;
|
|
|
|
MetamapsModel.boxEndCoordinates = false;
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
2013-01-05 22:31:38 +00:00
|
|
|
|
2013-01-05 21:28:04 +00:00
|
|
|
function onMouseMoveHandler(node, eventInfo, e) {
|
2013-01-24 03:05:24 +00:00
|
|
|
|
|
|
|
if (Mconsole.busy) return;
|
|
|
|
|
2013-01-06 04:12:32 +00:00
|
|
|
var node = eventInfo.getNode();
|
2013-01-11 03:01:24 +00:00
|
|
|
var edge = eventInfo.getEdge();
|
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) {
|
2013-01-11 03:01:24 +00:00
|
|
|
if (MetamapsModel.edgeHoveringOver) {
|
|
|
|
onMouseLeave(MetamapsModel.edgeHoveringOver);
|
2013-01-06 04:12:32 +00:00
|
|
|
}
|
2014-03-02 19:53:22 +00:00
|
|
|
$('canvas').css('cursor', 'pointer');
|
2013-01-06 04:12:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-02 19:53:22 +00:00
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
if (edge == false && MetamapsModel.edgeHoveringOver != false) {
|
2013-01-05 22:31:38 +00:00
|
|
|
//mouse not on an edge, but we were on an edge previously
|
2013-01-11 03:01:24 +00:00
|
|
|
onMouseLeave(MetamapsModel.edgeHoveringOver);
|
|
|
|
} else if (edge != false && MetamapsModel.edgeHoveringOver == 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-11 03:01:24 +00:00
|
|
|
} else if (edge != false && MetamapsModel.edgeHoveringOver != edge) {
|
2013-01-05 22:31:38 +00:00
|
|
|
//mouse is on an edge, but a different edge is stored
|
2013-01-11 03:01:24 +00:00
|
|
|
onMouseLeave(MetamapsModel.edgeHoveringOver)
|
2013-01-06 03:40:31 +00:00
|
|
|
onMouseEnter(edge);
|
2013-01-05 21:28:04 +00:00
|
|
|
}
|
2013-01-27 22:21:19 +00:00
|
|
|
|
|
|
|
//could be false
|
2013-01-11 03:01:24 +00:00
|
|
|
MetamapsModel.edgeHoveringOver = edge;
|
2014-03-02 20:01:06 +00:00
|
|
|
|
|
|
|
if (!node && !edge) {
|
|
|
|
$('canvas').css('cursor', 'default');
|
|
|
|
}
|
2013-01-05 22:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseEnter(edge) {
|
|
|
|
$('canvas').css('cursor', 'pointer');
|
2013-04-26 04:07:29 +00:00
|
|
|
var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(edge);
|
|
|
|
//following if statement only executes if the edge being hovered over is not selected
|
|
|
|
if (edgeIsSelected == -1) {
|
|
|
|
edge.setData('showDesc', true, 'current');
|
2013-01-06 03:40:31 +00:00
|
|
|
edge.setDataset('end', {
|
2013-04-26 04:07:29 +00:00
|
|
|
lineWidth: 4,
|
|
|
|
alpha: 1
|
2013-01-06 03:40:31 +00:00
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
2013-01-24 04:40:06 +00:00
|
|
|
modes: ['edge-property:lineWidth:color:alpha'],
|
2013-01-06 03:40:31 +00:00
|
|
|
duration: 100
|
|
|
|
});
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
2013-01-05 22:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseLeave(edge) {
|
|
|
|
$('canvas').css('cursor', 'default');
|
2013-04-26 04:07:29 +00:00
|
|
|
var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(edge);
|
|
|
|
//following if statement only executes if the edge being hovered over is not selected
|
|
|
|
if (edgeIsSelected == -1) {
|
|
|
|
edge.setData('showDesc', false, 'current');
|
2013-01-06 03:40:31 +00:00
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 2,
|
2013-01-24 04:40:06 +00:00
|
|
|
alpha: 0.4
|
2013-01-06 03:40:31 +00:00
|
|
|
});
|
|
|
|
Mconsole.fx.animate({
|
2013-01-24 04:40:06 +00:00
|
|
|
modes: ['edge-property:lineWidth:color:alpha'],
|
2013-01-06 03:40:31 +00:00
|
|
|
duration: 100
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Mconsole.plot();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is for hiding one topic from your canvas
|
2013-01-11 03:01:24 +00:00
|
|
|
function onDragEndTopicHandler(node, eventInfo, e, allowRealtime) {
|
|
|
|
if (tempInit && tempNode2 == null) {
|
|
|
|
$('#topic_addSynapse').val("true");
|
|
|
|
$('#new_topic').fadeIn('fast');
|
|
|
|
$('#topic_name').focus();
|
|
|
|
} else if (tempInit && tempNode2 != null) {
|
|
|
|
$('#topic_addSynapse').val("false");
|
|
|
|
$('#synapse_topic1id').val(tempNode.id);
|
|
|
|
$('#synapse_topic2id').val(tempNode2.id);
|
|
|
|
$('#new_synapse').fadeIn('fast');
|
|
|
|
$('#synapse_desc').focus();
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
2014-02-01 08:57:19 +00:00
|
|
|
} else if (dragged && dragged != 0 && goRealtime) {
|
2013-04-26 04:07:29 +00:00
|
|
|
saveLayout(dragged);
|
|
|
|
for (var i = 0; i < MetamapsModel.selectedNodes.length; i++) {
|
|
|
|
saveLayout(MetamapsModel.selectedNodes[i].id);
|
|
|
|
}
|
2013-01-06 04:37:24 +00:00
|
|
|
}
|
2013-01-11 03:01:24 +00:00
|
|
|
}//onDragEndTopicHandler
|
|
|
|
|
|
|
|
function onDragCancelHandler(node, eventInfo, e, centred) {
|
|
|
|
tempNode = null;
|
|
|
|
tempNode2 = null;
|
|
|
|
tempInit = false;
|
|
|
|
|
|
|
|
//not sure why this doesn't happen for centred graphs
|
|
|
|
if (!centred) {
|
|
|
|
$('#topic_addSynapse').val("false");
|
|
|
|
$('#topic_topic1id').val(0);
|
|
|
|
$('#topic_topic2id').val(0);
|
2013-01-06 03:40:31 +00:00
|
|
|
}
|
2013-01-11 03:01:24 +00:00
|
|
|
Mconsole.plot();
|
2013-01-07 05:17:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 03:01:24 +00:00
|
|
|
function onPlaceLabelHandler(domElement, node) {
|
2013-03-17 09:18:30 +00:00
|
|
|
var style = domElement.style;
|
|
|
|
var left = parseInt(style.left);
|
|
|
|
var top = parseInt(style.top);
|
|
|
|
var w = $('#topic_' + node.id + '_label').width();
|
|
|
|
style.left = (left - w / 2) + 'px';
|
|
|
|
style.top = (top+20) + 'px';
|
|
|
|
style.display = '';
|
|
|
|
|
|
|
|
// now position the showcard
|
|
|
|
if (MetamapsModel.showcardInUse != null) {
|
|
|
|
top = $('#' + MetamapsModel.showcardInUse).css('top');
|
|
|
|
left = parseInt($('#' + MetamapsModel.showcardInUse).css('left'));
|
|
|
|
if (0 != $('#topic_' + MetamapsModel.showcardInUse + '_label').width()) {
|
|
|
|
MetamapsModel.widthOfLabel = $('#topic_' + MetamapsModel.showcardInUse + '_label').width();
|
|
|
|
}
|
|
|
|
w = MetamapsModel.widthOfLabel/2;
|
|
|
|
left = (left + w) + 'px';
|
|
|
|
$('#showcard').css('top', top);
|
|
|
|
$('#showcard').css('left', left);
|
|
|
|
|
|
|
|
Mconsole.labels.hideLabel(Mconsole.graph.getNode(MetamapsModel.showcardInUse));
|
|
|
|
}
|
2013-01-07 05:17:39 +00:00
|
|
|
}
|
2013-02-16 22:32:50 +00:00
|
|
|
|
|
|
|
// thanks to http://stackoverflow.com/questions/4338963/
|
|
|
|
// convert-html-character-entities-back-to-regular-text-using-javascript
|
|
|
|
function decodeEntities(desc) {
|
|
|
|
var str, temp = document.createElement('p');
|
|
|
|
temp.innerHTML = desc; //browser handles the entities
|
|
|
|
str = temp.textContent || temp.innerText;
|
|
|
|
temp = null; //delete the element;
|
|
|
|
return str;
|
|
|
|
}//decodeEntities
|
|
|
|
|