332 lines
8.1 KiB
C#
332 lines
8.1 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Diagnostics;
|
|||
|
using CPF.Drawing;
|
|||
|
using CPF.Input;
|
|||
|
using CPF.ReoGrid.Drawing;
|
|||
|
using CPF.ReoGrid.Interaction;
|
|||
|
using CPF.ReoGrid.Rendering;
|
|||
|
|
|||
|
namespace CPF.ReoGrid.Chart
|
|||
|
{
|
|||
|
public abstract class Chart : DrawingComponent, IChart, IDrawingContainer, IDrawingObject, IFloatingObject, IUserVisual
|
|||
|
{
|
|||
|
public virtual IDrawingObject TitleView { get; set; }
|
|||
|
|
|||
|
public virtual string Title { get; set; }
|
|||
|
|
|||
|
protected Chart()
|
|||
|
{
|
|||
|
this.Title = "Chart";
|
|||
|
base.LineColor = Color.Silver;
|
|||
|
base.Padding = new PaddingValue(10f);
|
|||
|
ICollection<IDrawingObject> children = this.Children;
|
|||
|
DrawingComponent drawingComponent = new DrawingComponent();
|
|||
|
drawingComponent.FillColor = Color.Transparent;
|
|||
|
drawingComponent.LineColor = Color.Transparent;
|
|||
|
IDrawingContainer item = drawingComponent;
|
|||
|
this.PlotViewContainer = drawingComponent;
|
|||
|
children.Add(item);
|
|||
|
this.Children.Add(this.TitleView = new ChartTitle(this));
|
|||
|
this.Children.Add(this.PrimaryLegend = this.CreateChartLegend(LegendType.PrimaryLegend));
|
|||
|
}
|
|||
|
|
|||
|
public override Size GetPreferredSize()
|
|||
|
{
|
|||
|
float num = 400f;
|
|||
|
float num2 = 260f;
|
|||
|
return new Size(ref num, ref num2);
|
|||
|
}
|
|||
|
|
|||
|
public override void OnBoundsChanged(Rect oldRect)
|
|||
|
{
|
|||
|
base.OnBoundsChanged(oldRect);
|
|||
|
this.layoutDirty = true;
|
|||
|
}
|
|||
|
|
|||
|
internal void DirtyLayout()
|
|||
|
{
|
|||
|
this.layoutDirty = true;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void UpdateLayout()
|
|||
|
{
|
|||
|
Rect clientBounds = this.ClientBounds;
|
|||
|
Rect titleBounds = this.GetTitleBounds();
|
|||
|
float x = clientBounds.X;
|
|||
|
float num = titleBounds.Bottom + 20f;
|
|||
|
float width = clientBounds.Width;
|
|||
|
float num2 = clientBounds.Height - titleBounds.Bottom - 20f;
|
|||
|
Rect rect = new Rect(ref x, ref num, ref width, ref num2);
|
|||
|
bool flag = this.showLegend;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
Size size = default(Size);
|
|||
|
bool flag2 = this.PrimaryLegend != null;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
this.PrimaryLegend.MeasureSize(clientBounds);
|
|||
|
this.PrimaryLegend.Bounds = this.GetLegendBounds(rect, LegendType.PrimaryLegend, this.PrimaryLegend.LegendPosition);
|
|||
|
size = this.PrimaryLegend.Size;
|
|||
|
switch (this.PrimaryLegend.LegendPosition)
|
|||
|
{
|
|||
|
case LegendPosition.Bottom:
|
|||
|
rect.Height -= size.Height + 10f;
|
|||
|
goto IL_15A;
|
|||
|
case LegendPosition.Left:
|
|||
|
rect.X += size.Width + 10f;
|
|||
|
goto IL_15A;
|
|||
|
case LegendPosition.Top:
|
|||
|
rect.Y += size.Height + 10f;
|
|||
|
goto IL_15A;
|
|||
|
}
|
|||
|
rect.Width -= size.Width + 10f;
|
|||
|
IL_15A:;
|
|||
|
}
|
|||
|
}
|
|||
|
bool flag3 = this.PlotViewContainer != null;
|
|||
|
if (flag3)
|
|||
|
{
|
|||
|
this.PlotViewContainer.Bounds = this.GetPlotViewBounds(rect);
|
|||
|
}
|
|||
|
bool flag4 = this.TitleView != null;
|
|||
|
if (flag4)
|
|||
|
{
|
|||
|
this.TitleView.Bounds = titleBounds;
|
|||
|
}
|
|||
|
this.layoutDirty = false;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual Rect GetTitleBounds()
|
|||
|
{
|
|||
|
Rect clientBounds = this.ClientBounds;
|
|||
|
clientBounds.Height = 30f;
|
|||
|
return clientBounds;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual Rect GetPlotViewBounds(Rect bodyBounds)
|
|||
|
{
|
|||
|
return bodyBounds;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual Rect GetLegendBounds(Rect plotViewBounds, LegendType type, LegendPosition position)
|
|||
|
{
|
|||
|
bool flag = !this.showLegend;
|
|||
|
Rect result;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
float num = 0f;
|
|||
|
float num2 = 0f;
|
|||
|
float num3 = 0f;
|
|||
|
float num4 = 0f;
|
|||
|
result = new Rect(ref num, ref num2, ref num3, ref num4);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Rect clientBounds = this.ClientBounds;
|
|||
|
Size size = default(Size);
|
|||
|
if (type != LegendType.PrimaryLegend)
|
|||
|
{
|
|||
|
}
|
|||
|
size = this.PrimaryLegend.GetPreferredSize();
|
|||
|
float num;
|
|||
|
float num2;
|
|||
|
float num3;
|
|||
|
float num4;
|
|||
|
switch (position)
|
|||
|
{
|
|||
|
case LegendPosition.Bottom:
|
|||
|
num = plotViewBounds.X + (plotViewBounds.Width - size.Width) / 2f;
|
|||
|
num2 = plotViewBounds.Bottom - size.Height;
|
|||
|
num3 = size.Width;
|
|||
|
num4 = size.Height;
|
|||
|
return new Rect(ref num, ref num2, ref num3, ref num4);
|
|||
|
case LegendPosition.Left:
|
|||
|
num = 0f;
|
|||
|
num2 = plotViewBounds.Y + (plotViewBounds.Height - size.Height) / 2f;
|
|||
|
num3 = size.Width;
|
|||
|
num4 = size.Height;
|
|||
|
return new Rect(ref num, ref num2, ref num3, ref num4);
|
|||
|
case LegendPosition.Top:
|
|||
|
num = plotViewBounds.X + (plotViewBounds.Width - size.Width) / 2f;
|
|||
|
num2 = 0f;
|
|||
|
num3 = size.Width;
|
|||
|
num4 = size.Height;
|
|||
|
return new Rect(ref num, ref num2, ref num3, ref num4);
|
|||
|
}
|
|||
|
num = clientBounds.Right - size.Width;
|
|||
|
num2 = plotViewBounds.Y + (plotViewBounds.Height - size.Height) / 2f;
|
|||
|
num3 = size.Width;
|
|||
|
num4 = size.Height;
|
|||
|
result = new Rect(ref num, ref num2, ref num3, ref num4);
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnPaint(RDrawingContext dc)
|
|||
|
{
|
|||
|
bool flag = this.layoutDirty;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.UpdateLayout();
|
|||
|
}
|
|||
|
base.OnPaint(dc);
|
|||
|
}
|
|||
|
|
|||
|
public virtual WorksheetChartDataSource DataSource
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return this.dataSource;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
bool flag = this.dataSource != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.dataSource.DataChanged -= this.dataSource_DataChanged;
|
|||
|
}
|
|||
|
this.dataSource = value;
|
|||
|
bool flag2 = this.dataSource != null;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
this.dataSource.DataChanged += this.dataSource_DataChanged;
|
|||
|
}
|
|||
|
this.ResetDataSerialStyles();
|
|||
|
this.OnDataSourceChanged();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void dataSource_DataChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.OnDataChanged();
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void OnDataChanged()
|
|||
|
{
|
|||
|
this.UpdatePlotData();
|
|||
|
this.UpdateLayout();
|
|||
|
bool flag = this.ChartDataChanged != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.ChartDataChanged(this, null);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|||
|
public event EventHandler ChartDataChanged;
|
|||
|
|
|||
|
protected virtual void OnDataSourceChanged()
|
|||
|
{
|
|||
|
this.UpdatePlotData();
|
|||
|
this.UpdateLayout();
|
|||
|
bool flag = this.DataSourceChanged != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.DataSourceChanged(this, null);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|||
|
public event EventHandler DataSourceChanged;
|
|||
|
|
|||
|
protected virtual void UpdatePlotData()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public virtual IDrawingContainer PlotViewContainer { get; private set; }
|
|||
|
|
|||
|
protected virtual void AddPlotViewLayer(IPlotView view)
|
|||
|
{
|
|||
|
bool flag = this.PlotViewContainer != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
view.Bounds = this.PlotViewContainer.ClientBounds;
|
|||
|
this.PlotViewContainer.Children.Add(view);
|
|||
|
}
|
|||
|
this.Invalidate();
|
|||
|
}
|
|||
|
|
|||
|
public bool ShowLegend
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return this.showLegend;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
bool flag = this.showLegend != value;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.showLegend = value;
|
|||
|
bool flag2 = this.PrimaryLegend != null;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
this.PrimaryLegend.Visible = value;
|
|||
|
}
|
|||
|
this.DirtyLayout();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public virtual ChartLegend PrimaryLegend { get; set; }
|
|||
|
|
|||
|
protected virtual ChartLegend CreateChartLegend(LegendType type)
|
|||
|
{
|
|||
|
return new ChartLegend(this);
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void ResetDataSerialStyles()
|
|||
|
{
|
|||
|
WorksheetChartDataSource worksheetChartDataSource = this.dataSource;
|
|||
|
bool flag = worksheetChartDataSource == null;
|
|||
|
if (!flag)
|
|||
|
{
|
|||
|
int serialCount = this.dataSource.SerialCount;
|
|||
|
bool flag2 = this.dataSource == null || serialCount <= 0;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
this.serialStyles.Clear();
|
|||
|
}
|
|||
|
while (this.serialStyles.Count < serialCount)
|
|||
|
{
|
|||
|
this.serialStyles.Add(new DataSerialStyle(this)
|
|||
|
{
|
|||
|
FillColor = ChartUtility.GetDefaultDataSerialFillColor(this.serialStyles.Count),
|
|||
|
LineColor = ChartUtility.GetDefaultDataSerialFillColor(this.serialStyles.Count),
|
|||
|
LineWidth = 2f
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public virtual DataSerialStyleCollection DataSerialStyles
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
bool flag = this.dataSerialStyleCollection == null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.dataSerialStyleCollection = new DataSerialStyleCollection(this);
|
|||
|
}
|
|||
|
return this.dataSerialStyleCollection;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnMouseDown(Point location, MouseButtons button, InputModifiers modifiers)
|
|||
|
{
|
|||
|
return base.OnMouseDown(location, button, modifiers);
|
|||
|
}
|
|||
|
|
|||
|
private bool layoutDirty = true;
|
|||
|
|
|||
|
private WorksheetChartDataSource dataSource;
|
|||
|
|
|||
|
private bool showLegend = true;
|
|||
|
|
|||
|
internal List<DataSerialStyle> serialStyles = new List<DataSerialStyle>();
|
|||
|
|
|||
|
private DataSerialStyleCollection dataSerialStyleCollection = null;
|
|||
|
}
|
|||
|
}
|