summaryrefslogtreecommitdiff
path: root/www/lib/vis/examples/network/other/saveAndLoad.html
diff options
context:
space:
mode:
authorPliable Pixels <pliablepixels@gmail.com>2017-09-27 12:42:48 -0400
committerPliable Pixels <pliablepixels@gmail.com>2017-09-27 12:42:48 -0400
commit210e8feae2fb4842bfb2de38666e6c41671fef3c (patch)
treecbdafa34b1a6260bb20236d7e9de9eb1b690a1c5 /www/lib/vis/examples/network/other/saveAndLoad.html
parente7e7baeaad90229ccb3e0f45f4ebd77be7d79b14 (diff)
removed lib
Diffstat (limited to 'www/lib/vis/examples/network/other/saveAndLoad.html')
-rw-r--r--www/lib/vis/examples/network/other/saveAndLoad.html177
1 files changed, 0 insertions, 177 deletions
diff --git a/www/lib/vis/examples/network/other/saveAndLoad.html b/www/lib/vis/examples/network/other/saveAndLoad.html
deleted file mode 100644
index 08165c85..00000000
--- a/www/lib/vis/examples/network/other/saveAndLoad.html
+++ /dev/null
@@ -1,177 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
- <meta content="utf-8" http-equiv="encoding">
- <title>Network | Saving and loading networks</title>
-
- <style type="text/css">
- body {
- font: 10pt sans;
- }
- #network {
- float:left;
- width: 600px;
- height: 600px;
- margin:5px;
- border: 1px solid lightgray;
- }
- #config {
- float:left;
- width: 400px;
- height: 600px;
- }
- #input_output {
- height: 10%;
- width: 15%;
- }
-
- p {
- font-size:16px;
- max-width:700px;
- }
- </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 src="../../googleAnalytics.js"></script>
- </head>
-
- <body>
- <p>
- In this example, the network data can be exported to JSON and imported back into the network.
-
- Try this out by exporting the network to JSON, clearing the network and then importing it again. The nodes will all appear in the same position as they were before the network was destroyed.
- </p>
-
- <div id="network"></div>
-
- <div>
- <textarea id=input_output></textarea>
- <input type="button" id="import_button" onclick="importNetwork()" value="import"></input>
- <input type="button" id="export_button" onclick="exportNetwork()" value="export"></input>
- <input type="button" id="destroy_button" onclick="destroyNetwork()" value="destroy"></input>
- </div>
-
- <script type="text/javascript">
- var network;
- var container;
- var exportArea;
- var importButton;
- var exportButton;
-
- function init() {
- container = document.getElementById('network');
- exportArea = document.getElementById('input_output');
- importButton = document.getElementById('import_button');
- exportButton = document.getElementById('export_button');
-
- draw();
- }
-
- function addContextualInformation(elem, index, array) {
- addId(elem, index);
- addConnections(elem, index);
- }
-
- function addId(elem, index) {
- elem.id = index;
- }
-
- function addConnections(elem, index) {
- // need to replace this with a tree of the network, then get child direct children of the element
- elem.connections = network.getConnectedNodes(index);
- }
-
- function destroyNetwork() {
- network.destroy();
- }
-
- function clearOutputArea() {
- exportArea.value = "";
- }
-
- function draw() {
- // create a network of nodes
- var data = getScaleFreeNetwork(5);
-
- network = new vis.Network(container, data, {manipulation:{enabled:true}});
-
- clearOutputArea();
- }
-
- function exportNetwork() {
- clearOutputArea();
-
- var nodes = objectToArray(network.getPositions());
-
- nodes.forEach(addContextualInformation);
-
- // pretty print node data
- var exportValue = JSON.stringify(nodes, undefined, 2);
-
- exportArea.value = exportValue;
-
- resizeExportArea();
- }
-
- function importNetwork() {
- var inputValue = exportArea.value;
- var inputData = JSON.parse(inputValue);
-
- var data = {
- nodes: getNodeData(inputData),
- edges: getEdgeData(inputData)
- }
-
- network = new vis.Network(container, data, {});
-
- resizeExportArea();
- }
-
- function getNodeData(data) {
- var networkNodes = [];
-
- data.forEach(function(elem, index, array) {
- networkNodes.push({id: elem.id, label: elem.id, x: elem.x, y: elem.y});
- });
-
- return new vis.DataSet(networkNodes);
- }
-
- function getEdgeData(data) {
- var networkEdges = [];
-
- data.forEach(function(node, index, array) {
- // add the connection
- node.connections.forEach(function(connId, cIndex, conns) {
- networkEdges.push({from: node.id, to: connId});
-
- var elementConnections = array[connId].connections;
-
- // remove the connection from the other node to prevent duplicate connections
- var duplicateIndex = elementConnections.findIndex(function(connection) {
- connection === node.id;
- });
-
- elementConnections = elementConnections.splice(0, duplicateIndex - 1).concat(elementConnections.splice(duplicateIndex + 1, elementConnections.length))
- });
- });
-
- return new vis.DataSet(networkEdges);
- }
-
- function objectToArray(obj) {
- return Object.keys(obj).map(function (key) { return obj[key]; });
- }
-
- function resizeExportArea() {
- exportArea.style.height = (1 + exportArea.scrollHeight) + "px";
- }
-
- init();
- </script>
- </body>
-</html> \ No newline at end of file