-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (30 loc) · 1.16 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
const ndarray = require('ndarray');
const declare = require('./lib/declare');
const allocate = require('./lib/allocate');
const assign = require('./lib/assign');
const paint = require('./lib/paint');
var api = module.exports = function(output, series, hooks) {
// create the index and set default values for index.countsByKey and index.colorsByKey
['declare', 'allocate', 'assign'].forEach(name => {
if (typeof hooks[name] !== 'function') throw new Error(`${name} is a required hook`);
hooks[name] = hooks[name].bind(null);
});
var index = declare(output, hooks);
// tally up the total value for each key in index.countsByKey
allocate(series, index);
// create the color values for each key in index.colorsByKey
assign(series, index);
// make sure the colors are ints not floats
console.log('----> normalize');
index.colorsByKey.forEach((v, k) => {
index.colorsByKey.set(k, v.map(n => Math.floor(n)));
});
// apply the colors to the output
console.log('----> paint');
return paint(output, index);
}
api.open = require('./lib/open-series');
api.save = require('./lib/save');
api.make = function(w, h) {
return ndarray([], [w, h, 3]);
};