├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── index.js ├── package.json ├── rollup.config.js ├── viz-lite.render.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | *.sublime-workspace 2 | .DS_Store 3 | .esm-cache/ 4 | dist/ 5 | node_modules 6 | npm-debug.log 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.sublime-* 2 | .DS_Store 3 | .esm-cache/ 4 | dist/*.zip 5 | test/ 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 Observable, Inc. 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose 4 | with or without fee is hereby granted, provided that the above copyright notice 5 | and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 8 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 10 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 11 | OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 12 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 13 | THIS SOFTWARE. 14 | 15 | Copyright (c) 2014-2018 Michael Daines 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | this software and associated documentation files (the "Software"), to deal in 19 | the Software without restriction, including without limitation the rights to 20 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | the Software, and to permit persons to whom the Software is furnished to do so, 22 | subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in all 25 | copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | 34 | Graphviz 35 | Licensed under Eclipse Public License - v 1.0 36 | http://www.graphviz.org 37 | 38 | zlib 39 | Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler 40 | http://www.zlib.net/zlib_license.html 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @observablehq/graphviz 2 | 3 | Convenience methods for using [Graphviz](http://www.graphviz.org/) in [Observable](https://observablehq.com). See this notebook for examples: 4 | 5 | https://beta.observablehq.com/@mbostock/graphviz 6 | 7 | To load Graphviz: 8 | 9 | ```js 10 | dot = require("@observablehq/graphviz") 11 | ``` 12 | 13 | To display a happy little diagram: 14 | 15 | ```js 16 | dot`graph { n0 -- n1 -- n2 -- n3 -- n0; }` 17 | ``` 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {render, Module} from "./viz-lite.render.js"; 2 | 3 | const defaults = {files: [], format: "svg", engine: "dot"}; 4 | 5 | function Dot(options) { 6 | options = Object.assign({}, defaults, options); 7 | let module = Module(Object.assign({}, options)); 8 | return function dot(strings) { 9 | let string = strings[0] + "", i = 0, n = arguments.length; 10 | while (++i < n) string += arguments[i] + "" + strings[i]; 11 | const template = document.createElement("template"); 12 | try { 13 | template.innerHTML = render(module, string, options); 14 | } catch (error) { 15 | module = Module(Object.assign({}, options)); // See Viz.js caveats. 16 | throw error; 17 | } 18 | const svg = document.importNode(template.content.firstElementChild, true); 19 | svg.style.maxWidth = "100%"; 20 | svg.style.height = "auto"; 21 | return svg; 22 | }; 23 | } 24 | 25 | const dot = Dot({}); 26 | dot.options = Dot; 27 | export default dot; 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@observablehq/graphviz", 3 | "version": "0.2.1", 4 | "description": "A convenience method for using Graphviz.", 5 | "keywords": [ 6 | "graphviz" 7 | ], 8 | "homepage": "https://github.com/observablehq/graphviz", 9 | "repository": "https://github.com/observablehq/graphviz", 10 | "license": "ISC", 11 | "main": "dist/graphviz.min.js", 12 | "author": { 13 | "name": "Observable, Inc." 14 | }, 15 | "scripts": { 16 | "prepublishOnly": "rollup -c" 17 | }, 18 | "devDependencies": { 19 | "rollup": "0.66", 20 | "rollup-plugin-terser": "3", 21 | "viz.js": "2" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import {terser} from "rollup-plugin-terser"; 2 | 3 | export default [ 4 | { 5 | input: "index.js", 6 | output: { 7 | extend: true, 8 | banner: `// @observablehq/graphviz Copyright ${(new Date).getFullYear()} Observable, Inc. 9 | // Viz.js Copyright 2014-2018 Michael Daines`, 10 | file: "dist/graphviz.js", 11 | format: "umd", 12 | name: "O" 13 | } 14 | }, 15 | { 16 | input: "index.js", 17 | plugins: [ 18 | terser({ 19 | output: { 20 | preamble: `// @observablehq/graphviz Copyright ${(new Date).getFullYear()} Observable, Inc. 21 | // Viz.js Copyright 2014-2018 Michael Daines` 22 | } 23 | }) 24 | ], 25 | output: { 26 | extend: true, 27 | file: "dist/graphviz.min.js", 28 | format: "umd", 29 | name: "O" 30 | } 31 | } 32 | ]; 33 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@babel/code-frame@^7.0.0": 6 | version "7.0.0" 7 | resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8" 8 | dependencies: 9 | "@babel/highlight" "^7.0.0" 10 | 11 | "@babel/highlight@^7.0.0": 12 | version "7.0.0" 13 | resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0.tgz#f710c38c8d458e6dd9a201afb637fcb781ce99e4" 14 | dependencies: 15 | chalk "^2.0.0" 16 | esutils "^2.0.2" 17 | js-tokens "^4.0.0" 18 | 19 | "@types/estree@0.0.39": 20 | version "0.0.39" 21 | resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" 22 | 23 | "@types/node@*": 24 | version "10.11.3" 25 | resolved "https://registry.yarnpkg.com/@types/node/-/node-10.11.3.tgz#c055536ac8a5e871701aa01914be5731539d01ee" 26 | 27 | ansi-styles@^3.2.1: 28 | version "3.2.1" 29 | resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" 30 | dependencies: 31 | color-convert "^1.9.0" 32 | 33 | buffer-from@^1.0.0: 34 | version "1.1.1" 35 | resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" 36 | 37 | chalk@^2.0.0: 38 | version "2.4.1" 39 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" 40 | dependencies: 41 | ansi-styles "^3.2.1" 42 | escape-string-regexp "^1.0.5" 43 | supports-color "^5.3.0" 44 | 45 | color-convert@^1.9.0: 46 | version "1.9.3" 47 | resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" 48 | dependencies: 49 | color-name "1.1.3" 50 | 51 | color-name@1.1.3: 52 | version "1.1.3" 53 | resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" 54 | 55 | commander@~2.17.1: 56 | version "2.17.1" 57 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" 58 | 59 | core-util-is@~1.0.0: 60 | version "1.0.2" 61 | resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" 62 | 63 | escape-string-regexp@^1.0.5: 64 | version "1.0.5" 65 | resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" 66 | 67 | esutils@^2.0.2: 68 | version "2.0.2" 69 | resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" 70 | 71 | has-flag@^3.0.0: 72 | version "3.0.0" 73 | resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" 74 | 75 | inherits@~2.0.3: 76 | version "2.0.3" 77 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" 78 | 79 | isarray@~1.0.0: 80 | version "1.0.0" 81 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" 82 | 83 | jest-worker@^23.2.0: 84 | version "23.2.0" 85 | resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-23.2.0.tgz#faf706a8da36fae60eb26957257fa7b5d8ea02b9" 86 | dependencies: 87 | merge-stream "^1.0.1" 88 | 89 | js-tokens@^4.0.0: 90 | version "4.0.0" 91 | resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" 92 | 93 | merge-stream@^1.0.1: 94 | version "1.0.1" 95 | resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1" 96 | dependencies: 97 | readable-stream "^2.0.1" 98 | 99 | process-nextick-args@~2.0.0: 100 | version "2.0.0" 101 | resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa" 102 | 103 | readable-stream@^2.0.1: 104 | version "2.3.6" 105 | resolved "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" 106 | dependencies: 107 | core-util-is "~1.0.0" 108 | inherits "~2.0.3" 109 | isarray "~1.0.0" 110 | process-nextick-args "~2.0.0" 111 | safe-buffer "~5.1.1" 112 | string_decoder "~1.1.1" 113 | util-deprecate "~1.0.1" 114 | 115 | rollup-plugin-terser@3: 116 | version "3.0.0" 117 | resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-3.0.0.tgz#045bd7cf625ee1affcfe6971dab6fffe6fb48c65" 118 | dependencies: 119 | "@babel/code-frame" "^7.0.0" 120 | jest-worker "^23.2.0" 121 | serialize-javascript "^1.5.0" 122 | terser "^3.8.2" 123 | 124 | rollup@0.66: 125 | version "0.66.2" 126 | resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.66.2.tgz#77acdb9f4093f5f035ce75480577c40a81ea7999" 127 | dependencies: 128 | "@types/estree" "0.0.39" 129 | "@types/node" "*" 130 | 131 | safe-buffer@~5.1.0, safe-buffer@~5.1.1: 132 | version "5.1.2" 133 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" 134 | 135 | serialize-javascript@^1.5.0: 136 | version "1.5.0" 137 | resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.5.0.tgz#1aa336162c88a890ddad5384baebc93a655161fe" 138 | 139 | source-map-support@~0.5.6: 140 | version "0.5.9" 141 | resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.9.tgz#41bc953b2534267ea2d605bccfa7bfa3111ced5f" 142 | dependencies: 143 | buffer-from "^1.0.0" 144 | source-map "^0.6.0" 145 | 146 | source-map@^0.6.0, source-map@~0.6.1: 147 | version "0.6.1" 148 | resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" 149 | 150 | string_decoder@~1.1.1: 151 | version "1.1.1" 152 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" 153 | dependencies: 154 | safe-buffer "~5.1.0" 155 | 156 | supports-color@^5.3.0: 157 | version "5.5.0" 158 | resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" 159 | dependencies: 160 | has-flag "^3.0.0" 161 | 162 | terser@^3.8.2: 163 | version "3.9.2" 164 | resolved "https://registry.yarnpkg.com/terser/-/terser-3.9.2.tgz#d139d8292eb3a23091304c934fb539d9f456fb19" 165 | dependencies: 166 | commander "~2.17.1" 167 | source-map "~0.6.1" 168 | source-map-support "~0.5.6" 169 | 170 | util-deprecate@~1.0.1: 171 | version "1.0.2" 172 | resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" 173 | 174 | viz.js@2: 175 | version "2.0.0" 176 | resolved "https://registry.yarnpkg.com/viz.js/-/viz.js-2.0.0.tgz#d34aa8e68f3b4eb7107f16ea6d1530a77109f315" 177 | --------------------------------------------------------------------------------