Skip to content

Commit

Permalink
add spacing for units (electricitymaps#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Mads Nedergaard <[email protected]>
  • Loading branch information
tonypls and madsnedergaard authored Jan 12, 2023
1 parent ca9f0fa commit 59659f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions web/src/components/CarbonIntensitySquare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function CarbonIntensitySquare({
<animated.span className="font-bold">
{number.to((x) => `${Math.round(x) || '?'}`)}
</animated.span>
&nbsp;
<span>g</span>
</p>
</animated.div>
Expand Down
5 changes: 3 additions & 2 deletions web/src/features/exchanges/ExchangeTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function CarbonIntensity({ intensity }: { intensity?: number }) {
className="mr-1 h-3 w-3"
style={{ backgroundColor: co2ColorScale(intensity ?? 0) }}
/>
<b className="flex items-center">{Math.round(intensity ?? 0) || '?'}</b> gCO₂eq/kWh
<b className="flex items-center">{Math.round(intensity ?? 0) || '?'}</b>
<p className="pl-0.5"> gCO₂eq/kWh</p>
</div>
);
}
Expand All @@ -38,7 +39,7 @@ export default function ExchangeTooltip(
{__('tooltips.crossborderexport')}:
<div className="flex items-center p-1">
<ZoneName zone={zoneFrom} /> <p className="m-2"></p> <ZoneName zone={zoneTo} />
<b className="pt-0 text-xs ">:{formatPower(roundedNetFlow)}</b>
<b className="pt-0 text-xs ">: {formatPower(roundedNetFlow)}</b>
</div>
{__('tooltips.carbonintensityexport')}:
<div className="p-1">
Expand Down
5 changes: 4 additions & 1 deletion web/src/utils/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 59659f8

Please sign in to comment.