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.

82 lines
1.8 KiB

  1. function collectEventSeries(data) {
  2. var events = data.events;
  3. var series = {
  4. "visit": {
  5. name: "Visit",
  6. type: 'scatter',
  7. color: '#8f799e',
  8. y: 10,
  9. data: []
  10. },
  11. "paused_location_updates": {
  12. name: "Paused Location Updates",
  13. color: '#a0876e',
  14. y: 20,
  15. data: []
  16. },
  17. "resumed_location_updates": {
  18. name: "Resumed Location Updates",
  19. color: '#819e73',
  20. y: 30,
  21. data: []
  22. },
  23. "did_finish_deferred_updates": {
  24. name: "Finished Deferred Updates",
  25. color: '#9ea06e',
  26. y: 40,
  27. data: []
  28. },
  29. "did_enter_background": {
  30. name: "Entered Background",
  31. color: '#799b9e',
  32. y: 50,
  33. data: []
  34. },
  35. "will_resign_active": {
  36. name: "Will Resign Active",
  37. color: '#737f9e',
  38. y: 60,
  39. data: []
  40. },
  41. "will_terminate": {
  42. name: "Will Terminate",
  43. color: '#9e7773',
  44. y: 70,
  45. data: []
  46. }
  47. };
  48. for(var i=0; i<events.length; i++) {
  49. series[events[i].properties.action].data.push({
  50. x: new Date(events[i].properties.unixtime*1000),
  51. y: series[events[i].properties.action].y,
  52. location: events[i].geometry.coordinates
  53. });
  54. }
  55. var response = [];
  56. series = Object.values(series);
  57. for(var i=0; i<series.length; i++) {
  58. if(series[i].data.length > 0) {
  59. series[i].type = 'scatter';
  60. series[i].yAxis = 0;
  61. series[i].tooltip = {
  62. pointFormatter: function() {
  63. moveMarkerToPosition(this);
  64. var h = this.x.getHours();
  65. var m = this.x.getMinutes();
  66. var s = this.x.getSeconds();
  67. if(m < 10) m = '0'+m;
  68. if(s < 10) s = '0'+s;
  69. return h+':'+m+':'+s;
  70. }
  71. };
  72. response.push(series[i]);
  73. }
  74. }
  75. return response;
  76. }