Alexander Musikhin 16 часов назад
Родитель
Сommit
f45e911f69
1 измененных файлов с 35 добавлено и 3 удалено
  1. 35 3
      resources/views/reports/index.blade.php

+ 35 - 3
resources/views/reports/index.blade.php

@@ -313,12 +313,30 @@
     <script>
         const totalMafs = {{ $totalMafs }};
 
+        function formatMafPercent(value) {
+            const percent = totalMafs > 0 ? (value / totalMafs * 100) : 0;
+
+            return percent.toFixed(2).replace('.', ',');
+        }
+
+        function getBarValue(context) {
+            if (Array.isArray(context.raw)) {
+                return Math.abs(Number(context.raw[1] || 0) - Number(context.raw[0] || 0));
+            }
+
+            return Number(context.parsed?.y ?? context.parsed ?? 0);
+        }
+
         function mafTooltipLabel(context) {
             const value = Number(context.parsed || 0);
-            const percent = totalMafs > 0 ? (value / totalMafs * 100) : 0;
-            const formattedPercent = percent.toFixed(2).replace('.', ',');
 
-            return context.label + ': ' + value + ' МАФ (' + formattedPercent + '%)';
+            return context.label + ': ' + value + ' МАФ (' + formatMafPercent(value) + '%)';
+        }
+
+        function mafBarTooltipLabel(context) {
+            const value = getBarValue(context);
+
+            return context.dataset.label + ': ' + value + ' МАФ (' + formatMafPercent(value) + '%)';
         }
 
         const ctx = document.getElementById('order_types');
@@ -348,6 +366,13 @@
                 ]
             },
             options: {
+                plugins: {
+                    tooltip: {
+                        callbacks: {
+                            label: mafBarTooltipLabel
+                        }
+                    }
+                },
                 scales: {
                     y: {
                         beginAtZero: true
@@ -386,6 +411,13 @@
                 ]
             },
             options: {
+                plugins: {
+                    tooltip: {
+                        callbacks: {
+                            label: mafBarTooltipLabel
+                        }
+                    }
+                },
                 scales: {
                     y: {
                         beginAtZero: true