using System;

using DevExpress.Xpf.Charts;

namespace BeWo.View.Report.FLSReport
{
    public partial class FLSOverviewChart
    {
        public FLSOverviewChart()
        {
            this.InitializeComponent();
        }

        public void InitChart(FLSOverviewDetailRow row)
        {
            double soll = Decimal.ToDouble(row.SollFLS);
            double maxValue = soll;
            double minValue = 0;

            foreach (FLSOverviewDateValue val in row.DateValues)
            {
                if (val.HeaderValue != null)
                {
                    // SeriesPoint pointSoll = new SeriesPoint(val.HeaderValue, 0);
                    SeriesPoint pointSoll = new SeriesPoint(val.HeaderValue, soll);
                    double dval = 0;

                    if (Double.TryParse(val.DateValueText, out dval))
                    {
                        // dval = dval - soll;
                        if (dval > maxValue)
                        {
                            maxValue = dval;
                        }

                        if (dval < minValue)
                        {
                            minValue = dval;
                        }
                    }

                    SeriesPoint pointIst = new SeriesPoint(val.HeaderValue, dval);
                    this.seriesSoll.Points.Add(pointSoll);
                    this.seriesIst.Points.Add(pointIst);
                }
            }

            maxValue = Math.Ceiling(maxValue);
            minValue = Math.Floor(minValue);

            maxValue++;

            minValue--;

            if (minValue >= maxValue)
            {
                minValue = maxValue - 1;
            }

            if (maxValue == 0)
            {
                maxValue = 1;
            }

            (this.chart.Diagram as XYDiagram2D).AxisY.Range.MaxValue = maxValue;

            // (chart.Diagram as XYDiagram2D).AxisX.Range.SideMarginsEnabled = true;
            // (chart.Diagram as XYDiagram2D).AxisY.Range.MinValue = minValue;
        }

        private void CreateSeriesPoints()
        {
            // <dxc:AreaSeries.Points>
            // <dxc:SeriesPoint Argument="01.06." Value="4.5" />
            // <dxc:SeriesPoint Argument="02.06." Value="3"/>
            // <dxc:SeriesPoint Argument="03.06." Value="1"/>
            // <dxc:SeriesPoint Argument="04.06." Value="6"/>
            // <dxc:SeriesPoint Argument="05.06." Value="7"/>
            // <dxc:SeriesPoint Argument="06.06." Value="5"/>
            // <dxc:SeriesPoint Argument="07.06." Value="4"/>
            // <dxc:SeriesPoint Argument="08.06." Value="7"/>
            // <dxc:SeriesPoint Argument="09.06." Value="2"/>
            // <dxc:SeriesPoint Argument="10.06." Value="4"/>
            // <dxc:SeriesPoint Argument="11.06." Value="3"/>
            // <dxc:SeriesPoint Argument="12.06." Value="4.5"/>
            // <dxc:SeriesPoint Argument="13.06." Value="4"/>
            // <dxc:SeriesPoint Argument="14.06." Value="2"/>
            // </dxc:AreaSeries.Points>
        }
    }
}