117 lines
3.7 KiB
C#
117 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using CPF.Drawing;
|
|
using CPF.ReoGrid.Common;
|
|
using CPF.ReoGrid.Graphics;
|
|
using CPF.ReoGrid.Rendering;
|
|
|
|
namespace CPF.ReoGrid.Chart
|
|
{
|
|
public class AxisSerialLabelView : AxisInfoView
|
|
{
|
|
public AxisSerialLabelView(AxisChart chart, AxisTypes axisType = AxisTypes.Primary, AxisOrientation orientation = AxisOrientation.Horizontal) : base(chart, axisType)
|
|
{
|
|
this.orientation = orientation;
|
|
}
|
|
|
|
protected override void OnPaint(RDrawingContext dc)
|
|
{
|
|
base.OnPaint(dc);
|
|
bool flag = base.Chart == null;
|
|
if (!flag)
|
|
{
|
|
AxisDataInfo axisDataInfo = (base.AxisType == AxisTypes.Primary) ? base.Chart.PrimaryAxisInfo : base.Chart.SecondaryAxisInfo;
|
|
bool flag2 = axisDataInfo == null;
|
|
if (!flag2)
|
|
{
|
|
IGraphics graphics = dc.Graphics;
|
|
WorksheetChartDataSource dataSource = base.Chart.DataSource;
|
|
Rect clientBounds = this.ClientBounds;
|
|
Dictionary<int, string> dictionary = new Dictionary<int, string>();
|
|
List<Size> list = new List<Size>();
|
|
int categoryCount = dataSource.CategoryCount;
|
|
double minimum = axisDataInfo.Minimum;
|
|
for (int i = 0; i < categoryCount; i++)
|
|
{
|
|
string categoryName = dataSource.GetCategoryName(i);
|
|
bool flag3 = !string.IsNullOrEmpty(categoryName);
|
|
if (flag3)
|
|
{
|
|
dictionary[i] = categoryName;
|
|
list.Add(DrawingFactory.Default.MeasureString(categoryName, ResourcePoolManager.CreateFont(this.FontName, (double)this.FontSize, CPF.Drawing.FontStyles.Regular)));
|
|
}
|
|
else
|
|
{
|
|
List<Size> list2 = list;
|
|
float num = 0f;
|
|
float num2 = 0f;
|
|
list2.Add(new Size(ref num, ref num2));
|
|
}
|
|
}
|
|
bool flag4 = this.orientation == AxisOrientation.Horizontal;
|
|
if (flag4)
|
|
{
|
|
float num3 = clientBounds.Width / (float)categoryCount;
|
|
float num4 = list.Max((Size b) => b.Width);
|
|
float num5 = clientBounds.Width / num4;
|
|
int num6 = (int)Math.Ceiling((double)((float)categoryCount / num5));
|
|
bool flag5 = num6 < 1;
|
|
if (flag5)
|
|
{
|
|
num6 = 1;
|
|
}
|
|
float num7 = clientBounds.Width / (float)categoryCount;
|
|
for (int j = 0; j < categoryCount; j += num6)
|
|
{
|
|
string text;
|
|
bool flag6 = dictionary.TryGetValue(j, out text) && !string.IsNullOrEmpty(text);
|
|
if (flag6)
|
|
{
|
|
Size size = list[j];
|
|
float num = num3 * (float)j;
|
|
float num2 = 0f;
|
|
float num8 = clientBounds.Height;
|
|
Rect rect = new Rect(ref num, ref num2, ref num3, ref num8);
|
|
graphics.DrawText(text, this.FontName, this.FontSize, base.ForeColor, rect, ReoGridHorAlign.Center, ReoGridVerAlign.Middle);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag7 = this.orientation == AxisOrientation.Vertical;
|
|
if (flag7)
|
|
{
|
|
float num9 = clientBounds.Height / (float)categoryCount;
|
|
float num10 = list.Max((Size b) => b.Height);
|
|
float num11 = clientBounds.Width / num10;
|
|
int num12 = (int)Math.Ceiling((double)((float)categoryCount / num11));
|
|
bool flag8 = num12 < 1;
|
|
if (flag8)
|
|
{
|
|
num12 = 1;
|
|
}
|
|
for (int k = 0; k < categoryCount; k += num12)
|
|
{
|
|
string text2;
|
|
bool flag9 = dictionary.TryGetValue(k, out text2) && !string.IsNullOrEmpty(text2);
|
|
if (flag9)
|
|
{
|
|
Size size2 = list[k];
|
|
float num = 0f;
|
|
float num2 = num9 * (float)k;
|
|
float num8 = clientBounds.Width;
|
|
Rect rect2 = new Rect(ref num, ref num2, ref num8, ref num9);
|
|
graphics.DrawText(text2, this.FontName, this.FontSize, base.ForeColor, rect2, ReoGridHorAlign.Center, ReoGridVerAlign.Middle);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private AxisOrientation orientation;
|
|
}
|
|
}
|