-
Notifications
You must be signed in to change notification settings - Fork 2
/
web.js
42 lines (34 loc) · 1.08 KB
/
web.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
/* eslint-env browser */
/* global ace, Viz */
var lib = require('./lib.js'),
debounce = require('debounce'),
jsyaml = require('js-yaml');
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/yaml");
function drawError(msg) {
document.getElementById("diagram").innerHTML = '<div class="error"><h2>Error</h2><p>There was an error in ' + msg + '</p></div>';
}
function redraw() {
var json = {};
try {
json = jsyaml.safeLoad(editor.getValue());
} catch (e) {
return drawError('YAML conversion');
}
/* eslint new-cap: 0 */
try {
document.getElementById("diagram").innerHTML = Viz(
lib.getDotSrc(lib.transform(json)).join("\n"),
"svg"
);
} catch (e) {
drawError('generated GraphViz/DOT source, see console');
if (console && console.log) {
console.log("ERROR IN DOT SRC: ", lib.getDotSrc(lib.transform(json)).join("\n"));
}
}
}
redraw();
editor.getSession().on('change', debounce(redraw, 750));