From a9362cc6f9b974140a760ad05816cac51c849769 Mon Sep 17 00:00:00 2001
From: Neil <55785687+carkom@users.noreply.github.com>
Date: Sat, 2 Mar 2024 07:35:05 +0000
Subject: [PATCH] BarGraph crash (#2411)

* Fix crash

* notes
---
 .../src/components/reports/graphs/BarGraph.tsx    | 15 +++++++++++----
 .../reports/graphs/renderCustomLabel.tsx          |  1 +
 upcoming-release-notes/2411.md                    |  6 ++++++
 3 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 upcoming-release-notes/2411.md

diff --git a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
index 5ec4783c1..16e51f262 100644
--- a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
@@ -111,13 +111,17 @@ const CustomTooltip = ({
   }
 };
 
-const customLabel = props => {
+const customLabel = (props, typeOp) => {
   const calcX = props.x + props.width / 2;
   const calcY = props.y - (props.value > 0 ? 15 : -15);
   const textAnchor = 'middle';
   const display =
     props.value !== 0 && `${amountToCurrencyNoDecimal(props.value)}`;
-  const textSize = adjustTextSize(props.width, 'variable', props.value);
+  const textSize = adjustTextSize(
+    props.width,
+    typeOp === 'totalTotals' ? 'default' : 'variable',
+    props.value,
+  );
 
   return renderCustomLabel(calcX, calcY, textAnchor, display, textSize);
 };
@@ -226,7 +230,7 @@ export function BarGraph({
                   {viewLabels && !compact && (
                     <LabelList
                       dataKey={val => getVal(val)}
-                      content={customLabel}
+                      content={e => customLabel(e, balanceTypeOp)}
                     />
                   )}
                   {data.legend.map((entry, index) => (
@@ -240,7 +244,10 @@ export function BarGraph({
                 {yAxis === 'date' && balanceTypeOp === 'totalTotals' && (
                   <Bar dataKey="totalDebts" stackId="a">
                     {viewLabels && !compact && (
-                      <LabelList dataKey="totalDebts" content={customLabel} />
+                      <LabelList
+                        dataKey="totalDebts"
+                        content={e => customLabel(e, balanceTypeOp)}
+                      />
                     )}
                     {data[splitData].map((entry, index) => (
                       <Cell
diff --git a/packages/desktop-client/src/components/reports/graphs/renderCustomLabel.tsx b/packages/desktop-client/src/components/reports/graphs/renderCustomLabel.tsx
index 187b50394..103561f7f 100644
--- a/packages/desktop-client/src/components/reports/graphs/renderCustomLabel.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/renderCustomLabel.tsx
@@ -16,6 +16,7 @@ export const renderCustomLabel = (
 ) => {
   return !showLabel || Math.abs(showLabel) > showLabelThreshold ? (
     <text
+      key={fill + display}
       x={calcX}
       y={calcY}
       fill={fill}
diff --git a/upcoming-release-notes/2411.md b/upcoming-release-notes/2411.md
new file mode 100644
index 000000000..03ae4ba8b
--- /dev/null
+++ b/upcoming-release-notes/2411.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [carkom]
+---
+
+Fix crash in the BarGraph for Net/Interval.
-- 
GitLab