<commit_before>'use strict'

var nodeD3 = require('d3');
var jsdom = require('jsdom');
var decorators = require('./decorators.js');
var thunkify = require('thunkify');

var doctype = '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'

function svgGraphic(decoratorName, data, callback){
	var decorator = decorators[decoratorName];
	var doc = jsdom.env({
		html:'<html><body></body></html>',
		features:{QuerySelector:true},
		done:function(errors, window){
			window.d3 = nodeD3;
			window.d3.select('body').html('');
			var htmlbody = window.d3.select('body');
			
			htmlbody.call( decorator, data );

			if(errors){
				callback ( null, doctype + '' );				
			}else{
				callback ( null, doctype + htmlbody.html() );
			}

			window.__stopAllTimers();
			window.close();
		}
	});
}

module.exports = thunkify( svgGraphic );<commit_msg>a bit of code to check a decorator is an actual thing<commit_after>'use strict'

var nodeD3 = require('d3');
var jsdom = require('jsdom');
var decorators = require('./decorators.js');
var thunkify = require('thunkify');

var doctype = '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'

function svgGraphic(decoratorName, data, callback){
	var decorator = decorators[decoratorName];
	var doc = jsdom.env({
		html:'<html><body></body></html>',
		features:{QuerySelector:true},
		done:function(errors, window){
			if(typeof decorator == 'function'){
				window.d3 = nodeD3;
				window.d3.select('body').html('');
				var htmlbody = window.d3.select('body');
				
				htmlbody.call( decorator, data );

				if(errors){
					callback ( null, doctype + '' );				
				}else{
					callback ( null, doctype + htmlbody.html() );
				}
			}else{
				callback(null, 'not a graphic');
			}
			window.__stopAllTimers();
			window.close();
		}
	});
}

module.exports = thunkify( svgGraphic );
{'fraction_non_alphanumeric': 0.18592964824120603, 'fraction_numerical': 0.016080402010050253, 'mean_word_length': 3.9039408866995076, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 2, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3588509', 'n_tokens_mistral': 814, 'n_tokens_neox': 699, 'n_words': 143}