kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
2.87k stars 231 forks source link

Does not follow user profile configured "Number Format" #1010

Open howi42 opened 9 months ago

howi42 commented 9 months ago

the number format, as defined in the profile settings, is not honored.

ildar170975 commented 9 months ago

Same as closed https://github.com/kalkih/mini-graph-card/issues/774

howi42 commented 8 months ago

Regardless the state of this issue, the user interface does not look good with this. And , I have not found any settings combination ( language, number format, data format ), which at the end use the same style for numbers.

cataseven commented 8 months ago

Up up up

Lavve commented 7 months ago

Would be really nice to get this fixed, it looks a bit strange with different number formats on the dash.

CMDR-Sloma commented 6 months ago

This should be treated as a bug, not an enhancement.

cataseven commented 5 months ago

Up

ildar170975 commented 5 months ago

No need to "up" here. It only makes sense to prevent "stale". Using "upping" to force someone to implement the feature is inappropriate.

cataseven commented 5 months ago

Can you please label this as "bug"? This is not an enhc.

CMDR-Sloma commented 5 months ago

I also agree this is not an enhancement but a bug.

ildar170975 commented 5 months ago

I can set here "bug", but it may not "speed up" implementation... So, 2 labels - enhancement & bug - everyone is happy))))

cataseven commented 5 months ago

I found my solution. For those want to use "." as thousand seperator and "," for decimals. I am not a developer so I couldnt do it more generic way but It works anyway

numberFormat(a, b, c) {
  return !O(+a) && Intl ? new Intl.NumberFormat(b, {
    minimumFractionDigits: c
  }).format(+a) : a.toString()
}

change it with the code below. I prefered Turkish. So now my numbers are now formatted like 1.233.444,89 and I am still using HA in English.

numberFormat(a, b, c) {
  if (!isNaN(+a)) {
    const formattedNumber = (+a).toLocaleString('tr-TR', {
      minimumFractionDigits: c
    });
    return formattedNumber;
  } else {
    return a.toString();
  }
}
cataseven commented 5 months ago

I can set here "bug", but it may not "speed up" implementation... So, 2 labels - enhancement & bug - everyone is happy))))

Maybe My last suggestion speed it up ;)

aigarius commented 4 months ago

Not really, cat. The addon should be following the Home Assistant defined settings on the Number Format specifically and not just use the default number format of the language chosen for the HA UI. And also not one random language format. For example, I have HA UI language set to "English", but the Number format to "None" because I can not stand having extra thousand separator symbols. It works (almost) everywhere in HA, but this addon just ignores the very explicit Number format setting and instead tries to guess the number format from the UI language, which is a bug.

cataseven commented 4 months ago

Not really, cat. The addon should be following the Home Assistant defined settings on the Number Format specifically and not just use the default number format of the language chosen for the HA UI. And also not one random language format. For example, I have HA UI language set to "English", but the Number format to "None" because I can not stand having extra thousand separator symbols. It works (almost) everywhere in HA, but this addon just ignores the very explicit Number format setting and instead tries to guess the number format from the UI language, which is a bug.

Sure, but I at least some of us get what they need. Agree for the rest

aigarius commented 4 months ago

I wonder if https://github.com/home-assistant/frontend/pull/17249 can be used to get HA to format the values correctly.

ildar170975 commented 4 months ago

May be I am missing something, see no need to connect “number format” and “language”, imho these are independent settings.

aigarius commented 4 months ago

Yes, they are. Currently the code in mini-graph-card just uses "language" setting and then asks an external library to format numbers (and dates) in accordance to the rules of that language. And completely ignores the HA settings for number format and date format.

ildar170975 commented 4 months ago

And in HA itself there are some “connections” between a language and a number format - which makes a code more complex and buggy.

aigarius commented 4 months ago

There are indeed, like if I click on a value I get this wonderful screen: Screenshot from 2024-02-20 15-00-46

That screen has both correct number formatting preference (None) in the number display location (top right, "1078 ppm"), but at the same time chooses to use the language numbering preference for the Y axis ("2,000")

The second is a bug.

ildar170975 commented 4 months ago

What happens if you start playing with a language, will it affect mini-graph?

aigarius commented 4 months ago

Yes, switching from "English" to German, for example, would change the decimal separator from "." to "," and the thousand separator from "," to ".". And switching language to Esperanto would change the thousand separator to " " and decimal separator to ",".

The code in https://github.com/kalkih/mini-graph-card/blob/master/src/main.js#L720 literally just gives the value to the browser function Intl.NumberFormat along with the currently configured system language.

aigarius commented 4 months ago

https://developers.home-assistant.io/docs/frontend/data/#hassformatentityattributevaluestateobj-attribute-value describes the function that is there to format the value correctly, according to settings of both HA and of the entity itself (like you can set precision on the entity). It is available to mini-graph-card.

dr3amr commented 1 month ago

@ildar170975 @kalkih Any development to current issue ? No updates from Feb 20, is this still considered for implementation ?