using System;
using Core.Components.OxyPlot.Data;
using Core.Components.OxyPlot.Properties;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.WindowsForms;
namespace Core.Components.OxyPlot.Forms
{
public sealed class BaseChart : PlotView
{
private LinearAxis xAxis;
private LinearAxis yAxis;
///
/// Creates a new instance of .
///
public BaseChart()
{
Model = new PlotModel();
InitializeAxes();
InitializeDefaultStyle();
MinimumSize = new System.Drawing.Size(50, 75);
}
///
/// Sets the default look and feel of the
///
private void InitializeDefaultStyle()
{
xAxis.MajorGridlineStyle = LineStyle.Solid;
xAxis.MinorGridlineStyle = LineStyle.Dot;
yAxis.MajorGridlineStyle = LineStyle.Solid;
yAxis.MinorGridlineStyle = LineStyle.Dot;
}
///
/// Sets up default axes representations.
///
private void InitializeAxes()
{
xAxis = new LinearAxis
{
Title = Resources.BaseChart_XAxisTitle,
Position = AxisPosition.Bottom,
TickStyle = TickStyle.None,
ExtraGridlines = new[] { 0.0 },
ExtraGridlineThickness = 1,
Layer = AxisLayer.AboveSeries
};
yAxis = new LinearAxis
{
Title = Resources.BaseChart_YAxisTitle,
TickStyle = TickStyle.None,
ExtraGridlines = new[] { 0.0 },
ExtraGridlineThickness = 1,
Layer = AxisLayer.AboveSeries
};
Model.Axes.Add(xAxis);
Model.Axes.Add(yAxis);
}
///
/// Add to the .
///
/// The data to add to the .
/// Thrown when is null.
public void AddData(IChartData data)
{
if (data == null)
{
throw new ArgumentNullException("data", "Cannot add null data to the chart.");
}
data.AddTo(Model);
}
///
/// Remove all the that has been added to the .
///
public void ClearData()
{
Model.Series.Clear();
}
///
/// Sets the visibility of a series in this .
///
/// The to set the visibility for.
/// A boolean value representing the new visibility of the .
public void SetVisibility(IChartData series, bool visibility)
{
var chartData = series as Series;
if (chartData != null)
{
chartData.IsVisible = visibility;
Invalidate();
}
else
{
throw new ArgumentException("Visibility set for IChartData which was not of type Series.");
}
}
}
}