* UIPieChart:增加ToolTip设置,显示配色调整
This commit is contained in:
parent
5b43a40600
commit
1dfc3f6317
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -32,6 +32,9 @@
|
||||
option.Title.SubText = "Star";
|
||||
option.Title.Left = UILeftAlignment.Center;
|
||||
|
||||
//设置ToolTip
|
||||
option.ToolTip = new UIToolTip();
|
||||
|
||||
//设置Legend
|
||||
option.Legend = new UILegend();
|
||||
option.Legend.Orient = Orient.Vertical;
|
||||
|
1
SunnyUI.Demo/Controls/FCombobox.Designer.cs
generated
1
SunnyUI.Demo/Controls/FCombobox.Designer.cs
generated
@ -69,6 +69,7 @@
|
||||
//
|
||||
// uiDatetimePicker1
|
||||
//
|
||||
this.uiDatetimePicker1.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
|
||||
this.uiDatetimePicker1.FillColor = System.Drawing.Color.White;
|
||||
this.uiDatetimePicker1.Font = new System.Drawing.Font("微软雅黑", 12F);
|
||||
this.uiDatetimePicker1.Location = new System.Drawing.Point(388, 136);
|
||||
|
@ -15,8 +15,47 @@ namespace Sunny.UI
|
||||
foreColor = UIChartStyles.Plain.ForeColor;
|
||||
Width = 400;
|
||||
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;
|
||||
|
||||
[DefaultValue(UIChartStyleType.Plain)]
|
||||
@ -32,6 +71,10 @@ namespace Sunny.UI
|
||||
foreColor = ChartStyle.ForeColor;
|
||||
}
|
||||
|
||||
tip.FillColor = ChartStyle.BackColor;
|
||||
tip.RectColor = ChartStyle.ForeColor;
|
||||
tip.ForeColor = ChartStyle.ForeColor;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
@ -81,6 +124,11 @@ namespace Sunny.UI
|
||||
public void SetOption(UIOption option)
|
||||
{
|
||||
Option = option;
|
||||
CalcData(option);
|
||||
}
|
||||
|
||||
protected virtual void CalcData(UIOption o)
|
||||
{
|
||||
}
|
||||
|
||||
protected UIOption emptyOption;
|
||||
@ -90,7 +138,10 @@ namespace Sunny.UI
|
||||
get
|
||||
{
|
||||
if (emptyOption == null)
|
||||
{
|
||||
CreateEmptyOption();
|
||||
CalcData(emptyOption);
|
||||
}
|
||||
|
||||
return emptyOption;
|
||||
}
|
||||
@ -112,7 +163,7 @@ namespace Sunny.UI
|
||||
{
|
||||
if (o == null) return;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ namespace Sunny.UI
|
||||
|
||||
public UILegend Legend;
|
||||
|
||||
public UIToolTip ToolTip;
|
||||
|
||||
public void AddSeries(UISeries series)
|
||||
{
|
||||
Series.Add(series);
|
||||
@ -30,6 +32,11 @@ namespace Sunny.UI
|
||||
public int SeriesCount => Series.Count;
|
||||
}
|
||||
|
||||
public class UIToolTip
|
||||
{
|
||||
public string formatter { get; set; } = "{0}"+'\n'+"{1} : {2:f0} ({3:f2}%)";
|
||||
}
|
||||
|
||||
public class UILegend
|
||||
{
|
||||
public UILeftAlignment Left { get; set; } = UILeftAlignment.Center;
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
@ -11,56 +10,6 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
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()
|
||||
{
|
||||
if (emptyOption != null) return;
|
||||
@ -123,19 +72,16 @@ namespace Sunny.UI
|
||||
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];
|
||||
if (!Angles.ContainsKey(pieIndex))
|
||||
{
|
||||
Angles.TryAdd(pieIndex, new ConcurrentDictionary<int, Angle>());
|
||||
}
|
||||
var pie = o.Series[pieIndex];
|
||||
Angles.TryAdd(pieIndex, new ConcurrentDictionary<int, Angle>());
|
||||
|
||||
RectangleF rect = GetSeriesRect(pie);
|
||||
double all = 0;
|
||||
foreach (var data in pie.Data)
|
||||
{
|
||||
@ -147,17 +93,41 @@ namespace Sunny.UI
|
||||
for (int i = 0; i < pie.Data.Count; i++)
|
||||
{
|
||||
float angle = (float)(pie.Data[i].Value * 360.0f / all);
|
||||
string text = pie.Data[i].Name + ": " + pie.Data[i].Value.ToString("F0");
|
||||
SizeF sf = g.MeasureString(text, legendFont);
|
||||
Angles[pieIndex].AddOrUpdate(i, new Angle(start, angle, text, sf));
|
||||
float percent = (float)(pie.Data[i].Value * 100.0f / all);
|
||||
string text = "";
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
Color color = ChartStyle.SeriesColor[azIndex % ChartStyle.ColorCount];
|
||||
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);
|
||||
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)
|
||||
{
|
||||
SetPieAndAzIndex(pieIndex, azIndex);
|
||||
tip.Size = new Size((int)Angles[pieIndex][azIndex].Size.Width + 4, (int)Angles[pieIndex][azIndex].Size.Height + 4);
|
||||
tip.Text = Angles[pieIndex][azIndex].Text;
|
||||
tip.Left = e.Location.X + 15;
|
||||
tip.Top = e.Location.Y + 20;
|
||||
tip.Visible = true;
|
||||
if (tip.Text != Angles[pieIndex][azIndex].Text)
|
||||
{
|
||||
tip.Text = Angles[pieIndex][azIndex].Text;
|
||||
tip.Size = new Size((int)Angles[pieIndex][azIndex].Size.Width + 4, (int)Angles[pieIndex][azIndex].Size.Height + 4);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -294,22 +287,21 @@ namespace Sunny.UI
|
||||
return new RectangleF(left - halfRadius, top - halfRadius, halfRadius * 2, halfRadius * 2);
|
||||
}
|
||||
|
||||
public struct Angle
|
||||
public class Angle
|
||||
{
|
||||
public float Start { 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;
|
||||
Sweep = sweep;
|
||||
Text = text;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public SizeF Size { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public SizeF Size { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -263,7 +263,7 @@ namespace Sunny.UI
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
|
||||
if (IsDisposed || Disposing) return;
|
||||
if (ShowRect)
|
||||
{
|
||||
if (m.Msg == 0xf || m.Msg == 0x133)
|
||||
|
@ -1018,6 +1018,7 @@ namespace Sunny.UI
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
if (IsDisposed || Disposing) return;
|
||||
ScrollBarInfo.ShowScrollBar(Handle, 0, false);//0:horizontal,1:vertical,3:both
|
||||
}
|
||||
}
|
||||
|
@ -339,13 +339,6 @@ namespace Sunny.UI
|
||||
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)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
|
@ -60,7 +60,7 @@ namespace Sunny.UI
|
||||
Bar.Style = UIStyle.Custom;
|
||||
Bar.StyleCustomMode = true;
|
||||
Bar.FillColor = fillColor;
|
||||
|
||||
|
||||
Bar.ForeColor = Color.Silver;
|
||||
Bar.HoverColor = Color.Silver;
|
||||
Bar.PressColor = Color.Silver;
|
||||
@ -609,8 +609,8 @@ namespace Sunny.UI
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
//隐藏滚动条
|
||||
ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both
|
||||
if (IsDisposed || Disposing) return;
|
||||
ScrollBarInfo.ShowScrollBar(Handle, 3, false);
|
||||
}
|
||||
|
||||
public TreeNode CreateNode(string text, int pageIndex)
|
||||
|
46
SunnyUI/Controls/UITransparentPanel.cs
Normal file
46
SunnyUI/Controls/UITransparentPanel.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -565,9 +565,8 @@ namespace Sunny.UI
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
|
||||
//隐藏滚动条
|
||||
ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both
|
||||
|
||||
if (IsDisposed || Disposing) return;
|
||||
ScrollBarInfo.ShowScrollBar(Handle, 3, false);
|
||||
if (m.Msg == 0xf || m.Msg == 0x133)
|
||||
{
|
||||
if (BorderStyle == BorderStyle.FixedSingle)
|
||||
|
@ -110,6 +110,9 @@
|
||||
<Compile Include="Controls\UITimePicker.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\UITransparentPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\UINotifier.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -1,5 +1,9 @@
|
||||
+ 增加; - 删除; * 修改
|
||||
|
||||
2020.06.08
|
||||
* UINAVMenu:修改一处消息引起的Bug
|
||||
* UIPieChart:增加ToolTip设置,显示配色调整
|
||||
|
||||
2020.06.07
|
||||
* UITabControl:重绘了页面左右控制按钮
|
||||
* UIPieChart:增加Title,Legend,Tip
|
||||
|
Loading…
x
Reference in New Issue
Block a user