vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.3 KiB

/**
* Created by Alex on 2/2/2015.
*/
fs = require('fs')
function writeToFile(data, outputFilename, callback) {
fs.writeFile(outputFilename, JSON.stringify(data), function (err) {
if (err) {
console.log(err);
} else {
console.log("JSON saved to " + outputFilename);
callback();
//getNewAssignment();
}
});
}
function parse(data, callback) {
var objects = Object.keys(data.things);
var timelineData = [];
var groups = [];
var groupsObj = {};
for (var i = 0; i < objects.length; i++) {
var thing = data.things[objects[i]];
if (thing.properties.description && thing.properties.date) {
timelineData.push({
id:i,
content: thing.type,
start: new Date(thing.properties.date.value).valueOf(),
group: thing.type
});
if (groupsObj[thing.type] === undefined) {
groupsObj[thing.type] = true;
groups.push({id:thing.type, content:thing.type});
}
}
}
console.log("amont of data", timelineData.length, "amount of groups:", groups.length)
var dataToWrite = {data: timelineData, groups:groups};
writeToFile(dataToWrite, "timeline.json", function(){});
}
fs.readFile('./data.json', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
parse(JSON.parse(data));
});