Browse Source

Some fixes in the DOT parser

css_transitions
josdejong 11 years ago
parent
commit
0922851d46
4 changed files with 59 additions and 49 deletions
  1. +1
    -1
      src/graph/Edge.js
  2. +25
    -20
      src/graph/dotparser.js
  3. +27
    -22
      vis.js
  4. +6
    -6
      vis.min.js

+ 1
- 1
src/graph/Edge.js View File

@ -457,7 +457,7 @@ Edge.prototype._drawArrowEnd = function(ctx) {
var dy = (this.to.y - this.from.y);
var lEdge = Math.sqrt(dx * dx + dy * dy);
var lFrom = this.to.distanceToBorder(ctx, angle + Math.PI);
var lFrom = this.from.distanceToBorder(ctx, angle + Math.PI);
var pFrom = (lEdge - lFrom) / lEdge;
var xFrom = (pFrom) * this.from.x + (1 - pFrom) * this.to.x;
var yFrom = (pFrom) * this.from.y + (1 - pFrom) * this.to.y;

+ 25
- 20
src/graph/dotparser.js View File

@ -12,16 +12,15 @@
return parseGraph();
}
// token types enumeration
// token types enumeration
var TOKENTYPE = {
NULL : 0,
DELIMITER : 1,
NUMBER : 2,
STRING : 3,
UNKNOWN : 4
IDENTIFIER: 2,
UNKNOWN : 3
};
// map with all delimiters
// map with all delimiters
var DELIMITERS = {
'{': true,
'}': true,
@ -163,10 +162,10 @@
if (c == '#') {
// find the previous non-space character
var i = index - 1;
while (dot[i] == ' ' || dot[i] == '\t') {
while (dot.charAt(i) == ' ' || dot.charAt(i) == '\t') {
i--;
}
if (dot[i] == '\n' || dot[i] == '') {
if (dot.charAt(i) == '\n' || dot.charAt(i) == '') {
// the # is at the start of a line, this is indeed a line comment
while (c != '' && c != '\n') {
next();
@ -193,8 +192,8 @@
else {
next();
}
isComment = true;
}
isComment = true;
}
// skip over whitespaces
@ -239,17 +238,20 @@
token += c;
next();
}
if (!isNaN(Number(token))) {
token = Number(token);
tokenType = TOKENTYPE.NUMBER;
if (token == 'false') {
token = false; // cast to boolean
}
else {
tokenType = TOKENTYPE.STRING;
else if (token == 'true') {
token = true; // cast to boolean
}
else if (!isNaN(Number(token))) {
token = Number(token); // cast to number
}
tokenType = TOKENTYPE.IDENTIFIER;
return;
}
// check for a string
// check for a string enclosed by double quotes
if (c == '"') {
next();
while (c != '' && (c != '"' || (c == '"' && nextPreview() == '"'))) {
@ -263,7 +265,7 @@
throw newSyntaxError('End of string " expected');
}
next();
tokenType = TOKENTYPE.STRING;
tokenType = TOKENTYPE.IDENTIFIER;
return;
}
@ -301,7 +303,7 @@
}
// graph id
if (tokenType == TOKENTYPE.STRING) {
if (tokenType == TOKENTYPE.IDENTIFIER) {
graph.id = token;
getToken();
}
@ -335,8 +337,8 @@
*/
function parseStatements () {
while (token !== '' && token != '}') {
if (tokenType != TOKENTYPE.STRING && tokenType != TOKENTYPE.NUMBER) {
throw newSyntaxError('String expected');
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier expected');
}
parseStatement();
@ -439,7 +441,7 @@
getToken();
var attr = {};
while (token !== '' && token != ']') {
if (tokenType != TOKENTYPE.STRING) {
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Attribute name expected');
}
var name = token;
@ -450,7 +452,7 @@
}
getToken();
if (tokenType != TOKENTYPE.STRING && tokenType != TOKENTYPE.NUMBER) {
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Attribute value expected');
}
var value = token;
@ -503,6 +505,9 @@
label: id
};
merge(node, dotData.nodes[id].attr);
if (node.image) {
node.shape = 'image';
}
graphData.nodes.push(node);
}
}

+ 27
- 22
vis.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 0.0.8
* @date 2013-06-05
* @date 2013-06-06
*
* @license
* Copyright (C) 2011-2013 Almende B.V, http://almende.com
@ -6820,16 +6820,15 @@ Timeline.prototype.getItemRange = function getItemRange() {
return parseGraph();
}
// token types enumeration
// token types enumeration
var TOKENTYPE = {
NULL : 0,
DELIMITER : 1,
NUMBER : 2,
STRING : 3,
UNKNOWN : 4
IDENTIFIER: 2,
UNKNOWN : 3
};
// map with all delimiters
// map with all delimiters
var DELIMITERS = {
'{': true,
'}': true,
@ -6971,10 +6970,10 @@ Timeline.prototype.getItemRange = function getItemRange() {
if (c == '#') {
// find the previous non-space character
var i = index - 1;
while (dot[i] == ' ' || dot[i] == '\t') {
while (dot.charAt(i) == ' ' || dot.charAt(i) == '\t') {
i--;
}
if (dot[i] == '\n' || dot[i] == '') {
if (dot.charAt(i) == '\n' || dot.charAt(i) == '') {
// the # is at the start of a line, this is indeed a line comment
while (c != '' && c != '\n') {
next();
@ -7001,8 +7000,8 @@ Timeline.prototype.getItemRange = function getItemRange() {
else {
next();
}
isComment = true;
}
isComment = true;
}
// skip over whitespaces
@ -7047,17 +7046,20 @@ Timeline.prototype.getItemRange = function getItemRange() {
token += c;
next();
}
if (!isNaN(Number(token))) {
token = Number(token);
tokenType = TOKENTYPE.NUMBER;
if (token == 'false') {
token = false; // cast to boolean
}
else {
tokenType = TOKENTYPE.STRING;
else if (token == 'true') {
token = true; // cast to boolean
}
else if (!isNaN(Number(token))) {
token = Number(token); // cast to number
}
tokenType = TOKENTYPE.IDENTIFIER;
return;
}
// check for a string
// check for a string enclosed by double quotes
if (c == '"') {
next();
while (c != '' && (c != '"' || (c == '"' && nextPreview() == '"'))) {
@ -7071,7 +7073,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
throw newSyntaxError('End of string " expected');
}
next();
tokenType = TOKENTYPE.STRING;
tokenType = TOKENTYPE.IDENTIFIER;
return;
}
@ -7109,7 +7111,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
}
// graph id
if (tokenType == TOKENTYPE.STRING) {
if (tokenType == TOKENTYPE.IDENTIFIER) {
graph.id = token;
getToken();
}
@ -7143,8 +7145,8 @@ Timeline.prototype.getItemRange = function getItemRange() {
*/
function parseStatements () {
while (token !== '' && token != '}') {
if (tokenType != TOKENTYPE.STRING && tokenType != TOKENTYPE.NUMBER) {
throw newSyntaxError('String expected');
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Identifier expected');
}
parseStatement();
@ -7247,7 +7249,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
getToken();
var attr = {};
while (token !== '' && token != ']') {
if (tokenType != TOKENTYPE.STRING) {
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Attribute name expected');
}
var name = token;
@ -7258,7 +7260,7 @@ Timeline.prototype.getItemRange = function getItemRange() {
}
getToken();
if (tokenType != TOKENTYPE.STRING && tokenType != TOKENTYPE.NUMBER) {
if (tokenType != TOKENTYPE.IDENTIFIER) {
throw newSyntaxError('Attribute value expected');
}
var value = token;
@ -7311,6 +7313,9 @@ Timeline.prototype.getItemRange = function getItemRange() {
label: id
};
merge(node, dotData.nodes[id].attr);
if (node.image) {
node.shape = 'image';
}
graphData.nodes.push(node);
}
}
@ -8639,7 +8644,7 @@ Edge.prototype._drawArrowEnd = function(ctx) {
var dy = (this.to.y - this.from.y);
var lEdge = Math.sqrt(dx * dx + dy * dy);
var lFrom = this.to.distanceToBorder(ctx, angle + Math.PI);
var lFrom = this.from.distanceToBorder(ctx, angle + Math.PI);
var pFrom = (lEdge - lFrom) / lEdge;
var xFrom = (pFrom) * this.from.x + (1 - pFrom) * this.to.x;
var yFrom = (pFrom) * this.from.y + (1 - pFrom) * this.to.y;

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


Loading…
Cancel
Save