Comparing version 2.0.0-pre.4 to 2.0.0-pre.5
@@ -7,3 +7,3 @@ export as namespace Viz; | ||
constructor(options?: { worker?: string, render?: (src: string, options: object) => Promise<any> }); | ||
constructor(options?: { worker: string } | { Module: () => any, render: (instance: any, src: string, options: object) => Promise<any> }); | ||
@@ -37,3 +37,3 @@ renderString(src: string, options?: Viz.Options): Promise<string>; | ||
export interface Image { | ||
href: string; | ||
path: string; | ||
height: string | number; | ||
@@ -40,0 +40,0 @@ width: string | number; |
{ | ||
"name": "viz.js", | ||
"version": "2.0.0-pre.4", | ||
"version": "2.0.0-pre.5", | ||
"description": "A hack to put Graphviz on the web.", | ||
@@ -16,4 +16,4 @@ "main": "viz.js", | ||
"viz.js", | ||
"full.module", | ||
"lite.module", | ||
"full.js.opaque", | ||
"lite.js.opaque", | ||
"index.d.ts" | ||
@@ -41,2 +41,3 @@ ], | ||
"minimist": "^1.2.0", | ||
"mocha": "^5.1.1", | ||
"selenium-webdriver": "^2.45.1", | ||
@@ -43,0 +44,0 @@ "typescript": "^2.7.2" |
@@ -7,34 +7,18 @@ # Viz.js | ||
For more information, [see the wiki](https://github.com/mdaines/viz.js/wiki). | ||
## Getting Viz.js | ||
To install with Yarn: | ||
* Install the [`viz.js` package](https://www.npmjs.com/package/viz.js) from npm. | ||
* Download from the [releases page](https://github.com/mdaines/viz.js/releases). | ||
yarn add viz.js | ||
## Building From Source | ||
Or download from the [releases page](https://github.com/mdaines/viz.js/releases). | ||
To build from source, first [install the Emscripten SDK](http://kripken.github.io/emscripten-site/docs/getting_started/index.html). You'll also need [Node.js](https://nodejs.org/) and [Yarn](https://yarnpkg.com). | ||
## Usage | ||
Install the development dependencies using Yarn: | ||
Rendering a graph as an SVG element using a Web Worker: | ||
let viz = new Viz({ worker: 'path/to/full.module' ); | ||
viz.renderSVGElement('digraph { a -> b; }') | ||
.then(element => { | ||
document.body.appendChild(element); | ||
}); | ||
The input to `renderSVGElement` is a graph in the [DOT language](http://www.graphviz.org/content/dot-language). | ||
For more information, see the [API documentation](https://github.com/mdaines/viz.js/wiki/API). | ||
## Building Viz.js | ||
To build from source, you will need to [install the Emscripten SDK](http://kripken.github.io/emscripten-site/docs/getting_started/index.html). | ||
Then, install the development dependencies using Yarn: | ||
yarn install | ||
The build process for Viz.js is split into two parts: building the Graphviz and Expat dependencies, and building the "modules" and the main `viz.js` script. | ||
The build process for Viz.js is split into two parts: building the Graphviz and Expat dependencies, and building the rendering script files and API. | ||
@@ -48,3 +32,3 @@ make deps | ||
First, serve the project directory at http://localhost:8000. For example: | ||
First, serve the project directory at http://localhost:8000. | ||
@@ -51,0 +35,0 @@ python -m SimpleHTTPServer |
28
viz.js
/* | ||
Viz.js 2.0.0-pre.4 (Graphviz 2.40.1, Expat 2.2.5, Emscripten 1.37.36) | ||
Viz.js 2.0.0-pre.5 (Graphviz 2.40.1, Expat 2.2.5, Emscripten 1.37.36) | ||
Copyright (c) 2014-2018 Michael Daines | ||
@@ -129,2 +129,17 @@ Licensed under MIT license | ||
var ModuleWrapper = function ModuleWrapper(module, render) { | ||
_classCallCheck(this, ModuleWrapper); | ||
var instance = module(); | ||
this.render = function (src, options) { | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
resolve(render(instance, src, options)); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}; | ||
}; | ||
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding | ||
@@ -252,2 +267,3 @@ function b64EncodeUnicode(str) { | ||
worker = _ref3.worker, | ||
Module = _ref3.Module, | ||
render = _ref3.render; | ||
@@ -259,8 +275,8 @@ | ||
this.wrapper = new WorkerWrapper(worker); | ||
} else if (typeof render !== 'undefined') { | ||
this.wrapper = wrapRender(render); | ||
} else if (typeof Viz.render !== 'undefined') { | ||
this.wrapper = wrapRender(Viz.render); | ||
} else if (typeof Module !== 'undefined' && typeof render !== 'undefined') { | ||
this.wrapper = new ModuleWrapper(Module, render); | ||
} else if (typeof Viz.Module !== 'undefined' && typeof Viz.render !== 'undefined') { | ||
this.wrapper = new ModuleWrapper(Viz.Module, Viz.render); | ||
} else { | ||
throw new Error('Must specify worker or render options, or include one of full.module or lite.module after viz.js.'); | ||
throw new Error('Must specify worker option, Module and render options, or include one of full.js.opaque or lite.js.opaque after viz.js.'); | ||
} | ||
@@ -267,0 +283,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3434802
328
11
38