using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace TChart.ImageChart
{
    /// <summary>
    /// 线条图
    /// </summary>
    /// <remarks>
    /// 作者: Kingthy 
    /// 日期: 2007-09-11
    /// MSN:  Kingthy@gmail.com
    /// 转载请注明原作者,当你有更新修改时如果方便的希望能发一份给我.谢谢
    /// </remarks>
    public class LinePainter : MovementPainterBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="image"></param>
        public LinePainter(MovementImage image)
            : base(image)
        {
        }
        #region 实现父级方法
        /// <summary>
        /// 画值
        /// </summary>
        /// <param name="graphics">画布</param>
        /// <param name="xAxes">X轴数据</param>
        public override void DrawValue(System.Drawing.Graphics graphics, XAxisItemList xAxes)
        {
            int tmpXSpaceWidth;
            //tmpXSpaceWidth = Image.XSpaceWidth;
            tmpXSpaceWidth = Image.Xspace;
            //第一个X轴的起始点            
            Point p1 = new Point(tmpXSpaceWidth, Image.Height - Image.YSpaceWidth);
            Point p2 = new Point(tmpXSpaceWidth, 0);

            StringFormat format = new StringFormat
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            for (int i = 0; i < xAxes.Count; i++)
            {
                XAxisItem item = xAxes[i];
                //取得当前值的坐标
                p2.X += Image.XSpaceWidth;
                p2.Y = this.GetYPosition(item.Value);
                if (p2.Y < 0) p2.Y = 0;
                //画线(去掉第1点)
                if(i != 0)graphics.DrawLine(new Pen(item.DrawColor), p1, p2);

                //画值
                if (item.ValueVisible)
                {
                    //位置在 起始点的上方
                    graphics.DrawString(item.Value.ToString(), item.ValueFont, new SolidBrush(item.ValueColor), p2.X, p2.Y - this.Image.YSpaceWidth / 4, format);
                }

                //第一点往前移
                p1.X = p2.X;
                p1.Y = p2.Y;
            }
        }
        #endregion
    }
}
