Skip to content

Commit

Permalink
Histogram/Line meters: Fix remaining drawing issues
Browse files Browse the repository at this point in the history
These meter will now draw similarly to other graph type meters like Bar and Roundline with regards to specific ranges defined by MinValue/MaxValue.
  • Loading branch information
brianferguson committed Sep 19, 2022
1 parent b8e1a60 commit 227a5b8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Library/MeterHistogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
const FLOAT startStep = (FLOAT)(startValue + (step * i));

double range = m_MaxPrimaryValue - m_MinPrimaryValue;
double value = (range <= 0.0) ? 0.0 :
(m_PrimaryValues[(i + (m_MeterPos % displayH)) % displayH] - m_MinPrimaryValue) / range;
double value = (range < 0.0) ? 0.0 : (range == 0.0) ? 1.0 :
(m_PrimaryValues[(i + m_MeterPos) % displayH] - m_MinPrimaryValue) / range;

int primaryBarHeight = (int)(displayW * value);
primaryBarHeight = min(displayW, primaryBarHeight);
Expand All @@ -445,7 +445,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
if (secondaryMeasure)
{
range = m_MaxSecondaryValue - m_MinSecondaryValue;
value = (range <= 0.0) ? 0.0 :
value = (range < 0.0) ? 0.0 : (range == 0.0) ? 1.0 :
(m_SecondaryValues[(i + m_MeterPos) % displayH] - m_MinSecondaryValue) / range;

int secondaryBarHeight = (int)(displayW * value);
Expand Down Expand Up @@ -496,7 +496,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
const FLOAT startStep = (FLOAT)(startValue + (step * i));

double range = m_MaxPrimaryValue - m_MinPrimaryValue;
double value = (range <= 0.0) ? 0.0 :
double value = (range < 0.0) ? 0.0 : (range == 0.0) ? 1.0 :
(m_PrimaryValues[((i + m_MeterPos) % displayW)] - m_MinPrimaryValue) / range;

int primaryBarHeight = (int)(displayH * value);
Expand All @@ -508,7 +508,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
if (secondaryMeasure)
{
range = m_MaxSecondaryValue - m_MinSecondaryValue;
value = (range <= 0.0) ? 0.0 :
value = (range < 0.0) ? 0.0 : (range == 0.0) ? 1.0 :
(m_SecondaryValues[(i + m_MeterPos) % displayW] - m_MinSecondaryValue) / range;

int secondaryBarHeight = (int)(displayH * value);
Expand Down
38 changes: 30 additions & 8 deletions Library/MeterLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)

if (maxValue == minValue)
{
minValue = 0.0;
maxValue = 1.0;
//minValue = 0.0;
//maxValue = 1.0;
}

D2D1_RECT_F meterRect = GetMeterRectPadding();
Expand Down Expand Up @@ -334,9 +334,20 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)

auto calcX = [&](FLOAT& _x)
{
_x = ((FLOAT)(((*i)[pos] - minValue) * scale) + offset);
_x = min(_x, W + offset);
_x = max(_x, offset);
if (range == 0.0)
{
_x = W;
}
else if (range < 0.0)
{
_x = 1.0f;
}
else
{
_x = ((FLOAT)(((*i)[pos] - minValue) * scale) + offset);
_x = min(_x, W + offset);
_x = max(_x, offset);
}
_x = meterRect.left + (m_GraphStartLeft ? _x : W - _x + 1.0f);
};

Expand Down Expand Up @@ -396,9 +407,20 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)

auto calcY = [&](FLOAT& _y)
{
_y = ((FLOAT)(((*i)[pos] - minValue) * scale) + offset);
_y = min(_y, H + offset);
_y = max(_y, offset);
if (range == 0.0)
{
_y = H;
}
else if (range < 0.0)
{
_y = 0.0f;
}
else
{
_y = ((FLOAT)(((*i)[pos] - minValue) * scale) + offset);
_y = min(_y, H + offset);
_y = max(_y, offset);
}
_y = meterRect.top + (m_Flip ? _y : H - _y + 1.0f);
};

Expand Down

0 comments on commit 227a5b8

Please sign in to comment.