Unverified Commit e3e1460f authored by Tibor Katelbach's avatar Tibor Katelbach Committed by GitHub
Browse files

Merge pull request #5 from fluidlog/master

Remove fludy and keep only Fluidgraph lib
parents 28ea38a4 c856ce17
The MIT License (MIT)
Copyright (c) 2015 Fluidlog
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# fluidgraph
Library to create and manage graphs
Go to the wiki to read the documentation !
https://github.com/fluidlog/fluidgraph/wiki
## Code documentation
If you wish to contribute to the code documentation, we recently added a package.json which allow us to install JSDoc using npm.
Clone the project, and then:
```
npm install
```
This command should install both jsdoc and ink-docstrap into a node-modules directory.
We are using JSDoc, which is parsing the comments and annotations in the JS code. SO first step, adding relevant comments.
Then, use the following command to generate documentation:
```
./node_modules/.bin/jsdoc ./app -r -t ./node_modules/ink-docstrap/template -d ./documentation -R README.md
```
/**
* FluidGraph.prototype.d3DataToJsonD3 - Convert the current
* graph d3Data into a JSON stringified format
* @memberof FluidGraph.prototype
* @return {string} the D3 data in JSON format
*/
FluidGraph.prototype.d3DataToJsonD3 = function() {
thisGraph = this;
if (thisGraph.config.debug) console.log("d3DataToJsonD3 start");
//We copy d3Data object, cause we don't want to modify it... serializing and deserializing...
var localD3Data = JSON.parse(JSON.stringify(thisGraph.d3Data));
localD3Data.edges.forEach(function(edge){
edge.source = typeof edge.source.index != "undefined" ? edge.source.index : edge.source.id;
edge.target = typeof edge.target.index != "undefined" ? edge.target.index : edge.target.id;
});
localD3Data.name = thisGraph.graphName;
var jsonD3 = window.JSON.stringify(localD3Data);
if (thisGraph.config.debug) console.log("d3DataToJsonD3 end");
return jsonD3;
}
/**
* FluidGraph.prototype.d3DataToJsonLd - Convert the current
* graph d3Data into a JSON Linked Data object
* @return {object} the D3 data in JSON-LD
*/
FluidGraph.prototype.d3DataToJsonLd = function() {
thisGraph = this;
if (thisGraph.config.debug) console.log("d3DataToJsonLd start");
//We copy d3Data object, cause we don't want to modify it... serializing and deserializing...
var localD3Data = JSON.parse(JSON.stringify(thisGraph.d3Data));
localD3Data.nodes.forEach(function(node){
node.index = node.index.toString();
node.x = node.x.toString();
node.y = node.y.toString();
});
if (localD3Data.edges.length)
{
localD3Data.edges.forEach(function(edge){
edge.index = edge.index.toString();
edge.source = edge.source["@id"];
edge.target = edge.target["@id"];
});
}
else localD3Data.edges = [];
var jsonLd = {
"nodes": localD3Data.nodes,
"edges": localD3Data.edges,
"foaf:name": thisGraph.graphName
};
if (thisGraph.config.debug) console.log("d3DataToJsonLd end");
return jsonLd;
}
/**
* FluidGraph.prototype.jsonD3ToD3Data - Convert a JSON object
* containing the graph information to a d3 formatted object
*
* @param {object} jsonInput The json structure of the graph used as input data
* @return {object} Data that d3 will be able to process
*/
FluidGraph.prototype.jsonD3ToD3Data = function(jsonInput) {
thisGraph = this;
if (thisGraph.config.debug) console.log("jsonGraphToData start");
var d3data = {};
var newNodes = [];
var newEdges = [];
var jsonObj = JSON.parse(jsonInput);
thisGraph.graphName = jsonObj["foaf:name"];
newNodes = jsonObj.nodes;
newNodes.forEach(function(node){
if (typeof node["@type"] == "undefined") return false;
node.index = typeof node.index != "undefined" ? node.index : node.id ;
});
newEdges = jsonObj.edges;
newEdges.forEach(function(edge){
edge.source = newNodes.filter(function(node){
return node.index == edge.source || node.id == edge.source;
})[0];
edge.target = newNodes.filter(function(node){
return node.index == edge.target || node.id == edge.target;
})[0];
});
if (thisGraph.config.debug) console.log("jsonGraphToData end");
return {"nodes" : newNodes, "edges" : newEdges};
}
FluidGraph.prototype.jsonLdToD3Data = function(jsonObj) {
thisGraph = this;
if (thisGraph.config.debug) console.log("jsonLdToD3Data start");
var d3Data = {};
var newEdges = [];
var newNodes = [];
thisGraph.graphName = jsonObj["foaf:name"];
//Get the type of the object of nodes in case theres's only one node, it's an [object object]
var typeObjNodes = Object.prototype.toString.call( jsonObj.nodes );
if (typeObjNodes === '[object Array]')
newNodes = jsonObj.nodes;
else {
newNodes.push(jsonObj.nodes);
}
newNodes.forEach(function(node){
node.index = parseInt(node.index, 10);
node.x = parseInt(node.x, 10);
node.y = parseInt(node.y, 10);
});
if (jsonObj.edges)
{
//Get the type of the object of edges in case theres's only one edge, it's an [object object]
var typeObjEdges = Object.prototype.toString.call( jsonObj.edges );
if (typeObjEdges === '[object Array]')
newEdges = jsonObj.edges;
else {
newEdges.push(jsonObj.edges);
}
newEdges.forEach(function(edge){
edge.source = newNodes.filter(function(node){
return node.index == edge.source || node["@id"] == edge.source;
})[0];
edge.target = newNodes.filter(function(node){
return node.index == edge.target || node["@id"] == edge.target;
})[0];
edge.index = parseInt(edge.index, 10);
});
}
d3Data = {nodes : newNodes, edges : newEdges};
if (thisGraph.config.debug) console.log("jsonLdToD3Data end");
return d3Data;
}
/** @namespace */
var FluidGraph = function (firstBgElement){
/*
*
* Initialisation
*
****************************/
//Help to assure that it's the "this" of myGraph object
var thisGraph = this;
/**
* Configuration Object
* @memberof FluidGraph
*/
thisGraph.config = {
backgroundColor : "#F5F5F5",
xNewNode : 200,
yNewNode : 100,
bgElementType : "panzoom", //choixe : "panzoom" or "simple"
force : "Off",
elastic : "Off",
curvesLinks : "On",
openNodeOnHover : "Off",
displayIndex : "Off",
proportionalNodeSize : "On",
makeLinkSelectingNode : "Off", // default : Off
linkDistance : 200,
charge : -1000,
debug : false,
version : "loglink46",
curvesLinksType : "diagonal", // choice : "curve" or "diagonal" default : "curve"
viewerButtonLabel : "Launch Carto PAIR !",
bringNodeToFrontOnHover : false,
repulseNeighbourOnHover : false,
awsomeStrokeNode : true,
remindSelectedNodeOnSave : true,
editGraphMode : false, // only use for checkbox
allowDraggingNode : false, // default : false
allowModifyLink : false, // default : false
allowOpenNode : false, // default : false
editWithDoubleClick : false, // default : false
newNodeWithDoubleClickOnBg : false, // default : false
allowDragOnBg : false,
clicOnNodeAction : "options", // options, flod
customOptions : {
edit : true,
center : true,
focusContextOn : true,
focusContextOff : true,
hypertext : true,
close : true,
delete : true,
}
};
/**
* Base properties of the nodes
* @memberof FluidGraph
*/
thisGraph.customNodes = {
strokeWidth : 10,
strokeOpacity : .5,
displayType : "On",
displayText : "On",
strokeOpacityGhostNeighbour : 1,
listType : ["av:project","av:actor","av:idea","av:ressource","av:without"],
colorType : {"av:project" : "#89A5E5",
"av:actor" : "#F285B9",
"av:idea" : "#FFD98D",
"av:ressource" : "#CDF989",
"av:without" : "#999",
"av:gray" : "gray"},
colorTypeRgba : {"av:project" : "137,165,229",
"av:actor" : "242,133,185",
"av:idea" : "255,217,141",
"av:ressource" : "205,249,137",
"av:without" : "255,255,255",
"av:gray" : "200,200,200"},
strokeColor : "#CCC",
strokeNeighbourColorType : {"av:project" : "#89A5E5",
"av:actor" : "#F285B9",
"av:idea" : "#FFD98D",
"av:ressource" : "#CDF989",
"av:without" : "#999"},
strokeNeighbourColorTypeRgba : {"av:project" : "137,165,229",
"av:actor" : "242,133,185",
"av:idea" : "255,217,141",
"av:ressource" : "205,249,137",
"av:without" : "255,255,255"},
neighbourColorTypeRgba : {"av:project" : "137,165,229",
"av:actor" : "242,133,185",
"av:idea" : "255,217,141",
"av:ressource" : "205,249,137",
"av:without" : "255,255,255"},
imageType : {"av:project" : "lab", "av:actor" : "user", "av:idea" : "idea", "av:ressource" : "tree", "av:without" : "circle thin"},
maxCharactersInLabel : 50,
cursor : "move", //Value : grab or move (default), pointer, context-menu, text, crosshair, default
cursorOpen : "default", //Value : grab or move (default), pointer, context-menu, text, crosshair, default
heightClosed : 50,
maxRadius : 40,
// Width...
widthClosed : 50,
widthOpened : 260,
widthOpenedNeighboursBox : 250,
widthOpenedNeighbours : 220,
widthGhostNeighbourImage : 30,
widthGhostNeighbourTxt : 150,
widthGhostNeighbourButton : 30,
widthEdited : 220,
widthEditedDescription : 180,
widthEditedHypertext : 180,
widthStrokeHover : 20,
indiceProp : 2,
// Height...
heightOpened : 280,
heightOpenedLabel : 50,
heightOpenedOption : 20,
heightOpenedNeighbour : 25,
heightOpenedNeighboursMax : 200,
heightGhostNeighbour : 40,
heightGhostNeighbourTxt : 20,
heightGhostNeighbourTxtMax : 70,
heightEdited : 280,
heightEditedDescription :80,
heightEditedHypertext :60,
maxCharactersInOpenNodeLabel : 50,
maxCharactersInNeighbours : 20,
curvesCornersClosedNode : 50,
curvesCornersEditedNode : 20,
curvesCornersOpenedNode : 20,
// Transition...
transitionEasing : "elastic", //Values : linear (default), elastic
transitionDurationOpen : 300,
transitionDurationEdit : 1000,
transitionDurationClose : 300,
transitionDurationComeBack : 500,
transitionDurationConnector : 1500,
transitionDurationCenterNode : 1200,
transitionDelay : 0,
blankNodeLabel : "",
blankNodeType : "av:without",
uriBase : "http://fluidlog.com/node/", //Warning : with LDP, no uriBase... :-)
neighbourConnectorMessage : "Come here to create a link !",
dropNodeInNeighboursMessage : "Yes ! Now, drop it to create a new neighbour !",
neighbourConnectorOpacity : .9,
neighbourConnectorOpacityDropped : 1,
heightVideoInNode : 200,
}
if (thisGraph.config.awsomeStrokeNode == true)
{
thisGraph.customNodes.strokeColorType = {"av:project" : "#CCC",
"av:actor" : "#CCC",
"av:idea" : "#CCC",
"av:ressource" : "#CCC",
"av:without" : "#CCC"}
}
else {
thisGraph.customNodes.strokeColorType = {"av:project" : "#89A5E5",
"av:actor" : "#F285B9",
"av:idea" : "#FFD98D",
"av:ressource" : "#CDF989",
"av:without" : "#999"}
}
thisGraph.nodeTypeIcon = {
r : 13,
cxClosed : 0,
cxEdited : 0,
cyClosed : (thisGraph.customNodes.heightClosed/2)-10,
cyEdited : (thisGraph.customNodes.heightEdited/2)-10,
xClosed : -11,
xOpened : -11,
xEdited : -11,
yClosed : (thisGraph.customNodes.heightClosed/2)-20,
yEdited : (thisGraph.customNodes.heightEdited/2)-20,
}
thisGraph.nodeIndexCircle = {
r : 10,
cxClosed : 0,
cyClosed : -(thisGraph.customNodes.heightClosed/2)+6,
cxEdited : 0,
cyEdited : -(thisGraph.customNodes.heightOpened/2),
dxClosed : 0,
dyClosed : -(thisGraph.customNodes.heightClosed/2)+10,
dxEdited : 0,
dyEdited : -(thisGraph.customNodes.heightOpened/2)+5,
}
thisGraph.customNodesText = {
fontSize : 14,
FontFamily : "Helvetica Neue, Helvetica, Arial, sans-serif;",
strokeOpacity : .5,
widthMax : 160,
heightMax : 60,
curvesCorners : thisGraph.customNodes.curvesCornersOpenedNode,
}
thisGraph.customLinks = {
strokeWidth: 3,
strokeColor: "#CCC",
strokeColorError: "#FDAAAA",
strokeSelectedColor: "#999", //See also fluidgraph.css
uriBase : "http://fluidlog.com/edge/", //Warning : with LDP, no uriBase... :-)
predicate : "loglink:linkedto",
transitionDurationOverLinks : 300,
}
thisGraph.customLinksLabel = {
width : 200,
height : 80,
fillColor : "#CCC",
strokeColor : "#DDD",
curvesCorners : 20,
blankNodeLabel : "loglink:linkto",
}
thisGraph.svgContainer = {
width : window.innerWidth - 30,
height : window.innerHeight - 30,
}
/**
* Mouse event variables
* @memberof FluidGraph
*/
thisGraph.state = {
selectedNode : null,
selectedLink : null,
mouseDownNode : null,
mouseDownLink : null,
svgMouseDownNode : null,
mouseUpNode : null,
lastKeyDown : -1,
editedNode : null,
editedIndexNode : null,
openedNode : null,
editedLinkLabel : null,
dragStarted : null,
draggingNode : null,
draggingNodeSvg : null,
targetNode : null,
targetNodeSvg : null,
focusMode : null,
dNeighbourConnector : null,
neighbourConnectorIsSet : null,
neighbourConnection : null,
}
thisGraph.graphName = thisGraph.consts.UNTILTED_GRAPH_NAME;
thisGraph.openedGraph = null;
thisGraph.selectedGraphName = null;
thisGraph.ldpGraphName = null;
thisGraph.selectedLdpGraphName = null;
thisGraph.typeLdpServer = "local"; //local or external, default : local
thisGraph.mockData0 = null;
thisGraph.listOfLocalGraphs = [];
thisGraph.listOfExtenalGraphs = [];
thisGraph.graphToDeleteName = null;
thisGraph.firstBgElement = null;
thisGraph.d3Data = {};
thisGraph.d3Data.nodes = [];
thisGraph.d3Data.edges = [];
thisGraph.bgElement = null;
thisGraph.svgNodesEnter = [];
thisGraph.svgLinksEnter = [];
thisGraph.svgLinksLabelEnter = [];
thisGraph.diagonal = d3.svg.diagonal();
thisGraph.panBoundary = 20; // Within 20px from edges will pan when dragging.
thisGraph.panBgBoundaryRate = 10;
thisGraph.panBgLRBoundary = thisGraph.svgContainer.width / thisGraph.panBgBoundaryRate;
thisGraph.panBgUDRBoundary = thisGraph.svgContainer.height / thisGraph.panBgBoundaryRate;
thisGraph.panTimer = null;
thisGraph.panBgSpeed = 20;
thisGraph.panSpeed = 50;
thisGraph.zoomListener = null;
thisGraph.translateX = null;
thisGraph.translateY = null;
// dbpedia : http://dbpedia.org/resource/ (John_Lennon)
// thisGraph.rwwplayUri = "https://localhost:8443/2013/cartopair/";
// thisGraph.rwwplayUri = "https://212.47.232.171:8443/2013/cartopair/";
// thisGraph.semFormsUri = "http://localhost:9000/ldp/cartopair/";
/**
* URI of the External LDP Store currently used (should be in a config object ?)
* @memberof FluidGraph
*/
thisGraph.rwwplayUri = "https://ldp.virtual-assembly.org:8443/2013/cartopair/";
/**
* External LDP Store information stored as object
* @memberof FluidGraph
*/
thisGraph.externalStore = {
uri : thisGraph.rwwplayUri,
context : {
"@context":{
"loglink": "http://www.fluidlog.com/2013/05/loglink/core#",
"nodes": "http://www.fluidlog.com/2013/05/loglink/core#node",
"label": "http://www.w3.org/2000/01/rdf-schema#label",
"index": "http://www.fluidlog.com/2013/05/loglink/core#index",
"x": "http://www.fluidlog.com/2013/05/loglink/core#x",
"y": "http://www.fluidlog.com/2013/05/loglink/core#y",
"edges": "http://www.fluidlog.com/2013/05/loglink/core#edge",
"source": "http://www.fluidlog.com/2013/05/loglink/core#source",
"target": "http://www.fluidlog.com/2013/05/loglink/core#target",
"hypertext": "http://www.fluidlog.com/2013/05/loglink/core#hypertext",
"av": "http://www.assemblee-virtuelle.org/ontologies/v1.owl#",
"foaf": "http://xmlns.com/foaf/0.1/"
}
}
}
}
/**
* Some constant defined to be used by the Graph instance
* Come from : https://github.com/cjrd/directed-graph-creator/blob/master/graph-creator.js
* @memberof FluidGraph
*/
FluidGraph.prototype.consts = {
selectedClass: "selected",
connectClass: "connect-node",
circleGClass: "conceptG",
graphClass: "graph",
BACKSPACE_KEY: 8,
DELETE_KEY: 46,
ENTER_KEY: 13,
nodeRadius: 50,
OPENED_GRAPH_KEY: "openedGraph",
UNTILTED_GRAPH_NAME: "Untilted",
};
var data = [];
data[0] = {
nodes: [
{ "@id":"http://fluidlog.com/node/0",
"@type": "av:without",
index:0,
label: "",
hypertext: "",
x:300,
y:200,
},
],
edges: []
}
data[1] = {
nodes: [
{index:0, label: "A", "@type":"av:project", x:100, y:100, "@id":"http://fluidlog.com/node/0" },
{index:1, label: "B", "@type":"av:idea", x:200, y:200, "@id":"http://fluidlog.com/node/1" },
{index:2, label: "C", "@type":"av:project", x:300, y:300, "@id":"http://fluidlog.com/node/2" },
],
edges: [
{ source: 0, target: 1 },
]
}
data[2] = {
nodes: [
{index:0, label: "A petit texte", "@type":"av:project", x:100, y:100, "@id":"http://fluidlog.com/node/0" },
{index:1, label: "B texte sur deux longues lignes", type:"av:idea", x:200, y:200, "@id":"http://fluidlog.com/node/1" },
{index:2, label: "C", "@type":"av:project", x:400, y:200, "@id":"http://fluidlog.com/node/2" },
{index:3, label: "D", "@type":"av:idea", x:400, y:400, "@id":"http://fluidlog.com/node/3" },
{index:4, label: "E", "@type":"av:project", x:300, y:400, "@id":"http://fluidlog.com/node/4" },
{index:5, label: "F", "@type":"av:project", x:500, y:300, "@id":"http://fluidlog.com/node/5" },
{index:6, label: "G", "@type":"av:project", x:300, y:500, "@id":"http://fluidlog.com/node/6" },
{index:7, label: "H", "@type":"av:project", x:400, y:500, "@id":"http://fluidlog.com/node/7" },
],