Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Major bug correction in render

  • Loading branch information...
commit 84aeb93b8a2d87bea8f1515a1c3d1c75a77255ad 1 parent e847bd5
@glejeune authored
View
75 lib/deps/graph.js
@@ -40,11 +40,11 @@ var Graph = exports.Graph = function(graph, id) {
*/
Graph.prototype.addNode = function(id, attrs) {
this.nodes.setItem(id, new Node(this, id));
- if( attrs ) {
- for( k in attrs ) {
- this.nodes.items[id].set( k, attrs[k] );
- }
- }
+ if( attrs ) {
+ for( k in attrs ) {
+ this.nodes.items[id].set( k, attrs[k] );
+ }
+ }
return this.nodes.items[id];
}
@@ -96,11 +96,11 @@ Graph.prototype.addEdge = function(nodeOne, nodeTwo, attrs) {
}
var edge = new Edge(this, _nodeOne, _nodeTwo);
- if( attrs ) {
- for( k in attrs ) {
- edge.set( k, attrs[k] );
- }
- }
+ if( attrs ) {
+ for( k in attrs ) {
+ edge.set( k, attrs[k] );
+ }
+ }
this.edges.push( edge );
return edge;
@@ -234,7 +234,7 @@ Graph.prototype.to_dot = function() {
// Graph attributs
for( var name in this.graphAttributs.items ) {
dotScript = dotScript + ' ' + name + ' = \"' +
- this.graphAttributs.items[name] + '\";\n'
+ this.graphAttributs.items[name] + '\";\n'
}
// Nodes attributs
@@ -243,7 +243,7 @@ Graph.prototype.to_dot = function() {
var sep = ' '
for( var name in this.nodesAttributs.items ) {
dotScript = dotScript + sep + name + ' = \"' +
- this.nodesAttributs.items[name] + '\"'
+ this.nodesAttributs.items[name] + '\"'
sep = ',\n '
}
dotScript = dotScript + '\n ];\n'
@@ -255,7 +255,7 @@ Graph.prototype.to_dot = function() {
var sep = ' '
for( var name in this.edgesAttributs.items ) {
dotScript = dotScript + sep + name + ' = \"' +
- this.edgesAttributs.items[name] + '\"'
+ this.edgesAttributs.items[name] + '\"'
sep = ',\n '
}
dotScript = dotScript + '\n ];\n'
@@ -290,28 +290,37 @@ Graph.prototype.to_dot = function() {
* @api public
*/
Graph.prototype.render = function(type, name_or_callback, errback) {
- var dotScript = this.to_dot();
-
- var cmd = this.use;
- if( this.gvPath != '' ) {
- cmd = path.join( this.gvPath, this.use )
- }
-
- var rendered = null;
- var parameters = ['-T' + type];
- var outcallback = function(data) { rendered = data; };
-
- if( typeof(name_or_callback) == 'string' ) {
- parameters.push( '-o' + name_or_callback )
- outcallback = function(data) { if(data) console.log(data); }
- }
-
+ var dotScript = this.to_dot();
+
+ var cmd = this.use;
+ if( this.gvPath != '' ) {
+ cmd = path.join( this.gvPath, this.use )
+ }
+
+ var rendered = null;
+ var parameters = ['-T' + type];
+ var outcallback = function(data) {
+ if( rendered == null ) {
+ rendered = data;
+ } else {
+ __b = new Buffer( rendered.length + data.length )
+ rendered.copy(__b, 0, 0)
+ data.copy(__b, rendered.length, 0)
+ rendered = __b
+ }
+ };
+
+ if( typeof(name_or_callback) == 'string' ) {
+ parameters.push( '-o' + name_or_callback )
+ outcallback = function(data) { if(data) console.log(data); }
+ }
+
graphviz = spawn(cmd, parameters);
graphviz.stdout.on('data', outcallback);
graphviz.stderr.on('data', function(data) {
- if(data) console.log(data);
- });
- graphviz.on('exit', function(code) {
+ if(data) console.log("STDERR:"+data);
+ });
+ graphviz.on('exit', function(code) {
if(code !== 0) {
if(errback) { errback(code) }
} else {
@@ -323,7 +332,7 @@ Graph.prototype.render = function(type, name_or_callback, errback) {
}
// Compatibility
Graph.prototype.output = function(type, name_or_callback, errback) {
- this.render(type, name_or_callback, errback);
+ this.render(type, name_or_callback, errback);
}
/**
View
26 lib/graphviz.js
@@ -33,24 +33,24 @@ exports.digraph = function(id) {
}
exports.parse = function(file, callback, errback) {
- var gvprScript = path.join( __dirname, "ext", "gvpr", "dot2js.g" )
- var parameters = ["-f"+gvprScript, file]
- var cmd = "gvpr"
- var __graph_eval;
-
- graphviz = spawn(cmd, parameters);
+ var gvprScript = path.join( __dirname, "ext", "gvpr", "dot2js.g" )
+ var parameters = ["-f"+gvprScript, file]
+ var cmd = "gvpr"
+ var __graph_eval;
+
+ graphviz = spawn(cmd, parameters);
graphviz.stdout.on('data', function(data) {
- eval(data.toString());
+ eval(data.toString());
});
graphviz.stderr.on('data', function(data) {
- if(data) console.log( "STDERR: "+data);
- });
+ if(data) console.log( "STDERR: "+data);
+ });
graphviz.stdin.end();
- graphviz.on('exit', function(code) {
+ graphviz.on('exit', function(code) {
if(code !== 0) {
- if(errback) { errback(code) }
+ if(errback) { errback(code) }
} else {
- callback(__graph_eval)
- }
+ callback(__graph_eval)
+ }
});
}
View
6 tests/parse.js
@@ -4,3 +4,9 @@ var sys = require('sys'),
graphviz.parse( "cluster.dot", function(graph) {
graph.render( "png", "cluster.png" );
})
+
+graphviz.parse( "cluster.dot", function(graph) {
+ graph.render( "png", function(render) {
+ process.stdout.write( render );
+ });
+});
View
31 tests/server/app.js
@@ -1,25 +1,32 @@
-var app = require('express').createServer();
+var express = require('express'),
+ app = express.createServer(),
+ temp = require('temp'),
+ fs = require('fs');
var sys = require('sys'),
graphviz = require('graphviz');
app.set('views', __dirname + '/views');
+app.configure(function(){
+ app.use(express.bodyDecoder());
+})
app.get('/', function(req, res){
res.render('index.ejs', {});
});
-app.get('/image.png', function(req,res){
- var g = graphviz.digraph("G");
- var n1 = g.addNode( "Hello" );
- n1.set( "color", "red" );
- n1.set( "style", "filled" );
- g.addNode( "World" );
- var e = g.addEdge( n1, "World" );
- e.set( "color", "red" );
- g.render( "png", function(render) {
- res.send(render, { 'Content-Type': 'image/png' })
- } );
+app.post('/test', function(req,res){
+ temp.open('dotGraph', function(err, info) {
+ fs.write(info.fd, req.body.data);
+ fs.close(info.fd, function(err) {
+ graphviz.parse( info.path, function(graph) {
+ graph.render( "png", function(render) {
+ img = '<img src="data:image/png;base64,'+render.toString("base64")+'"/>'
+ res.send(img)
+ });
+ });
+ });
+ });
})
app.listen(3000);
View
22 tests/server/views/index.ejs
@@ -1,3 +1,21 @@
-<p>Hello !</p>
+<h1>dotGraph</h1>
+
+<table>
+ <tr><td>
+ <textarea id="dot" cols="60" rows="20"></textarea>
+ </td><td>
+ <div id="result"></div>
+ </td></tr>
+</table>
+
+<input id="button" type="button" value="Generate" />
+
+
+<script type="text/javascript">
+ $('#button').click(function() {
+ $.post('test', { data: $('#dot').val() }, function(data) {
+ $('#result').html(data);
+ });
+ });
+</script>
-<img src="/image.png" />
View
12 tests/server/views/layout.ejs
@@ -1,5 +1,11 @@
<html>
- <body>
- <%- body %>
- </body>
+ <head>
+ <style>
+ #button { background-color:#EEE; cursor:pointer; }
+ </style>
+ <script src="http://code.jquery.com/jquery-latest.min.js"></script>
+ </head>
+ <body>
+ <%- body %>
+ </body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.