111 lines
2.6 KiB
C#
111 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CPF.Drawing;
|
|
|
|
namespace CPF.ReoGrid.Chart
|
|
{
|
|
public class PieChart : Chart
|
|
{
|
|
internal virtual PieChartDataInfo DataInfo { get; private set; }
|
|
|
|
internal virtual List<float> PlotPieAngles { get; private set; }
|
|
|
|
internal virtual PiePlotView PiePlotView { get; private set; }
|
|
|
|
public PieChart()
|
|
{
|
|
this.DataInfo = new PieChartDataInfo();
|
|
this.PlotPieAngles = new List<float>();
|
|
this.AddPlotViewLayer(this.PiePlotView = this.CreatePlotViewInstance());
|
|
}
|
|
|
|
protected override ChartLegend CreateChartLegend(LegendType type)
|
|
{
|
|
ChartLegend chartLegend = base.CreateChartLegend(type);
|
|
bool flag = type == LegendType.PrimaryLegend;
|
|
if (flag)
|
|
{
|
|
chartLegend.LegendPosition = LegendPosition.Bottom;
|
|
}
|
|
return chartLegend;
|
|
}
|
|
|
|
protected virtual PiePlotView CreatePlotViewInstance()
|
|
{
|
|
return new PiePlotView(this);
|
|
}
|
|
|
|
protected override Rect GetPlotViewBounds(Rect bodyBounds)
|
|
{
|
|
float num = Math.Min(bodyBounds.Width, bodyBounds.Height);
|
|
float num2 = bodyBounds.X + (bodyBounds.Width - num) / 2f;
|
|
float num3 = bodyBounds.Y + (bodyBounds.Height - num) / 2f;
|
|
return new Rect(ref num2, ref num3, ref num, ref num);
|
|
}
|
|
|
|
protected override void UpdatePlotData()
|
|
{
|
|
WorksheetChartDataSource dataSource = this.DataSource;
|
|
bool flag = dataSource == null;
|
|
if (!flag)
|
|
{
|
|
double num = 0.0;
|
|
bool flag2 = dataSource != null && dataSource.SerialCount > 0;
|
|
if (flag2)
|
|
{
|
|
for (int i = 0; i < dataSource.SerialCount; i++)
|
|
{
|
|
double? num2 = dataSource[i][0];
|
|
bool flag3 = num2 != null;
|
|
if (flag3)
|
|
{
|
|
num += num2.Value;
|
|
}
|
|
}
|
|
}
|
|
this.DataInfo.Total = num;
|
|
this.UpdatePlotPoints();
|
|
}
|
|
}
|
|
|
|
protected virtual void UpdatePlotPoints()
|
|
{
|
|
WorksheetChartDataSource dataSource = this.DataSource;
|
|
bool flag = dataSource != null;
|
|
if (flag)
|
|
{
|
|
int serialCount = dataSource.SerialCount;
|
|
Rect clientBounds = this.ClientBounds;
|
|
float num = (float)(360.0 / this.DataInfo.Total);
|
|
for (int i = 0; i < serialCount; i++)
|
|
{
|
|
double? num2 = dataSource[i][0];
|
|
bool flag2 = num2 != null;
|
|
if (flag2)
|
|
{
|
|
float num3 = (float)(num2 * (double)num).Value;
|
|
bool flag3 = i >= this.PlotPieAngles.Count;
|
|
if (flag3)
|
|
{
|
|
this.PlotPieAngles.Add(num3);
|
|
}
|
|
else
|
|
{
|
|
this.PlotPieAngles[i] = num3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.PlotPieAngles.Clear();
|
|
}
|
|
bool flag4 = this.PiePlotView != null;
|
|
if (flag4)
|
|
{
|
|
this.PiePlotView.Invalidate();
|
|
}
|
|
}
|
|
}
|
|
}
|