From 59659f8552322ca09f808a441c7d7617a6daeb06 Mon Sep 17 00:00:00 2001
From: Tony
Date: Thu, 12 Jan 2023 22:25:37 +0100
Subject: [PATCH] add spacing for units (#140)
Co-authored-by: Mads Nedergaard
---
web/src/components/CarbonIntensitySquare.tsx | 1 +
web/src/features/exchanges/ExchangeTooltip.tsx | 5 +++--
web/src/utils/formatting.ts | 5 ++++-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/web/src/components/CarbonIntensitySquare.tsx b/web/src/components/CarbonIntensitySquare.tsx
index 455a71b006..1e2b6bf295 100644
--- a/web/src/components/CarbonIntensitySquare.tsx
+++ b/web/src/components/CarbonIntensitySquare.tsx
@@ -55,6 +55,7 @@ function CarbonIntensitySquare({
{number.to((x) => `${Math.round(x) || '?'}`)}
+
g
diff --git a/web/src/features/exchanges/ExchangeTooltip.tsx b/web/src/features/exchanges/ExchangeTooltip.tsx
index b5c8462f69..4d3c69bb7b 100644
--- a/web/src/features/exchanges/ExchangeTooltip.tsx
+++ b/web/src/features/exchanges/ExchangeTooltip.tsx
@@ -14,7 +14,8 @@ export function CarbonIntensity({ intensity }: { intensity?: number }) {
className="mr-1 h-3 w-3"
style={{ backgroundColor: co2ColorScale(intensity ?? 0) }}
/>
- {Math.round(intensity ?? 0) || '?'} gCO₂eq/kWh
+ {Math.round(intensity ?? 0) || '?'}
+ gCO₂eq/kWh
);
}
@@ -38,7 +39,7 @@ export default function ExchangeTooltip(
{__('tooltips.crossborderexport')}:
→
-
:{formatPower(roundedNetFlow)}
+
: {formatPower(roundedNetFlow)}
{__('tooltips.carbonintensityexport')}:
diff --git a/web/src/utils/formatting.ts b/web/src/utils/formatting.ts
index b959b44ddd..5b07f3182f 100644
--- a/web/src/utils/formatting.ts
+++ b/web/src/utils/formatting.ts
@@ -9,7 +9,10 @@ export const formatPower = function (d: number, numberDigits = DEFAULT_NUM_DIGIT
if (d == undefined || Number.isNaN(d)) {
return d;
}
- return `${d3.format(`.${numberDigits}s`)(d * 1e6)}W`;
+ const power = `${d3.format(`.${numberDigits}s`)(d * 1e6)}W` //Add a space between the number and the unit
+ .replace(/([A-Z])/, ' $1')
+ .trim();
+ return power;
};
export const formatCo2 = function (d, numberDigits = DEFAULT_NUM_DIGITS) {