From 319b98b3485c95382647e78ba1147ba7ae1a7257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Tue, 16 May 2023 07:51:26 +0200 Subject: [PATCH] Add the kWh unit for tooltips of power tracks. --- locales/en-US/app.ftl | 22 ++++++++++++++++++++++ src/components/tooltip/TrackPower.js | 10 +++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/locales/en-US/app.ftl b/locales/en-US/app.ftl index 62977a680a..1e01f06651 100644 --- a/locales/en-US/app.ftl +++ b/locales/en-US/app.ftl @@ -807,6 +807,12 @@ TrackMemoryGraph--operations-since-the-previous-sample = operations since the pr ## consumption. The carbon dioxide equivalent represents the equivalent amount ## of CO₂ to achieve the same level of global warming potential. +# This is used in the tooltip when the power value uses the kilowatt unit. +# Variables: +# $value (String) - the power value at this location +TrackPower--tooltip-power-kilowatt = { $value } kW + .label = Power + # This is used in the tooltip when the power value uses the watt unit. # Variables: # $value (String) - the power value at this location @@ -819,6 +825,14 @@ TrackPower--tooltip-power-watt = { $value } W TrackPower--tooltip-power-milliwatt = { $value } mW .label = Power +# This is used in the tooltip when the energy used in the current range uses the +# kilowatt-hour unit. +# Variables: +# $value (String) - the energy value for this range +# $carbonValue (string) - the carbon dioxide equivalent (CO₂e) value (kilograms) +TrackPower--tooltip-energy-carbon-used-in-range-kilowatthour = { $value } kWh ({ $carbonValue } kg CO₂e) + .label = Energy used in the visible range + # This is used in the tooltip when the energy used in the current range uses the # watt-hour unit. # Variables: @@ -843,6 +857,14 @@ TrackPower--tooltip-energy-carbon-used-in-range-milliwatthour = { $value } mWh ( TrackPower--tooltip-energy-carbon-used-in-range-microwatthour = { $value } µWh ({ $carbonValue } mg CO₂e) .label = Energy used in the visible range +# This is used in the tooltip when the energy used in the current preview +# selection uses the kilowatt-hour unit. +# Variables: +# $value (String) - the energy value for this range +# $carbonValue (string) - the carbon dioxide equivalent (CO₂e) value (kilograms) +TrackPower--tooltip-energy-carbon-used-in-preview-kilowatthour = { $value } kWh ({ $carbonValue } kg CO₂e) + .label = Energy used in the current selection + # This is used in the tooltip when the energy used in the current preview # selection uses the watt-hour unit. # Variables: diff --git a/src/components/tooltip/TrackPower.js b/src/components/tooltip/TrackPower.js index 27bbdb3537..99597dc6a3 100644 --- a/src/components/tooltip/TrackPower.js +++ b/src/components/tooltip/TrackPower.js @@ -90,13 +90,18 @@ class TooltipTrackPowerImpl extends React.PureComponent { _formatPowerValue( power: number, + l10nIdKiloUnit, l10nIdUnit, l10nIdMilliUnit, l10nIdMicroUnit ): Localized { let value, l10nId, carbonValue; const carbon = this._computeCO2eFromPower(power); - if (power > 1) { + if (power > 1000) { + value = formatNumber(power / 1000, 3); + carbonValue = formatNumber(carbon / 1000, 2); + l10nId = l10nIdKiloUnit; + } else if (power > 1) { value = formatNumber(power, 3); carbonValue = formatNumber(carbon, 3); l10nId = l10nIdUnit; @@ -153,12 +158,14 @@ class TooltipTrackPowerImpl extends React.PureComponent { {this._formatPowerValue( power, + 'TrackPower--tooltip-power-kilowatt', 'TrackPower--tooltip-power-watt', 'TrackPower--tooltip-power-milliwatt' )} {previewSelection.hasSelection ? this._formatPowerValue( this._computePowerSumForPreviewRange(previewSelection), + 'TrackPower--tooltip-energy-carbon-used-in-preview-kilowatthour', 'TrackPower--tooltip-energy-carbon-used-in-preview-watthour', 'TrackPower--tooltip-energy-carbon-used-in-preview-milliwatthour', 'TrackPower--tooltip-energy-carbon-used-in-preview-microwatthour' @@ -166,6 +173,7 @@ class TooltipTrackPowerImpl extends React.PureComponent { : null} {this._formatPowerValue( this._computePowerSumForCommittedRange(committedRange), + 'TrackPower--tooltip-energy-carbon-used-in-range-kilowatthour', 'TrackPower--tooltip-energy-carbon-used-in-range-watthour', 'TrackPower--tooltip-energy-carbon-used-in-range-milliwatthour', 'TrackPower--tooltip-energy-carbon-used-in-range-microwatthour'