using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace SnimaceStisku
{
    class FlowGraphData
    {
        Point[] FHodnoty = null;
        Point FZeroPoint;
        Int32 FMinValue;
        Int32 FMaxValue;
        Int32 FDrawHeight;
        Brush FColor;

        public FlowGraphData(Point ZeroPoint, Int32 MinValue, Int32 MaxValue, Int32 DrawHeight, Int32 DrawWidth, Brush Color)
        {
            FZeroPoint = new Point(ZeroPoint.X, ZeroPoint.Y);
            FMinValue = MinValue;
            FMaxValue = MaxValue;
            FDrawHeight = DrawHeight;
            FColor = Color;
            FHodnoty = new Point[DrawWidth];
            Clear();
        }

        public void AddValue(Int32 Value)
        {
            Int32 i = 0;
            for (i = 0; i < FHodnoty.Length - 1; i++)
            {
                FHodnoty.SetValue(new Point(FHodnoty[i + 1].X - 1, FHodnoty[i + 1].Y), i);
            }
            if (Value > FMaxValue) FHodnoty[FHodnoty.Length - 1] = new Point(FZeroPoint.X + FHodnoty.Length - 1, FZeroPoint.Y - FDrawHeight);
            else if (Value < FMinValue) FHodnoty[FHodnoty.Length - 1] = new Point(FZeroPoint.X + FHodnoty.Length - 1, FZeroPoint.Y);
            else FHodnoty[FHodnoty.Length - 1] = new Point(FZeroPoint.X + FHodnoty.Length - 1, FZeroPoint.Y - (Int32)Math.Round(FDrawHeight / (Double)(FMaxValue - FMinValue) * Value));
        }

        public void Clear()
        {
            Int32 i = 0;
            for (i = 0; i < FHodnoty.Length; i++)
                FHodnoty[i] = new Point(FZeroPoint.X + i, FZeroPoint.Y);
        }

        public void Resize(Int32 DrawHeight)
        {
            FHodnoty = new Point[DrawHeight];
            Clear();
        }

        public Point[] Data
        {
            get
            {
                return FHodnoty;
            }
        }

        public Brush Color
        {
            get
            {
                return FColor;
            }
            set
            {
                FColor = value;
            }
        }
    }
}
