* UIPieChart:增加ToolTip设置,显示配色调整

This commit is contained in:
Sunny 2020-06-08 22:22:35 +08:00
parent 5b43a40600
commit 1dfc3f6317
17 changed files with 189 additions and 89 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -32,6 +32,9 @@
option.Title.SubText = "Star"; option.Title.SubText = "Star";
option.Title.Left = UILeftAlignment.Center; option.Title.Left = UILeftAlignment.Center;
//设置ToolTip
option.ToolTip = new UIToolTip();
//设置Legend //设置Legend
option.Legend = new UILegend(); option.Legend = new UILegend();
option.Legend.Orient = Orient.Vertical; option.Legend.Orient = Orient.Vertical;

View File

@ -69,6 +69,7 @@
// //
// uiDatetimePicker1 // uiDatetimePicker1
// //
this.uiDatetimePicker1.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
this.uiDatetimePicker1.FillColor = System.Drawing.Color.White; this.uiDatetimePicker1.FillColor = System.Drawing.Color.White;
this.uiDatetimePicker1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiDatetimePicker1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiDatetimePicker1.Location = new System.Drawing.Point(388, 136); this.uiDatetimePicker1.Location = new System.Drawing.Point(388, 136);

View File

@ -15,8 +15,47 @@ namespace Sunny.UI
foreColor = UIChartStyles.Plain.ForeColor; foreColor = UIChartStyles.Plain.ForeColor;
Width = 400; Width = 400;
Height = 300; Height = 300;
tip.Parent = this;
tip.Height = 32;
tip.Width = 200;
tip.Left = 1;
tip.Top = 1;
tip.StyleCustomMode = true;
tip.Style = UIStyle.Custom;
tip.Font = UIFontColor.SubFont;
tip.RadiusSides = UICornerRadiusSides.None;
tip.Visible = false;
tip.FillColor = UIChartStyles.Plain.BackColor;
tip.RectColor = UIChartStyles.Plain.ForeColor;
tip.ForeColor = UIChartStyles.Plain.ForeColor;
tip.Visible = false;
tip.MouseEnter += Tip_MouseEnter;
} }
private void Tip_MouseEnter(object sender, System.EventArgs e)
{
tip.Visible = false;
}
private int decimalNumber;
[DefaultValue(0),Description("显示数据格式化小数点后位数")]
public int DecimalNumber
{
get => decimalNumber;
set
{
if (decimalNumber != value)
{
decimalNumber = value;
Invalidate();
}
}
}
protected readonly UITransparentPanel tip = new UITransparentPanel();
private UIChartStyleType chartStyleType = UIChartStyleType.Plain; private UIChartStyleType chartStyleType = UIChartStyleType.Plain;
[DefaultValue(UIChartStyleType.Plain)] [DefaultValue(UIChartStyleType.Plain)]
@ -32,6 +71,10 @@ namespace Sunny.UI
foreColor = ChartStyle.ForeColor; foreColor = ChartStyle.ForeColor;
} }
tip.FillColor = ChartStyle.BackColor;
tip.RectColor = ChartStyle.ForeColor;
tip.ForeColor = ChartStyle.ForeColor;
Invalidate(); Invalidate();
} }
} }
@ -81,6 +124,11 @@ namespace Sunny.UI
public void SetOption(UIOption option) public void SetOption(UIOption option)
{ {
Option = option; Option = option;
CalcData(option);
}
protected virtual void CalcData(UIOption o)
{
} }
protected UIOption emptyOption; protected UIOption emptyOption;
@ -90,7 +138,10 @@ namespace Sunny.UI
get get
{ {
if (emptyOption == null) if (emptyOption == null)
{
CreateEmptyOption(); CreateEmptyOption();
CalcData(emptyOption);
}
return emptyOption; return emptyOption;
} }
@ -112,7 +163,7 @@ namespace Sunny.UI
{ {
if (o == null) return; if (o == null) return;
if (o.Title != null) DrawTitle(g, o.Title); if (o.Title != null) DrawTitle(g, o.Title);
if (o.Series.Count > 0) DrawSeries(g, o.Series); if (o.Series.Count > 0) DrawSeries(g,o, o.Series);
if (o.Legend != null) DrawLegend(g, o.Legend); if (o.Legend != null) DrawLegend(g, o.Legend);
} }
@ -120,7 +171,7 @@ namespace Sunny.UI
{ {
} }
protected virtual void DrawSeries(Graphics g, List<UISeries> series) protected virtual void DrawSeries(Graphics g,UIOption o, List<UISeries> series)
{ {
} }

View File

@ -12,6 +12,8 @@ namespace Sunny.UI
public UILegend Legend; public UILegend Legend;
public UIToolTip ToolTip;
public void AddSeries(UISeries series) public void AddSeries(UISeries series)
{ {
Series.Add(series); Series.Add(series);
@ -30,6 +32,11 @@ namespace Sunny.UI
public int SeriesCount => Series.Count; public int SeriesCount => Series.Count;
} }
public class UIToolTip
{
public string formatter { get; set; } = "{0}"+'\n'+"{1} : {2:f0} ({3:f2}%)";
}
public class UILegend public class UILegend
{ {
public UILeftAlignment Left { get; set; } = UILeftAlignment.Center; public UILeftAlignment Left { get; set; } = UILeftAlignment.Center;

View File

@ -3,7 +3,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms; using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
@ -11,56 +10,6 @@ namespace Sunny.UI
[ToolboxItem(true)] [ToolboxItem(true)]
public sealed class UIPieChart : UIChart public sealed class UIPieChart : UIChart
{ {
public UIPieChart()
{
tip.Parent = this;
tip.Height = 32;
tip.Width = 200;
tip.Left = 1;
tip.Top = 1;
tip.BackColor = Color.FromArgb(80, Color.Black);
tip.Font = UIFontColor.SubFont;
tip.Style = UIStyle.Custom;
tip.StyleCustomMode = true;
tip.FillColor = Color.Black;
tip.RectColor = Color.FromArgb(100, Color.Black);
tip.Visible = false;
}
private readonly UIAlphaPanel tip = new UIAlphaPanel();
public class UIAlphaPanel : UIPanel
{
private int _opacity = 50;
[Bindable(true), Category("Custom"), DefaultValue(125), Description("背景的透明度. 有效值0-255")]
public int Opacity
{
get { return _opacity; }
set
{
if (value > 255) value = 255;
else if (value < 0) value = 0;
_opacity = value;
this.Invalidate();
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaintFill(Graphics g, GraphicsPath path)
{
}
}
protected override void CreateEmptyOption() protected override void CreateEmptyOption()
{ {
if (emptyOption != null) return; if (emptyOption != null) return;
@ -123,19 +72,16 @@ namespace Sunny.UI
g.DrawString(title.SubText, subFont, ChartStyle.ForeColor, left, top); g.DrawString(title.SubText, subFont, ChartStyle.ForeColor, left, top);
} }
protected override void DrawSeries(Graphics g, List<UISeries> series) protected override void CalcData(UIOption o)
{ {
if (series == null || series.Count == 0) return; Angles.Clear();
if (o == null || o.Series == null || o.Series.Count == 0) return;
for (int pieIndex = 0; pieIndex < series.Count; pieIndex++) for (int pieIndex = 0; pieIndex < o.Series.Count; pieIndex++)
{ {
var pie = series[pieIndex]; var pie = o.Series[pieIndex];
if (!Angles.ContainsKey(pieIndex)) Angles.TryAdd(pieIndex, new ConcurrentDictionary<int, Angle>());
{
Angles.TryAdd(pieIndex, new ConcurrentDictionary<int, Angle>());
}
RectangleF rect = GetSeriesRect(pie);
double all = 0; double all = 0;
foreach (var data in pie.Data) foreach (var data in pie.Data)
{ {
@ -147,17 +93,41 @@ namespace Sunny.UI
for (int i = 0; i < pie.Data.Count; i++) for (int i = 0; i < pie.Data.Count; i++)
{ {
float angle = (float)(pie.Data[i].Value * 360.0f / all); float angle = (float)(pie.Data[i].Value * 360.0f / all);
string text = pie.Data[i].Name + ": " + pie.Data[i].Value.ToString("F0"); float percent = (float)(pie.Data[i].Value * 100.0f / all);
SizeF sf = g.MeasureString(text, legendFont); string text = "";
Angles[pieIndex].AddOrUpdate(i, new Angle(start, angle, text, sf)); if (o.ToolTip != null)
{
try
{
text = string.Format(o.ToolTip.formatter, pie.Name, pie.Data[i].Name, pie.Data[i].Value, percent);
}
catch
{
text = pie.Data[i].Name + " : " + pie.Data[i].Value.ToString("F" + DecimalNumber) + "(" + percent.ToString("F2") + "%)";
if (pie.Name.IsValid()) text = pie.Name + '\n' + text;
}
}
Angles[pieIndex].AddOrUpdate(i, new Angle(start, angle, text));
start += angle; start += angle;
} }
}
}
protected override void DrawSeries(Graphics g, UIOption o, List<UISeries> series)
{
if (series == null || series.Count == 0) return;
for (int pieIndex = 0; pieIndex < series.Count; pieIndex++)
{
var pie = series[pieIndex];
RectangleF rect = GetSeriesRect(pie);
for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++) for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++)
{ {
Color color = ChartStyle.SeriesColor[azIndex % ChartStyle.ColorCount]; Color color = ChartStyle.SeriesColor[azIndex % ChartStyle.ColorCount];
RectangleF rectx = new RectangleF(rect.X - 10, rect.Y - 10, rect.Width + 20, rect.Width + 20); RectangleF rectx = new RectangleF(rect.X - 10, rect.Y - 10, rect.Width + 20, rect.Width + 20);
g.FillPie(color, (ActivePieIndex == pieIndex && ActiveAzIndex == azIndex) ? rectx : rect, Angles[pieIndex][azIndex].Start - 90, Angles[pieIndex][azIndex].Sweep); g.FillPie(color, (ActivePieIndex == pieIndex && ActiveAzIndex == azIndex) ? rectx : rect, Angles[pieIndex][azIndex].Start - 90, Angles[pieIndex][azIndex].Sweep);
Angles[pieIndex][azIndex].Size = g.MeasureString(Angles[pieIndex][azIndex].Text, legendFont);
} }
} }
} }
@ -257,11 +227,34 @@ namespace Sunny.UI
if (az >= Angles[pieIndex][azIndex].Start && az <= Angles[pieIndex][azIndex].Start + Angles[pieIndex][azIndex].Sweep) if (az >= Angles[pieIndex][azIndex].Start && az <= Angles[pieIndex][azIndex].Start + Angles[pieIndex][azIndex].Sweep)
{ {
SetPieAndAzIndex(pieIndex, azIndex); SetPieAndAzIndex(pieIndex, azIndex);
tip.Size = new Size((int)Angles[pieIndex][azIndex].Size.Width + 4, (int)Angles[pieIndex][azIndex].Size.Height + 4); if (tip.Text != Angles[pieIndex][azIndex].Text)
tip.Text = Angles[pieIndex][azIndex].Text; {
tip.Left = e.Location.X + 15; tip.Text = Angles[pieIndex][azIndex].Text;
tip.Top = e.Location.Y + 20; tip.Size = new Size((int)Angles[pieIndex][azIndex].Size.Width + 4, (int)Angles[pieIndex][azIndex].Size.Height + 4);
tip.Visible = true; }
if (az >= 0 && az < 90)
{
tip.Top = e.Location.Y + 20;
tip.Left = e.Location.X - tip.Width;
}
else if (az >= 90 && az < 180)
{
tip.Left = e.Location.X - tip.Width;
tip.Top = e.Location.Y - tip.Height - 2;
}
else if (az >= 180 && az < 270)
{
tip.Left = e.Location.X ;
tip.Top = e.Location.Y - tip.Height - 2;
}
else if (az >= 270 && az < 360)
{
tip.Left = e.Location.X + 15;
tip.Top = e.Location.Y + 20;
}
if (!tip.Visible) tip.Visible = Angles[pieIndex][azIndex].Text.IsValid();
return; return;
} }
} }
@ -294,22 +287,21 @@ namespace Sunny.UI
return new RectangleF(left - halfRadius, top - halfRadius, halfRadius * 2, halfRadius * 2); return new RectangleF(left - halfRadius, top - halfRadius, halfRadius * 2, halfRadius * 2);
} }
public struct Angle public class Angle
{ {
public float Start { get; set; } public float Start { get; set; }
public float Sweep { get; set; } public float Sweep { get; set; }
public Angle(float start, float sweep, string text, SizeF size) public Angle(float start, float sweep, string text)
{ {
Start = start; Start = start;
Sweep = sweep; Sweep = sweep;
Text = text; Text = text;
Size = size;
} }
public SizeF Size { get; set; }
public string Text { get; set; } public string Text { get; set; }
public SizeF Size { get; set; }
} }
} }
} }

View File

@ -263,7 +263,7 @@ namespace Sunny.UI
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
base.WndProc(ref m); base.WndProc(ref m);
if (IsDisposed || Disposing) return;
if (ShowRect) if (ShowRect)
{ {
if (m.Msg == 0xf || m.Msg == 0x133) if (m.Msg == 0xf || m.Msg == 0x133)

View File

@ -1018,6 +1018,7 @@ namespace Sunny.UI
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
base.WndProc(ref m); base.WndProc(ref m);
if (IsDisposed || Disposing) return;
ScrollBarInfo.ShowScrollBar(Handle, 0, false);//0:horizontal,1:vertical,3:both ScrollBarInfo.ShowScrollBar(Handle, 0, false);//0:horizontal,1:vertical,3:both
} }
} }

View File

@ -339,13 +339,6 @@ namespace Sunny.UI
set => SetStyle(value); set => SetStyle(value);
} }
// protected override void WndProc(ref Message m)
// {
// base.WndProc(ref m);
// //隐藏滚动条
// ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both
// }
protected override void OnMouseWheel(MouseEventArgs e) protected override void OnMouseWheel(MouseEventArgs e)
{ {
base.OnMouseWheel(e); base.OnMouseWheel(e);

View File

@ -60,7 +60,7 @@ namespace Sunny.UI
Bar.Style = UIStyle.Custom; Bar.Style = UIStyle.Custom;
Bar.StyleCustomMode = true; Bar.StyleCustomMode = true;
Bar.FillColor = fillColor; Bar.FillColor = fillColor;
Bar.ForeColor = Color.Silver; Bar.ForeColor = Color.Silver;
Bar.HoverColor = Color.Silver; Bar.HoverColor = Color.Silver;
Bar.PressColor = Color.Silver; Bar.PressColor = Color.Silver;
@ -609,8 +609,8 @@ namespace Sunny.UI
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
base.WndProc(ref m); base.WndProc(ref m);
//隐藏滚动条 if (IsDisposed || Disposing) return;
ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both ScrollBarInfo.ShowScrollBar(Handle, 3, false);
} }
public TreeNode CreateNode(string text, int pageIndex) public TreeNode CreateNode(string text, int pageIndex)

View File

@ -0,0 +1,46 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(false)]
public class UITransparentPanel : UIPanel
{
private int _opacity = 150;
[Bindable(true), Category("Custom"), DefaultValue(150), Description("背景的透明度. 有效值0-255")]
public int Opacity
{
get { return _opacity; }
set
{
if (value > 255) value = 255;
else if (value < 0) value = 0;
_opacity = value;
Invalidate();
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void AfterSetFillColor(Color color)
{
base.AfterSetFillColor(color);
BackColor = Color.FromArgb(Opacity, FillColor);
}
protected override void OnPaintFill(Graphics g, GraphicsPath path)
{
}
}
}

View File

@ -565,9 +565,8 @@ namespace Sunny.UI
{ {
base.WndProc(ref m); base.WndProc(ref m);
//隐藏滚动条 if (IsDisposed || Disposing) return;
ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both ScrollBarInfo.ShowScrollBar(Handle, 3, false);
if (m.Msg == 0xf || m.Msg == 0x133) if (m.Msg == 0xf || m.Msg == 0x133)
{ {
if (BorderStyle == BorderStyle.FixedSingle) if (BorderStyle == BorderStyle.FixedSingle)

View File

@ -110,6 +110,9 @@
<Compile Include="Controls\UITimePicker.cs"> <Compile Include="Controls\UITimePicker.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Controls\UITransparentPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Forms\UINotifier.cs"> <Compile Include="Forms\UINotifier.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@ -1,5 +1,9 @@
+ 增加; - 删除; * 修改 + 增加; - 删除; * 修改
2020.06.08
* UINAVMenu修改一处消息引起的Bug
* UIPieChart增加ToolTip设置显示配色调整
2020.06.07 2020.06.07
* UITabControl重绘了页面左右控制按钮 * UITabControl重绘了页面左右控制按钮
* UIPieChart增加TitleLegendTip * UIPieChart增加TitleLegendTip