* 修改图表控件的一些小BUG

This commit is contained in:
Sunny 2020-07-18 10:00:31 +08:00
parent 26c2013848
commit 7c5d84185f
7 changed files with 51 additions and 25 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -196,36 +196,43 @@ namespace Sunny.UI
{ {
base.OnMouseMove(e); base.OnMouseMove(e);
if (BarOption.ToolTip == null) return; try
if (e.Location.X > BarOption.Grid.Left && e.Location.X < Width - BarOption.Grid.Right
&& e.Location.Y > BarOption.Grid.Top &&
e.Location.Y < Height - BarOption.Grid.Bottom)
{ {
SelectIndex = (int)((e.Location.X - BarOption.Grid.Left) / DrawBarWidth); if (BarOption.ToolTip == null) return;
} if (e.Location.X > BarOption.Grid.Left && e.Location.X < Width - BarOption.Grid.Right
else && e.Location.Y > BarOption.Grid.Top &&
{ e.Location.Y < Height - BarOption.Grid.Bottom)
SelectIndex = -1;
}
if (SelectIndex >= 0)
{
if (tip.Text != Bars[0][selectIndex].Tips)
{ {
tip.Text = Bars[0][selectIndex].Tips; SelectIndex = (int)((e.Location.X - BarOption.Grid.Left) / DrawBarWidth);
tip.Size = new Size((int)Bars[0][selectIndex].Size.Width + 4, (int)Bars[0][selectIndex].Size.Height + 4); }
else
{
SelectIndex = -1;
} }
int x = e.Location.X + 15; if (SelectIndex >= 0 && Bars.Count > 0)
int y = e.Location.Y + 20; {
if (e.Location.X + 15 + tip.Width > Width - BarOption.Grid.Right) if (tip.Text != Bars[0][selectIndex].Tips)
x = e.Location.X - tip.Width - 2; {
if (e.Location.Y + 20 + tip.Height > Height - BarOption.Grid.Bottom) tip.Text = Bars[0][selectIndex].Tips;
y = e.Location.Y - tip.Height - 2; tip.Size = new Size((int)Bars[0][selectIndex].Size.Width + 4, (int)Bars[0][selectIndex].Size.Height + 4);
}
tip.Left = x; int x = e.Location.X + 15;
tip.Top = y; int y = e.Location.Y + 20;
if (!tip.Visible) tip.Visible = Bars[0][selectIndex].Tips.IsValid(); if (e.Location.X + 15 + tip.Width > Width - BarOption.Grid.Right)
x = e.Location.X - tip.Width - 2;
if (e.Location.Y + 20 + tip.Height > Height - BarOption.Grid.Bottom)
y = e.Location.Y - tip.Height - 2;
tip.Left = x;
tip.Top = y;
if (!tip.Visible) tip.Visible = Bars[0][selectIndex].Tips.IsValid();
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
} }
} }

View File

@ -36,6 +36,7 @@ namespace Sunny.UI
public double Value { get; set; } public double Value { get; set; }
public string Name { get; set; } public string Name { get; set; }
public Color Color { get; set; } public Color Color { get; set; }
public UILeftAlignment Left { get; set; }
} }
public class UILegend public class UILegend

View File

@ -68,6 +68,8 @@ namespace Sunny.UI
DrawLegend(g, PieOption.Legend); DrawLegend(g, PieOption.Legend);
} }
private bool AllIsZero;
protected override void CalcData(UIOption option) protected override void CalcData(UIOption option)
{ {
Angles.Clear(); Angles.Clear();
@ -85,6 +87,7 @@ namespace Sunny.UI
all += data.Value; all += data.Value;
} }
AllIsZero = all.IsZero();
if (all.IsZero()) return; if (all.IsZero()) return;
float start = 0; float start = 0;
for (int i = 0; i < pie.Data.Count; i++) for (int i = 0; i < pie.Data.Count; i++)
@ -120,6 +123,17 @@ namespace Sunny.UI
{ {
if (series == null || series.Count == 0) return; if (series == null || series.Count == 0) return;
if (AllIsZero)
{
if (series.Count > 0)
{
RectangleF rect = GetSeriesRect(series[0]);
g.DrawEllipse(Color.Red, rect);
}
return;
}
for (int pieIndex = 0; pieIndex < series.Count; pieIndex++) for (int pieIndex = 0; pieIndex < series.Count; pieIndex++)
{ {
var pie = series[pieIndex]; var pie = series[pieIndex];
@ -184,6 +198,8 @@ namespace Sunny.UI
return; return;
} }
if (AllIsZero) return;
for (int pieIndex = 0; pieIndex < PieOption.SeriesCount; pieIndex++) for (int pieIndex = 0; pieIndex < PieOption.SeriesCount; pieIndex++)
{ {
RectangleF rect = GetSeriesRect(PieOption.Series[pieIndex]); RectangleF rect = GetSeriesRect(PieOption.Series[pieIndex]);

View File

@ -179,6 +179,8 @@ namespace Sunny.UI
{ {
Checked = true; Checked = true;
} }
base.OnClick(e);
} }
public override void SetStyleColor(UIBaseStyle uiColor) public override void SetStyleColor(UIBaseStyle uiColor)