-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
40 lines (33 loc) · 1.23 KB
/
demo.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
'use strict';
var superagent = require('superagent');
var json5 = require('json5');
var netlistSvg = require('../built');
var up3down5 = require('../test/digital/up3down5.json');
var skins = ['lib/default.svg', 'lib/analog.svg'];
var textarea = document.querySelector('textarea');
var skinSelect = document.querySelector('#skinSelect');
var renderButton = document.querySelector('#renderButton');
var formatButton = document.querySelector('#formatButton');
var svgArea = document.querySelector('#svgArea');
textarea.value = json5.stringify(up3down5, null, 4);
skins.forEach(function(skinPath, i) {
superagent.get(skinPath).end(function(err, r) {
var option = document.createElement('option');
option.selected = i === 0;
option.value = r.text;
option.text = skinPath;
skinSelect.append(option);
});
});
function render() {
var netlist = json5.parse(textarea.value);
netlistSvg.render(skinSelect.value, netlist, function(e, svg) {
svgArea.src = 'data:image/svg+xml,' + encodeURIComponent(svg);
});
}
function format() {
var netlist = json5.parse(textarea.value);
textarea.value = json5.stringify(netlist, null, 4);
}
renderButton.onclick = render;
formatButton.onclick = format;