gonuit / gauge_indicator

MIT License
29 stars 12 forks source link

Support negative values #2

Closed tobiasht closed 1 year ago

tobiasht commented 1 year ago

The package currently does not support negative values. I would be great to add some scaling to the inputs to support this.

The example values that i used: min: -3000, max: 3000, value: -750,

tobiasht commented 1 year ago

It also struggles a lot, when you toggle between different min and max ranges. I think both of these issues can be fixed by scaling this values better. I attahced the formula i used in my code. Maybe you can implement this within the widget itself?

double normalize(
  double oldMin,
  double oldMax,
  double? value, {
  double newMin = 0,
  double newMax = 100,
}) {
  if (value == null) return newMin;
  if (oldMax - oldMin == 0) return 0;

  return (((value - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin;
}
gonuit commented 1 year ago

Thank you @tobiasht for that 💪🏻 I will try to make some improvements in the upcoming version.

I will post updates here.

JPFrancoia commented 1 year ago

That would be awesome. I'm in a situation where I'd need to set the max value to 0 and dynamically change the min value. The min value needs to be negative.

gonuit commented 1 year ago

This was implemented/fixed by @dino-keskic in #7 and released in version 0.4.3 💪🏻.

If there are further problems, please reopen this issue.

JPFrancoia commented 1 year ago

Awesome! thank you very much! I'll test it now