using System.Collections.Generic;
using System.Linq;
using System.Drawing;
namespace RealTimeGraphX
{
///
/// Represents an base class.
///
/// The type of the data series.
///
///
public abstract class GraphRenderer : GraphObject, IGraphRenderer where TDataSeries : IGraphDataSeries
{
///
/// Converts the specified relative x position to a graph surface absolute position.
///
/// The target surface.
/// The relative x position.
///
protected virtual float ConvertXValueToRendererValue(IGraphSurface surface, double x)
{
return (float)(x * surface.GetSize().Width / 100);
}
///
/// Converts the specified relative y position to a graph surface absolute position.
///
/// The surface.
/// The relative y position.
///
protected virtual float ConvertYValueToRendererValue(IGraphSurface surface, double y)
{
return (float)(surface.GetSize().Height - (y * surface.GetSize().Height / 100));
}
///
/// Arranges the series of data points and returns a series of drawing points.
///
/// The target graph surface.
/// The instance of the current rendered data series.
/// Instance of graph range.
/// Collection of x coordinates.
/// Collection of y coordinates.
/// The minimum x coordinates value.
/// The maximum x coordinates value.
/// The minimum y coordinates value.
/// The maximum y coordinates value.
///
public abstract IEnumerable Render(IGraphSurface surface, TDataSeries series, IGraphRange range, List xx, List yy, GraphDataPoint minimumX, GraphDataPoint maximumX, GraphDataPoint minimumY, GraphDataPoint maximumY);
///
/// Draws the specified data series points on the target surface.
///
/// The target graph surface.
/// The instance of the current rendered data series.
/// The collection of the current data series drawing points.
/// The index of the current data series within the collection of data series.
/// The length of the data series collection.
public abstract void Draw(IGraphSurface surface, TDataSeries series, IEnumerable points, int index, int count);
///
/// Gets a closed polygon version of the specified drawing points.
///
/// The target surface.
/// The drawing points.
///
protected virtual IEnumerable GetFillPoints(IGraphSurface surface, IEnumerable points)
{
List closed = points.ToList();
closed.Add(new PointF(points.Last().X, surface.GetSize().Width));
closed.Add(new PointF(0, surface.GetSize().Height));
return closed.ToArray();
}
}
}