From 18c12b718c476381c1044fc1cfa1e729290660f1 Mon Sep 17 00:00:00 2001
From: Guilhem CARRON <gcarron@grandlyon.com>
Date: Thu, 28 Oct 2021 14:27:42 +0000
Subject: [PATCH] feat(conso): Comparison graph now scales on comparison data
 if no actual data instead of default scale

---
 src/components/Charts/BarChart.tsx | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/components/Charts/BarChart.tsx b/src/components/Charts/BarChart.tsx
index 99d735425..2068381d2 100644
--- a/src/components/Charts/BarChart.tsx
+++ b/src/components/Charts/BarChart.tsx
@@ -49,11 +49,19 @@ const BarChart: React.FC<BarChartProps> = ({
     const maxCompare = chartData.comparisonData
       ? Math.max(...chartData.comparisonData.map(d => d.value))
       : 0
-    let max = chartData.actualData
+
+    const max = chartData.actualData
       ? Math.max(...chartData.actualData.map(d => d.value))
       : 0
-    max = max <= 0 ? 15 : max
-    return showCompare ? Math.max(max, maxCompare) : max
+
+    if (showCompare) {
+      if (max <= 0 && maxCompare <= 0) return 15
+      else return Math.max(max, maxCompare)
+    } else {
+      if (max <= 0) {
+        return 15
+      } else return max
+    }
   }
 
   const xScale: ScaleBand<string> = scaleBand()
-- 
GitLab