NetworkSmallGraph.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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->configChartsSettings->timeframe = 'day';
  50. $this->timeframe = 'day';
  51. }
  52. public function prepareAjaxData()
  53. {
  54. session_write_close();
  55. $labels = [];
  56. $dataSets = [
  57. 'netin' => [],
  58. 'netout' => [],
  59. ];
  60. foreach ($this->rrdDataQuery() as $rrd)
  61. {
  62. $labels[] = $rrd->date;
  63. $dataSets['netin'][] = isset($rrd->netin) ? (float)$rrd->netin : 0;
  64. $dataSets['netout'][] = isset($rrd->netout) ? (float)$rrd->netout : 0;
  65. }
  66. //Labels
  67. $this->setLabels($labels);
  68. //net in
  69. $lang = sl('lang');
  70. $dataSet = new DataSet();
  71. $dataSet->setTitle($lang->tr('Net In'))
  72. ->setData($dataSets['netin'])
  73. ->setConfigurationDataSet([
  74. "backgroundColor" => 'rgba(174, 198, 57, 0.79)',
  75. "borderColor" => 'rgba(174, 198, 57, 1)',
  76. ]);
  77. $this->addDataSet($dataSet);
  78. //net out
  79. $dataSet = new DataSet();
  80. $dataSet->setTitle($lang->tr('Net Out'))
  81. ->setData($dataSets['netout'])
  82. ->setConfigurationDataSet([
  83. "backgroundColor" => 'rgba(39, 133, 134, 0.91)',
  84. "borderColor" => 'rgba(39, 133, 134, 1)',
  85. ]);
  86. $this->addDataSet($dataSet);
  87. }
  88. }