Skip to content

Commit

Permalink
fix: dataLabels would not follow float_precision
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Feb 4, 2021
1 parent 9747257 commit cf9b63a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ views:
extend_to_end: false
type: column
invert: true
float_precision: 3
group_by:
func: avg
fill: 'last'
Expand Down
12 changes: 8 additions & 4 deletions src/apex-layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ export function getLayoutConfig(config: ChartCardConfig, hass: HomeAssistant | u
},
},
dataLabels: {
formatter: function (value) {
formatter: function (value, opts, conf = config) {
if (value === null) return;
let lValue = value;
if (value !== null && typeof value === 'number' && !Number.isInteger(value)) {
lValue = (value as number).toFixed(1);
if (lValue !== null && typeof lValue === 'number' && !Number.isInteger(lValue)) {
lValue = (lValue as number).toFixed(
conf.series_in_graph[opts.seriesIndex].float_precision === undefined
? DEFAULT_FLOAT_PRECISION
: conf.series_in_graph[opts.seriesIndex].float_precision,
);
}
if (lValue === null) return;
return lValue;
},
},
Expand Down

0 comments on commit cf9b63a

Please sign in to comment.