using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace RealTimeGraphX.Renderers
{
///
/// Represents a scrolling style .
///
/// The type of the data series.
///
public class ScrollingLineRenderer : GraphRenderer where TDataSeries : IGraphDataSeries
{
///
/// 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 override IEnumerable Render(IGraphSurface surface, TDataSeries series, IGraphRange range, List xx, List yy, GraphDataPoint minimumX, GraphDataPoint maximumX, GraphDataPoint minimumY, GraphDataPoint maximumY)
{
var dxList = xx.Select(x => x.ComputeRelativePosition(minimumX, maximumX)).ToList();
var dyList = yy.Select(x => x.ComputeRelativePosition(minimumY, maximumY)).ToList();
if (maximumX - minimumX > range.MaximumX)
{
var offset = ((maximumX - minimumX) - range.MaximumX) + minimumX;
for (int i = 0; i < xx.Count; i++)
{
if (xx[i] < offset)
{
xx.RemoveAt(i);
yy.RemoveAt(i);
i--;
}
else
{
break;
}
}
}
List points = new List();
for (int i = 0; i < dxList.Count; i++)
{
float image_x = ConvertXValueToRendererValue(surface,dxList[i]);
float image_y = (float)Math.Min(ConvertYValueToRendererValue(surface, dyList[i]), surface.GetSize().Height - 2);
PointF point = new PointF(image_x, image_y);
points.Add(point);
}
return points;
}
///
/// 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 override void Draw(IGraphSurface surface, TDataSeries series, IEnumerable points, int index, int count)
{
if (series.UseFill)
{
surface.FillSeries(series, GetFillPoints(surface, points));
}
surface.DrawSeries(series, GetFillPoints(surface, points));
}
}
}