<commit_before># d3-to-png

This is not really a library or a tool so much as it is a proof of concept in
which we use [d3.js](http://d3js.org) and
[jsdom](https://github.com/tmpvar/jsdom) to generate SVG documents from the
command line.

Here's how to run it:

```
# first, install the prerequisites: jsom, d3, and optimist
$ npm install
...
$ node index.js script.js > output.svg
```

You'll want to replace `script.js` above with your own Node script that looks
like this:

```
module.exports = function(window, options, callback) {
  var d3 = window.d3,
      svg = d3.select("svg");
  // do something fancy with svg here
  callback(null, svg.node());
};
```

and which accepts the following arguments:

* `window` the DOM window for the current context. Get your reference to d3 via
  `window.d3`.
* `options` is a dictionary of command line options from
  [optimist](https://github.com/substack/node-optimist).
* `callback` is a function to call when you're done rendering, in the form
  `callback(error, node)`. Note that `node` here is the *DOM node*, not a d3
  selection, which you can get by calling [selection.node()](https://github.com/mbostock/d3/wiki/Selections#wiki-node).

See [circles.js](blob/master/circles.js) for an example.<commit_msg>update note about passing DOM nodes to callback()<commit_after># d3-to-png

This is not really a library or a tool so much as it is a proof of concept in
which we use [d3.js](http://d3js.org) and
[jsdom](https://github.com/tmpvar/jsdom) to generate SVG documents from the
command line.

Here's how to run it:

```
# first, install the prerequisites: jsom, d3, and optimist
$ npm install
...
$ node index.js script.js > output.svg
```

You'll want to replace `script.js` above with your own Node script that looks
like this:

```
module.exports = function(window, options, callback) {
  var d3 = window.d3,
      svg = d3.select("svg");
  // do something fancy with svg here
  callback(null, svg.node());
};
```

and which accepts the following arguments:

* `window` the DOM window for the current context. Get your reference to d3 via
  `window.d3`.
* `options` is a dictionary of command line options from
  [optimist](https://github.com/substack/node-optimist).
* `callback` is a function to call when you're done rendering, in the form
  `callback(error, node)`. `node` may either by a d3 selection or a DOM node.

See [circles.js](blob/master/circles.js) for an example.
{'fraction_non_alphanumeric': 0.11960542540073983, 'fraction_numerical': 0.008631319358816275, 'mean_word_length': 3.9371196754563895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1387858', 'n_tokens_mistral': 788, 'n_tokens_neox': 762, 'n_words': 310}