-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
27 lines (24 loc) · 873 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {render, Module} from "./viz-lite.render.js";
const defaults = {files: [], format: "svg", engine: "dot"};
function Dot(options) {
options = Object.assign({}, defaults, options);
let module = Module(Object.assign({}, options));
return function dot(strings) {
let string = strings[0] + "", i = 0, n = arguments.length;
while (++i < n) string += arguments[i] + "" + strings[i];
const template = document.createElement("template");
try {
template.innerHTML = render(module, string, options);
} catch (error) {
module = Module(Object.assign({}, options)); // See Viz.js caveats.
throw error;
}
const svg = document.importNode(template.content.firstElementChild, true);
svg.style.maxWidth = "100%";
svg.style.height = "auto";
return svg;
};
}
const dot = Dot({});
dot.options = Dot;
export default dot;