diff --git a/.devcontainer/ui-lovelace.yaml b/.devcontainer/ui-lovelace.yaml index 766b91c..64bb4b8 100644 --- a/.devcontainer/ui-lovelace.yaml +++ b/.devcontainer/ui-lovelace.yaml @@ -317,7 +317,7 @@ views: func: avg fill: 'last' show: - legend_value: false + legend_value: true datalabels: true - entity: sensor.random0_100 extend_to_end: false diff --git a/src/apex-layouts.ts b/src/apex-layouts.ts index bd2744f..3f836af 100644 --- a/src/apex-layouts.ts +++ b/src/apex-layouts.ts @@ -271,8 +271,12 @@ function getXTooltipFormatter( function getYTooltipFormatter(config: ChartCardConfig, hass: HomeAssistant | undefined) { return function (value, opts, conf = config, hass2 = hass) { + let lValue = value; + if (conf.series_in_graph[opts.seriesIndex]?.invert && lValue) { + lValue = -lValue; + } if (!conf.series_in_graph[opts.seriesIndex]?.show.as_duration) { - value = truncateFloat(value, conf.series_in_graph[opts.seriesIndex].float_precision); + lValue = truncateFloat(lValue, conf.series_in_graph[opts.seriesIndex].float_precision); } const uom = computeUom( opts.seriesIndex, @@ -282,8 +286,8 @@ function getYTooltipFormatter(config: ChartCardConfig, hass: HomeAssistant | und ); return conf.series_in_graph[opts.seriesIndex]?.show.as_duration ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - [`${prettyPrintTime(value, conf.series_in_graph[opts.seriesIndex].show.as_duration!)}`] - : [`${value} ${uom}`]; + [`${prettyPrintTime(lValue, conf.series_in_graph[opts.seriesIndex].show.as_duration!)}`] + : [`${lValue} ${uom}`]; }; } @@ -296,7 +300,11 @@ function getDataLabelsFormatter(config: ChartCardConfig) { ); } if (value === null) return; - return truncateFloat(value, conf.series_in_graph[opts.seriesIndex].float_precision); + let lValue = value; + if (conf.series_in_graph[opts.seriesIndex]?.invert && lValue) { + lValue = -lValue; + } + return truncateFloat(lValue, conf.series_in_graph[opts.seriesIndex].float_precision); }; } @@ -326,6 +334,9 @@ function getLegendFormatter(config: ChartCardConfig, hass: HomeAssistant | undef let value = TIMESERIES_TYPES.includes(config.chart_type) ? opts.w.globals.series[opts.seriesIndex].slice(-1)[0] : opts.w.globals.series[opts.seriesIndex]; + if (conf.series_in_graph[opts.seriesIndex]?.invert && value) { + value = -value; + } if (!conf.series_in_graph[opts.seriesIndex]?.show.as_duration) { value = truncateFloat(value, conf.series_in_graph[opts.seriesIndex].float_precision); }