Browse Source

Minor improvements in the DOT parser, better error handling

css_transitions
josdejong 11 years ago
parent
commit
9e161ef381
4 changed files with 31 additions and 11 deletions
  1. +0
    -2
      examples/graph/graphviz/graphviz_gallery.html
  2. +14
    -3
      src/graph/dotparser.js
  3. +14
    -3
      vis.js
  4. +3
    -3
      vis.min.js

+ 0
- 2
examples/graph/graphviz/graphviz_gallery.html View File

@ -57,9 +57,7 @@
<option value="data/transparency.gv.txt">transparency</option> <option value="data/transparency.gv.txt">transparency</option>
<option value="data/twopi2.gv.txt">twopi2</option> <option value="data/twopi2.gv.txt">twopi2</option>
<option value="data/unix.gv.txt">unix</option> <option value="data/unix.gv.txt">unix</option>
<!-- TODO: get example world working (needs some extension of the DOT parser)
<option value="data/world.gv.txt">world</option> <option value="data/world.gv.txt">world</option>
-->
</select> </select>
</p> </p>

+ 14
- 3
src/graph/dotparser.js View File

@ -439,6 +439,9 @@
} }
// parse node // parse node
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier expected');
}
var id = token; // id can be a string or a number var id = token; // id can be a string or a number
getToken(); getToken();
@ -448,6 +451,9 @@
if (!graph.attr) { if (!graph.attr) {
graph.attr = {}; graph.attr = {};
} }
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier expected');
}
graph.attr[id] = token; graph.attr[id] = token;
getToken(); getToken();
// TODO: implement comma separated list with "ID=ID" // TODO: implement comma separated list with "ID=ID"
@ -468,7 +474,7 @@
// optional subgraph keyword // optional subgraph keyword
if (token == 'subgraph') { if (token == 'subgraph') {
subgraph = {}; subgraph = {};
subgraph.type = token;
subgraph.type = 'subgraph';
getToken(); getToken();
// optional graph id // optional graph id
@ -488,7 +494,7 @@
}; };
} }
// TODO: copy global node and edge attributes into subgraph?
// TODO: copy global node and edge attributes into subgraph or not?
// statements // statements
parseStatements(subgraph); parseStatements(subgraph);
@ -591,14 +597,19 @@
to = subgraph; to = subgraph;
} }
else { else {
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier or subgraph expected');
}
to = token; to = token;
addNode(graph, { addNode(graph, {
id: to id: to
}); });
getToken(); getToken();
var attr = parseAttributeList();
} }
// parse edge attributes
var attr = parseAttributeList();
// create edge // create edge
var edge = createEdge(graph, from, to, type, attr); var edge = createEdge(graph, from, to, type, attr);
addEdge(graph, edge); addEdge(graph, edge);

+ 14
- 3
vis.js View File

@ -7247,6 +7247,9 @@ Timeline.prototype.getItemRange = function getItemRange() {
} }
// parse node // parse node
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier expected');
}
var id = token; // id can be a string or a number var id = token; // id can be a string or a number
getToken(); getToken();
@ -7256,6 +7259,9 @@ Timeline.prototype.getItemRange = function getItemRange() {
if (!graph.attr) { if (!graph.attr) {
graph.attr = {}; graph.attr = {};
} }
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier expected');
}
graph.attr[id] = token; graph.attr[id] = token;
getToken(); getToken();
// TODO: implement comma separated list with "ID=ID" // TODO: implement comma separated list with "ID=ID"
@ -7276,7 +7282,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
// optional subgraph keyword // optional subgraph keyword
if (token == 'subgraph') { if (token == 'subgraph') {
subgraph = {}; subgraph = {};
subgraph.type = token;
subgraph.type = 'subgraph';
getToken(); getToken();
// optional graph id // optional graph id
@ -7296,7 +7302,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
}; };
} }
// TODO: copy global node and edge attributes into subgraph?
// TODO: copy global node and edge attributes into subgraph or not?
// statements // statements
parseStatements(subgraph); parseStatements(subgraph);
@ -7399,14 +7405,19 @@ Timeline.prototype.getItemRange = function getItemRange() {
to = subgraph; to = subgraph;
} }
else { else {
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier or subgraph expected');
}
to = token; to = token;
addNode(graph, { addNode(graph, {
id: to id: to
}); });
getToken(); getToken();
var attr = parseAttributeList();
} }
// parse edge attributes
var attr = parseAttributeList();
// create edge // create edge
var edge = createEdge(graph, from, to, type, attr); var edge = createEdge(graph, from, to, type, attr);
addEdge(graph, edge); addEdge(graph, edge);

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


Loading…
Cancel
Save