Skip to content

Commit

Permalink
fix(datalabels): Truncate floats to 1 digit after the decimal point
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Jan 27, 2021
1 parent fb74956 commit f5f744f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ views:
graph_span: 24h
span:
start: day
apex_config:
dataLabels:
enabled: true
dropShadow:
enabled: true
series:
- entity: sensor.random0_100
extend_to_end: false
Expand Down
10 changes: 10 additions & 0 deletions src/apex-layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ export function getLayoutConfig(config: ChartCardConfig, hass: HomeAssistant | u
postion: 'topRight',
},
},
dataLabels: {
formatter: function (value, _) {
let lValue = value;
if (value !== null && typeof value === 'number' && !Number.isInteger(value)) {
lValue = (value as number).toFixed(1);
}
if (lValue === null) return;
return lValue;
},
},
legend: {
formatter: function (_, opts, conf = config, hass2 = hass) {
const name =
Expand Down

0 comments on commit f5f744f

Please sign in to comment.