81 lines
1.9 KiB
C#
81 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CPF.Drawing;
|
|
using CPF.ReoGrid.Drawing.Shapes;
|
|
using CPF.ReoGrid.Rendering;
|
|
|
|
namespace CPF.ReoGrid.Chart
|
|
{
|
|
public class PiePlotView : ChartPlotView
|
|
{
|
|
public PiePlotView(Chart chart) : base(chart)
|
|
{
|
|
base.Chart.DataSourceChanged += this.Chart_DataSourceChanged;
|
|
base.Chart.ChartDataChanged += this.Chart_DataSourceChanged;
|
|
}
|
|
|
|
~PiePlotView()
|
|
{
|
|
base.Chart.DataSourceChanged -= this.Chart_DataSourceChanged;
|
|
base.Chart.ChartDataChanged -= this.Chart_DataSourceChanged;
|
|
}
|
|
|
|
private void Chart_DataSourceChanged(object sender, EventArgs e)
|
|
{
|
|
this.UpdatePieShapes();
|
|
}
|
|
|
|
protected virtual void UpdatePieShapes()
|
|
{
|
|
PieChart pieChart = base.Chart as PieChart;
|
|
bool flag = pieChart == null;
|
|
if (!flag)
|
|
{
|
|
WorksheetChartDataSource dataSource = base.Chart.DataSource;
|
|
bool flag2 = dataSource != null;
|
|
if (flag2)
|
|
{
|
|
int serialCount = dataSource.SerialCount;
|
|
float num = 0f;
|
|
int num2 = 0;
|
|
while (num2 < serialCount && num2 < pieChart.PlotPieAngles.Count)
|
|
{
|
|
float num3 = pieChart.PlotPieAngles[num2];
|
|
bool flag3 = num2 >= this.PlotPieShapes.Count;
|
|
if (flag3)
|
|
{
|
|
this.PlotPieShapes.Add(this.CreatePieShape(this.ClientBounds));
|
|
}
|
|
PieShape pieShape = this.PlotPieShapes[num2];
|
|
pieShape.StartAngle = num;
|
|
pieShape.SweepAngle = num3;
|
|
pieShape.FillColor = pieChart.DataSerialStyles[num2].FillColor;
|
|
num += num3;
|
|
num2++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected virtual PieShape CreatePieShape(Rect bounds)
|
|
{
|
|
return new PieShape
|
|
{
|
|
Bounds = bounds,
|
|
LineColor = Color.Transparent
|
|
};
|
|
}
|
|
|
|
protected override void OnPaint(RDrawingContext dc)
|
|
{
|
|
base.OnPaint(dc);
|
|
foreach (PieShape pieShape in this.PlotPieShapes)
|
|
{
|
|
pieShape.Draw(dc);
|
|
}
|
|
}
|
|
|
|
protected List<PieShape> PlotPieShapes = new List<PieShape>();
|
|
}
|
|
}
|