-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
48 lines (41 loc) · 1.21 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var fs = require('fs');
var parseSdf = require('sdf-parser');
var jsdom = require('jsdom');
var d3 = require('d3');
var _ = require('lodash');
var render = require('./src/renderer');
var parseMol = require('./src/mol.js');
module.exports.renderSdfToSvg = function(sdfRaw, options, callback) {
var sdf = parseSdf(sdfRaw);
var molecule = parseMol(sdf);
jsdom.env({
html: '<html><body></body></html>',
features: { QuerySelector: true },
done: function (errors, window) {
render(window, molecule, options)
svg = d3.select(window.document).select('body').html()
if(_.isFunction(callback)) {
callback(svg);
}
else if(_.isFunction(options)) {
options(svg);
}
}
});
}
module.exports.renderSdfToSvgFile = function(inputFile, outputFile, options, callback) {
fs.readFile(inputFile, 'utf-8', function(err, sdfRaw) {
if(err) throw err;
module.exports.renderSdfToSvg(sdfRaw, options, function(svg) {
fs.writeFile(outputFile, svg, function(err) {
if(err) throw err;
if(_.isFunction(callback)) {
callback(svg);
}
else if(_.isFunction(options)) {
options(svg);
}
});
});
});
}