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

  1. /**
  2. * Created by Alex on 2/2/2015.
  3. */
  4. fs = require('fs')
  5. function writeToFile(data, outputFilename, callback) {
  6. fs.writeFile(outputFilename, JSON.stringify(data), function (err) {
  7. if (err) {
  8. console.log(err);
  9. } else {
  10. console.log("JSON saved to " + outputFilename);
  11. callback();
  12. //getNewAssignment();
  13. }
  14. });
  15. }
  16. function parse(data, callback) {
  17. var objects = Object.keys(data.things);
  18. var timelineData = [];
  19. var groups = [];
  20. var groupsObj = {};
  21. for (var i = 0; i < objects.length; i++) {
  22. var thing = data.things[objects[i]];
  23. if (thing.properties.description && thing.properties.date) {
  24. timelineData.push({
  25. id:i,
  26. content: thing.type,
  27. start: new Date(thing.properties.date.value).valueOf(),
  28. group: thing.type
  29. });
  30. if (groupsObj[thing.type] === undefined) {
  31. groupsObj[thing.type] = true;
  32. groups.push({id:thing.type, content:thing.type});
  33. }
  34. }
  35. }
  36. console.log("amont of data", timelineData.length, "amount of groups:", groups.length)
  37. var dataToWrite = {data: timelineData, groups:groups};
  38. writeToFile(dataToWrite, "timeline.json", function(){});
  39. }
  40. fs.readFile('./data.json', 'utf8', function (err, data) {
  41. if (err) {
  42. return console.log(err);
  43. }
  44. parse(JSON.parse(data));
  45. });