Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage outside of the browser - in NodeJS with node-canvas #29

Closed
prantlf opened this issue Jul 30, 2015 · 6 comments
Closed

Allow usage outside of the browser - in NodeJS with node-canvas #29

prantlf opened this issue Jul 30, 2015 · 6 comments

Comments

@prantlf
Copy link
Contributor

prantlf commented Jul 30, 2015

Thanks a lot for publishing this project! I believe that it has more potential than powering the web page editor.

I'd like to use nomnoml for generating diagrams in developer documentation. Instead of checking in binary images together with nomnoml sources, just the nomnoml sources would be maintained and the images would be generated when the documentation output is generated. It would mean calling nomnoml from a command-line tool.

When not running in the browser, the tool would have to either start the browser in the background and communicate with it, or integrate a headless browser like PhantomJS, or use an alternative canvas implementation like node-canvas. The former two possibilities would be tricky to make for a quickly executable tool. The latter would need a reliable canvas implementation. Let's have a look at the latter:

// Writes a simple PNG diagram to the standard output
var Canvas = require('canvas'),
    nomnoml = require('nomnoml'),
    canvas = new Canvas(640, 480);
nomnoml.draw(canvas, '[nomnoml]is->[awesome]');
canvas.pngStream().pipe(process.stdout);

Luckily, nomnoml does not use other browser features than the canvas. What prevents nomnoml from being used like this?

  • Access to the global window object
  • Embedding the dagre module. which works only in the browser

I tried to make the necessary changes in my fork. Would you be interested in making nomnoml usable from NodeJS?

@prantlf
Copy link
Contributor Author

prantlf commented Jul 30, 2015

The node-canvas module has a native dependency, which needs installing some pre-requisites depending on the operating system before the actual module can be installed. I was not sure if you wanted to add it to the development dependencies; I did it and included a testing script in the nodejs-test branch and I can create a pull request if you like.

@prantlf
Copy link
Contributor Author

prantlf commented Jul 31, 2015

I found the closed issue #27 by chance when googling. Your opinion makes sense, not to make everyone, who integrates nomnoml on a web page, depend on PhantomJS or other heavy dependency. I created nomnoml-cli for the command-line and/or NodeJS integrations.

About the dagre integration: I'd prefer depending on dagre loaded from node_modules to doing the current workaround (#31). I cannot simply load the newest dagre version, because its interface was changed when the version 0.5.0 was released. The last working dagre version is 0.4.6. Was there a reason to upgrade nomnoml to the new interface?

@prantlf
Copy link
Contributor Author

prantlf commented Jul 31, 2015

The pull requests are marked with a build failure:

Could not find .travis.yml, using standard configuration.

Apparently the registration of this project for the Travis CI builds has not been finished yet, but I assure you that the code works :-)

I tested using the test pages and the Jasmine test specs. The pages open OK. 1 spec from the 16 failed but the failure was not caused by my changes.

@skanaar
Copy link
Owner

skanaar commented Aug 4, 2015

It is not supposed to use Travis (yet). Fixing that.

We saw some layout differences in later versions of Dagre, and earlier versions don't have RequireJS support. That is the reason for embedding the Dagre source inside the project.

The goal is to have NodeJS support, but it is a work in progress. I will probably refactor the renderer so that it receives the dagre as a parameter instead of depending on it being available globally.

@prantlf
Copy link
Contributor Author

prantlf commented Aug 9, 2015

I tried to handle the dependency on dagre in the same way as on lodash in a8239cd. In the nodejs-separate-dagre branch I load lodash and dagre installed by NPM on the command line; dagre version must be < 0.5.0. In the browser I still load the files from the lib directory, which could be changed too.

@skanaar
Copy link
Owner

skanaar commented Apr 18, 2016

I just merged the SVG branch that allows (rudimentary) support for SVG rendering, which by it nature is node-compatible since no canvas is involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants