* UIChart: 修改可能显示出错的问题

This commit is contained in:
Sunny 2021-12-09 11:50:21 +08:00
parent 560a6f00f6
commit f53b3a56a0
8 changed files with 104 additions and 79 deletions

Binary file not shown.

View File

@ -485,20 +485,18 @@ namespace Sunny.UI
} }
} }
using Font tmp = this.DPIScaleFont(Font,SubTextFontSize);
if (Option.XAxis.AxisLabel.Show) if (Option.XAxis.AxisLabel.Show)
{ {
float start = DrawOrigin.X + DrawBarWidth / 2.0f; float start = DrawOrigin.X + DrawBarWidth / 2.0f;
foreach (var data in Option.XAxis.Data) foreach (var data in Option.XAxis.Data)
{ {
SizeF sf = g.MeasureString(data, tmp); SizeF sf = g.MeasureString(data, TempFont);
g.DrawString(data, tmp, ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length); g.DrawString(data, TempFont, ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
start += DrawBarWidth; start += DrawBarWidth;
} }
SizeF sfname = g.MeasureString(Option.XAxis.Name, tmp); SizeF sfname = g.MeasureString(Option.XAxis.Name, TempFont);
g.DrawString(Option.XAxis.Name, tmp, ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfname.Height); g.DrawString(Option.XAxis.Name, TempFont, ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfname.Height);
} }
if (Option.YAxis.AxisTick.Show) if (Option.YAxis.AxisTick.Show)
@ -547,16 +545,16 @@ namespace Sunny.UI
for (int i = YAxisStart; i <= YAxisEnd; i++) for (int i = YAxisStart; i <= YAxisEnd; i++)
{ {
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx); string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
SizeF sf = g.MeasureString(label, tmp); SizeF sf = g.MeasureString(label, TempFont);
wmax = Math.Max(wmax, sf.Width); wmax = Math.Max(wmax, sf.Width);
g.DrawString(label, tmp, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f); g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
start -= DrawBarHeight; start -= DrawBarHeight;
} }
SizeF sfname = g.MeasureString(Option.YAxis.Name, tmp); SizeF sfname = g.MeasureString(Option.YAxis.Name, TempFont);
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height); int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2); int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(Option.YAxis.Name, tmp, ForeColor, new Point(x, y), g.DrawString(Option.YAxis.Name, TempFont, ForeColor, new Point(x, y),
new StringFormat() { Alignment = StringAlignment.Center }, 270); new StringFormat() { Alignment = StringAlignment.Center }, 270);
} }
} }
@ -575,15 +573,14 @@ namespace Sunny.UI
g.DrawLine(pn, DrawOrigin.X, pos, Width - Option.Grid.Right, pos); g.DrawLine(pn, DrawOrigin.X, pos, Width - Option.Grid.Right, pos);
} }
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); SizeF sf = g.MeasureString(line.Name, TempFont);
SizeF sf = g.MeasureString(line.Name, tmp);
if (line.Left == UILeftAlignment.Left) if (line.Left == UILeftAlignment.Left)
g.DrawString(line.Name, tmp, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height); g.DrawString(line.Name, TempFont, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Center) if (line.Left == UILeftAlignment.Center)
g.DrawString(line.Name, tmp, line.Color, DrawOrigin.X + (Width - Option.Grid.Left - Option.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height); g.DrawString(line.Name, TempFont, line.Color, DrawOrigin.X + (Width - Option.Grid.Left - Option.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Right) if (line.Left == UILeftAlignment.Right)
g.DrawString(line.Name, tmp, line.Color, Width - sf.Width - 4 - Option.Grid.Right, pos - 2 - sf.Height); g.DrawString(line.Name, TempFont, line.Color, Width - sf.Width - 4 - Option.Grid.Right, pos - 2 - sf.Height);
} }
} }
@ -602,8 +599,7 @@ namespace Sunny.UI
for (int i = 0; i < Option.XAxis.Data.Count; i++) for (int i = 0; i < Option.XAxis.Data.Count; i++)
{ {
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); Bars[0][i].Size = g.MeasureString(Bars[0][i].Tips, TempFont);
Bars[0][i].Size = g.MeasureString(Bars[0][i].Tips, tmp);
} }
} }

View File

@ -453,7 +453,6 @@ namespace Sunny.UI
protected override void DrawSeries(Graphics g, List<UIBarSeries> series) protected override void DrawSeries(Graphics g, List<UIBarSeries> series)
{ {
if (series == null || series.Count == 0) return; if (series == null || series.Count == 0) return;
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize);
for (int i = 0; i < Bars.Count; i++) for (int i = 0; i < Bars.Count; i++)
{ {
@ -466,13 +465,13 @@ namespace Sunny.UI
{ {
if (s.BarName.Count > 0 && j < s.BarName.Count) if (s.BarName.Count > 0 && j < s.BarName.Count)
{ {
SizeF sf = g.MeasureString(s.BarName[j], tmp); SizeF sf = g.MeasureString(s.BarName[j], TempFont);
if (s.Data[j] >= 0) if (s.Data[j] >= 0)
g.DrawString(s.BarName[j], tmp, ChartStyle.ForeColor, g.DrawString(s.BarName[j], TempFont, ChartStyle.ForeColor,
bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2,
bars[j].Rect.Bottom + 1); bars[j].Rect.Bottom + 1);
else else
g.DrawString(s.BarName[j], tmp, ChartStyle.ForeColor, g.DrawString(s.BarName[j], TempFont, ChartStyle.ForeColor,
bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2,
bars[j].Rect.Top - sf.Height); bars[j].Rect.Top - sf.Height);
} }
@ -480,28 +479,23 @@ namespace Sunny.UI
if (s.ShowValue) if (s.ShowValue)
{ {
Font fontShow = null;
if (s.ShowValueFontSize > 0) fontShow = new Font(tmp.Name, s.ShowValueFontSize);
string value = s.Data[j].ToString("F" + Option.YAxis.AxisLabel.DecimalCount); string value = s.Data[j].ToString("F" + Option.YAxis.AxisLabel.DecimalCount);
SizeF sf = g.MeasureString(value, fontShow ?? tmp); SizeF sf = g.MeasureString(value, TempFont);
if (s.Data[j] < 0) if (s.Data[j] < 0)
g.DrawString(value, fontShow ?? tmp, bars[j].Color, g.DrawString(value, TempFont, bars[j].Color,
bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2,
bars[j].Rect.Bottom + 1); bars[j].Rect.Bottom + 1);
else else
g.DrawString(value, fontShow ?? tmp, bars[j].Color, g.DrawString(value, TempFont, bars[j].Color,
bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2,
bars[j].Rect.Top - sf.Height); bars[j].Rect.Top - sf.Height);
fontShow?.Dispose();
} }
} }
} }
for (int i = 0; i < Option.Series.Count; i++) for (int i = 0; i < Option.Series.Count; i++)
{ {
Bars[i][0].Size = g.MeasureString(Bars[i][0].Tips, tmp); Bars[i][0].Size = g.MeasureString(Bars[i][0].Tips, TempFont);
} }
} }
@ -579,7 +573,6 @@ namespace Sunny.UI
} }
} }
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize);
//绘制X轴标签 //绘制X轴标签
if (Option.XAxis.AxisLabel.Show) if (Option.XAxis.AxisLabel.Show)
{ {
@ -589,12 +582,12 @@ namespace Sunny.UI
foreach (var data in Option.Series) foreach (var data in Option.Series)
{ {
float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount; float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount;
SizeF sf = g.MeasureString(data.Name, tmp); SizeF sf = g.MeasureString(data.Name, TempFont);
if (Option.XAxis.AxisLabel.Angle != 0) if (Option.XAxis.AxisLabel.Angle != 0)
g.DrawString(data.Name, tmp, ChartStyle.ForeColor, new PointF(start + w / 2.0f - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f), g.DrawString(data.Name, TempFont, ChartStyle.ForeColor, new PointF(start + w / 2.0f - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f),
new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360); new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360);
else else
g.DrawString(data.Name, tmp, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance); g.DrawString(data.Name, TempFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
start += w; start += w;
} }
} }
@ -603,18 +596,18 @@ namespace Sunny.UI
float start = DrawOrigin.X + DrawBarWidth / 2.0f; float start = DrawOrigin.X + DrawBarWidth / 2.0f;
foreach (var data in Option.Series) foreach (var data in Option.Series)
{ {
SizeF sf = g.MeasureString(data.Name, tmp); SizeF sf = g.MeasureString(data.Name, TempFont);
if (Option.XAxis.AxisLabel.Angle != 0) if (Option.XAxis.AxisLabel.Angle != 0)
g.DrawString(data.Name, tmp, ChartStyle.ForeColor, new PointF(start - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f), g.DrawString(data.Name, TempFont, ChartStyle.ForeColor, new PointF(start - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f),
new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360); new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360);
else else
g.DrawString(data.Name, tmp, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance); g.DrawString(data.Name, TempFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
start += DrawBarWidth; start += DrawBarWidth;
} }
} }
SizeF sfName = g.MeasureString(Option.XAxis.Name, tmp); SizeF sfName = g.MeasureString(Option.XAxis.Name, TempFont);
g.DrawString(Option.XAxis.Name, tmp, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance + sfName.Height); g.DrawString(Option.XAxis.Name, TempFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance + sfName.Height);
} }
//绘制Y轴刻度 //绘制Y轴刻度
@ -665,16 +658,16 @@ namespace Sunny.UI
for (int i = YAxisStart; i <= YAxisEnd; i++) for (int i = YAxisStart; i <= YAxisEnd; i++)
{ {
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx); string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
SizeF sf = g.MeasureString(label, tmp); SizeF sf = g.MeasureString(label, TempFont);
wmax = Math.Max(wmax, sf.Width); wmax = Math.Max(wmax, sf.Width);
g.DrawString(label, tmp, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f); g.DrawString(label, TempFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
start -= DrawBarHeight; start -= DrawBarHeight;
} }
SizeF sfname = g.MeasureString(Option.YAxis.Name, tmp); SizeF sfname = g.MeasureString(Option.YAxis.Name, TempFont);
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height); int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2); int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
g.DrawString(Option.YAxis.Name, tmp, ChartStyle.ForeColor, new Point(x, y), g.DrawString(Option.YAxis.Name, TempFont, ChartStyle.ForeColor, new Point(x, y),
new StringFormat() { Alignment = StringAlignment.Center }, 270); new StringFormat() { Alignment = StringAlignment.Center }, 270);
} }
} }

View File

@ -57,6 +57,13 @@ namespace Sunny.UI
tip.MouseEnter += Tip_MouseEnter; tip.MouseEnter += Tip_MouseEnter;
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
tmpFont?.Dispose();
tmpLegendFont?.Dispose();
}
private void Tip_MouseEnter(object sender, EventArgs e) private void Tip_MouseEnter(object sender, EventArgs e)
{ {
tip.Visible = false; tip.Visible = false;
@ -195,6 +202,38 @@ namespace Sunny.UI
} }
} }
Font tmpFont;
protected Font TempFont
{
get
{
if (tmpFont == null || !tmpFont.Size.EqualsFloat(SubTextFontSize / this.DPIScale()))
{
tmpFont?.Dispose();
tmpFont = this.DPIScaleFont(Font, SubTextFontSize);
}
return tmpFont;
}
}
Font tmpLegendFont;
protected Font TempLegendFont
{
get
{
if (tmpLegendFont == null || !tmpLegendFont.Size.EqualsFloat(LegendFontSize / this.DPIScale()))
{
tmpLegendFont?.Dispose();
tmpLegendFont = this.DPIScaleFont(Font, SubTextFontSize);
}
return tmpLegendFont;
}
}
protected virtual void DrawOption(Graphics g) protected virtual void DrawOption(Graphics g)
{ {
} }
@ -242,8 +281,7 @@ namespace Sunny.UI
g.DrawString(title.Text, Font, ChartStyle.ForeColor, left, top); g.DrawString(title.Text, Font, ChartStyle.ForeColor, left, top);
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); SizeF sfs = g.MeasureString(title.SubText, TempFont);
SizeF sfs = g.MeasureString(title.SubText, tmp);
switch (title.Left) switch (title.Left)
{ {
case UILeftAlignment.Left: left = TextInterval; break; case UILeftAlignment.Left: left = TextInterval; break;
@ -257,7 +295,7 @@ namespace Sunny.UI
case UITopAlignment.Bottom: top = top - sf.Height; break; case UITopAlignment.Bottom: top = top - sf.Height; break;
} }
g.DrawString(title.SubText, tmp, ChartStyle.ForeColor, left, top); g.DrawString(title.SubText, TempFont, ChartStyle.ForeColor, left, top);
} }
protected void DrawLegend(Graphics g, UILegend legend) protected void DrawLegend(Graphics g, UILegend legend)
@ -269,10 +307,9 @@ namespace Sunny.UI
float maxWidth = 0; float maxWidth = 0;
float oneHeight = 0; float oneHeight = 0;
using Font tmp = this.DPIScaleFont(Font, LegendFontSize);
foreach (var data in legend.Data) foreach (var data in legend.Data)
{ {
SizeF sf = g.MeasureString(data, tmp); SizeF sf = g.MeasureString(data, TempLegendFont);
totalHeight += sf.Height; totalHeight += sf.Height;
totalWidth += sf.Width; totalWidth += sf.Width;
totalWidth += 20; totalWidth += 20;
@ -311,7 +348,7 @@ namespace Sunny.UI
for (int i = 0; i < legend.DataCount; i++) for (int i = 0; i < legend.DataCount; i++)
{ {
var data = legend.Data[i]; var data = legend.Data[i];
SizeF sf = g.MeasureString(data, tmp); SizeF sf = g.MeasureString(data, TempLegendFont);
Color color = ChartStyle.GetColor(i); Color color = ChartStyle.GetColor(i);
if (legend.Colors.Count > 0 && i >= 0 && i < legend.Colors.Count) if (legend.Colors.Count > 0 && i >= 0 && i < legend.Colors.Count)
@ -320,7 +357,7 @@ namespace Sunny.UI
if (legend.Orient == UIOrient.Horizontal) if (legend.Orient == UIOrient.Horizontal)
{ {
g.FillRoundRectangle(color, (int)startLeft, (int)top + 1, 18, (int)oneHeight - 2, 5); g.FillRoundRectangle(color, (int)startLeft, (int)top + 1, 18, (int)oneHeight - 2, 5);
g.DrawString(data, tmp, color, startLeft + 20, top); g.DrawString(data, TempLegendFont, color, startLeft + 20, top);
startLeft += 22; startLeft += 22;
startLeft += sf.Width; startLeft += sf.Width;
} }
@ -328,7 +365,7 @@ namespace Sunny.UI
if (legend.Orient == UIOrient.Vertical) if (legend.Orient == UIOrient.Vertical)
{ {
g.FillRoundRectangle(color, (int)left, (int)startTop + 1, 18, (int)oneHeight - 2, 5); g.FillRoundRectangle(color, (int)left, (int)startTop + 1, 18, (int)oneHeight - 2, 5);
g.DrawString(data, tmp, color, left + 20, startTop); g.DrawString(data, TempLegendFont, color, left + 20, startTop);
startTop += oneHeight; startTop += oneHeight;
} }
} }

View File

@ -142,7 +142,7 @@ namespace Sunny.UI
private void DrawSeries(Graphics g, List<UIDoughnutSeries> series) private void DrawSeries(Graphics g, List<UIDoughnutSeries> series)
{ {
if (series == null || series.Count == 0) return; if (series == null || series.Count == 0) return;
using Font tmp = this. DPIScaleFont(Font, LegendFontSize);
for (int pieIndex = 0; pieIndex < series.Count; pieIndex++) for (int pieIndex = 0; pieIndex < series.Count; pieIndex++)
{ {
var pie = series[pieIndex]; var pie = series[pieIndex];
@ -159,7 +159,7 @@ namespace Sunny.UI
else else
g.FillFan(color, angle.Center, angle.Inner, angle.Outer, angle.Start - 90, angle.Sweep); g.FillFan(color, angle.Center, angle.Inner, angle.Outer, angle.Start - 90, angle.Sweep);
Angles[pieIndex][azIndex].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, tmp); Angles[pieIndex][azIndex].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, TempFont);
if (pie.Label.Show && ActiveAzIndex == azIndex) if (pie.Label.Show && ActiveAzIndex == azIndex)
{ {

View File

@ -217,7 +217,7 @@ namespace Sunny.UI
} }
if (XScale == null || YScale == null) return; if (XScale == null || YScale == null) return;
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize);
//X Tick //X Tick
if (Option.XAxis.AxisTick.Show) if (Option.XAxis.AxisTick.Show)
{ {
@ -245,8 +245,8 @@ namespace Sunny.UI
label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount); label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount);
} }
SizeF sf = g.MeasureString(label, tmp); SizeF sf = g.MeasureString(label, TempFont);
g.DrawString(label, tmp, ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length); g.DrawString(label, TempFont, ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
} }
if (x.Equals(DrawOrigin.X)) continue; if (x.Equals(DrawOrigin.X)) continue;
@ -260,8 +260,8 @@ namespace Sunny.UI
} }
} }
SizeF sfName = g.MeasureString(Option.XAxis.Name, tmp); SizeF sfName = g.MeasureString(Option.XAxis.Name, TempFont);
g.DrawString(Option.XAxis.Name, tmp, ForeColor, g.DrawString(Option.XAxis.Name, TempFont, ForeColor,
DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f,
DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfName.Height); DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfName.Height);
} }
@ -279,9 +279,9 @@ namespace Sunny.UI
if (Option.YAxis.AxisLabel.Show) if (Option.YAxis.AxisLabel.Show)
{ {
string label = YLabels[i].ToString(YScale.Format); string label = YLabels[i].ToString(YScale.Format);
SizeF sf = g.MeasureString(label, tmp); SizeF sf = g.MeasureString(label, TempFont);
widthMax = Math.Max(widthMax, sf.Width); widthMax = Math.Max(widthMax, sf.Width);
g.DrawString(label, tmp, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f); g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
} }
if (y.Equals(DrawOrigin.Y)) continue; if (y.Equals(DrawOrigin.Y)) continue;
@ -295,10 +295,10 @@ namespace Sunny.UI
} }
} }
SizeF sfName = g.MeasureString(Option.YAxis.Name, tmp); SizeF sfName = g.MeasureString(Option.YAxis.Name, TempFont);
float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f; float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f;
float yy = Option.Grid.Top + DrawSize.Height / 2.0f; float yy = Option.Grid.Top + DrawSize.Height / 2.0f;
g.DrawStringRotateAtCenter(Option.YAxis.Name, tmp, ForeColor, new PointF(xx, yy), 270); g.DrawStringRotateAtCenter(Option.YAxis.Name, TempFont, ForeColor, new PointF(xx, yy), 270);
} }
} }
@ -534,7 +534,7 @@ namespace Sunny.UI
private void DrawAxisScales(Graphics g) private void DrawAxisScales(Graphics g)
{ {
if (YScale == null) return; if (YScale == null) return;
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize);
foreach (var line in Option.YAxisScaleLines) foreach (var line in Option.YAxisScaleLines)
{ {
float pos = YScale.CalcYPixel(line.Value, DrawOrigin.Y, DrawSize.Height); float pos = YScale.CalcYPixel(line.Value, DrawOrigin.Y, DrawSize.Height);
@ -546,14 +546,14 @@ namespace Sunny.UI
} }
SizeF sf = g.MeasureString(line.Name, tmp); SizeF sf = g.MeasureString(line.Name, TempFont);
if (line.Left == UILeftAlignment.Left) if (line.Left == UILeftAlignment.Left)
g.DrawString(line.Name, tmp, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height); g.DrawString(line.Name, TempFont, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Center) if (line.Left == UILeftAlignment.Center)
g.DrawString(line.Name, tmp, line.Color, DrawOrigin.X + (Width - Option.Grid.Left - Option.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height); g.DrawString(line.Name, TempFont, line.Color, DrawOrigin.X + (Width - Option.Grid.Left - Option.Grid.Right - sf.Width) / 2, pos - 2 - sf.Height);
if (line.Left == UILeftAlignment.Right) if (line.Left == UILeftAlignment.Right)
g.DrawString(line.Name, tmp, line.Color, Width - sf.Width - 4 - Option.Grid.Right, pos - 2 - sf.Height); g.DrawString(line.Name, TempFont, line.Color, Width - sf.Width - 4 - Option.Grid.Right, pos - 2 - sf.Height);
} }
int idx = 0; int idx = 0;
@ -567,7 +567,7 @@ namespace Sunny.UI
g.DrawLine(pn, pos, DrawOrigin.Y - 1, pos, Option.Grid.Top + 1); g.DrawLine(pn, pos, DrawOrigin.Y - 1, pos, Option.Grid.Top + 1);
} }
SizeF sf = g.MeasureString(line.Name, tmp); SizeF sf = g.MeasureString(line.Name, TempFont);
float x = pos - sf.Width; float x = pos - sf.Width;
if (x < Option.Grid.Left) x = pos + 2; if (x < Option.Grid.Left) x = pos + 2;
float y = Option.Grid.Top + 4 + sf.Height * idx; float y = Option.Grid.Top + 4 + sf.Height * idx;
@ -578,7 +578,7 @@ namespace Sunny.UI
} }
idx++; idx++;
g.DrawString(line.Name, tmp, line.Color, x, y); g.DrawString(line.Name, TempFont, line.Color, x, y);
} }
} }
@ -669,8 +669,7 @@ namespace Sunny.UI
{ {
using (Graphics g = this.CreateGraphics()) using (Graphics g = this.CreateGraphics())
{ {
using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); SizeF sf = g.MeasureString(sb.ToString(), TempFont);
SizeF sf = g.MeasureString(sb.ToString(), tmp);
tip.Size = new Size((int)sf.Width + 4, (int)sf.Height + 4); tip.Size = new Size((int)sf.Width + 4, (int)sf.Height + 4);
} }

View File

@ -158,7 +158,7 @@ namespace Sunny.UI
{ {
var pie = series[pieIndex]; var pie = series[pieIndex];
RectangleF rect = GetSeriesRect(pie); RectangleF rect = GetSeriesRect(pie);
using Font tmp = this.DPIScaleFont(Font, LegendFontSize);
for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++) for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++)
{ {
Color color = ChartStyle.GetColor(azIndex); Color color = ChartStyle.GetColor(azIndex);
@ -166,7 +166,7 @@ namespace Sunny.UI
if (data.StyleCustomMode) color = data.Color; if (data.StyleCustomMode) color = data.Color;
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].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, tmp); Angles[pieIndex][azIndex].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, TempFont);
if (pie.Label.Show) if (pie.Label.Show)
{ {
@ -178,7 +178,7 @@ namespace Sunny.UI
if (pie.Data[azIndex].Value > 0) if (pie.Data[azIndex].Value > 0)
{ {
string text = name + pie.Data[azIndex].Value.ToString("F0"); string text = name + pie.Data[azIndex].Value.ToString("F0");
SizeF sf = g.MeasureString(text, tmp); SizeF sf = g.MeasureString(text, TempFont);
PointF pf; PointF pf;
int added = 9; int added = 9;
if (az >= 0 && az < 90) if (az >= 0 && az < 90)
@ -191,7 +191,7 @@ namespace Sunny.UI
pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - added); pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - added);
if (pie.Data[azIndex].Value > 0) if (pie.Data[azIndex].Value > 0)
g.DrawString(text, tmp, color, pf.X, pf.Y); g.DrawString(text, TempFont, color, pf.X, pf.Y);
} }
} }
} }

View File

@ -52,8 +52,8 @@ namespace Sunny.UI
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); base.Dispose(disposing);
TempTitleFont?.Dispose(); tmpTitleFont?.Dispose();
TempFont?.Dispose(); tmpFont?.Dispose();
} }
[DefaultValue(typeof(Font), "微软雅黑, 9pt"), Description("字体"), Category("SunnyUI")] [DefaultValue(typeof(Font), "微软雅黑, 9pt"), Description("字体"), Category("SunnyUI")]