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.

120 lines
2.6 KiB

  1. function pointFromGeoJSON(geo) {
  2. if(geo) {
  3. return L.latLng(geo[1], geo[0])
  4. }
  5. }
  6. function showBatteryGraph(response) {
  7. var data = response.linestring;
  8. var batteryStateBands = [];
  9. var buckets = data.properties.map(function(d){return d.battery_state}).findRanges();
  10. for(var i in buckets) {
  11. for(var j=0; j<buckets[i].length; j++) {
  12. switch(i) {
  13. case "charging":
  14. buckets[i][j].color = "rgba(193,236,171,0.4)";
  15. break;
  16. case "full":
  17. buckets[i][j].color = "rgba(171,204,236,0.4)";
  18. break;
  19. case "unplugged":
  20. buckets[i][j].color = "rgba(236,178,171,0.4)";
  21. break;
  22. default:
  23. buckets[i][j].color = "#ffffff";
  24. break;
  25. }
  26. buckets[i][j].from = new Date(data.properties[buckets[i][j].from].unixtime * 1000);
  27. buckets[i][j].to = new Date(data.properties[buckets[i][j].to].unixtime * 1000);
  28. batteryStateBands.push(buckets[i][j]);
  29. }
  30. }
  31. $('#battery-chart').highcharts({
  32. chart: {
  33. height: 160,
  34. zoomType: 'x',
  35. panning: true,
  36. panKey: 'shift'
  37. },
  38. title: {
  39. text: '',
  40. style: {
  41. display: 'none'
  42. }
  43. },
  44. subtitle: {
  45. text: '',
  46. style: {
  47. display: 'none'
  48. }
  49. },
  50. legend: {
  51. enabled: false
  52. },
  53. xAxis: {
  54. type: 'datetime',
  55. plotBands: batteryStateBands,
  56. labels: {
  57. rotation: -35,
  58. style: {
  59. fontSize: '8px'
  60. }
  61. }
  62. },
  63. yAxis: [{
  64. title: {
  65. text: 'Battery %'
  66. },
  67. plotLines: [{
  68. value: 0,
  69. width: 1,
  70. color: '#808080'
  71. }],
  72. max: 100,
  73. min: 0
  74. },{
  75. title: {
  76. text: 'Speed'
  77. },
  78. plotLines: [{
  79. value: 0,
  80. width: 1,
  81. color: '#dddddd'
  82. }],
  83. min: 0,
  84. opposite: true
  85. }],
  86. series: [
  87. {
  88. name: 'Battery',
  89. yAxis: 0,
  90. data: data.properties.map(function(d,i){
  91. return {
  92. x: new Date(d.unixtime*1000), // i,
  93. y: ('battery_level' in d ? Math.round(d.battery_level * 100) : null),
  94. state: d.battery_state,
  95. location: data.coordinates[i]
  96. }
  97. }),
  98. tooltip: {
  99. animation: true,
  100. pointFormatter: function(){
  101. moveMarkerToPosition(this);
  102. return this.state+'<br><b>'+this.y+'%</b>';
  103. }
  104. },
  105. turboThreshold: 0,
  106. lineWidth: 1,
  107. color: '#a8cff4',
  108. marker: {
  109. enabled: true,
  110. radius: 2,
  111. fillColor: '#7cb5ec'
  112. }
  113. }].concat(speedSeries(response)).concat(collectEventSeries(response)),
  114. });
  115. }