using System;
using System.Collections.Generic;
using System.Text;

using System.Drawing;

namespace Chart
{
    public class SimpleSeriesPainter : ISeriesPainter
    {

        #region Fields

        protected Color color;

        protected ChartPerformer performer;

        protected double[,] dSize = new double[2, 2];

        protected int[] pointStart = new int[2];
        protected int[] pointFinish = new int[2];

        protected Pen pen;// = new Pen(Color.Black);


        #endregion

        #region Constructors
   
        public SimpleSeriesPainter(ChartPerformer performer, Color color)
        {
            this.performer = performer;
            this.color = color;
            pen = new Pen(color);
        }

        #endregion

        #region ISeriesPainter Members

        public virtual void Draw(ISeries series, Graphics g)
 		{
            IList<IPoint> points = series.Points;
			if (points.Count < 2)
			{
				return;
			}
			IPoint xx = points[0];
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 2; j++)
				{
					dSize[i, j] = performer[i, j];
				}
			}
			if ((dSize[0, 1] == dSize[1, 1]) | (dSize[0, 0] == dSize[1, 0]))
			{
				return;
			}
			int[] size = performer.CanvasSize;
			performer.Transform(xx.X, xx.Y, pointStart);
			for (int i = 1; i < points.Count; i++)
			{
				xx = points[i];
				performer.Transform(xx.X, xx.Y, pointFinish);
				int dx = Math.Abs(pointStart[0] - pointFinish[0]);
				int dy = Math.Abs(pointStart[1] - pointFinish[1]);
				if ((dx < performer.StepX) | (dy < performer.StepY))
				{
					continue;
				}
				g.DrawLine(pen, pointStart[0], pointStart[1], pointFinish[0], pointFinish[1]);
				pointStart[0] = pointFinish[0];
				pointStart[1] = pointFinish[1];
			}		
		}

        #endregion
    }
}