Browse Source

DOT parser does now maintain order of nodes, is returned as an array instead of a map

css_transitions
josdejong 11 years ago
parent
commit
44562dc205
5 changed files with 68 additions and 55 deletions
  1. +1
    -7
      examples/graph/15_dot_language_playground.html
  2. +1
    -0
      package.json
  3. +30
    -21
      src/graph/dotparser.js
  4. +32
    -23
      vis.js
  5. +4
    -4
      vis.min.js

+ 1
- 7
examples/graph/15_dot_language_playground.html View File

@ -48,7 +48,7 @@
}
</style>
</head>
<body>
<body onload="drawExample('example1')">
<table id="frame">
<col width="50%">
@ -199,11 +199,5 @@ digraph G {
}
</textarea>
<script>
// draw example1 now
drawExample('example1');
</script>
</body>
</html>

+ 1
- 0
package.json View File

@ -27,6 +27,7 @@
"devDependencies": {
"jake": "latest",
"jake-utils": "latest",
"browserify": "latest",
"moment": "latest"
}
}

+ 30
- 21
src/graph/dotparser.js View File

@ -109,10 +109,21 @@
* @param {Object} node
*/
function addNode(node) {
if (!graph.nodes) {
graph.nodes = {};
var nodes = graph.nodes;
if (!nodes) {
nodes = [];
graph.nodes = nodes;
}
var current = graph.nodes[node.id];
// find existing node
var current = null;
for (var i = 0, len = nodes.length; i < len; i++) {
if (node.id === nodes[i].id) {
current = nodes[i];
break;
}
}
if (current) {
// merge attributes
if (node.attr) {
@ -121,7 +132,7 @@
}
else {
// add
graph.nodes[node.id] = node;
graph.nodes.push(node);
if (nodeAttr) {
var attr = merge({}, nodeAttr); // clone global attributes
node.attr = merge(attr, node.attr); // merge attributes
@ -130,7 +141,7 @@
}
/**
* Add an edge to the current graph obect
* Add an edge to the current graph object
* @param {Object} edge
*/
function addEdge(edge) {
@ -395,7 +406,7 @@
else {
// node statement
var node = {
id: String(id)
id: id
};
attr = parseAttributes();
if (attr) {
@ -411,15 +422,15 @@
var to = token;
addNode({
id: String(to)
id: to
});
getToken();
attr = parseAttributes();
// create edge
var edge = {
from: String(from),
to: String(to),
from: from,
to: to,
type: type
};
if (attr) {
@ -510,19 +521,17 @@
// copy the nodes
if (dotData.nodes) {
for (var id in dotData.nodes) {
if (dotData.nodes.hasOwnProperty(id)) {
var node = {
id: id,
label: id
};
merge(node, dotData.nodes[id].attr);
if (node.image) {
node.shape = 'image';
}
graphData.nodes.push(node);
dotData.nodes.forEach(function (dotNode) {
var graphNode = {
id: dotNode.id,
label: String(dotNode.label || dotNode.id)
};
merge(graphNode, dotNode.attr);
if (graphNode.image) {
graphNode.shape = 'image';
}
}
graphData.nodes.push(graphNode);
});
}
// copy the edges

+ 32
- 23
vis.js View File

@ -4,8 +4,8 @@
*
* A dynamic, browser-based visualization library.
*
* @version 0.0.9
* @date 2013-06-07
* @version 0.1.0-SNAPSHOT
* @date 2013-06-10
*
* @license
* Copyright (C) 2011-2013 Almende B.V, http://almende.com
@ -6917,10 +6917,21 @@ Timeline.prototype.getItemRange = function getItemRange() {
* @param {Object} node
*/
function addNode(node) {
if (!graph.nodes) {
graph.nodes = {};
var nodes = graph.nodes;
if (!nodes) {
nodes = [];
graph.nodes = nodes;
}
var current = graph.nodes[node.id];
// find existing node
var current = null;
for (var i = 0, len = nodes.length; i < len; i++) {
if (node.id === nodes[i].id) {
current = nodes[i];
break;
}
}
if (current) {
// merge attributes
if (node.attr) {
@ -6929,7 +6940,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
}
else {
// add
graph.nodes[node.id] = node;
graph.nodes.push(node);
if (nodeAttr) {
var attr = merge({}, nodeAttr); // clone global attributes
node.attr = merge(attr, node.attr); // merge attributes
@ -6938,7 +6949,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
}
/**
* Add an edge to the current graph obect
* Add an edge to the current graph object
* @param {Object} edge
*/
function addEdge(edge) {
@ -7203,7 +7214,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
else {
// node statement
var node = {
id: String(id)
id: id
};
attr = parseAttributes();
if (attr) {
@ -7219,15 +7230,15 @@ Timeline.prototype.getItemRange = function getItemRange() {
var to = token;
addNode({
id: String(to)
id: to
});
getToken();
attr = parseAttributes();
// create edge
var edge = {
from: String(from),
to: String(to),
from: from,
to: to,
type: type
};
if (attr) {
@ -7318,19 +7329,17 @@ Timeline.prototype.getItemRange = function getItemRange() {
// copy the nodes
if (dotData.nodes) {
for (var id in dotData.nodes) {
if (dotData.nodes.hasOwnProperty(id)) {
var node = {
id: id,
label: id
};
merge(node, dotData.nodes[id].attr);
if (node.image) {
node.shape = 'image';
}
graphData.nodes.push(node);
dotData.nodes.forEach(function (dotNode) {
var graphNode = {
id: dotNode.id,
label: String(dotNode.label || dotNode.id)
};
merge(graphNode, dotNode.attr);
if (graphNode.image) {
graphNode.shape = 'image';
}
}
graphData.nodes.push(graphNode);
});
}
// copy the edges

+ 4
- 4
vis.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save