-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 882 Bytes
/
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
//chiasm-dsv-dataset.js
//
//A Chiasm plugin that loads data files.
var Model = require("model-js");
var ChiasmComponent = require("chiasm-component");
var d3 = require("d3");
var dsvDataset = require("dsv-dataset");
function ChiasmDatasetLoader(){
var my = ChiasmComponent({
path: Model.None
});
my.when("path", function (path){
if(path !== Model.None){
d3.json(path + ".json", function(error, metadata) {
if(error){ throw error; }
my.metadata = metadata;
});
d3.xhr(path + ".csv", function (error, xhr){
if(error){ throw error; }
my.dsvString = xhr.response;
});
}
});
my.when(["dsvString", "metadata"], function (dsvString, metadata){
my.dataset = dsvDataset.parse({
dsvString: dsvString,
metadata: metadata
});
});
return my;
}
module.exports = ChiasmDatasetLoader;