I want to add an autoscaling option for the histogram. It occurred to me to check Rainmeter's source and try to see how it handles autoscaling.
I found this (https://github.com/rainmeter/rainmeter/blob/master/Library/MeterHistogram.cpp line 357)
Code: Select all
if (m_Autoscale)
{
// Go through all values and find the max
double newValue = 0.0;
for (int i = 0; i < maxSize; ++i)
{
newValue = max(newValue, m_PrimaryValues[i]);
}
// Scale the value up to nearest power of 2
if (newValue > DBL_MAX / 2.0)
{
m_MaxPrimaryValue = DBL_MAX;
}
else
{
m_MaxPrimaryValue = 2.0;
while (m_MaxPrimaryValue < newValue)
{
m_MaxPrimaryValue *= 2.0;
}
}
Thanks
Update
I got this working to my satisfaction. The C++ code was a bit of a red herring, though it did get me thinking along the right lines in the end. Here is my solution:
Code: Select all
if auto then
if Values[i] == maxV then
h = maxHeight
else
h = math.ceil((Values[i]/maxV)*maxHeight)
end
else
h = math.ceil(Values[i]*maxHeight)
end
It looks to me like the first nested if/else (if Values[i] == maxV) is redundant; I don't see why I can't get rid of it and just have:
Code: Select all
if auto then
h = math.ceil((Values[i]/maxV)*maxHeight)
else
h = math.ceil(Values[i]*maxHeight)
end