提交记录删除UI/Librays/RadarDemo.cs+0 −157
| @@ -1,157 +0,0 @@ | ||
| 1 | 删除:using System; | |
| 2 | 删除:using System.Collections.Generic; | |
| 3 | 删除:using System.Drawing; | |
| 4 | 删除:using System.Drawing.Imaging; | |
| 5 | 删除:using System.Linq; | |
| 6 | 删除:using System.Text; | |
| 7 | 删除:using System.Threading.Tasks; | |
| 8 | 删除: | |
| 9 | 删除:namespace UI.Librays | |
| 10 | 删除:{ | |
| 11 | 删除: public static class RadarDemo | |
| 12 | 删除: { | |
| 13 | 删除: static float mW = 1200; | |
| 14 | 删除: static float mH = 1200; | |
| 15 | 删除: static Dictionary<string, float> mData = new Dictionary<string, float> | |
| 16 | 删除: { | |
| 17 | 删除: //{ "速度",77}, | |
| 18 | 删除: { "力量", 72}, | |
| 19 | 删除: { "防守", 110}, | |
| 20 | 删除: { "射门", 50}, | |
| 21 | 删除: { "传球", 80}, | |
| 22 | 删除: { "耐力", 60 } | |
| 23 | 删除: };//维度数据 | |
| 24 | 删除: static float mCount = mData.Count; //边数 | |
| 25 | 删除: static float mCenter = mW * 0.5f; //中心点 | |
| 26 | 删除: static float mRadius = mCenter - 100; //半径(减去的值用于给绘制的文本留空间) | |
| 27 | 删除: static double mAngle = (Math.PI * 2) / mCount; //角度 | |
| 28 | 删除: static Graphics graphics = null; | |
| 29 | 删除: static int mPointRadius = 5; // 各个维度分值圆点的半径 | |
| 30 | 删除: static int textFontSize = 18; //顶点文字大小 px | |
| 31 | 删除: const string textFontFamily = "Microsoft Yahei"; //顶点字体 | |
| 32 | 删除: static Color lineColor = Color.Green; | |
| 33 | 删除: static Color fillColor = Color.FromArgb(128, 255, 0, 0); | |
| 34 | 删除: static Color fontColor = Color.Black; | |
| 35 | 删除: public static void Show() | |
| 36 | 删除: { | |
| 37 | 删除: Bitmap img = new Bitmap((int)mW, (int)mH); | |
| 38 | 删除: graphics = Graphics.FromImage(img); | |
| 39 | 删除: graphics.Clear(Color.White); | |
| 40 | 删除: img.Save($"{AppDomain.CurrentDomain.BaseDirectory}/0.png", ImageFormat.Jpeg); | |
| 41 | 删除: DrawPolygon(graphics); | |
| 42 | 删除: img.Save($"{AppDomain.CurrentDomain.BaseDirectory}/1.png", ImageFormat.Png); | |
| 43 | 删除: DrawLines(graphics); | |
| 44 | 删除: img.Save($"{AppDomain.CurrentDomain.BaseDirectory}/2.png", ImageFormat.Png); | |
| 45 | 删除: DrawText(graphics); | |
| 46 | 删除: img.Save($"{AppDomain.CurrentDomain.BaseDirectory}/3.png", ImageFormat.Png); | |
| 47 | 删除: DrawRegion(graphics); | |
| 48 | 删除: img.Save($"{AppDomain.CurrentDomain.BaseDirectory}/4.png", ImageFormat.Png); | |
| 49 | 删除: DrawCircle(graphics); | |
| 50 | 删除: img.Save($"{AppDomain.CurrentDomain.BaseDirectory}/5.png", ImageFormat.Png); | |
| 51 | 删除: img.Dispose(); | |
| 52 | 删除: graphics.Dispose(); | |
| 53 | 删除: } | |
| 54 | 删除: // 绘制多边形边 | |
| 55 | 删除: private static void DrawPolygon(Graphics ctx) | |
| 56 | 删除: { | |
| 57 | 删除: var r = mRadius / mCount; //单位半径 | |
| 58 | 删除: Pen pen = new Pen(lineColor); | |
| 59 | 删除: //画6个圈 | |
| 60 | 删除: for (var i = 0; i < mCount; i++) | |
| 61 | 删除: { | |
| 62 | 删除: var points = new List<PointF>(); | |
| 63 | 删除: var currR = r * (i + 1); //当前半径 | |
| 64 | 删除: //画6条边 | |
| 65 | 删除: for (var j = 0; j < mCount; j++) | |
| 66 | 删除: { | |
| 67 | 删除: var x = (float)(mCenter + currR * Math.Cos(mAngle * j)); | |
| 68 | 删除: var y = (float)(mCenter + currR * Math.Sin(mAngle * j)); | |
| 69 | 删除: points.Add(new PointF { X = x, Y = y }); | |
| 70 | 删除: } | |
| 71 | 删除: ctx.DrawPolygon(pen, points.ToArray()); | |
| 72 | 删除: //break; | |
| 73 | 删除: } | |
| 74 | 删除: ctx.Save(); | |
| 75 | 删除: } | |
| 76 | 删除: //顶点连线 | |
| 77 | 删除: private static void DrawLines(Graphics ctx) | |
| 78 | 删除: { | |
| 79 | 删除: for (var i = 0; i < mCount; i++) | |
| 80 | 删除: { | |
| 81 | 删除: var x = (float)(mCenter + mRadius * Math.Cos(mAngle * i)); | |
| 82 | 删除: var y = (float)(mCenter + mRadius * Math.Sin(mAngle * i)); | |
| 83 | 删除: ctx.DrawLine(new Pen(lineColor), new PointF { X = mCenter, Y = mCenter }, new PointF { X = x, Y = y }); | |
| 84 | 删除: //break; | |
| 85 | 删除: } | |
| 86 | 删除: ctx.Save(); | |
| 87 | 删除: } | |
| 88 | 删除: //绘制文本 | |
| 89 | 删除: private static void DrawText(Graphics ctx) | |
| 90 | 删除: { | |
| 91 | 删除: var fontSize = textFontSize;//mCenter / 12; | |
| 92 | 删除: Font font = new Font(textFontFamily, fontSize, FontStyle.Regular); | |
| 93 | 删除: int i = 0; | |
| 94 | 删除: foreach (var item in mData) | |
| 95 | 删除: { | |
| 96 | 删除: var x = (float)(mCenter + mRadius * Math.Cos(mAngle * i)); | |
| 97 | 删除: var y = (float)(mCenter + mRadius * Math.Sin(mAngle * i) - fontSize); | |
| 98 | 删除: if (mAngle * i > 0 && mAngle * i <= Math.PI / 2) | |
| 99 | 删除: { | |
| 100 | 删除: ctx.DrawString(item.Key, font, new SolidBrush(fontColor), x - ctx.MeasureString(item.Key, font).Width * 0.5f, y + fontSize/* y + fontSize*/); | |
| 101 | 删除: } | |
| 102 | 删除: else if (mAngle * i > Math.PI / 2 && mAngle * i <= Math.PI) | |
| 103 | 删除: { | |
| 104 | 删除: ctx.DrawString(item.Key, font, new SolidBrush(fontColor), x - ctx.MeasureString(item.Key, font).Width, y /*y + fontSize*/); | |
| 105 | 删除: } | |
| 106 | 删除: else if (mAngle * i > Math.PI && mAngle * i <= Math.PI * 3 / 2) | |
| 107 | 删除: { | |
| 108 | 删除: ctx.DrawString(item.Key, font, new SolidBrush(fontColor), x - ctx.MeasureString(item.Key, font).Width, y); | |
| 109 | 删除: } | |
| 110 | 删除: else if (mAngle * i > Math.PI * 3 / 2) | |
| 111 | 删除: { | |
| 112 | 删除: ctx.DrawString(item.Key, font, new SolidBrush(fontColor), x - ctx.MeasureString(item.Key, font).Width * 0.5f, y - fontSize * 0.5f); | |
| 113 | 删除: } | |
| 114 | 删除: else | |
| 115 | 删除: { | |
| 116 | 删除: ctx.DrawString(item.Key, font, new SolidBrush(fontColor), x, y /* y + fontSize*/); | |
| 117 | 删除: } | |
| 118 | 删除: i++; | |
| 119 | 删除: } | |
| 120 | 删除: ctx.Save(); | |
| 121 | 删除: } | |
| 122 | 删除: //绘制数据区域 | |
| 123 | 删除: private static void DrawRegion(Graphics ctx) | |
| 124 | 删除: { | |
| 125 | 删除: int i = 0; | |
| 126 | 删除: List<PointF> points = new List<PointF>(); | |
| 127 | 删除: foreach (var item in mData) | |
| 128 | 删除: { | |
| 129 | 删除: var x = (float)(mCenter + mRadius * Math.Cos(mAngle * i) * item.Value / 100); | |
| 130 | 删除: var y = (float)(mCenter + mRadius * Math.Sin(mAngle * i) * item.Value / 100); | |
| 131 | 删除: points.Add(new PointF { X = x, Y = y }); | |
| 132 | 删除: //ctx.DrawArc(new Pen(lineColor), x, y, r, r, 0, (float)Math.PI * 2); | |
| 133 | 删除: i++; | |
| 134 | 删除: } | |
| 135 | 删除: //GraphicsPath path = new GraphicsPath(); | |
| 136 | 删除: //path.AddLines(points.ToArray()); | |
| 137 | 删除: ctx.FillPolygon(new SolidBrush(fillColor), points.ToArray()); | |
| 138 | 删除: ctx.Save(); | |
| 139 | 删除: } | |
| 140 | 删除: //画点 | |
| 141 | 删除: private static void DrawCircle(Graphics ctx) | |
| 142 | 删除: { | |
| 143 | 删除: //var r = mCenter / 18; | |
| 144 | 删除: var r = mPointRadius; | |
| 145 | 删除: int i = 0; | |
| 146 | 删除: foreach (var item in mData) | |
| 147 | 删除: { | |
| 148 | 删除: var x = (float)(mCenter + mRadius * Math.Cos(mAngle * i) * item.Value / 100); | |
| 149 | 删除: var y = (float)(mCenter + mRadius * Math.Sin(mAngle * i) * item.Value / 100); | |
| 150 | 删除: ctx.FillPie(new SolidBrush(fillColor), x - r, y - r, r * 2, r * 2, 0, 360); | |
| 151 | 删除: //ctx.DrawArc(new Pen(lineColor), x, y, r, r, 0, (float)Math.PI * 2); | |
| 152 | 删除: i++; | |
| 153 | 删除: } | |
| 154 | 删除: ctx.Save(); | |
| 155 | 删除: } | |
| 156 | 删除: } | |
| 157 | 删除:} | |

