* UILineChart: 增加了一种开关量曲线的显示方式
This commit is contained in:
parent
e74a9891d2
commit
c23e3f5634
@ -42,6 +42,7 @@
|
|||||||
* 2022-09-19: V3.2.4 增加鼠标可框选缩放属性MouseZoom
|
* 2022-09-19: V3.2.4 增加鼠标可框选缩放属性MouseZoom
|
||||||
* 2023-03-26: V3.3.3 自定义X轴坐标时,点数据提示显示为原始值
|
* 2023-03-26: V3.3.3 自定义X轴坐标时,点数据提示显示为原始值
|
||||||
* 2023-04-23: V3.3.5 打开Smooth绘制,建议数据差距不大时可平滑绘制
|
* 2023-04-23: V3.3.5 打开Smooth绘制,建议数据差距不大时可平滑绘制
|
||||||
|
* 2023-05-12: V3.3.6 增加了一种开关量曲线的显示方式
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -95,6 +96,13 @@ namespace Sunny.UI
|
|||||||
series.CalcData(this, XScale, Y2Scale);
|
series.CalcData(this, XScale, Y2Scale);
|
||||||
else
|
else
|
||||||
series.CalcData(this, XScale, YScale);
|
series.CalcData(this, XScale, YScale);
|
||||||
|
|
||||||
|
if (series is UISwitchLineSeries lineSeries)
|
||||||
|
{
|
||||||
|
lineSeries.YOffsetPos = series.IsY2 ?
|
||||||
|
Y2Scale.CalcYPixel(lineSeries.YOffset, DrawOrigin.Y, DrawSize.Height) :
|
||||||
|
YScale.CalcYPixel(lineSeries.YOffset, DrawOrigin.Y, DrawSize.Height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NeedDraw = true;
|
NeedDraw = true;
|
||||||
@ -481,6 +489,18 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
g.SetHighQuality();
|
g.SetHighQuality();
|
||||||
|
|
||||||
|
if (series is UISwitchLineSeries lineSeries)
|
||||||
|
{
|
||||||
|
List<PointF> points = new List<PointF>();
|
||||||
|
points.Add(new PointF(lineSeries.Points[0].X, lineSeries.YOffsetPos));
|
||||||
|
points.AddRange(lineSeries.Points);
|
||||||
|
points.Add(new PointF(lineSeries.Points[series.Points.Count - 1].X, lineSeries.YOffsetPos));
|
||||||
|
g.FillPath(color, points.ToArray().Path());
|
||||||
|
g.DrawLine(color, points[0], points[points.Count - 1]);
|
||||||
|
points.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (series.ContainsNan || !series.Smooth || series.Points.Count == 2 || ZoomAreas.Count > 5)
|
if (series.ContainsNan || !series.Smooth || series.Points.Count == 2 || ZoomAreas.Count > 5)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < series.Points.Count - 1; i++)
|
for (int i = 0; i < series.Points.Count - 1; i++)
|
||||||
@ -502,6 +522,7 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g.SetDefaultQuality();
|
g.SetDefaultQuality();
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,21 @@ namespace Sunny.UI
|
|||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UILineSeries AddSwitchLineSeries(string seriesName, float Offset = 0, bool isY2 = false)
|
||||||
|
{
|
||||||
|
if (seriesName.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
throw new NullReferenceException("seriesName 不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ExistsSeries(seriesName)) return Series[seriesName];
|
||||||
|
|
||||||
|
UISwitchLineSeries series = new UISwitchLineSeries(seriesName, isY2);
|
||||||
|
series.YOffset = Offset;
|
||||||
|
AddSeries(series);
|
||||||
|
return series;
|
||||||
|
}
|
||||||
|
|
||||||
public bool ExistsSeries(string seriesName)
|
public bool ExistsSeries(string seriesName)
|
||||||
{
|
{
|
||||||
return seriesName.IsValid() && Series.ContainsKey(seriesName);
|
return seriesName.IsValid() && Series.ContainsKey(seriesName);
|
||||||
@ -360,6 +375,31 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UISwitchLineSeries : UILineSeries
|
||||||
|
{
|
||||||
|
public UISwitchLineSeries(string name, bool isY2 = false) : base(name, isY2)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public UISwitchLineSeries(string name, Color color, bool isY2 = false) : base(name, color, isY2)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public UISwitchLineSeries(string name, double yOffset, bool isY2 = false) : base(name, isY2)
|
||||||
|
{
|
||||||
|
YOffset = yOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UISwitchLineSeries(string name, Color color, double yOffset, bool isY2 = false) : base(name, color, isY2)
|
||||||
|
{
|
||||||
|
YOffset = yOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal float YOffsetPos { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class UILineSeries
|
public class UILineSeries
|
||||||
{
|
{
|
||||||
public UILineSeries(string name, bool isY2 = false)
|
public UILineSeries(string name, bool isY2 = false)
|
||||||
@ -387,6 +427,8 @@ namespace Sunny.UI
|
|||||||
IsY2 = isY2;
|
IsY2 = isY2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double YOffset { get; set; } = 0;
|
||||||
|
|
||||||
public void SetValueFormat(int xAxisDecimalPlaces, int yAxisDecimalPlaces)
|
public void SetValueFormat(int xAxisDecimalPlaces, int yAxisDecimalPlaces)
|
||||||
{
|
{
|
||||||
XAxisDecimalPlaces = xAxisDecimalPlaces;
|
XAxisDecimalPlaces = xAxisDecimalPlaces;
|
||||||
@ -481,14 +523,14 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
private readonly List<double> PointsY = new List<double>();
|
private readonly List<double> PointsY = new List<double>();
|
||||||
|
|
||||||
private int MaxCount = 0;
|
protected int MaxCount = 0;
|
||||||
|
|
||||||
public void UpdateYData(int index, double value)
|
public void UpdateYData(int index, double value)
|
||||||
{
|
{
|
||||||
if (YData.Count == 0) return;
|
if (YData.Count == 0) return;
|
||||||
if (index >= 0 && index < YData.Count)
|
if (index >= 0 && index < YData.Count)
|
||||||
{
|
{
|
||||||
YData[index] = value;
|
YData[index] = value + YOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,7 +642,7 @@ namespace Sunny.UI
|
|||||||
XData.Add(x);
|
XData.Add(x);
|
||||||
if (y.IsInfinity()) y = double.NaN;
|
if (y.IsInfinity()) y = double.NaN;
|
||||||
if (y.IsNan()) ContainsNan = true;
|
if (y.IsNan()) ContainsNan = true;
|
||||||
YData.Add(y);
|
YData.Add(y + YOffset);
|
||||||
|
|
||||||
if (MaxCount > 0 && XData.Count > MaxCount)
|
if (MaxCount > 0 && XData.Count > MaxCount)
|
||||||
Remove(1);
|
Remove(1);
|
||||||
@ -612,7 +654,7 @@ namespace Sunny.UI
|
|||||||
XData.Add(t);
|
XData.Add(t);
|
||||||
if (y.IsInfinity()) y = double.NaN;
|
if (y.IsInfinity()) y = double.NaN;
|
||||||
if (y.IsNan()) ContainsNan = true;
|
if (y.IsNan()) ContainsNan = true;
|
||||||
YData.Add(y);
|
YData.Add(y + YOffset);
|
||||||
|
|
||||||
if (MaxCount > 0 && XData.Count > MaxCount)
|
if (MaxCount > 0 && XData.Count > MaxCount)
|
||||||
Remove(1);
|
Remove(1);
|
||||||
@ -624,7 +666,7 @@ namespace Sunny.UI
|
|||||||
XData.Add(cnt);
|
XData.Add(cnt);
|
||||||
if (y.IsInfinity()) y = double.NaN;
|
if (y.IsInfinity()) y = double.NaN;
|
||||||
if (y.IsNan()) ContainsNan = true;
|
if (y.IsNan()) ContainsNan = true;
|
||||||
YData.Add(y);
|
YData.Add(y + YOffset);
|
||||||
|
|
||||||
if (MaxCount > 0 && XData.Count > MaxCount)
|
if (MaxCount > 0 && XData.Count > MaxCount)
|
||||||
Remove(1);
|
Remove(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user