On Jun 22, 2011, at 19:30, Nick wrote:
> I've been trying to get Canviz to read data from a dot-formatted
> string passed from a server, but to no avail. I tried adapting the
> advice given in this thread: http://groups.google.com/group/canviz/browse_thread/thread/76590248a40fa225,
> but I think it must be out of date (Canviz doesn't have a Graph class
> anymore, I'm assuming).
Graph got renamed to CanvizGraph to attempt to not pollute the global namespace with generic names. You don't need to deal with CanvizGraphs directly though, you can just create the Canviz object and use its methods.
> Is there a simple way to get Canviz to parse a
> string? Unfortunately, Google App Engine doesn't allow you to write
> files to disk, so reading from a file isn't an option.
>
> It seems like I should just be able to call the parse() method on a
> string, but I haven't been able to figure out how to make a new Canviz
> object without a file to pass in. I'm a bit of a beginner, obviously.
By the way I rescind my last remark at the end of the thread you referenced -- "I don't think you'll need to use this directly" -- I acknowledge that it some cases you do need to get the parsed xdot graph into a string yourself, and then pass it to the Canviz parse() method. And this should work fine. Only the first argument of the Canviz() constructor is required; the second parameter (the URL) is optional. So this should work (if your page has a div named "canviz"):
var graph_in_xdot = 'digraph hello_world {\n\
node [label="\N", href="javascript:void(click_node(\'\N\'))"];\n\
graph [bb="0,0,146,108",\n\
_draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 108 147 \
108 147 -1 ",\n\
xdotversion="1.2"];\n\
hello [pos="35,90", width="0.97222", height="0.5", _draw_="c 9 \
-#000000ff e 35 90 35 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 \
-#000000ff T 35 85 0 35 5 -hello "];\n\
world [pos="108,18", width="1.0556", height="0.5", _draw_="c 9 \
-#000000ff e 108 18 38 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 \
-#000000ff T 108 13 0 39 5 -world "];\n\
hello:e -> world:w [pos="e,70,18 70,90 96.75,90 56.416,39.687 \
61.154,23.178", _draw_="c 9 -#000000ff B 4 70 90 97 90 56 40 61 23 ", \
_hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 63 26 70 18 60 \
20 "];\n\
}';
document.observe('dom:loaded', function() {
var my_canviz = new Canviz('canviz');
my_canviz.parse(graph_in_xdot);
});