Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. var dispatch = d3.dispatch("dataLoaded","stationHovered","nodesUpdated");
  2.  
  3. d3.json("stations.json", function(error, stations)
  4. {
  5. var data = {};
  6. data.nodes = stations.nodes;
  7. data.links = stations.links;
  8.  
  9. for(var i = 0; i < data.nodes.length; i++)
  10. {
  11. var links = stations.links.filter(function(link)
  12. {
  13. return link.source === i || link.target === i;
  14. });
  15.  
  16. var linksColors = links.map(function(link) { return link.color; });
  17. var allEqual = linksColors.filter(function(color) { return color !== linksColors[0]; }).length === 0;
  18.  
  19. data.nodes[i].color = allEqual ? linksColors[0] : '000';
  20. }
  21.  
  22. if (error) throw error;
  23. else
  24. {
  25. d3.json("turnstile-gtfs-mapping.json", function(error, mapping)
  26. {
  27. if (error) throw error;
  28. else
  29. {
  30. d3.json("turnstile-heatmap.json", function(error, entrances)
  31. {
  32. if (error) throw error;
  33. else
  34. {
  35. entrances.stops.forEach(function(stop)
  36. {
  37. var stationId = mapping[stop.name];
  38.  
  39. data.nodes.filter(function(station)
  40. {
  41. return station.id === stationId;
  42. })[0]['entrances'] = stop.entrancesByType.all;
  43. });
  44.  
  45. dispatch.call('dataLoaded', null, data);
  46. }
  47. });
  48. }
  49. });
  50. }
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement