NetworkSmallGraph.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Oct 1, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Graph\Pages;
  20. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Models\DataSet;
  21. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  22. class NetworkSmallGraph extends BaseSmallGraph
  23. {
  24. protected $id = 'networkSmallGraph';
  25. protected $name = 'networkSmallGraph';
  26. public function initContent()
  27. {
  28. $this->updateChartScale('yAxes', [
  29. [
  30. 'scaleLabel' => [
  31. 'display' => $this->displayScaleLabel,
  32. 'labelString' => sl('lang')->tr('Network')
  33. ],
  34. 'ticks' => [
  35. 'callback' => 'mgBytesToSize',
  36. 'beginAtZero' => true,
  37. 'fontSize' => 10
  38. ],
  39. ]]);
  40. $this->updateChartOption('tooltips', [
  41. 'callbacks' => [
  42. 'label' => 'mgTooltipCallbackForNet'
  43. ]
  44. ]);
  45. $this->updateChartScale('xAxes', [
  46. [
  47. 'display' => false
  48. ]]);
  49. $this->timeframe = 'day';
  50. }
  51. public function prepareAjaxData()
  52. {
  53. session_write_close();
  54. $labels = [];
  55. $dataSets = [
  56. 'netin' => [],
  57. 'netout' => [],
  58. ];
  59. foreach ($this->rrdDataQuery() as $rrd)
  60. {
  61. $labels[] = $rrd->date;
  62. $dataSets['netin'][] = isset($rrd->netin) ? (float)$rrd->netin : 0;
  63. $dataSets['netout'][] = isset($rrd->netout) ? (float)$rrd->netout : 0;
  64. }
  65. //Labels
  66. $this->setLabels($labels);
  67. //net in
  68. $lang = sl('lang');
  69. $dataSet = new DataSet();
  70. $dataSet->setTitle($lang->tr('Net In'))
  71. ->setData($dataSets['netin'])
  72. ->setConfigurationDataSet([
  73. "backgroundColor" => 'rgba(174, 198, 57, 0.79)',
  74. "borderColor" => 'rgba(174, 198, 57, 1)',
  75. ]);
  76. $this->addDataSet($dataSet);
  77. //net out
  78. $dataSet = new DataSet();
  79. $dataSet->setTitle($lang->tr('Net Out'))
  80. ->setData($dataSets['netout'])
  81. ->setConfigurationDataSet([
  82. "backgroundColor" => 'rgba(39, 133, 134, 0.91)',
  83. "borderColor" => 'rgba(39, 133, 134, 1)',
  84. ]);
  85. $this->addDataSet($dataSet);
  86. }
  87. }