mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Add Y-axis label formatter to energy charts (#28298)
This commit is contained in:
@@ -56,6 +56,19 @@ export function getSuggestedPeriod(
|
|||||||
return dayDifference > 35 ? "month" : dayDifference > 2 ? "day" : "hour";
|
return dayDifference > 35 ? "month" : dayDifference > 2 ? "day" : "hour";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createYAxisLabelFormatter(locale: FrontendLocaleData) {
|
||||||
|
let previousValue: number | undefined;
|
||||||
|
|
||||||
|
return (value: number): string => {
|
||||||
|
const maximumFractionDigits = Math.max(
|
||||||
|
1,
|
||||||
|
-Math.floor(Math.log10(Math.abs(value - (previousValue ?? value) || 1)))
|
||||||
|
);
|
||||||
|
previousValue = value;
|
||||||
|
return formatNumber(value, locale, { maximumFractionDigits });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function getCommonOptions(
|
export function getCommonOptions(
|
||||||
start: Date,
|
start: Date,
|
||||||
end: Date,
|
end: Date,
|
||||||
@@ -86,7 +99,7 @@ export function getCommonOptions(
|
|||||||
align: "left",
|
align: "left",
|
||||||
},
|
},
|
||||||
axisLabel: {
|
axisLabel: {
|
||||||
formatter: (value: number) => formatNumber(Math.abs(value), locale),
|
formatter: createYAxisLabelFormatter(locale),
|
||||||
},
|
},
|
||||||
splitLine: {
|
splitLine: {
|
||||||
show: true,
|
show: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user