custom-cards / bar-card

Customizable Animated Bar card for Home Assistant Lovelace
MIT License
378 stars 54 forks source link

Logaritmic scale #164

Open brechtvhb opened 1 year ago

brechtvhb commented 1 year ago

It would be nice to be able to set the scale of the bar card to logaritmic.

Eg: when showing power usage of devices right now when you have a device using 10w, one using 100w, one using 1000w and one using 3000w (assuming min is 1 and max is 3000). It would resolve in having the devices being 0.3% wide, 3% wide, 30% wide and 100% wide.

Being able to set a logarithmic scale (example below) would result in these widths: 28.7%, 57.5%, 86.2% and 100%.

var minval = 1,
    maxval = 3000,
    minlog = Math.log10(minval),
    maxlog = Math.log10(maxval),
    range = maxlog - minlog,
    lineartolog = function(n){
        return (Math.log10(n) - minlog) / range;
    },
    logplots = [
        10,
        100,
        1000,
        3000
    ].map(lineartolog);

console.log(logplots );