userMonitor.blade.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. @extends('admin.layouts')
  2. @section('content')
  3. <div class="page-content container-fluid">
  4. <x-ui.panel :title="trans('admin.monitor.user')">
  5. <x-slot:alert>
  6. <x-alert type="info">
  7. <h4 class="block">{{ $username }}</h4>
  8. {!! trans('admin.monitor.hint') !!}
  9. </x-alert>
  10. </x-slot:alert>
  11. <div class="row">
  12. <div class="col-md-6">
  13. <canvas id="dailyChart" role="img" aria-label="{{ trans('admin.monitor.daily_chart') }}"></canvas>
  14. </div>
  15. <div class="col-md-6">
  16. <canvas id="monthlyChart" role="img" aria-label="{{ trans('admin.monitor.monthly_chart') }}"></canvas>
  17. </div>
  18. </div>
  19. </x-ui.panel>
  20. </div>
  21. @endsection
  22. @section('javascript')
  23. <script src="/assets/global/vendor/chart-js/chart.umd.min.js"></script>
  24. <script>
  25. function common_options(tail) {
  26. return {
  27. responsive: true,
  28. scales: {
  29. x: {
  30. ticks: {
  31. callback: function(value) {
  32. return this.getLabelForValue(value) + ' ' + tail;
  33. },
  34. },
  35. grid: {
  36. display: false,
  37. },
  38. },
  39. y: {
  40. ticks: {
  41. callback: function(value) {
  42. return this.getLabelForValue(value) + ' GB';
  43. },
  44. },
  45. grid: {
  46. display: false,
  47. },
  48. min: 0,
  49. },
  50. },
  51. plugins: {
  52. legend: false,
  53. tooltip: {
  54. mode: 'index',
  55. intersect: false,
  56. callbacks: {
  57. title: function(context) {
  58. return context[0].label + ' ' + tail;
  59. },
  60. label: function(context) {
  61. return context.parsed.y + ' GB';
  62. },
  63. },
  64. },
  65. },
  66. };
  67. }
  68. function datasets(label, data) {
  69. return {
  70. labels: label,
  71. datasets: [{
  72. backgroundColor: 'rgba(184, 215, 255)',
  73. borderColor: 'rgba(184, 215, 255)',
  74. data: data,
  75. tension: 0.4,
  76. }],
  77. };
  78. }
  79. new Chart(document.getElementById('dailyChart'), {
  80. type: 'line',
  81. data: datasets(@json($dayHours), @json($trafficHourly)),
  82. options: common_options(@json(trans_choice('common.hour', 2))),
  83. });
  84. new Chart(document.getElementById('monthlyChart'), {
  85. type: 'line',
  86. data: datasets(@json($monthDays), @json($trafficDaily)),
  87. options: common_options(@json(trans_choice('common.days.attribute', 2))),
  88. });
  89. </script>
  90. @endsection