我试图将我的.dot文件从Graphviz输出转换为SVG,以便可以使用D3.js对其进行操作。现在,我只是试图读取我的.dot文件并将其打印到控制台。目前,这是我拥有的javascript
var fs = require('fs');
var dot = require('graphlib-dot');
var graph = dot.read(fs.readFileSync('profile.dot', 'UTF-8'));
console.log(dot.write(graph));
当我尝试在节点中运行文件时,出现以下错误
/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:114
result[k] = v[3];
^
TypeError: Cannot read property '3' of null
at peg$c34 (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:114:28)
at peg$parseidDef (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:1421:16)
at peg$parseaList (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:1144:12)
at peg$parseattrListBlock (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:1093:16)
at peg$parseattrList (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:1012:12)
at peg$parsenodeStmt (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:808:16)
at peg$parsestmt (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:689:20)
at peg$parsestmtList (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:615:22)
at peg$parsegraphStmt (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:452:28)
at Object.parse (/Users/blank/node_modules/graphlib-dot/lib/dot-grammar.js:2372:18)
这是我的.dot文件
digraph G {
pad = 0.5;
nodesep = 0.5;
"legend" [label = < <table border="0" cellborder="1"
cellspacing="0"><tr><td>Helix</td><td>Triplet</td>
<td>Frequency</td></tr>
<tr><td>1</td><td>1 73 8</td><td>1000</td></tr>
<tr><td>2</td><td>50 66 5</td><td>656</td></tr>
<tr><td>3</td><td>17 32 5</td><td>614</td></tr>
<tr><td>4</td><td>12 36 6</td><td>585</td></tr>
<tr><td>5</td><td>40 52 5</td><td>545</td></tr>
<tr><td>6</td><td>13 47 8</td><td>278</td></tr>
</table>>, shape = plaintext, fontsize=11];
"1 2 3 4 5 " [shape = box];
"1 2 6 " [shape = box];
"1 3 4 5 " [shape = box];
"1 " [shape = box];
"1 2 " [style = dashed];
"1 2 3 4 5 " [label = "[1[4[3]][5][2]]\n372/372"];
"1 2 6 " [label = "[1[6][2]]\n208/238"];
"1 3 4 5 " [label = "[1[4[3]][5]]\n165/537"];
"1 " [label = "[1]\n121/1000"];
"1 2 " [label = "[1[2]]\n12/656"];
"1 " [label = "[1]\n121/1000"];
"1 3 4 5 " -> "1 2 3 4 5 " [label = "2 ", arrowhead = vee];
"1 2 " -> "1 2 3 4 5 " [label = "3 4 5 ", arrowhead = vee];
"1 2 " -> "1 2 6 " [label = "6 ", arrowhead = vee];
"1 " -> "1 2 3 4 5 " [label = "2 3 4 5 ", arrowhead = vee];
"1 " -> "1 2 6 " [label = "2 6 ", arrowhead = vee];
"1 " -> "1 3 4 5 " [label = "3 4 5 ", arrowhead = vee];
"1 " -> "1 " [label = "", arrowhead = vee];
"1 " -> "1 2 " [label = "2 ", arrowhead = vee];
}
答案 0 :(得分:0)
要了解问题是否出在您的DOT或graphlib-dot代码上,您可以尝试使用其他库,例如https://github.com/anvaka/dotparser/或https://github.com/siefkenj/dotgraph。如果其他库之一正常工作,则它可能是graphlib-dot的问题。希望有帮助!