Merge pull request #237 from hungqbui/main

Add fan levels auto-adjust
This commit is contained in:
Serge
2023-04-15 01:12:15 +02:00
committed by GitHub

View File

@@ -432,6 +432,13 @@ namespace GHelper
{
curPoint.XValue = dx;
curPoint.YValues[0] = dy;
if (hit.Series is not null) {
AdjustAllLevels(hit.PointIndex, dy, dx, hit.Series);
}
tip = true;
}
@@ -452,6 +459,75 @@ namespace GHelper
}
private void AdjustAllLevels(int index, double curYVal, double curXVal, Series series) {
// Get the neighboring DataPoints of the hit point
DataPoint upperPoint = null;
DataPoint lowerPoint = null;
if (index > 0)
{
lowerPoint = series.Points[index - 1];
}
if (index < series.Points.Count - 1)
{
upperPoint = series.Points[index + 1];
}
// Adjust the values according to the comparison between the value and its neighbors
if (upperPoint != null)
{
if (curYVal > upperPoint.YValues[0])
{
for (int i = index + 1; i < series.Points.Count; i++)
{
DataPoint curUpper = series.Points[i];
if (curUpper.YValues[0] >= curYVal) break;
curUpper.YValues[0] = curYVal;
}
}
if (curXVal > upperPoint.XValue)
{
for (int i = index + 1; i < series.Points.Count; i++)
{
DataPoint curUpper = series.Points[i];
if (curUpper.XValue >= curXVal) break;
curUpper.XValue = curXVal;
}
}
}
if (lowerPoint != null)
{
if (curYVal < lowerPoint.YValues[0])
{
for (int i = index - 1; i > 0; i--)
{
DataPoint curLower = series.Points[i];
if (curLower.YValues[0] <= curYVal) break;
curLower.YValues[0] = curYVal;
}
}
if (curXVal < lowerPoint.XValue)
{
for (int i = index - 1; i > 0; i--)
{
DataPoint curLower = series.Points[i];
if (curLower.XValue <= curXVal) break;
curLower.XValue = curXVal;
}
}
}
}
}
}