I haven’t read your code, but you probably have to check your maths and in which range the numbers are:
gain = 0 => dB = -infinity (defaults to -80.0, can be specified)
gain = 0.5 => dB = - 6dB
gain = 1 => dB = 0
so you can simply map to your rect:
auto y = jmap (Decibels::gainToDecibels (magnitude, -80.8f), -80.0f, 0.0f, rect.getBottom(), rect.getY());
BTW. I think this thread will be interesting for you: