* UILineChart: 增加了绘制线的DashStyle样式

This commit is contained in:
Sunny 2023-10-20 23:16:13 +08:00
parent fa7aaad7b4
commit 047a1f508d
4 changed files with 44 additions and 16 deletions

View File

@ -50,6 +50,7 @@
* 2023-07-14: V3.4.0
* 2023-10-04: V3.5.0 Y轴数据由上向下绘制
* 2023-10-05: V3.5.0 X轴和Y轴鼠标选择区域并返回选中范围
* 2023-10-20: V3.5.1 线DashStyle样式
******************************************************************************/
using System;
@ -546,6 +547,8 @@ namespace Sunny.UI
{
using (Pen pen = new Pen(color, series.Width))
{
pen.DashStyle = series.DashStyle;
if (series.DashPattern.IsValid()) pen.DashPattern = series.DashPattern;
g.SetHighQuality();
if (series is UISwitchLineSeries lineSeries)

View File

@ -28,6 +28,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
namespace Sunny.UI
@ -496,6 +497,10 @@ namespace Sunny.UI
public float Width { get; set; } = 2;
public Color Color { get; set; }
public DashStyle DashStyle { get; set; } = DashStyle.Solid;
public float[] DashPattern { get; set; }
public UILinePointSymbol Symbol { get; set; } = UILinePointSymbol.None;
/// <summary>

View File

@ -268,11 +268,11 @@ namespace Sunny.UI
/// <param name="color">颜色</param>
/// <param name="centerPoint">文字中心点</param>
/// <param name="angle">角度</param>
public static void DrawRotateString(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle)
public static void DrawRotateString(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle, int offsetX = 0, int offsetY = 0)
{
if (text.IsNullOrEmpty()) return;
using Brush br = color.Brush();
g.DrawRotateString(text, font, br, centerPoint, angle);
g.DrawRotateString(text, font, br, centerPoint, angle, offsetX, offsetY);
}
/// <summary>
@ -284,25 +284,25 @@ namespace Sunny.UI
/// <param name="brush">笔刷</param>
/// <param name="centerPoint">文字中心点</param>
/// <param name="angle">角度</param>
private static void DrawRotateString(this Graphics g, string text, Font font, Brush brush, PointF centerPoint, float angle)
private static void DrawRotateString(this Graphics g, string text, Font font, Brush brush, PointF centerPoint, float angle, int offsetX = 0, int offsetY = 0)
{
if (text.IsNullOrEmpty()) return;
SizeF sf = TextRenderer.MeasureText(text, font);
float x1 = centerPoint.X - sf.Width / 2.0f;
float y1 = centerPoint.Y - sf.Height / 2.0f;
float x1 = centerPoint.X - sf.Width / 2.0f + offsetX;
float y1 = centerPoint.Y - sf.Height / 2.0f + offsetY;
// 把画板的原点(默认是左上角)定位移到文字中心
g.TranslateTransform(x1 + sf.Width / 2, y1 + sf.Height / 2);
g.TranslateTransform(x1 + sf.Width / 2.0f, y1 + sf.Height / 2.0f);
// 旋转画板
g.RotateTransform(angle);
// 回退画板x,y轴移动过的距离
g.TranslateTransform(-(x1 + sf.Width / 2), -(y1 + sf.Height / 2));
g.TranslateTransform(-(x1 + sf.Width / 2.0f), -(y1 + sf.Height / 2.0f));
g.DrawString(text, font, brush, x1, y1);
//恢复
g.TranslateTransform(x1 + sf.Width / 2, y1 + sf.Height / 2);
g.TranslateTransform(x1 + sf.Width / 2.0f, y1 + sf.Height / 2.0f);
g.RotateTransform(-angle);
g.TranslateTransform(-(x1 + sf.Width / 2), -(y1 + sf.Height / 2));
g.TranslateTransform(-(x1 + sf.Width / 2.0f), -(y1 + sf.Height / 2.0f));
}
/// <summary>

View File

@ -106,11 +106,35 @@ namespace Sunny.UI
/// <param name="xOffset">×óÓÒÆ«ÒÆ</param>
/// <param name="yOffSet">ÉÏÏÂÆ«ÒÆ</param>
public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color,
RectangleF rect, int xOffset = 0, int yOffSet = 0, int angle = 0)
{
SizeF sf = graphics.GetFontImageSize(symbol, symbolSize);
if (angle == 0)
{
graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(),
rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet);
}
else
{
graphics.DrawFontImage(symbol, symbolSize, color, angle, rect, xOffset, yOffSet);
}
}
public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color, int angle,
RectangleF rect, int xOffset = 0, int yOffSet = 0)
{
SizeF sf = graphics.GetFontImageSize(symbol, symbolSize);
graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(),
rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet);
PointF center = rect.Center();
Font font = GetFont(symbol, symbolSize);
var symbolValue = GetSymbolValue(symbol);
string text = char.ConvertFromUtf32(symbolValue);
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
graphics.DrawRotateString(text, font, color, center, angle, xOffset, yOffSet);
graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
graphics.InterpolationMode = InterpolationMode.Default;
}
/// <summary>
@ -127,12 +151,8 @@ namespace Sunny.UI
public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color,
float left, float top, int xOffset = 0, int yOffSet = 0)
{
//×ÖÌå
Font font = GetFont(symbol, symbolSize);
if (font == null)
{
return;
}
if (font == null) return;
var symbolValue = GetSymbolValue(symbol);
string text = char.ConvertFromUtf32(symbolValue);