bpartridge / graphviz.js

Graphviz layout engine running in the browser using the Emscripten cross-compiler
74 stars 11 forks source link

Failing to run #1

Open captncraig opened 12 years ago

captncraig commented 12 years ago

I know this project is fairly new, but I am quite interested in seeing if this works out. When I try to run the demo file with the default input, the browser crahes because _Pshortestpath is not a function.

Looking at graphviz.js it looks like the function is called, but never defined, except on line 154263: var _Pshortestpath;. Perhaps there is additional source somewhere that is not being translated.

Have you gotten the sample input working yet, or is this a known issue?

Also, just out of curiosity, what are your intentions for actually rendering the graphs? or what is the expected output format?

bpartridge commented 12 years ago

The sample input does work on my machine. Try taking --llvm-opts 3 out of the makefile, I have that change locally but didn't push it, optimizations don't work yet. Emscripten is insane when it comes to dead code stripping, in that it strips out a lot of things that shouldn't be stripped, and it's very fragile. Maybe try checking out your Emscripten to 1e6009144e50f9a920208868003b6b93ea972732.

My original intent was to be able to have automatically-arranging divs on websites, passing in their sizes and relationships and then parsing the simple output (which is kind of like a tab-separated values format giving node locations).

I'm working on a number of other projects at the moment, but let me know if there's anything that's unclear in the documentation.

captncraig commented 12 years ago

Interesting. I was not running emscripten at all, only running your precompiled version. I'll try and build it locally and see what happens.

bpartridge commented 12 years ago

Interesting. What browser are you running?

izuzak commented 12 years ago

@bpartridge I'm having the same issue. Cloned the GH repo, opened DEMO.html and getting the Uncaught TypeError: Property '_Pshortestpath' of object [object Window] is not a function error in the console. I've tried using Chromium 21.0.1137.0, Chrome 21.0.1163.0 and Firefox 12.0.

@captncraig Did building locally resolve the issue for you? If so, updating the GH repo with the non-optimized version sounds like a good idea, @bpartridge.

izuzak commented 12 years ago

Hi @bpartridge,

I tried building graphviz.js myself, but have run into some problems. Please let me know if you can help.

1) One minor error first. make fails on decompressing with:

mkdir -p graphviz-src
tar xjf graphviz-src.tar.gz -C graphviz-src --strip=1
bzip2: (stdin) is not a bzip2 file.
tar: Child returned status 2
tar: Error is not recoverable: exiting now
make: *** [graphviz-src] Error 2

I fixed this by replacing xjf with xvf in the Makefile

2) using the latest emscripten version (commit c406b3bc87fa69ae6a1fc7a1c6c8b7118f4ffec4), the build fails with the error:

Making all in tools
make[4]: Entering directory `/home/izuzak/graphviz.js/graphviz-src/cmd/tools'
  CCLD   mm2gv
/home/izuzak/llvm/bin/llvm-link: link error in '/tmp/emscripten_temp_INXAN8/ar_output_8777/utils.o': Linking globals named 'agdictobjmem': symbol multiply defined!
Traceback (most recent call last):
  File "/home/izuzak/emscripten/emcc", line 718, in <module>
    shared.Building.link(temp_files, specified_target)
  File "/home/izuzak/emscripten/tools/shared.py", line 581, in link
    assert os.path.exists(target) and (output is None or 'Could not open input file' not in output), 'Linking error: ' + output
AssertionError: Linking error: 
make[4]: *** [mm2gv] Error 1
make[4]: Leaving directory `/home/izuzak/graphviz.js/graphviz-src/cmd/tools'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/izuzak/graphviz.js/graphviz-src/cmd'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/izuzak/graphviz.js/graphviz-src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/izuzak/graphviz.js/graphviz-src'
make: *** [graphviz-install/lib] Error 2

Using --ignore-dynamic-linking as per in https://github.com/kripken/emscripten/issues/266 does not make a difference. Removing --llvm-opts 3 also makes no difference.

3) using commit 1e6009144e50f9a920208868003b6b93ea972732 of emscripten (as you suggest in an earlier comment), I get this error:

emcc: running variable eliminator
Traceback (most recent call last):
  File "/home/izuzak/emscripten/emcc", line 1111, in <module>
    final = shared.Building.eliminator(final)
  File "/home/izuzak/emscripten/tools/shared.py", line 765, in eliminator
    assert len(output) > 0, 'Error in eliminator: ' + err + '\n\n' + output
AssertionError: Error in eliminator: path.exists is deprecated. It is now called `fs.exists`.
TypeError: Cannot call method 'replace' of undefined
    at /home/izuzak/emscripten/tools/eliminator/eliminator.coffee:425:57
    at Object.<anonymous> (/home/izuzak/emscripten/tools/eliminator/eliminator.coffee:450:3)
    at Object.<anonymous> (/home/izuzak/emscripten/tools/eliminator/eliminator.coffee:451:4)
    at Module._compile (module.js:449:26)
    at Object.run (/home/izuzak/emscripten/tools/eliminator/node_modules/coffee-script/lib/coffee-script.js:57:25)
    at /home/izuzak/emscripten/tools/eliminator/node_modules/coffee-script/lib/command.js:147:29
    at /home/izuzak/emscripten/tools/eliminator/node_modules/coffee-script/lib/command.js:115:26
    at Object.oncomplete (fs.js:149:14)

This a minor problem with nodejs. After replacing path.exists with fs.exists in emscripten/tools/eliminator/node_modules/coffee-script/lib/command.js, the build error changes to:

emcc: running variable eliminator
Traceback (most recent call last):
  File "/home/izuzak/emscripten/emcc", line 1111, in <module>
    final = shared.Building.eliminator(final)
  File "/home/izuzak/emscripten/tools/shared.py", line 765, in eliminator
    assert len(output) > 0, 'Error in eliminator: ' + err + '\n\n' + output
AssertionError: Error in eliminator: TypeError: Cannot call method 'replace' of undefined
    at /home/izuzak/emscripten/tools/eliminator/eliminator.coffee:425:57
    at Object.<anonymous> (/home/izuzak/emscripten/tools/eliminator/eliminator.coffee:450:3)
    at Object.<anonymous> (/home/izuzak/emscripten/tools/eliminator/eliminator.coffee:451:4)
    at Module._compile (module.js:449:26)
    at Object.run (/home/izuzak/emscripten/tools/eliminator/node_modules/coffee-script/lib/coffee-script.js:57:25)
    at /home/izuzak/emscripten/tools/eliminator/node_modules/coffee-script/lib/command.js:147:29
    at /home/izuzak/emscripten/tools/eliminator/node_modules/coffee-script/lib/command.js:115:26
    at Object.oncomplete (fs.js:149:14)

Deleting --llvm-opts 3 from makefile does not help.

bpartridge commented 12 years ago

Hey everyone, I certainly didn't expect this much interest when I released this little hack! I never tested it on any system except my own, and while I thought I had isolated this code from my machine's configuration, it's certainly possible I overlooked some things. I'll look into all these problems as soon as I can!

kripken commented 12 years ago

You can disable dead code elimination in emcc with -s LINKABLE=1.

The multiply-defined symbols problem can potentially be fixed by not using .a files. Instead compile to .so's and link those (.a files link in odd ways). I don't know how easy it is to modify the build system to do that though. If that doesn't help, please file a bug on emscripten with the relevant files so I can reproduce and debug it.

izuzak commented 12 years ago

@bpartridge great, thanks! :) I'm hoping to use graphviz.js instead of calling Google's API, in a webapp I'm building. I think that the lib will be interesting to many other people, also :)

Anyway, thanks to @kripken's help (advice regarding -s LINKABLE=1), I've managed to build graphviz.js, but only using the older emscripten version (commit 1e60091, bullet 3 from my previous comment). However, after building graphviz.js, the original problem remains as the DEMO.html page is throwing an error: Uncaught TypeError: Property '_Pshortestpath' of object [object Window] is not a function. Digging deeper in this direction, I notice that _Pshortestpath is actually declared in graphviz.js in line 154263, called in lines 73929 and 74985, but is not defined anywhere in the file. The same is true for functions _make_polyline and _Proutespline which are only declared in lines 154265 and 154267, but not defined anywhere.

In graphviz, the Pshortestpath function is defined in lib/pathplan/shortest.c. Looking through the build log of graphviz.js, I can see that the pathplan lib actually was built, and that libpathplan.a exists in graphviz-install/lib. Perhaps it was not linked into graphviz.js due to linking issues with .a files mentioned by @kripken?

gregsadetsky commented 12 years ago

While looking around for a pure JavaScript implementation of GraphViz, I found this very impressive .dot renderer:

http://ushiroad.com/jsviz/ (press the "Play" button in the lower left corner of the code overlay)

The about page mentions that the algo was ported using Emscripten, although the resulting source code was obviously hand-cleaned.

I'm trying to contact the author to recommend that he put up his library on GitHub. With a bit of documentation, it seems like a useable, client-side GraphViz library is well within reach...!

Edit: The author, @gyuque seems to be active on GitHub. Ueyama, would you please consider putting up Liviz.js on GitHub? A lot of people would be quite happy! Also see this thread on StackOverflow.

izuzak commented 12 years ago

@gregsadetsky Woot! That really is impressive, nice find. Looking forward to seeing this on GitHub, and in the meantime I'll just poke around the source code :)

Edit: Btw. the "Tour" is really cool: the small arrow next to the play button opens a menu, click "Take a tour" in the menu and enjoy :).

gyuque commented 12 years ago

Sorry to keep you waiting. I've put Liviz.js on github. Liviz.js modifies Emscripten's javascript template so please read README.md

https://github.com/gyuque/livizjs