V2.2.8 最终版本

This commit is contained in:
Sunny 2020-10-12 20:56:03 +08:00
parent b545068aa5
commit 63b11666df
24 changed files with 521 additions and 320 deletions

Binary file not shown.

Binary file not shown.

View File

@ -57,7 +57,6 @@
this.BarChart.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(54)))), ((int)(((byte)(54)))));
this.BarChart.Location = new System.Drawing.Point(30, 48);
this.BarChart.Name = "BarChart";
this.BarChart.Option = null;
this.BarChart.Size = new System.Drawing.Size(670, 400);
this.BarChart.TabIndex = 0;
this.BarChart.Text = "uiBarChart1";

View File

@ -125,7 +125,6 @@
this.BarChart.Location = new System.Drawing.Point(30, 48);
this.BarChart.MinimumSize = new System.Drawing.Size(1, 1);
this.BarChart.Name = "BarChart";
this.BarChart.Option = null;
this.BarChart.Size = new System.Drawing.Size(670, 400);
this.BarChart.TabIndex = 35;
this.BarChart.Text = "uiBarChartEx1";

View File

@ -57,7 +57,6 @@
this.DoughnutChart.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(54)))), ((int)(((byte)(54)))));
this.DoughnutChart.Location = new System.Drawing.Point(30, 48);
this.DoughnutChart.Name = "DoughnutChart";
this.DoughnutChart.Option = null;
this.DoughnutChart.Size = new System.Drawing.Size(670, 400);
this.DoughnutChart.TabIndex = 0;
this.DoughnutChart.Text = "uiDoughnutChart1";

View File

@ -125,7 +125,6 @@
this.LineChart.Location = new System.Drawing.Point(30, 48);
this.LineChart.MinimumSize = new System.Drawing.Size(1, 1);
this.LineChart.Name = "LineChart";
this.LineChart.Option = null;
this.LineChart.Size = new System.Drawing.Size(670, 400);
this.LineChart.TabIndex = 35;
this.LineChart.Text = "uiLineChart1";

View File

@ -70,7 +70,6 @@
this.PieChart.LegendFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.PieChart.Location = new System.Drawing.Point(30, 48);
this.PieChart.Name = "PieChart";
this.PieChart.Option = null;
this.PieChart.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None;
this.PieChart.Size = new System.Drawing.Size(670, 400);
this.PieChart.SubFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

View File

@ -435,6 +435,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Forms\Pages\FTitlePage3.resx">
<DependentUpon>FTitlePage3.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>

View File

@ -107,21 +107,21 @@ namespace Sunny.UI
{
Bars.Clear();
NeedDraw = false;
if (BarOption == null || BarOption.Series == null || BarOption.SeriesCount == 0) return;
if (Option == null || Option.Series == null || Option.SeriesCount == 0) return;
DrawOrigin = new Point(BarOption.Grid.Left, Height - BarOption.Grid.Bottom);
DrawSize = new Size(Width - BarOption.Grid.Left - BarOption.Grid.Right,
Height - BarOption.Grid.Top - BarOption.Grid.Bottom);
DrawOrigin = new Point(Option.Grid.Left, Height - Option.Grid.Bottom);
DrawSize = new Size(Width - Option.Grid.Left - Option.Grid.Right,
Height - Option.Grid.Top - Option.Grid.Bottom);
if (DrawSize.Width <= 0 || DrawSize.Height <= 0) return;
if (BarOption.XAxis.Data.Count == 0) return;
if (Option.XAxis.Data.Count == 0) return;
NeedDraw = true;
DrawBarWidth = DrawSize.Width * 1.0f / BarOption.XAxis.Data.Count;
DrawBarWidth = DrawSize.Width * 1.0f / Option.XAxis.Data.Count;
double min = double.MaxValue;
double max = double.MinValue;
foreach (var series in BarOption.Series)
foreach (var series in Option.Series)
{
if (series.Data.Count > 0)
{
@ -130,10 +130,10 @@ namespace Sunny.UI
}
}
if (min > 0 && max > 0 && !BarOption.YAxis.Scale) min = 0;
if (min < 0 && max < 0 && !BarOption.YAxis.Scale) max = 0;
if (!BarOption.YAxis.MaxAuto) max = BarOption.YAxis.Max;
if (!BarOption.YAxis.MinAuto) min = BarOption.YAxis.Min;
if (min > 0 && max > 0 && !Option.YAxis.Scale) min = 0;
if (min < 0 && max < 0 && !Option.YAxis.Scale) max = 0;
if (!Option.YAxis.MaxAuto) max = Option.YAxis.Max;
if (!Option.YAxis.MinAuto) min = Option.YAxis.Min;
if ((max - min).IsZero())
{
@ -141,20 +141,20 @@ namespace Sunny.UI
min = 0;
}
CalcDegreeScale(min, max, BarOption.YAxis.SplitNumber,
CalcDegreeScale(min, max, Option.YAxis.SplitNumber,
out int start, out int end, out double interval);
YAxisStart = start;
YAxisEnd = end;
YAxisInterval = interval;
float x1 = DrawBarWidth / (BarOption.SeriesCount * 2 + BarOption.SeriesCount + 1);
float x1 = DrawBarWidth / (Option.SeriesCount * 2 + Option.SeriesCount + 1);
float x2 = x1 * 2;
for (int i = 0; i < BarOption.SeriesCount; i++)
for (int i = 0; i < Option.SeriesCount; i++)
{
float barX = DrawOrigin.X;
var series = BarOption.Series[i];
var series = Option.Series[i];
Bars.TryAdd(i, new List<BarInfo>());
for (int j = 0; j < series.Data.Count; j++)
{
@ -181,7 +181,7 @@ namespace Sunny.UI
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
Bars[i].Add(new BarInfo()
{
Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
Rect = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
Color = color
});
}
@ -227,15 +227,15 @@ namespace Sunny.UI
}
}
if (BarOption.ToolTip != null)
if (Option.ToolTip != null)
{
for (int i = 0; i < BarOption.XAxis.Data.Count; i++)
for (int i = 0; i < Option.XAxis.Data.Count; i++)
{
string str = BarOption.XAxis.Data[i];
foreach (var series in BarOption.Series)
string str = Option.XAxis.Data[i];
foreach (var series in Option.Series)
{
str += '\n';
str += series.Name + " : " + series.Data[i].ToString(BarOption.ToolTip.ValueFormat);
str += series.Name + " : " + series.Data[i].ToString(Option.ToolTip.ValueFormat);
}
Bars[0][i].Tips = str;
@ -258,7 +258,7 @@ namespace Sunny.UI
get => selectIndex;
set
{
if (BarOption.ToolTip != null && selectIndex != value)
if (Option.ToolTip != null && selectIndex != value)
{
selectIndex = value;
Invalidate();
@ -274,12 +274,12 @@ namespace Sunny.UI
try
{
if (!BarOption.ToolTip.Visible) return;
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)
if (!Option.ToolTip.Visible) return;
if (e.Location.X > Option.Grid.Left && e.Location.X < Width - Option.Grid.Right
&& e.Location.Y > Option.Grid.Top &&
e.Location.Y < Height - Option.Grid.Bottom)
{
SelectIndex = (int)((e.Location.X - BarOption.Grid.Left) / DrawBarWidth);
SelectIndex = (int)((e.Location.X - Option.Grid.Left) / DrawBarWidth);
}
else
{
@ -296,9 +296,9 @@ namespace Sunny.UI
int x = e.Location.X + 15;
int y = e.Location.Y + 20;
if (e.Location.X + 15 + tip.Width > Width - BarOption.Grid.Right)
if (e.Location.X + 15 + tip.Width > Width - Option.Grid.Right)
x = e.Location.X - tip.Width - 2;
if (e.Location.Y + 20 + tip.Height > Height - BarOption.Grid.Bottom)
if (e.Location.Y + 20 + tip.Height > Height - Option.Grid.Bottom)
y = e.Location.Y - tip.Height - 2;
tip.Left = x;
@ -312,14 +312,19 @@ namespace Sunny.UI
}
}
[Browsable(false)]
protected UIBarOption BarOption
[Browsable(false), DefaultValue(null)]
public UIBarOption Option
{
get
{
UIOption option = Option ?? EmptyOption;
UIOption option = BaseOption ?? EmptyOption;
return (UIBarOption)option;
}
set
{
SetOption(value);
}
}
protected override void CreateEmptyOption()
@ -371,51 +376,51 @@ namespace Sunny.UI
protected override void DrawOption(Graphics g)
{
if (BarOption == null) return;
if (Option == null) return;
if (!NeedDraw) return;
if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow) DrawToolTip(g);
if (Option.ToolTip != null && Option.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow) DrawToolTip(g);
DrawAxis(g);
DrawTitle(g, BarOption.Title);
DrawSeries(g, BarOption.Series);
if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line) DrawToolTip(g);
DrawLegend(g, BarOption.Legend);
DrawTitle(g, Option.Title);
DrawSeries(g, Option.Series);
if (Option.ToolTip != null && Option.ToolTip.AxisPointer.Type == UIAxisPointerType.Line) DrawToolTip(g);
DrawLegend(g, Option.Legend);
DrawAxisScales(g);
}
protected virtual void DrawToolTip(Graphics g)
{
if (selectIndex < 0) return;
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
if (Option.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
{
float x = DrawOrigin.X + SelectIndex * DrawBarWidth + DrawBarWidth / 2.0f;
g.DrawLine(ChartStyle.ToolTipShadowColor, x, DrawOrigin.Y, x, BarOption.Grid.Top);
g.DrawLine(ChartStyle.ToolTipShadowColor, x, DrawOrigin.Y, x, Option.Grid.Top);
}
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow)
if (Option.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow)
{
float x = DrawOrigin.X + SelectIndex * DrawBarWidth;
g.FillRectangle(ChartStyle.ToolTipShadowColor, x, BarOption.Grid.Top, DrawBarWidth, Height - BarOption.Grid.Top - BarOption.Grid.Bottom);
g.FillRectangle(ChartStyle.ToolTipShadowColor, x, Option.Grid.Top, DrawBarWidth, Height - Option.Grid.Top - Option.Grid.Bottom);
}
}
protected virtual void DrawAxis(Graphics g)
{
if (YAxisStart >= 0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, BarOption.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, BarOption.Grid.Top));
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, Option.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, Option.Grid.Top));
g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
if (BarOption.XAxis.AxisTick.Show)
if (Option.XAxis.AxisTick.Show)
{
float start;
if (BarOption.XAxis.AxisTick.AlignWithLabel)
if (Option.XAxis.AxisTick.AlignWithLabel)
{
start = DrawOrigin.X + DrawBarWidth / 2.0f;
for (int i = 0; i < BarOption.XAxis.Data.Count; i++)
for (int i = 0; i < Option.XAxis.Data.Count; i++)
{
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += DrawBarWidth;
}
}
@ -434,36 +439,36 @@ namespace Sunny.UI
if (!haveZero)
{
start = DrawOrigin.X;
for (int i = 0; i <= BarOption.XAxis.Data.Count; i++)
for (int i = 0; i <= Option.XAxis.Data.Count; i++)
{
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += DrawBarWidth;
}
}
}
}
if (BarOption.XAxis.AxisLabel.Show)
if (Option.XAxis.AxisLabel.Show)
{
float start = DrawOrigin.X + DrawBarWidth / 2.0f;
foreach (var data in BarOption.XAxis.Data)
foreach (var data in Option.XAxis.Data)
{
SizeF sf = g.MeasureString(data, SubFont);
g.DrawString(data, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
g.DrawString(data, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += DrawBarWidth;
}
SizeF sfname = g.MeasureString(BarOption.XAxis.Name, SubFont);
g.DrawString(BarOption.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + sfname.Height);
SizeF sfname = g.MeasureString(Option.XAxis.Name, SubFont);
g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfname.Height);
}
if (BarOption.YAxis.AxisTick.Show)
if (Option.YAxis.AxisTick.Show)
{
float start = DrawOrigin.Y;
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
for (int i = YAxisStart; i <= YAxisEnd; i++)
{
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, DrawOrigin.X - BarOption.YAxis.AxisTick.Length, start);
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, DrawOrigin.X - Option.YAxis.AxisTick.Length, start);
if (i != 0)
{
@ -471,17 +476,17 @@ namespace Sunny.UI
{
pn.DashStyle = DashStyle.Dash;
pn.DashPattern = new float[] { 3, 3 };
g.DrawLine(pn, DrawOrigin.X, start, Width - BarOption.Grid.Right, start);
g.DrawLine(pn, DrawOrigin.X, start, Width - Option.Grid.Right, start);
}
}
else
{
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - BarOption.Grid.Right, start);
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - Option.Grid.Right, start);
float lineStart = DrawOrigin.X;
for (int j = 0; j <= BarOption.XAxis.Data.Count; j++)
for (int j = 0; j <= Option.XAxis.Data.Count; j++)
{
g.DrawLine(ChartStyle.ForeColor, lineStart, start, lineStart, start + BarOption.XAxis.AxisTick.Length);
g.DrawLine(ChartStyle.ForeColor, lineStart, start, lineStart, start + Option.XAxis.AxisTick.Length);
lineStart += DrawBarWidth;
}
}
@ -490,7 +495,7 @@ namespace Sunny.UI
}
}
if (BarOption.YAxis.AxisLabel.Show)
if (Option.YAxis.AxisLabel.Show)
{
float start = DrawOrigin.Y;
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
@ -498,32 +503,32 @@ namespace Sunny.UI
float wmax = 0;
for (int i = YAxisStart; i <= YAxisEnd; i++)
{
string label = BarOption.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
SizeF sf = g.MeasureString(label, SubFont);
wmax = Math.Max(wmax, sf.Width);
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - BarOption.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
start -= DrawBarHeight;
}
SizeF sfname = g.MeasureString(BarOption.YAxis.Name, SubFont);
int x = (int)(DrawOrigin.X - BarOption.YAxis.AxisTick.Length - wmax - sfname.Height);
int y = (int)(BarOption.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(BarOption.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y),
SizeF sfname = g.MeasureString(Option.YAxis.Name, SubFont);
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y),
new StringFormat() { Alignment = StringAlignment.Center }, 270);
}
}
private void DrawAxisScales(Graphics g)
{
foreach (var line in BarOption.YAxisScaleLines)
foreach (var line in Option.YAxisScaleLines)
{
double ymin = YAxisStart * YAxisInterval;
double ymax = YAxisEnd * YAxisInterval;
float pos = (float)((line.Value - ymin) * (Height - BarOption.Grid.Top - BarOption.Grid.Bottom) / (ymax - ymin));
pos = (Height - BarOption.Grid.Bottom - pos);
float pos = (float)((line.Value - ymin) * (Height - Option.Grid.Top - Option.Grid.Bottom) / (ymax - ymin));
pos = (Height - Option.Grid.Bottom - pos);
using (Pen pn = new Pen(line.Color, line.Size))
{
g.DrawLine(pn, DrawOrigin.X, pos, Width - BarOption.Grid.Right, pos);
g.DrawLine(pn, DrawOrigin.X, pos, Width - Option.Grid.Right, pos);
}
SizeF sf = g.MeasureString(line.Name, SubFont);
@ -531,9 +536,9 @@ namespace Sunny.UI
if (line.Left == UILeftAlignment.Left)
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Center)
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + (Width - BarOption.Grid.Left - BarOption.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height);
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + (Width - Option.Grid.Left - Option.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Right)
g.DrawString(line.Name, SubFont, line.Color, Width - sf.Width - 4 - BarOption.Grid.Right, pos - 2 - sf.Height);
g.DrawString(line.Name, SubFont, line.Color, Width - sf.Width - 4 - Option.Grid.Right, pos - 2 - sf.Height);
}
}
@ -550,7 +555,7 @@ namespace Sunny.UI
}
}
for (int i = 0; i < BarOption.XAxis.Data.Count; i++)
for (int i = 0; i < Option.XAxis.Data.Count; i++)
{
Bars[0][i].Size = g.MeasureString(Bars[0][i].Tips, SubFont);
}

View File

@ -34,38 +34,38 @@ namespace Sunny.UI
{
Bars.Clear();
NeedDraw = false;
if (BarOption == null || BarOption.Series == null || BarOption.SeriesCount == 0) return;
if (Option == null || Option.Series == null || Option.SeriesCount == 0) return;
DrawOrigin = new Point(BarOption.Grid.Left, Height - BarOption.Grid.Bottom);
DrawSize = new Size(Width - BarOption.Grid.Left - BarOption.Grid.Right,
Height - BarOption.Grid.Top - BarOption.Grid.Bottom);
DrawOrigin = new Point(Option.Grid.Left, Height - Option.Grid.Bottom);
DrawSize = new Size(Width - Option.Grid.Left - Option.Grid.Right,
Height - Option.Grid.Top - Option.Grid.Bottom);
if (DrawSize.Width <= 0 || DrawSize.Height <= 0) return;
if (BarOption.Series.Count == 0) return;
if (Option.Series.Count == 0) return;
NeedDraw = true;
DrawBarWidth = DrawSize.Width * 1.0f / BarOption.Series.Count;
DrawBarWidth = DrawSize.Width * 1.0f / Option.Series.Count;
double min = double.MaxValue;
double max = double.MinValue;
foreach (var series in BarOption.Series)
foreach (var series in Option.Series)
{
min = Math.Min(min, series.Data.Min());
max = Math.Max(max, series.Data.Max());
}
if (min > 0 && max > 0 && !BarOption.YAxis.Scale)
if (min > 0 && max > 0 && !Option.YAxis.Scale)
{
min = 0;
}
if (min < 0 && max < 0 && !BarOption.YAxis.Scale)
if (min < 0 && max < 0 && !Option.YAxis.Scale)
{
max = 0;
}
if (!BarOption.YAxis.MaxAuto) max = BarOption.YAxis.Max;
if (!BarOption.YAxis.MinAuto) min = BarOption.YAxis.Min;
if (!Option.YAxis.MaxAuto) max = Option.YAxis.Max;
if (!Option.YAxis.MinAuto) min = Option.YAxis.Min;
if ((max - min).IsZero())
{
@ -73,7 +73,7 @@ namespace Sunny.UI
min = 0;
}
CalcDegreeScale(min, max, BarOption.YAxis.SplitNumber,
CalcDegreeScale(min, max, Option.YAxis.SplitNumber,
out int start, out int end, out double interval);
YAxisStart = start;
@ -81,14 +81,14 @@ namespace Sunny.UI
YAxisInterval = interval;
float barX = DrawOrigin.X;
if (BarOption.AutoSizeBars)
if (Option.AutoSizeBars)
{
float x1 = DrawSize.Width * 1.0f / DataCount / 4;
float x2 = x1 * 2;
for (int i = 0; i < BarOption.SeriesCount; i++)
for (int i = 0; i < Option.SeriesCount; i++)
{
var series = BarOption.Series[i];
var series = Option.Series[i];
Bars.TryAdd(i, new List<BarInfo>());
for (int j = 0; j < series.Data.Count; j++)
@ -116,7 +116,7 @@ namespace Sunny.UI
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
Bars[i].Add(new BarInfo()
{
Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
Rect = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
Color = color
});
}
@ -161,12 +161,12 @@ namespace Sunny.UI
}
else
{
for (int i = 0; i < BarOption.SeriesCount; i++)
for (int i = 0; i < Option.SeriesCount; i++)
{
var series = BarOption.Series[i];
var series = Option.Series[i];
float x1;
if (BarOption.FixedSeriesCount > 0)
x1 = DrawBarWidth / (BarOption.FixedSeriesCount * 2 + BarOption.FixedSeriesCount + 1);
if (Option.FixedSeriesCount > 0)
x1 = DrawBarWidth / (Option.FixedSeriesCount * 2 + Option.FixedSeriesCount + 1);
else
x1 = DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1);
@ -180,7 +180,7 @@ namespace Sunny.UI
color = series.Colors[j];
float xx;
if (BarOption.FixedSeriesCount > 0)
if (Option.FixedSeriesCount > 0)
xx = barX + DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1) * ((j + 1) * 3 - 1);
else
xx = barX + x1 * ((j + 1) * 3 - 1);
@ -203,7 +203,7 @@ namespace Sunny.UI
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
Bars[i].Add(new BarInfo()
{
Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
Rect = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
Color = color
});
}
@ -247,19 +247,19 @@ namespace Sunny.UI
}
}
if (BarOption.ToolTip != null)
if (Option.ToolTip != null)
{
for (int i = 0; i < BarOption.Series.Count; i++)
for (int i = 0; i < Option.Series.Count; i++)
{
var series = BarOption.Series[i];
string str = BarOption.Series[i].Name;
var series = Option.Series[i];
string str = Option.Series[i].Name;
for (int j = 0; j < series.Data.Count; j++)
{
str += '\n';
if (series.BarName.Count > 0 && j < series.BarName.Count)
str += series.BarName[j] + " : ";
str += series.Data[j].ToString(BarOption.ToolTip.ValueFormat);
str += series.Data[j].ToString(Option.ToolTip.ValueFormat);
}
Bars[i][0].Tips = str;
@ -277,7 +277,7 @@ namespace Sunny.UI
for (int j = 0; j < bars.Count; j++)
{
g.FillRectangle(bars[j].Color, bars[j].Rect);
var s = BarOption.Series[i];
var s = Option.Series[i];
if (s.ShowBarName)
{
if (s.BarName.Count > 0 && j < s.BarName.Count)
@ -296,7 +296,7 @@ namespace Sunny.UI
if (s.ShowValue)
{
string value = s.Data[j].ToString("F" + BarOption.YAxis.AxisLabel.DecimalCount);
string value = s.Data[j].ToString("F" + Option.YAxis.AxisLabel.DecimalCount);
SizeF sf = g.MeasureString(value, SubFont);
if (s.Data[j] < 0)
g.DrawString(value, SubFont, bars[j].Color,
@ -310,7 +310,7 @@ namespace Sunny.UI
}
}
for (int i = 0; i < BarOption.Series.Count; i++)
for (int i = 0; i < Option.Series.Count; i++)
{
Bars[i][0].Size = g.MeasureString(Bars[i][0].Tips, SubFont);
}
@ -321,9 +321,9 @@ namespace Sunny.UI
get
{
int dataCount = 0;
for (int i = 0; i < BarOption.SeriesCount; i++)
for (int i = 0; i < Option.SeriesCount; i++)
{
dataCount += BarOption.Series[i].Data.Count;
dataCount += Option.Series[i].Data.Count;
}
return dataCount;
@ -333,33 +333,33 @@ namespace Sunny.UI
protected override void DrawAxis(Graphics g)
{
if (YAxisStart >= 0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, BarOption.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, BarOption.Grid.Top));
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, Option.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, Option.Grid.Top));
g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
//绘制X轴刻度
if (BarOption.XAxis.AxisTick.Show)
if (Option.XAxis.AxisTick.Show)
{
float start;
if (BarOption.XAxis.AxisTick.AlignWithLabel)
if (Option.XAxis.AxisTick.AlignWithLabel)
{
if (BarOption.AutoSizeBars)
if (Option.AutoSizeBars)
{
start = DrawOrigin.X;
for (int i = 0; i < BarOption.Series.Count; i++)
for (int i = 0; i < Option.Series.Count; i++)
{
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
g.DrawLine(ChartStyle.ForeColor, start + (int)(w / 2), DrawOrigin.Y, start + (int)(w / 2), DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
float w = DrawSize.Width * Option.Series[i].Data.Count * 1.0f / DataCount;
g.DrawLine(ChartStyle.ForeColor, start + (int)(w / 2), DrawOrigin.Y, start + (int)(w / 2), DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += (int)w;
}
}
else
{
start = DrawOrigin.X + DrawBarWidth / 2.0f;
for (int i = 0; i < BarOption.Series.Count; i++)
for (int i = 0; i < Option.Series.Count; i++)
{
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += DrawBarWidth;
}
}
@ -368,22 +368,22 @@ namespace Sunny.UI
{
start = DrawOrigin.X;
if (BarOption.AutoSizeBars)
if (Option.AutoSizeBars)
{
for (int i = 0; i < BarOption.Series.Count; i++)
for (int i = 0; i < Option.Series.Count; i++)
{
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
float w = DrawSize.Width * Option.Series[i].Data.Count * 1.0f / DataCount;
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += (int)w;
}
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X + DrawSize.Width, DrawOrigin.Y, DrawOrigin.X + DrawSize.Width, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X + DrawSize.Width, DrawOrigin.Y, DrawOrigin.X + DrawSize.Width, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
}
else
{
for (int i = 0; i <= BarOption.Series.Count; i++)
for (int i = 0; i <= Option.Series.Count; i++)
{
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += DrawBarWidth;
}
}
@ -391,42 +391,42 @@ namespace Sunny.UI
}
//绘制X轴标签
if (BarOption.XAxis.AxisLabel.Show)
if (Option.XAxis.AxisLabel.Show)
{
if (BarOption.AutoSizeBars)
if (Option.AutoSizeBars)
{
float start = DrawOrigin.X;
foreach (var data in BarOption.Series)
foreach (var data in Option.Series)
{
float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount;
SizeF sf = g.MeasureString(data.Name, SubFont);
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance);
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
start += w;
}
}
else
{
float start = DrawOrigin.X + DrawBarWidth / 2.0f;
foreach (var data in BarOption.Series)
foreach (var data in Option.Series)
{
SizeF sf = g.MeasureString(data.Name, SubFont);
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance);
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
start += DrawBarWidth;
}
}
SizeF sfName = g.MeasureString(BarOption.XAxis.Name, SubFont);
g.DrawString(BarOption.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance + sfName.Height);
SizeF sfName = g.MeasureString(Option.XAxis.Name, SubFont);
g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance + sfName.Height);
}
//绘制Y轴刻度
if (BarOption.YAxis.AxisTick.Show)
if (Option.YAxis.AxisTick.Show)
{
float start = DrawOrigin.Y;
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
for (int i = YAxisStart; i <= YAxisEnd; i++)
{
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, DrawOrigin.X - BarOption.YAxis.AxisTick.Length, start);
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, DrawOrigin.X - Option.YAxis.AxisTick.Length, start);
if (i != 0)
{
@ -434,12 +434,12 @@ namespace Sunny.UI
{
pn.DashStyle = DashStyle.Dash;
pn.DashPattern = new float[] { 3, 3 };
g.DrawLine(pn, DrawOrigin.X, start, Width - BarOption.Grid.Right, start);
g.DrawLine(pn, DrawOrigin.X, start, Width - Option.Grid.Right, start);
}
}
else
{
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - BarOption.Grid.Right, start);
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - Option.Grid.Right, start);
// float lineStart = DrawOrigin.X;
// for (int j = 0; j <= BarOption.Series.Count; j++)
@ -454,7 +454,7 @@ namespace Sunny.UI
}
//绘制Y轴标签
if (BarOption.YAxis.AxisLabel.Show)
if (Option.YAxis.AxisLabel.Show)
{
float start = DrawOrigin.Y;
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
@ -462,17 +462,17 @@ namespace Sunny.UI
float wmax = 0;
for (int i = YAxisStart; i <= YAxisEnd; i++)
{
string label = BarOption.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
SizeF sf = g.MeasureString(label, SubFont);
wmax = Math.Max(wmax, sf.Width);
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - BarOption.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
start -= DrawBarHeight;
}
SizeF sfname = g.MeasureString(BarOption.YAxis.Name, SubFont);
int x = (int)(DrawOrigin.X - BarOption.YAxis.AxisTick.Length - wmax - sfname.Height);
int y = (int)(BarOption.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(BarOption.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y),
SizeF sfname = g.MeasureString(Option.YAxis.Name, SubFont);
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y),
new StringFormat() { Alignment = StringAlignment.Center }, 270);
}
}
@ -481,18 +481,18 @@ namespace Sunny.UI
{
try
{
if (!BarOption.ToolTip.Visible) return;
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)
if (!Option.ToolTip.Visible) return;
if (e.Location.X > Option.Grid.Left &&
e.Location.X < Width - Option.Grid.Right &&
e.Location.Y > Option.Grid.Top &&
e.Location.Y < Height - Option.Grid.Bottom)
{
if (BarOption.AutoSizeBars)
if (Option.AutoSizeBars)
{
float startX = DrawOrigin.X;
for (int i = 0; i < BarOption.Series.Count; i++)
for (int i = 0; i < Option.Series.Count; i++)
{
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
float w = DrawSize.Width * Option.Series[i].Data.Count * 1.0f / DataCount;
if (e.Location.X >= startX && e.Location.X < startX + w)
{
SelectIndex = i;
@ -504,7 +504,7 @@ namespace Sunny.UI
}
else
{
SelectIndex = (int)((e.Location.X - BarOption.Grid.Left) / DrawBarWidth);
SelectIndex = (int)((e.Location.X - Option.Grid.Left) / DrawBarWidth);
}
}
else
@ -522,9 +522,9 @@ namespace Sunny.UI
int x = e.Location.X + 15;
int y = e.Location.Y + 20;
if (e.Location.X + 15 + tip.Width > Width - BarOption.Grid.Right)
if (e.Location.X + 15 + tip.Width > Width - Option.Grid.Right)
x = e.Location.X - tip.Width - 2;
if (e.Location.Y + 20 + tip.Height > Height - BarOption.Grid.Bottom)
if (e.Location.Y + 20 + tip.Height > Height - Option.Grid.Bottom)
y = e.Location.Y - tip.Height - 2;
tip.Left = x;
@ -542,25 +542,25 @@ namespace Sunny.UI
{
if (selectIndex < 0) return;
if (BarOption.AutoSizeBars)
if (Option.AutoSizeBars)
{
float startX = DrawOrigin.X;
for (int i = 0; i < BarOption.SeriesCount; i++)
for (int i = 0; i < Option.SeriesCount; i++)
{
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
float w = DrawSize.Width * Option.Series[i].Data.Count * 1.0f / DataCount;
if (i == selectIndex)
{
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
if (Option.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
{
float x = startX + w / 2.0f;
g.DrawLine(ChartStyle.ToolTipShadowColor, x, DrawOrigin.Y, x, BarOption.Grid.Top);
g.DrawLine(ChartStyle.ToolTipShadowColor, x, DrawOrigin.Y, x, Option.Grid.Top);
}
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow)
if (Option.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow)
{
g.FillRectangle(ChartStyle.ToolTipShadowColor, startX, BarOption.Grid.Top, w, Height - BarOption.Grid.Top - BarOption.Grid.Bottom);
g.FillRectangle(ChartStyle.ToolTipShadowColor, startX, Option.Grid.Top, w, Height - Option.Grid.Top - Option.Grid.Bottom);
}
}

View File

@ -127,8 +127,8 @@ namespace Sunny.UI
private UIOption _option;
[Browsable(false)]
public UIOption Option
[Browsable(false), DefaultValue(null)]
protected UIOption BaseOption
{
get => _option;
set
@ -140,7 +140,7 @@ namespace Sunny.UI
public void SetOption(UIOption option)
{
Option = option;
BaseOption = option;
CalcData();
}

View File

@ -63,20 +63,20 @@ namespace Sunny.UI
protected override void DrawOption(Graphics g)
{
if (DoughnutOption == null) return;
DrawTitle(g, DoughnutOption.Title);
DrawSeries(g, DoughnutOption.Series);
DrawLegend(g, DoughnutOption.Legend);
if (Option == null) return;
DrawTitle(g, Option.Title);
DrawSeries(g, Option.Series);
DrawLegend(g, Option.Legend);
}
protected override void CalcData()
{
Angles.Clear();
if (DoughnutOption == null || DoughnutOption.Series == null || DoughnutOption.Series.Count == 0) return;
if (Option == null || Option.Series == null || Option.Series.Count == 0) return;
for (int pieIndex = 0; pieIndex < DoughnutOption.Series.Count; pieIndex++)
for (int pieIndex = 0; pieIndex < Option.Series.Count; pieIndex++)
{
var pie = DoughnutOption.Series[pieIndex];
var pie = Option.Series[pieIndex];
Angles.TryAdd(pieIndex, new ConcurrentDictionary<int, Angle>());
double all = 0;
@ -92,14 +92,14 @@ namespace Sunny.UI
float angle = (float)(pie.Data[i].Value * 360.0f / all);
float percent = (float)(pie.Data[i].Value * 100.0f / all);
string text = "";
if (DoughnutOption.ToolTip != null)
if (Option.ToolTip != null)
{
try
{
UITemplate template = new UITemplate(DoughnutOption.ToolTip.Formatter);
UITemplate template = new UITemplate(Option.ToolTip.Formatter);
template.Set("a", pie.Name);
template.Set("b", pie.Data[i].Name);
template.Set("c", pie.Data[i].Value.ToString(DoughnutOption.ToolTip.ValueFormat));
template.Set("c", pie.Data[i].Value.ToString(Option.ToolTip.ValueFormat));
template.Set("d", percent.ToString("F2"));
text = template.Render();
}
@ -154,30 +154,35 @@ namespace Sunny.UI
private readonly ConcurrentDictionary<int, ConcurrentDictionary<int, Angle>> Angles = new ConcurrentDictionary<int, ConcurrentDictionary<int, Angle>>();
[Browsable(false)]
private UIDoughnutOption DoughnutOption
[Browsable(false), DefaultValue(null)]
public UIDoughnutOption Option
{
get
{
UIOption option = Option ?? EmptyOption;
UIOption option = BaseOption ?? EmptyOption;
UIDoughnutOption o = (UIDoughnutOption)option;
return o;
}
set
{
SetOption(value);
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (DoughnutOption.SeriesCount == 0)
if (Option.SeriesCount == 0)
{
SetPieAndAzIndex(-1, -1);
return;
}
for (int pieIndex = 0; pieIndex < DoughnutOption.SeriesCount; pieIndex++)
for (int pieIndex = 0; pieIndex < Option.SeriesCount; pieIndex++)
{
for (int azIndex = 0; azIndex < DoughnutOption.Series[pieIndex].Data.Count; azIndex++)
for (int azIndex = 0; azIndex < Option.Series[pieIndex].Data.Count; azIndex++)
{
Angle angle = Angles[pieIndex][azIndex];
PointF pf = angle.Center;
@ -214,7 +219,7 @@ namespace Sunny.UI
tip.Top = e.Location.Y + 20;
}
if (DoughnutOption.ToolTip.Visible)
if (Option.ToolTip.Visible)
{
if (!tip.Visible) tip.Visible = angle.Text.IsValid();
}

View File

@ -1,4 +1,25 @@
using System;
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2020 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@qq.com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UILineChart.cs
* : 线
* : V2.2
* : 2020-10-01
*
* 2020-10-01: V2.2.8 线
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
@ -26,16 +47,16 @@ namespace Sunny.UI
protected override void CalcData()
{
NeedDraw = false;
if (LineOption == null || LineOption.Series == null || LineOption.Series.Count == 0) return;
if (Option?.Series == null || Option.Series.Count == 0) return;
DrawOrigin = new Point(LineOption.Grid.Left, Height - LineOption.Grid.Bottom);
DrawSize = new Size(Width - LineOption.Grid.Left - LineOption.Grid.Right,
Height - LineOption.Grid.Top - LineOption.Grid.Bottom);
DrawOrigin = new Point(Option.Grid.Left, Height - Option.Grid.Bottom);
DrawSize = new Size(Width - Option.Grid.Left - Option.Grid.Right,
Height - Option.Grid.Top - Option.Grid.Bottom);
if (DrawSize.Width <= 0 || DrawSize.Height <= 0) return;
CalcAxises();
foreach (var series in LineOption.Series.Values)
foreach (var series in Option.Series.Values)
{
series.ClearPoints();
float[] x = XScale.CalcXPixels(series.XData.ToArray(), DrawOrigin.X, DrawSize.Width);
@ -53,7 +74,7 @@ namespace Sunny.UI
private void CalcAxises()
{
if (LineOption.XAxisType == UIAxisType.DateTime)
if (Option.XAxisType == UIAxisType.DateTime)
XScale = new UIDateScale();
else
XScale = new UILinearScale();
@ -62,35 +83,40 @@ namespace Sunny.UI
//Y轴
{
LineOption.GetAllDataYRange(out double min, out double max);
if (min > 0 && max > 0 && !LineOption.YAxis.Scale) min = 0;
if (min < 0 && max < 0 && !LineOption.YAxis.Scale) max = 0;
Option.GetAllDataYRange(out double min, out double max);
if (min > 0 && max > 0 && !Option.YAxis.Scale) min = 0;
if (min < 0 && max < 0 && !Option.YAxis.Scale) max = 0;
YScale.SetRange(min, max);
if (!LineOption.YAxis.MaxAuto) YScale.Max = LineOption.YAxis.Max;
if (!LineOption.YAxis.MinAuto) YScale.Min = LineOption.YAxis.Min;
if (!Option.YAxis.MaxAuto) YScale.Max = Option.YAxis.Max;
if (!Option.YAxis.MinAuto) YScale.Min = Option.YAxis.Min;
YScale.AxisChange();
YLabels = YScale.CalcLabels();
}
//X轴
{
LineOption.GetAllDataXRange(out double min, out double max);
Option.GetAllDataXRange(out double min, out double max);
XScale.SetRange(min, max);
if (!LineOption.XAxis.MaxAuto) XScale.Max = LineOption.XAxis.Max;
if (!LineOption.XAxis.MinAuto) XScale.Min = LineOption.XAxis.Min;
if (!Option.XAxis.MaxAuto) XScale.Max = Option.XAxis.Max;
if (!Option.XAxis.MinAuto) XScale.Min = Option.XAxis.Min;
XScale.AxisChange();
XLabels = XScale.CalcLabels();
}
}
[Browsable(false)]
private UILineOption LineOption
[Browsable(false), DefaultValue(null)]
public UILineOption Option
{
get
{
UIOption option = Option ?? EmptyOption;
UIOption option = BaseOption ?? EmptyOption;
return (UILineOption)option;
}
set
{
SetOption(value);
}
}
protected override void CreateEmptyOption()
@ -124,40 +150,42 @@ namespace Sunny.UI
protected override void DrawOption(Graphics g)
{
if (LineOption == null) return;
if (Option == null) return;
if (!NeedDraw) return;
// if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow) DrawToolTip(g);
DrawAxis(g);
DrawTitle(g, LineOption.Title);
DrawTitle(g, Option.Title);
DrawAxisScales(g);
DrawSeries(g);
// if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line) DrawToolTip(g);
DrawLegend(g, LineOption.Legend);
DrawLegend(g, Option.Legend);
}
private void DrawAxis(Graphics g)
{
g.DrawRectangle(ChartStyle.ForeColor, LineOption.Grid.Left, LineOption.Grid.Top, DrawSize.Width, DrawSize.Height);
g.DrawRectangle(ChartStyle.ForeColor, Option.Grid.Left, Option.Grid.Top, DrawSize.Width, DrawSize.Height);
float zeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos);
if (XScale == null || YScale == null) return;
//X Tick
if (LineOption.XAxis.AxisTick.Show)
if (Option.XAxis.AxisTick.Show)
{
float[] xlabels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);
for (int i = 0; i < xlabels.Length; i++)
float[] labels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);
for (int i = 0; i < labels.Length; i++)
{
float x = xlabels[i];
if (LineOption.XAxis.AxisLabel.Show)
float x = labels[i];
if (Option.XAxis.AxisLabel.Show)
{
string label;
if (LineOption.XAxisType == UIAxisType.DateTime)
if (Option.XAxisType == UIAxisType.DateTime)
label = new DateTimeInt64(XLabels[i]).ToString(XScale.Format);
else
label = XLabels[i].ToString(XScale.Format);
SizeF sf = g.MeasureString(label, SubFont);
g.DrawString(label, SubFont, ChartStyle.ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + LineOption.XAxis.AxisTick.Length);
g.DrawString(label, SubFont, ChartStyle.ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
}
if (x.Equals(DrawOrigin.X)) continue;
@ -167,30 +195,30 @@ namespace Sunny.UI
{
pn.DashStyle = DashStyle.Dash;
pn.DashPattern = new float[] { 3, 3 };
g.DrawLine(pn, x, DrawOrigin.Y, x, LineOption.Grid.Top);
g.DrawLine(pn, x, DrawOrigin.Y, x, Option.Grid.Top);
}
}
SizeF sfname = g.MeasureString(LineOption.XAxis.Name, SubFont);
g.DrawString(LineOption.XAxis.Name, SubFont, ChartStyle.ForeColor,
DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f,
DrawOrigin.Y + LineOption.XAxis.AxisTick.Length + sfname.Height);
SizeF sfName = g.MeasureString(Option.XAxis.Name, SubFont);
g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor,
DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f,
DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfName.Height);
}
//Y Tick
if (LineOption.YAxis.AxisTick.Show)
if (Option.YAxis.AxisTick.Show)
{
float[] ylabels = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height);
float wmax = 0;
for (int i = 0; i < ylabels.Length; i++)
float[] labels = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height);
float widthMax = 0;
for (int i = 0; i < labels.Length; i++)
{
float y = ylabels[i];
if (LineOption.YAxis.AxisLabel.Show)
float y = labels[i];
if (Option.YAxis.AxisLabel.Show)
{
string label = YLabels[i].ToString(YScale.Format);
SizeF sf = g.MeasureString(label, SubFont);
wmax = Math.Max(wmax, sf.Width);
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - LineOption.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
widthMax = Math.Max(widthMax, sf.Width);
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
}
if (y.Equals(DrawOrigin.Y)) continue;
@ -200,15 +228,15 @@ namespace Sunny.UI
{
pn.DashStyle = DashStyle.Dash;
pn.DashPattern = new float[] { 3, 3 };
g.DrawLine(pn, DrawOrigin.X, y, Width - LineOption.Grid.Right, y);
g.DrawLine(pn, DrawOrigin.X, y, Width - Option.Grid.Right, y);
}
}
SizeF sfname = g.MeasureString(LineOption.YAxis.Name, SubFont);
int xx = (int)(DrawOrigin.X - LineOption.YAxis.AxisTick.Length - wmax - sfname.Height);
int yy = (int)(LineOption.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(LineOption.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(xx, yy),
SizeF sfName = g.MeasureString(Option.YAxis.Name, SubFont);
int xx = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height);
int yy = (int)(Option.Grid.Top + (DrawSize.Height - sfName.Width) / 2);
g.DrawString(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(xx, yy),
new StringFormat() { Alignment = StringAlignment.Center }, 270);
}
}
@ -222,7 +250,7 @@ namespace Sunny.UI
if (series.Points.Count == 1 && series.Symbol == UILinePointSymbol.None)
{
g.FillEllipse(color, series.Points[0].X - 2, series.Points[0].Y - 2, 4, 4);
g.DrawPoint(color, series.Points[0], 4);
return;
}
@ -242,9 +270,9 @@ namespace Sunny.UI
if (YScale == null) return;
int idx = 0;
if (LineOption.GreaterWarningArea == null && LineOption.LessWarningArea == null)
if (Option.GreaterWarningArea == null && Option.LessWarningArea == null)
{
foreach (var series in LineOption.Series.Values)
foreach (var series in Option.Series.Values)
{
Color color = series.Color;
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
@ -260,7 +288,7 @@ namespace Sunny.UI
float wTop = 0;
float wBottom = Height;
foreach (var series in LineOption.Series.Values)
foreach (var series in Option.Series.Values)
{
Color color = series.Color;
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
@ -270,35 +298,35 @@ namespace Sunny.UI
DrawSeries(graphics, color, series);
}
if (LineOption.GreaterWarningArea != null)
if (Option.GreaterWarningArea != null)
{
using (Graphics graphics = bmpGreater.Graphics())
{
DrawSeries(graphics, LineOption.GreaterWarningArea.Color, series);
DrawSeries(graphics, Option.GreaterWarningArea.Color, series);
}
}
if (LineOption.LessWarningArea != null)
if (Option.LessWarningArea != null)
{
using (Graphics graphics = bmpLess.Graphics())
{
DrawSeries(graphics, LineOption.LessWarningArea.Color, series);
DrawSeries(graphics, Option.LessWarningArea.Color, series);
}
}
idx++;
}
if (LineOption.GreaterWarningArea != null)
if (Option.GreaterWarningArea != null)
{
wTop = YScale.CalcYPixel(LineOption.GreaterWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
wTop = YScale.CalcYPixel(Option.GreaterWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
g.DrawImage(bmpGreater, new Rectangle(0, 0, Width, (int)wTop),
new Rectangle(0, 0, Width, (int)wTop), GraphicsUnit.Pixel);
}
if (LineOption.LessWarningArea != null)
if (Option.LessWarningArea != null)
{
wBottom = YScale.CalcYPixel(LineOption.LessWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
wBottom = YScale.CalcYPixel(Option.LessWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
g.DrawImage(bmpLess, new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom),
new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom), GraphicsUnit.Pixel);
}
@ -312,7 +340,7 @@ namespace Sunny.UI
}
idx = 0;
foreach (var series in LineOption.Series.Values)
foreach (var series in Option.Series.Values)
{
Color color = series.Color;
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
@ -320,7 +348,7 @@ namespace Sunny.UI
if (series.Symbol != UILinePointSymbol.None)
{
using (Brush br = new SolidBrush(ChartStyle.BackColor))
using (Pen pn = new Pen(series.SymbolColor, series.SymbolLineWidth))
using (Pen pn = new Pen(color, series.SymbolLineWidth))
{
foreach (var p in series.Points)
{
@ -389,12 +417,12 @@ namespace Sunny.UI
{
if (YScale == null) return;
foreach (var line in LineOption.YAxisScaleLines)
foreach (var line in Option.YAxisScaleLines)
{
float pos = YScale.CalcYPixel(line.Value, DrawOrigin.Y, DrawSize.Height);
using (Pen pn = new Pen(line.Color, line.Size))
{
g.DrawLine(pn, DrawOrigin.X, pos, Width - LineOption.Grid.Right, pos);
g.DrawLine(pn, DrawOrigin.X, pos, Width - Option.Grid.Right, pos);
}
SizeF sf = g.MeasureString(line.Name, SubFont);
@ -402,9 +430,9 @@ namespace Sunny.UI
if (line.Left == UILeftAlignment.Left)
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Center)
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + (Width - LineOption.Grid.Left - LineOption.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height);
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + (Width - Option.Grid.Left - Option.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Right)
g.DrawString(line.Name, SubFont, line.Color, Width - sf.Width - 4 - LineOption.Grid.Right, pos - 2 - sf.Height);
g.DrawString(line.Name, SubFont, line.Color, Width - sf.Width - 4 - Option.Grid.Right, pos - 2 - sf.Height);
}
}
@ -417,7 +445,7 @@ namespace Sunny.UI
if (!NeedDraw) return;
selectPointsTemp.Clear();
foreach (var series in LineOption.Series.Values)
foreach (var series in Option.Series.Values)
{
if (series.DataCount == 0) continue;
if (series.GetNearestPoint(e.Location, 4, out double x, out double y, out int index))
@ -472,17 +500,17 @@ namespace Sunny.UI
sb.Append(point.Name);
sb.Append('\n');
sb.Append(LineOption.XAxis.Name + ": ");
if (LineOption.XAxisType == UIAxisType.DateTime)
sb.Append(new DateTimeInt64(point.X).ToString(LineOption.XAxis.AxisLabel.DateTimeFormat));
sb.Append(Option.XAxis.Name + ": ");
if (Option.XAxisType == UIAxisType.DateTime)
sb.Append(new DateTimeInt64(point.X).ToString(Option.XAxis.AxisLabel.DateTimeFormat));
else
sb.Append(point.X.ToString("F" + LineOption.XAxis.AxisLabel.DecimalCount));
sb.Append(point.X.ToString("F" + Option.XAxis.AxisLabel.DecimalCount));
sb.Append('\n');
sb.Append(LineOption.YAxis.Name + ": " + point.Y.ToString("F" + LineOption.YAxis.AxisLabel.DecimalCount));
sb.Append(Option.YAxis.Name + ": " + point.Y.ToString("F" + Option.YAxis.AxisLabel.DecimalCount));
idx++;
}
if (LineOption.ToolTip.Visible)
if (Option.ToolTip.Visible)
{
if (sb.ToString().IsNullOrEmpty())
{
@ -498,9 +526,9 @@ namespace Sunny.UI
int x = e.Location.X + 15;
int y = e.Location.Y + 20;
if (e.Location.X + 15 + tip.Width > Width - LineOption.Grid.Right)
if (e.Location.X + 15 + tip.Width > Width - Option.Grid.Right)
x = e.Location.X - tip.Width - 2;
if (e.Location.Y + 20 + tip.Height > Height - LineOption.Grid.Bottom)
if (e.Location.Y + 20 + tip.Height > Height - Option.Grid.Bottom)
y = e.Location.Y - tip.Height - 2;
tip.Left = x;

View File

@ -1,4 +1,25 @@
using System;
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2020 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@qq.com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UILineChartOption.cs
* : 线
* : V2.2
* : 2020-10-01
*
* 2020-10-01: V2.2.8 线
******************************************************************************/
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;

View File

@ -26,7 +26,7 @@ namespace Sunny.UI
{
public abstract class UIOption
{
public UITitle Title;
public UITitle Title = new UITitle();
public UILegend Legend;
}
@ -109,7 +109,7 @@ namespace Sunny.UI
public class UITitle
{
public string Text { get; set; } = "UIPieChart";
public string Text { get; set; } = "SunnyUI Chart";
public string SubText { get; set; } = "";

View File

@ -62,10 +62,10 @@ namespace Sunny.UI
protected override void DrawOption(Graphics g)
{
if (PieOption == null) return;
DrawTitle(g, PieOption.Title);
DrawSeries(g, PieOption.Series);
DrawLegend(g, PieOption.Legend);
if (Option == null) return;
DrawTitle(g, Option.Title);
DrawSeries(g, Option.Series);
DrawLegend(g, Option.Legend);
}
private bool AllIsZero;
@ -73,11 +73,11 @@ namespace Sunny.UI
protected override void CalcData()
{
Angles.Clear();
if (PieOption == null || PieOption.Series == null || PieOption.Series.Count == 0) return;
if (Option == null || Option.Series == null || Option.Series.Count == 0) return;
for (int pieIndex = 0; pieIndex < PieOption.Series.Count; pieIndex++)
for (int pieIndex = 0; pieIndex < Option.Series.Count; pieIndex++)
{
var pie = PieOption.Series[pieIndex];
var pie = Option.Series[pieIndex];
Angles.TryAdd(pieIndex, new ConcurrentDictionary<int, Angle>());
double all = 0;
@ -94,14 +94,14 @@ namespace Sunny.UI
float angle = (float)(pie.Data[i].Value * 360.0f / all);
float percent = (float)(pie.Data[i].Value * 100.0f / all);
string text = "";
if (PieOption.ToolTip != null)
if (Option.ToolTip != null)
{
try
{
UITemplate template = new UITemplate(PieOption.ToolTip.Formatter);
UITemplate template = new UITemplate(Option.ToolTip.Formatter);
template.Set("a", pie.Name);
template.Set("b", pie.Data[i].Name);
template.Set("c", pie.Data[i].Value.ToString(PieOption.ToolTip.ValueFormat));
template.Set("c", pie.Data[i].Value.ToString(Option.ToolTip.ValueFormat));
template.Set("d", percent.ToString("F2"));
text = template.Render();
}
@ -178,14 +178,18 @@ namespace Sunny.UI
private readonly ConcurrentDictionary<int, ConcurrentDictionary<int, Angle>> Angles = new ConcurrentDictionary<int, ConcurrentDictionary<int, Angle>>();
[Browsable(false)]
private UIPieOption PieOption
[Browsable(false), DefaultValue(null)]
public UIPieOption Option
{
get
{
UIOption option = Option ?? EmptyOption;
UIPieOption o = (UIPieOption)option;
return o;
UIOption option = BaseOption ?? EmptyOption;
return (UIPieOption)option;
}
set
{
SetOption(value);
}
}
@ -193,7 +197,7 @@ namespace Sunny.UI
{
base.OnMouseMove(e);
if (PieOption.SeriesCount == 0)
if (Option.SeriesCount == 0)
{
SetPieAndAzIndex(-1, -1);
return;
@ -201,16 +205,16 @@ namespace Sunny.UI
if (AllIsZero) return;
for (int pieIndex = 0; pieIndex < PieOption.SeriesCount; pieIndex++)
for (int pieIndex = 0; pieIndex < Option.SeriesCount; pieIndex++)
{
RectangleF rect = GetSeriesRect(PieOption.Series[pieIndex]);
RectangleF rect = GetSeriesRect(Option.Series[pieIndex]);
if (!e.Location.InRect(rect)) continue;
PointF pf = new PointF(rect.Left + rect.Width / 2.0f, rect.Top + rect.Height / 2.0f);
if (MathEx.CalcDistance(e.Location, pf) * 2 > rect.Width) continue;
double az = MathEx.CalcAngle(e.Location, pf);
for (int azIndex = 0; azIndex < PieOption.Series[pieIndex].Data.Count; azIndex++)
for (int azIndex = 0; azIndex < Option.Series[pieIndex].Data.Count; azIndex++)
{
Angle angle = Angles[pieIndex][azIndex];
if (az >= angle.Start && az <= angle.Start + angle.Sweep)
@ -243,7 +247,7 @@ namespace Sunny.UI
tip.Top = e.Location.Y + 20;
}
if (PieOption.ToolTip.Visible)
if (Option.ToolTip.Visible)
{
if (!tip.Visible) tip.Visible = angle.Text.IsValid();
}

View File

@ -1,4 +1,25 @@
using System;
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2020 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@qq.com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UIScale.cs
* :
* : V2.2
* : 2020-10-01
*
* 2020-10-01: V2.2.8 线
******************************************************************************/
using System;
using System.Globalization;
using static System.Double;

View File

@ -8,6 +8,9 @@ namespace Sunny.UI
public UIColorItem()
{
InitializeComponent();
btnOK.Text = UILocalize.OK;
btnCancel.Text = UILocalize.Cancel;
}
private LabelRotate m_colorSample;

View File

@ -705,6 +705,9 @@ namespace Sunny.UI
months.Add("十月");
months.Add("十一月");
months.Add("十二月");
btnOK.Text = UILocalize.OK;
btnCancel.Text = UILocalize.Cancel;
}
private int activeDay = -1;

View File

@ -414,6 +414,8 @@ namespace Sunny.UI
{
InitializeComponent();
this.MouseWheel += UITimeItem_MouseWheel;
btnOK.Text = UILocalize.OK;
btnCancel.Text = UILocalize.Cancel;
}
private void UITimeItem_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)

View File

@ -157,9 +157,10 @@ namespace Sunny.UI
return isOk;
}
public static bool ShowMessageDialog(string message, string title, bool isShowCancel, UIStyle style)
public static bool ShowMessageDialog(string message, string title, bool isShowCancel, UIStyle style, bool topMost = false)
{
UIMessageForm frm = new UIMessageForm();
frm.TopMost = topMost;
frm.ShowMessage(message, title, isShowCancel, style);
frm.ShowDialog();
bool isOk = frm.IsOK;
@ -168,6 +169,57 @@ namespace Sunny.UI
}
}
public static class UIMessageBox
{
public static void Show(string text)
{
Show(text, UILocalize.InfoTitle);
}
public static void ShowInfo(string text)
{
Show(text, UILocalize.InfoTitle, UIStyle.Gray);
}
public static void ShowSuccess(string text)
{
Show(text, UILocalize.SuccessTitle, UIStyle.Green);
}
public static void ShowWarning(string text)
{
Show(text, UILocalize.WarningTitle, UIStyle.Orange);
}
public static void ShowError(string text)
{
Show(text, UILocalize.ErrorTitle, UIStyle.Red);
}
public static bool ShowAsk(string text)
{
return Show(text, UILocalize.AskTitle, UIStyle.Blue, UIMessageBoxButtons.OKCancel);
}
public static bool Show(string text, string caption, UIStyle style = UIStyle.Blue, UIMessageBoxButtons buttons = UIMessageBoxButtons.OK, bool topMost = false)
{
return UIMessageDialog.ShowMessageDialog(text, caption, buttons == UIMessageBoxButtons.OKCancel, style, topMost);
}
}
public enum UIMessageBoxButtons
{
/// <summary>
/// 确定
/// </summary>
OK = 0,
/// <summary>
/// 确定、取消
/// </summary>
OKCancel = 1
}
public static class UIInputDialog
{
private static bool InputStringDialog(ref string value, bool checkEmpty = true, string desc = "请输入字符串:", UIStyle style = UIStyle.Blue, bool topMost = false)

Binary file not shown.

View File

@ -35,6 +35,34 @@ namespace Sunny.UI
return Color.FromArgb(alpha, color);
}
private static Graphics graphics;
/// <summary>
/// 提供一个Graphics常用于需要计算文字大小时
/// </summary>
/// <returns>大小</returns>
public static Graphics Graphics()
{
if (graphics == null)
{
Bitmap bmp = new Bitmap(1, 1);
graphics = bmp.Graphics();
}
return graphics;
}
/// <summary>
/// 计算文字大小
/// </summary>
/// <param name="text">文字</param>
/// <param name="font">字体</param>
/// <returns>大小</returns>
public static SizeF MeasureString(this string text, Font font)
{
return Graphics().MeasureString(text, font);
}
/// <summary>
/// 九宫切图背景填充,#http://st233.com/blog.php?id=24
/// 例如按钮是图片分成九个区域 然后只需要将四角填充到目标区域 其余的拉伸就可以了
@ -149,15 +177,15 @@ namespace Sunny.UI
return point.X >= rect.Left && point.X <= rect.Right && point.Y >= rect.Top && point.Y <= rect.Bottom;
}
public static void Smooth(this Graphics graphics, bool smooth = true)
public static void Smooth(this Graphics g, bool smooth = true)
{
if (smooth)
{
graphics.SetHighQuality();
g.SetHighQuality();
}
else
{
graphics.SetDefaultQuality();
g.SetDefaultQuality();
}
}
@ -195,9 +223,9 @@ namespace Sunny.UI
g.DrawString(text, font, color, pt.X, pt.Y);
}
public static void DrawLines(this Graphics g, Color color, Point[] points, bool smooth = false)
public static void DrawLines(this Graphics g, Color color, Point[] points, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawLines(pen, points);
@ -205,9 +233,9 @@ namespace Sunny.UI
}
}
public static void DrawLines(this Graphics g, Color color, PointF[] points, bool smooth = false)
public static void DrawLines(this Graphics g, Color color, PointF[] points, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawLines(pen, points);
@ -215,9 +243,9 @@ namespace Sunny.UI
}
}
public static void DrawCurve(this Graphics g, Color color, Point[] points, bool smooth = false)
public static void DrawCurve(this Graphics g, Color color, Point[] points, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawCurve(pen, points);
@ -225,9 +253,9 @@ namespace Sunny.UI
}
}
public static void DrawCurve(this Graphics g, Color color, PointF[] points, bool smooth = false)
public static void DrawCurve(this Graphics g, Color color, PointF[] points, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawCurve(pen, points);
@ -235,9 +263,9 @@ namespace Sunny.UI
}
}
public static void DrawLine(this Graphics g, Color color, int x1, int y1, int x2, int y2, bool smooth = false)
public static void DrawLine(this Graphics g, Color color, int x1, int y1, int x2, int y2, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawLine(pen, x1, y1, x2, y2);
@ -245,9 +273,9 @@ namespace Sunny.UI
}
}
public static void DrawLine(this Graphics g, Color color, Point pt1, Point pt2, bool smooth = false)
public static void DrawLine(this Graphics g, Color color, Point pt1, Point pt2, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawLine(pen, pt1, pt2);
@ -255,9 +283,9 @@ namespace Sunny.UI
}
}
public static void DrawLine(this Graphics g, Color color, float x1, float y1, float x2, float y2, bool smooth = false)
public static void DrawLine(this Graphics g, Color color, float x1, float y1, float x2, float y2, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawLine(pen, x1, y1, x2, y2);
@ -265,9 +293,9 @@ namespace Sunny.UI
}
}
public static void DrawLine(this Graphics g, Color color, PointF pt1, PointF pt2, bool smooth = false)
public static void DrawLine(this Graphics g, Color color, PointF pt1, PointF pt2, bool smooth = false, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawLine(pen, pt1, pt2);
@ -275,9 +303,9 @@ namespace Sunny.UI
}
}
public static void DrawArc(this Graphics g, Color color, int x, int y, int width, int height, int startAngle, int sweepAngle, bool smooth = true)
public static void DrawArc(this Graphics g, Color color, int x, int y, int width, int height, int startAngle, int sweepAngle, bool smooth = true, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawArc(pen, x, y, width, height, startAngle, sweepAngle);
@ -285,9 +313,9 @@ namespace Sunny.UI
}
}
public static void DrawArc(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true)
public static void DrawArc(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true, float penWidth = 1)
{
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawArc(pen, x, y, width, height, startAngle, sweepAngle);
@ -305,9 +333,9 @@ namespace Sunny.UI
}
}
public static void DrawPath(this Graphics g, Color color, GraphicsPath path, bool smooth = true)
public static void DrawPath(this Graphics g, Color color, GraphicsPath path, bool smooth = true, float penWidth = 1)
{
using (Pen pn = new Pen(color))
using (Pen pn = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawPath(pn, path);
@ -325,9 +353,9 @@ namespace Sunny.UI
}
}
public static void DrawEllipse(this Graphics g, Color color, Rectangle rect, bool smooth = true)
public static void DrawEllipse(this Graphics g, Color color, Rectangle rect, bool smooth = true, float penWidth = 1)
{
using (Pen pn = new Pen(color))
using (Pen pn = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawEllipse(pn, rect);
@ -345,9 +373,9 @@ namespace Sunny.UI
}
}
public static void DrawEllipse(this Graphics g, Color color, RectangleF rect, bool smooth = true)
public static void DrawEllipse(this Graphics g, Color color, RectangleF rect, bool smooth = true, float penWidth = 1)
{
using (Pen pn = new Pen(color))
using (Pen pn = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawEllipse(pn, rect);
@ -385,9 +413,9 @@ namespace Sunny.UI
}
}
public static void DrawRectangle(this Graphics g, Color color, Rectangle rect, bool smooth = false)
public static void DrawRectangle(this Graphics g, Color color, Rectangle rect, bool smooth = false, float penWidth = 1)
{
using (Pen pn = new Pen(color))
using (Pen pn = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawRectangle(pn, rect);
@ -405,9 +433,9 @@ namespace Sunny.UI
}
}
public static void DrawRectangle(this Graphics g, Color color, RectangleF rect, bool smooth = false)
public static void DrawRectangle(this Graphics g, Color color, RectangleF rect, bool smooth = false, float penWidth = 1)
{
using (Pen pn = new Pen(color))
using (Pen pn = new Pen(color, penWidth))
{
g.Smooth(smooth);
g.DrawRectangle(pn, rect.X, rect.Y, rect.Width, rect.Height);
@ -648,10 +676,10 @@ namespace Sunny.UI
g.FillPie(color, rect.Left, rect.Top, rect.Width, rect.Height, startAngle, sweepAngle, smooth);
}
public static void DrawPie(this Graphics g, Color color, int x, int y, int width, int height, float startAngle, float sweepAngle, bool smooth = true)
public static void DrawPie(this Graphics g, Color color, int x, int y, int width, int height, float startAngle, float sweepAngle, bool smooth = true, float penWidth = 1)
{
g.Smooth(smooth);
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.DrawPie(pen, x, y, width, height, startAngle, sweepAngle);
}
@ -659,15 +687,35 @@ namespace Sunny.UI
g.Smooth(false);
}
public static void DrawPoint(this Graphics g, Color color, int x, int y, float size)
{
g.FillEllipse(color, x - size / 2.0f, y - size / 2.0f, size, size);
}
public static void DrawPoint(this Graphics g, Color color, float x, float y, float size)
{
g.FillEllipse(color, x - size / 2.0f, y - size / 2.0f, size, size);
}
public static void DrawPoint(this Graphics g, Color color, Point point, float size)
{
g.DrawPoint(color, point.X, point.Y, size);
}
public static void DrawPoint(this Graphics g, Color color, PointF point, float size)
{
g.DrawPoint(color, point.X, point.Y, size);
}
public static void DrawPie(this Graphics g, Color color, Rectangle rect, float startAngle, float sweepAngle, bool smooth = true)
{
g.DrawPie(color, rect.Left, rect.Top, rect.Width, rect.Height, startAngle, sweepAngle, smooth);
}
public static void DrawPie(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true)
public static void DrawPie(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true, float penWidth = 1)
{
g.Smooth(smooth);
using (Pen pen = new Pen(color))
using (Pen pen = new Pen(color, penWidth))
{
g.DrawPie(pen, x, y, width, height, startAngle, sweepAngle);
}

View File

@ -1,5 +1,18 @@
+ 增加; - 删除; * 修改
2020-10-12 V2.2.8
+ UILineChart完成曲线图表
+ UIScale增加坐标轴刻度计算类
+ UIFlowLayoutPanel增加
+ UIBarChartEx增加了一个新的柱状图类型序列个数可以不相等
+ UDateTimeInt64增加DateTimeInt64类时间整形互转类
* UIForm增加窗体阴影
* UIMainFrame页面框架增加Selecting事件在页面切换时执行该事件
* UITextBox解决Anchor包含Top、Bottom时在窗体最小化后恢复时高度变化
* UISwitch增加长方形形状开关取消长宽比锁定
* UITreeView背景色可改设置FillColor以及SystemCustomMode = true
* UIDataGridView解决水平滚动条在有列冻结时出错的问题
2020-09-17 V2.2.7
+ 新增双主键线程安全字典,分组线程安全字典
+ UIHorScrollBarExUIVerScrollBarEx重写了两个滚动条