Skip to content

Commit

Permalink
fix: header units for radialBar
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Mar 1, 2021
1 parent 7d96703 commit 6883a8f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,13 @@ views:
show: true
title: radialBar
chart_type: radialBar
header:
show: true
show_states: true
series:
- entity: sensor.random0_100
- entity: sensor.random_0_1000
unit: Mbits/s
min: 0
max: 1000
- type: custom:apexcharts-card
Expand Down
15 changes: 9 additions & 6 deletions src/apex-layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,15 @@ function getLegendFormatter(config: ChartCardConfig, hass: HomeAssistant | undef
if (!conf.series_in_graph[opts.seriesIndex]?.show.as_duration) {
value = truncateFloat(value, conf.series_in_graph[opts.seriesIndex].float_precision);
}
const uom = computeUom(
opts.seriesIndex,
conf.series_in_graph,
undefined,
hass2?.states[conf.series_in_graph[opts.seriesIndex].entity],
);
const uom =
config.chart_type === 'radialBar'
? '%'
: computeUom(
opts.seriesIndex,
conf.series_in_graph,
undefined,
hass2?.states[conf.series_in_graph[opts.seriesIndex].entity],
);
let valueString = '';
if (value === undefined || value === null) {
valueString = `<strong>${NO_VALUE} ${uom}</strong>`;
Expand Down
1 change: 0 additions & 1 deletion src/apexcharts-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ class ChartsCard extends LitElement {
serie.fill_raw = serie.fill_raw || DEFAULT_FILL_RAW;
serie.extend_to_end = serie.extend_to_end !== undefined ? serie.extend_to_end : true;
serie.type = this._config?.chart_type ? undefined : serie.type || DEFAULT_SERIE_TYPE;
serie.unit = this._config?.chart_type === 'radialBar' ? '%' : serie.unit;
if (!serie.group_by) {
serie.group_by = { duration: DEFAULT_DURATION, func: DEFAULT_FUNC, fill: DEFAULT_GROUP_BY_FILL };
} else {
Expand Down

0 comments on commit 6883a8f

Please sign in to comment.