using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using C1.Win.Chart;
using System.Drawing.Drawing2D;

namespace FlexChartExplorer.Samples
{
    public partial class Waterfall : UserControl
    {
        C1.Win.Chart.Waterfall waterfall;

        public Waterfall()
        {
            InitializeComponent();
            InitializeControls();

            SetupChart();
        }

        void SetupChart()
        {
            flexChart1.BeginUpdate();

            flexChart1.Series.Clear();

            var rnd = new Random();
            var items = new List<object>();
            string[] names = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
            foreach (var name in names)
            {
                items.Add(new 
                {
                    Name = name,
                    Value = Math.Round((0.5 - rnd.NextDouble()) * 1000)
                });
            }

            waterfall = new C1.Win.Chart.Waterfall() { Name = "Increase, Decrease, Total" };
            waterfall.Start = 100;
            waterfall.IntermediateTotalLabels = new List<string> { "Q1", "Q2", "Q3", "Q4"};
            waterfall.IntermediateTotalPositions = new List<int> { 3, 6, 9, 12 };

            waterfall.StartStyle.FillColor = Color.FromArgb(unchecked((int)0xff7dc7ed));
            waterfall.FallingStyle.FillColor = Color.FromArgb(unchecked((int)0xffdd2714));
            waterfall.RisingStyle.FillColor = Color.FromArgb(unchecked((int)0xff0f9d58));
            waterfall.RisingStyle.StrokeColor = Color.FromArgb(unchecked((int)0xff0f9d58));
            waterfall.IntermediateTotalStyle.FillColor = Color.FromArgb(unchecked((int)0xff7dc7ed));
            waterfall.TotalStyle.FillColor = Color.FromArgb(unchecked((int)0xff7dc7ed));
            waterfall.ConnectorLineStyle.StrokeColor = Color.FromArgb(unchecked((int)0xff030303));
            waterfall.ConnectorLineStyle.StrokeDashPattern = new float[] { 3,3 };
            waterfall.ConnectorLineStyle.StrokeWidth = 2;

            flexChart1.Series.Add(waterfall);

            flexChart1.BindingX = "Name";
            flexChart1.Binding = "Value";
            flexChart1.DataSource = items;

            flexChart1.EndUpdate();
        }

        private void InitializeControls()
        {

            #region Init controls

            //Set localized text
            baseSample1.lblTitle.Text = Localizer.GetItem("waterfall", "title");
            baseSample1.tbDescription.Rtf = Localizer.GetItem("waterfall", "description").MakeRtf();

            flexChart1 = baseSample1.flexChart1;

            var checkBox1 = new CheckBox()
            {
                Text = "Relative Data",
                FlatStyle = FlatStyle.Flat,
                Checked = false,
                AutoSize = true
            };
            checkBox1.CheckedChanged += (s, e) => waterfall.RelativeData = checkBox1.Checked;

            var checkBox2 = new CheckBox()
            {
                Text = "Connector Lines",
                FlatStyle = FlatStyle.Flat,
                Checked = false,
                AutoSize = true
            };
            checkBox2.CheckedChanged += (s, e) => waterfall.ConnectorLines = checkBox2.Checked;

            var checkBox3 = new CheckBox()
            {
                Text = "Show Totals",
                FlatStyle = FlatStyle.Flat,
                Checked = false,
                AutoSize = true
            };
            checkBox3.CheckedChanged += (s, e) => waterfall.ShowTotal = checkBox3.Checked;

            var checkBox4 = new CheckBox()
            {
                Text = "Show Intermediate Totals",
                FlatStyle = FlatStyle.Flat,
                Checked = false,
                AutoSize = true
            };
            checkBox4.CheckedChanged += (s, e) => waterfall.ShowIntermediateTotal = checkBox4.Checked;

            baseSample1.pControls.Controls.Add(checkBox1);
            baseSample1.pControls.Controls.Add(checkBox2);
            baseSample1.pControls.Controls.Add(checkBox3);
            baseSample1.pControls.Controls.Add(checkBox4);
            #endregion
        }
    }
}
