@ -1,246 +0,0 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Localization</title> | |||
<style type="text/css"> | |||
body, select { | |||
font: 10pt sans; | |||
} | |||
#mynetwork { | |||
position:relative; | |||
width: 800px; | |||
height: 600px; | |||
border: 1px solid lightgray; | |||
} | |||
table.legend_table { | |||
font-size: 11px; | |||
border-width:1px; | |||
border-color:#d3d3d3; | |||
border-style:solid; | |||
} | |||
table.legend_table,td { | |||
border-width:1px; | |||
border-color:#d3d3d3; | |||
border-style:solid; | |||
padding: 2px; | |||
} | |||
div.table_content { | |||
width:80px; | |||
text-align:center; | |||
} | |||
div.table_description { | |||
width:100px; | |||
} | |||
#operation { | |||
font-size:28px; | |||
} | |||
#network-popUp { | |||
display:none; | |||
position:absolute; | |||
top:350px; | |||
left:170px; | |||
z-index:299; | |||
width:250px; | |||
height:120px; | |||
background-color: #f9f9f9; | |||
border-style:solid; | |||
border-width:3px; | |||
border-color: #5394ed; | |||
padding:10px; | |||
text-align: center; | |||
} | |||
</style> | |||
<script type="text/javascript" src="../../dist/vis.js"></script> | |||
<link type="text/css" rel="stylesheet" href="../../dist/vis.css"> | |||
<script type="text/javascript"> | |||
var nodes = null; | |||
var edges = null; | |||
var network = null; | |||
function destroy() { | |||
if (network !== null) { | |||
network.destroy(); | |||
network = null; | |||
} | |||
} | |||
function draw() { | |||
destroy(); | |||
nodes = []; | |||
edges = []; | |||
var connectionCount = []; | |||
// randomly create some nodes and edges | |||
var nodeCount = 25; | |||
for (var i = 0; i < nodeCount; i++) { | |||
nodes.push({ | |||
id: i, | |||
label: String(i) | |||
}); | |||
connectionCount[i] = 0; | |||
// create edges in a scale-free-network way | |||
if (i == 1) { | |||
var from = i; | |||
var to = 0; | |||
edges.push({ | |||
from: from, | |||
to: to | |||
}); | |||
connectionCount[from]++; | |||
connectionCount[to]++; | |||
} | |||
else if (i > 1) { | |||
var conn = edges.length * 2; | |||
var rand = Math.floor(Math.random() * conn); | |||
var cum = 0; | |||
var j = 0; | |||
while (j < connectionCount.length && cum < rand) { | |||
cum += connectionCount[j]; | |||
j++; | |||
} | |||
var from = i; | |||
var to = j; | |||
edges.push({ | |||
from: from, | |||
to: to | |||
}); | |||
connectionCount[from]++; | |||
connectionCount[to]++; | |||
} | |||
} | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var data = { | |||
nodes: nodes, | |||
edges: edges | |||
}; | |||
var options = { | |||
physics: { | |||
stabilization: false | |||
}, | |||
manipulation: { | |||
//handlerFunctions: { | |||
addNode: function(data,callback) { | |||
var span = document.getElementById('operation'); | |||
var idInput = document.getElementById('node-id'); | |||
var labelInput = document.getElementById('node-label'); | |||
var saveButton = document.getElementById('saveButton'); | |||
var cancelButton = document.getElementById('cancelButton'); | |||
var div = document.getElementById('network-popUp'); | |||
span.innerHTML = "Add Node"; | |||
idInput.value = data.id; | |||
labelInput.value = data.label; | |||
saveButton.onclick = saveData.bind(this,data,callback); | |||
cancelButton.onclick = clearPopUp.bind(); | |||
div.style.display = 'block'; | |||
}, | |||
editNode: function(data,callback) { | |||
var span = document.getElementById('operation'); | |||
var idInput = document.getElementById('node-id'); | |||
var labelInput = document.getElementById('node-label'); | |||
var saveButton = document.getElementById('saveButton'); | |||
var cancelButton = document.getElementById('cancelButton'); | |||
var div = document.getElementById('network-popUp'); | |||
span.innerHTML = "Edit Node"; | |||
idInput.value = data.id; | |||
labelInput.value = data.label; | |||
saveButton.onclick = saveData.bind(this,data,callback); | |||
cancelButton.onclick = clearPopUp.bind(); | |||
div.style.display = 'block'; | |||
}, | |||
addEdge: function(data,callback) { | |||
if (data.from == data.to) { | |||
var r=confirm("Do you want to connect the node to itself?"); | |||
if (r==true) { | |||
callback(data); | |||
} | |||
} | |||
else { | |||
callback(data); | |||
} | |||
} | |||
//} | |||
} | |||
}; | |||
network = new vis.Network(container, data, options); | |||
// add event listeners | |||
network.on('select', function(params) { | |||
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes; | |||
}); | |||
network.on("resize", function(params) {console.log(params.width,params.height)}); | |||
function clearPopUp() { | |||
var saveButton = document.getElementById('saveButton'); | |||
var cancelButton = document.getElementById('cancelButton'); | |||
saveButton.onclick = null; | |||
cancelButton.onclick = null; | |||
var div = document.getElementById('network-popUp'); | |||
div.style.display = 'none'; | |||
} | |||
function saveData(data,callback) { | |||
var idInput = document.getElementById('node-id'); | |||
var labelInput = document.getElementById('node-label'); | |||
data.id = idInput.value; | |||
data.label = labelInput.value; | |||
clearPopUp(); | |||
callback(data); | |||
} | |||
// update the locale when changing the select box value | |||
var select = document.getElementById('locale'); | |||
select.onchange = function () { | |||
network.setOptions({ | |||
manipulation: { | |||
locale: this.value | |||
} | |||
}); | |||
}; | |||
select.onchange(); | |||
} | |||
</script> | |||
<script src="../googleAnalytics.js"></script> | |||
</head> | |||
<body onload="draw();"> | |||
<h2>Editing the dataset (localized)</h2> | |||
<p style="width: 700px; font-size:14px; text-align: justify;"> | |||
This is the same example as <a href="21_data_manipulation.html">21_data_manipulation.html</a>, except that there is a select box added which allows to switch locale. The localization is only relevant to the manipulation buttons. | |||
</p> | |||
<p> | |||
<label for="locale">Select a locale:</label> | |||
<select id="locale"> | |||
<option value="en" selected>en</option> | |||
<option value="nl">nl</option> | |||
</select> | |||
</p> | |||
<div id="network-popUp"> | |||
<span id="operation">node</span> <br> | |||
<table style="margin:auto;"><tr> | |||
<td>id</td><td><input id="node-id" value="new value" /></td> | |||
</tr> | |||
<tr> | |||
<td>label</td><td><input id="node-label" value="new value" /></td> | |||
</tr></table> | |||
<input type="button" value="save" id="saveButton" /> | |||
<input type="button" value="cancel" id="cancelButton" /> | |||
</div> | |||
<br /> | |||
<div id="mynetwork"></div> | |||
<p id="selection"></p> | |||
</body> | |||
</html> | |||
@ -1,105 +0,0 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Clustering</title> | |||
<script type="text/javascript" src="../../dist/vis.js"></script> | |||
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" /> | |||
<style type="text/css"> | |||
#mynetwork { | |||
width: 400px; | |||
height: 400px; | |||
border: 1px solid lightgray; | |||
} | |||
</style> | |||
<script src="../googleAnalytics.js"></script> | |||
</head> | |||
<body> | |||
<div id="mynetwork"></div> | |||
<script type="text/javascript"> | |||
// create an array with nodes | |||
var nodes = [ | |||
{id: 1, label: 'Node 1'}, | |||
{id: 2, label: 'Node 2'}, | |||
{id: 3, label: 'Node 3'}, | |||
{id: 4, label: 'Node 4'}, | |||
{id: 5, label: 'Node 5'}, | |||
{id: 6, label: 'Node 6', cid:1}, | |||
{id: 7, label: 'Node 7', cid:1}, | |||
{id: 8, label: 'Node 8', cid:1}, | |||
{id: 9, label: 'Node 9', cid:1}, | |||
{id: 10, label: 'Node 10', cid:1} | |||
]; | |||
// create an array with edges | |||
var edges = [ | |||
{from: 1, to: 2}, | |||
{from: 1, to: 3}, | |||
{from: 10, to: 4}, | |||
{from: 2, to: 5}, | |||
{from: 6, to: 2}, | |||
{from: 7, to: 5}, | |||
{from: 8, to: 6}, | |||
{from: 9, to: 7}, | |||
{from: 10, to: 9} | |||
]; | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var data = { | |||
nodes: nodes, | |||
edges: edges | |||
}; | |||
var options = {}; | |||
var network = new vis.Network(container, data, options); | |||
// | |||
// var clusterOptions = { | |||
// joinCondition:function(parentOptions,childOptions) { | |||
// return true; | |||
// }, | |||
// processClusterProperties: function (properties, childNodes, childEdges) { | |||
// return properties; | |||
// }, | |||
// clusterNodeProperties: {id:'bla', borderWidth:2}, | |||
// } | |||
var clusterOptionsByData = { | |||
joinCondition:function(childOptions) { | |||
console.log(childOptions.id) | |||
return childOptions.cid == 1; | |||
}, | |||
processProperties: function (properties, childNodes, childEdges) { | |||
return properties; | |||
}, | |||
clusterNodeProperties: {id:'bla', borderWidth:2} | |||
} | |||
network.clustering.cluster(clusterOptionsByData) | |||
// network.clustering.clusterOutliers({clusterNodeProperties: {shape:'database',borderWidth:3}}) | |||
// network.clusterByConnection(2, clusterOptions); | |||
// network.clusterByConnection(9, { | |||
// joinCondition:function(parentOptions,childOptions) {return true;}, | |||
// processProperties:function (properties, childNodes, childEdges) { | |||
// return properties; | |||
// }, | |||
// clusterNodeProperties: {id:'bla2', label:"bla2", borderWidth:8} | |||
// }); | |||
network.body.emitter.on("select", function(params) { | |||
if (params.nodes.length == 1) { | |||
if (network.clustering.isCluster(params.nodes[0]) == true) { | |||
network.clustering.openCluster(params.nodes[0]) | |||
} | |||
} | |||
}) | |||
// network.openCluster('bla'); | |||
// network.openCluster('bla2'); | |||
</script> | |||
</body> | |||
</html> |
@ -0,0 +1,75 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Basic usage</title> | |||
<script type="text/javascript" src="../../../../dist/vis.js"></script> | |||
<link href="../../../../dist/vis.css" rel="stylesheet" type="text/css"/> | |||
<style type="text/css"> | |||
#mynetwork { | |||
width: 600px; | |||
height: 400px; | |||
border: 1px solid lightgray; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<p> | |||
Create a simple network with some nodes and edges. | |||
</p> | |||
<div id="mynetwork"></div> | |||
<pre id="eventSpan"></pre> | |||
<script type="text/javascript"> | |||
// create an array with nodes | |||
var nodes = new vis.DataSet([ | |||
{id: 1, label: 'Node 1', title: 'I have a popup!'}, | |||
{id: 2, label: 'Node 2', title: 'I have a popup!'}, | |||
{id: 3, label: 'Node 3', title: 'I have a popup!'}, | |||
{id: 4, label: 'Node 4', title: 'I have a popup!'}, | |||
{id: 5, label: 'Node 5', title: 'I have a popup!'} | |||
]); | |||
// create an array with edges | |||
var edges = new vis.DataSet([ | |||
{from: 1, to: 3}, | |||
{from: 1, to: 2}, | |||
{from: 2, to: 4}, | |||
{from: 2, to: 5} | |||
]); | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var data = { | |||
nodes: nodes, | |||
edges: edges | |||
}; | |||
var options = {}; | |||
var network = new vis.Network(container, data, options); | |||
network.on("click", function (params) { | |||
params.event = "[original event]"; | |||
document.getElementById('eventSpan').innerHTML = '<h2>Click event:</h2>' + JSON.stringify(params, null, 4); | |||
}); | |||
network.on("doubleClick", function (params) { | |||
params.event = "[original event]"; | |||
document.getElementById('eventSpan').innerHTML = '<h2>doubleClick event:</h2>' + JSON.stringify(params, null, 4); | |||
}); | |||
network.on("oncontext", function (params) { | |||
params.event = "[original event]"; | |||
document.getElementById('eventSpan').innerHTML = '<h2>oncontext (right click) event:</h2>' + JSON.stringify(params, null, 4); | |||
}); | |||
network.on("zoom", function (params) { | |||
document.getElementById('eventSpan').innerHTML = '<h2>zoom event:</h2>' + JSON.stringify(params, null, 4); | |||
}); | |||
network.on("showPopup", function (params) { | |||
document.getElementById('eventSpan').innerHTML = '<h2>showPopup event: </h2>' + JSON.stringify(params, null, 4); | |||
}); | |||
</script> | |||
<script src="../../../googleAnalytics.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,73 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Basic usage</title> | |||
<script type="text/javascript" src="../../../../dist/vis.js"></script> | |||
<link href="../../../../dist/vis.css" rel="stylesheet" type="text/css"/> | |||
<style type="text/css"> | |||
#mynetwork { | |||
width: 600px; | |||
height: 400px; | |||
border: 1px solid lightgray; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<p> | |||
Create a simple network with some nodes and edges. | |||
</p> | |||
<div id="mynetwork"></div> | |||
<pre id="eventSpan"></pre> | |||
<script type="text/javascript"> | |||
// create an array with nodes | |||
var nodes = new vis.DataSet([ | |||
{id: 1, label: 'Node 1'}, | |||
{id: 2, label: 'Node 2'}, | |||
{id: 3, label: 'Node 3'}, | |||
{id: 4, label: 'Node 4'}, | |||
{id: 5, label: 'Node 5'} | |||
]); | |||
// create an array with edges | |||
var edges = new vis.DataSet([ | |||
{from: 1, to: 3}, | |||
{from: 1, to: 2}, | |||
{from: 2, to: 4}, | |||
{from: 2, to: 5} | |||
]); | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var data = { | |||
nodes: nodes, | |||
edges: edges | |||
}; | |||
var options = {}; | |||
var network = new vis.Network(container, data, options); | |||
network.on("startStabilizing", function (params) { | |||
document.getElementById('eventSpan').innerHTML = '<h3>Starting Stabilization</h3>'; | |||
console.log("started") | |||
}); | |||
network.on("stabilizationProgress", function (params) { | |||
document.getElementById('eventSpan').innerHTML = '<h3>Stabilization progress</h3>' + JSON.stringify(params, null, 4); | |||
console.log("progress:",params); | |||
}); | |||
network.on("stabilizationIterationsDone", function (params) { | |||
document.getElementById('eventSpan').innerHTML = '<h3>Stabilization iterations complete</h3>'; | |||
console.log("finished stabilization interations"); | |||
}); | |||
network.on("stabilized", function (params) { | |||
document.getElementById('eventSpan').innerHTML = '<h3>Stabilized!</h3>' + JSON.stringify(params, null, 4); | |||
console.log("stabilized!", params); | |||
}); | |||
</script> | |||
<script src="../../../googleAnalytics.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,83 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Basic usage</title> | |||
<script type="text/javascript" src="../../../../dist/vis.js"></script> | |||
<link href="../../../../dist/vis.css" rel="stylesheet" type="text/css"/> | |||
<style type="text/css"> | |||
#mynetwork { | |||
width: 600px; | |||
height: 400px; | |||
border: 1px solid lightgray; | |||
} | |||
p { | |||
max-width:600px; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<p> | |||
You can draw on the canvas using normal HTML5 canvas functions. The before drawing will be behind the network, the after drawing will be in front of the network. | |||
</p> | |||
<div id="mynetwork"></div> | |||
<pre id="eventSpan"></pre> | |||
<script type="text/javascript"> | |||
// create an array with nodes | |||
var nodes = new vis.DataSet([ | |||
{id: 1, label: 'Node 1'}, | |||
{id: 2, label: 'Node 2'}, | |||
{id: 3, label: 'Node 3'}, | |||
{id: 4, label: 'Node 4'}, | |||
{id: 5, label: 'Node 5'} | |||
]); | |||
// create an array with edges | |||
var edges = new vis.DataSet([ | |||
{from: 1, to: 3}, | |||
{from: 1, to: 2}, | |||
{from: 2, to: 4}, | |||
{from: 2, to: 5} | |||
]); | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var data = { | |||
nodes: nodes, | |||
edges: edges | |||
}; | |||
var options = {}; | |||
var network = new vis.Network(container, data, options); | |||
network.on("initRedraw", function () { | |||
// do something like move some custom elements? | |||
}); | |||
network.on("beforeDrawing", function (ctx) { | |||
var nodeId = 1; | |||
var nodePosition = network.getPositions([nodeId]); | |||
ctx.strokeStyle = '#A6D5F7'; | |||
ctx.fillStyle = '#294475'; | |||
ctx.circle(nodePosition[nodeId].x, nodePosition[nodeId].y,50); | |||
ctx.fill(); | |||
ctx.stroke(); | |||
}); | |||
network.on("afterDrawing", function (ctx) { | |||
var nodeId = 1; | |||
var nodePosition = network.getPositions([nodeId]); | |||
ctx.strokeStyle = '#294475'; | |||
ctx.lineWidth = 4; | |||
ctx.fillStyle = '#A6D5F7'; | |||
ctx.circle(nodePosition[nodeId].x, nodePosition[nodeId].y,20); | |||
ctx.fill(); | |||
ctx.stroke(); | |||
}); | |||
</script> | |||
<script src="../../../googleAnalytics.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,141 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Clustering</title> | |||
<script type="text/javascript" src="../../../../dist/vis.js"></script> | |||
<link href="../../../../dist/vis.css" rel="stylesheet" type="text/css" /> | |||
<style type="text/css"> | |||
#mynetwork { | |||
width: 600px; | |||
height: 600px; | |||
border: 1px solid lightgray; | |||
} | |||
p { | |||
max-width:600px; | |||
} | |||
h4 { | |||
margin-bottom:3px; | |||
} | |||
</style> | |||
<script src="../../../googleAnalytics.js"></script> | |||
</head> | |||
<body> | |||
<p> | |||
Click any of the buttons below to cluster the network. On every push the network will be reinitialized first. You can click on a cluster to open it. | |||
</p> | |||
<input type="button" onclick="clusterByCid()" value="Cluster all nodes with CID = 1"> <br /> | |||
<input type="button" onclick="clusterByColor()" value="Cluster by color"> <br /> | |||
<input type="button" onclick="clusterByConnection()" value="Cluster 'node 1' by connections"> <br /> | |||
<input type="button" onclick="clusterOutliers()" value="Cluster outliers"> <br /> | |||
<input type="button" onclick="clusterByHubsize()" value="Cluster by hubsize"> <br /> | |||
<div id="mynetwork"></div> | |||
<script type="text/javascript"> | |||
// create an array with nodes | |||
var nodes = [ | |||
{id: 1, label: 'Node 1', color:'orange'}, | |||
{id: 2, label: 'Node 2', color:'DarkViolet'}, | |||
{id: 3, label: 'Node 3', color:'orange'}, | |||
{id: 4, label: 'Node 4', color:'DarkViolet'}, | |||
{id: 5, label: 'Node 5', color:'orange'}, | |||
{id: 6, label: 'cid = 1', cid:1, color:'orange'}, | |||
{id: 7, label: 'cid = 1', cid:1, color:'DarkViolet'}, | |||
{id: 8, label: 'cid = 1', cid:1, color:'lime'}, | |||
{id: 9, label: 'cid = 1', cid:1, color:'orange'}, | |||
{id: 10, label: 'cid = 1', cid:1, color:'lime'} | |||
]; | |||
// create an array with edges | |||
var edges = [ | |||
{from: 1, to: 2}, | |||
{from: 1, to: 3}, | |||
{from: 10, to: 4}, | |||
{from: 2, to: 5}, | |||
{from: 6, to: 2}, | |||
{from: 7, to: 5}, | |||
{from: 8, to: 6}, | |||
{from: 9, to: 7}, | |||
{from: 10, to: 9} | |||
]; | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var data = { | |||
nodes: nodes, | |||
edges: edges | |||
}; | |||
var options = {layout:{randomSeed:8},nodes:{font:{strokeWidth:5}}}; | |||
var network = new vis.Network(container, data, options); | |||
network.on("selectNode", function(params) { | |||
if (params.nodes.length == 1) { | |||
if (network.isCluster(params.nodes[0]) == true) { | |||
network.openCluster(params.nodes[0]) | |||
} | |||
} | |||
}) | |||
function clusterByCid() { | |||
network.setData(data); | |||
var clusterOptionsByData = { | |||
joinCondition:function(childOptions) { | |||
return childOptions.cid == 1; | |||
}, | |||
clusterNodeProperties: {id:'cidCluster', borderWidth:3, shape:'database'} | |||
} | |||
network.cluster(clusterOptionsByData); | |||
} | |||
function clusterByColor() { | |||
network.setData(data); | |||
var colors = ['orange','lime','DarkViolet']; | |||
var clusterOptionsByData; | |||
for (var i = 0; i < colors.length; i++) { | |||
var color = colors[i]; | |||
clusterOptionsByData = { | |||
joinCondition: function (childOptions) { | |||
return childOptions.color.background == color; // the color is fully defined in the node. | |||
}, | |||
processProperties: function (clusterOptions, childNodes, childEdges) { | |||
var totalMass = 0; | |||
for (var i = 0; i < childNodes.length; i++) { | |||
totalMass += childNodes[i].mass; | |||
} | |||
clusterOptions.mass = totalMass; | |||
return clusterOptions; | |||
}, | |||
clusterNodeProperties: {id: 'cluster:' + color, borderWidth: 3, shape: 'database', color:color, label:'color:' + color} | |||
} | |||
network.cluster(clusterOptionsByData); | |||
} | |||
} | |||
function clusterByConnection() { | |||
network.setData(data); | |||
network.clusterByConnection(1) | |||
} | |||
function clusterOutliers() { | |||
network.setData(data); | |||
network.clusterOutliers(); | |||
} | |||
function clusterByHubsize() { | |||
network.setData(data); | |||
var clusterOptionsByData = { | |||
processProperties: function(clusterOptions, childNodes) { | |||
clusterOptions.label = "[" + childNodes.length + "]"; | |||
return clusterOptions; | |||
}, | |||
clusterNodeProperties: {borderWidth:3, shape:'box', font:{size:30}} | |||
} | |||
network.clusterByHubsize(undefined, clusterOptionsByData); | |||
} | |||
</script> | |||
</body> | |||
</html> |
@ -0,0 +1,167 @@ | |||
<!doctype html> | |||
<html> | |||
<head> | |||
<title>Network | Localization</title> | |||
<style type="text/css"> | |||
body, select { | |||
font: 10pt sans; | |||
} | |||
#mynetwork { | |||
position:relative; | |||
width: 800px; | |||
height: 600px; | |||
border: 1px solid lightgray; | |||
} | |||
table.legend_table { | |||
font-size: 11px; | |||
border-width:1px; | |||
border-color:#d3d3d3; | |||
border-style:solid; | |||
} | |||
table.legend_table,td { | |||
border-width:1px; | |||
border-color:#d3d3d3; | |||
border-style:solid; | |||
padding: 2px; | |||
} | |||
div.table_content { | |||
width:80px; | |||
text-align:center; | |||
} | |||
div.table_description { | |||
width:100px; | |||
} | |||
#operation { | |||
font-size:28px; | |||
} | |||
#network-popUp { | |||
display:none; | |||
position:absolute; | |||
top:350px; | |||
left:170px; | |||
z-index:299; | |||
width:250px; | |||
height:120px; | |||
background-color: #f9f9f9; | |||
border-style:solid; | |||
border-width:3px; | |||
border-color: #5394ed; | |||
padding:10px; | |||
text-align: center; | |||
} | |||
</style> | |||
<script type="text/javascript" src="../../exampleUtil.js"></script> | |||
<script type="text/javascript" src="../../../../dist/vis.js"></script> | |||
<link href="../../../../dist/vis.css" rel="stylesheet" type="text/css" /> | |||
<script type="text/javascript"> | |||
var nodes = null; | |||
var edges = null; | |||
var network = null; | |||
// randomly create some nodes and edges | |||
var data = getScaleFreeNetwork(25); | |||
var seed = 2; | |||
function destroy() { | |||
if (network !== null) { | |||
network.destroy(); | |||
network = null; | |||
} | |||
} | |||
function draw() { | |||
destroy(); | |||
nodes = []; | |||
edges = []; | |||
// create a network | |||
var container = document.getElementById('mynetwork'); | |||
var options = { | |||
layout: {randomSeed:seed}, // just to make sure the layout is the same when the locale is changed | |||
locale: document.getElementById('locale').value, | |||
manipulation: { | |||
addNode: function (data, callback) { | |||
// filling in the popup DOM elements | |||
document.getElementById('operation').innerHTML = "Add Node"; | |||
document.getElementById('node-id').value = data.id; | |||
document.getElementById('node-label').value = data.label; | |||
document.getElementById('saveButton').onclick = saveData.bind(this, data, callback); | |||
document.getElementById('cancelButton').onclick = clearPopUp.bind(); | |||
document.getElementById('network-popUp').style.display = 'block'; | |||
}, | |||
editNode: function (data, callback) { | |||
// filling in the popup DOM elements | |||
document.getElementById('operation').innerHTML = "Edit Node"; | |||
document.getElementById('node-id').value = data.id; | |||
document.getElementById('node-label').value = data.label; | |||
document.getElementById('saveButton').onclick = saveData.bind(this, data, callback); | |||
document.getElementById('cancelButton').onclick = clearPopUp.bind(); | |||
document.getElementById('network-popUp').style.display = 'block'; | |||
}, | |||
addEdge: function (data, callback) { | |||
if (data.from == data.to) { | |||
var r = confirm("Do you want to connect the node to itself?"); | |||
if (r == true) { | |||
callback(data); | |||
} | |||
} | |||
else { | |||
callback(data); | |||
} | |||
} | |||
} | |||
}; | |||
network = new vis.Network(container, data, options); | |||
} | |||
function clearPopUp() { | |||
document.getElementById('saveButton').onclick = null; | |||
document.getElementById('cancelButton').onclick = null; | |||
document.getElementById('network-popUp').style.display = 'none'; | |||
} | |||
function saveData(data,callback) { | |||
data.id = document.getElementById('node-id').value; | |||
data.label = document.getElementById('node-label').value; | |||
clearPopUp(); | |||
callback(data); | |||
} | |||
</script> | |||
<script src="../../../googleAnalytics.js"></script> | |||
</head> | |||
<body onload="draw();"> | |||
<h2>Editing the nodes and edges (localized)</h2> | |||
<p style="width: 700px; font-size:14px; text-align: justify;"> | |||
The localization is only relevant to the manipulation buttons. | |||
</p> | |||
<p> | |||
<label for="locale">Select a locale:</label> | |||
<select id="locale" onchange="draw();"> | |||
<option value="en" selected>en</option> | |||
<option value="nl">nl</option> | |||
</select> | |||
</p> | |||
<div id="network-popUp"> | |||
<span id="operation">node</span> <br> | |||
<table style="margin:auto;"><tr> | |||
<td>id</td><td><input id="node-id" value="new value" /></td> | |||
</tr> | |||
<tr> | |||
<td>label</td><td><input id="node-label" value="new value" /></td> | |||
</tr></table> | |||
<input type="button" value="save" id="saveButton" /> | |||
<input type="button" value="cancel" id="cancelButton" /> | |||
</div> | |||
<br /> | |||
<div id="mynetwork"></div> | |||
</body> | |||
</html> | |||