using C1.Xaml.Chart;
using System;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;


namespace ControlExplorer.Controls.Chart
{
    public partial class LoadAnimation : UserControl
    {
        Random rnd = new Random();
        ChartType[] chartTypes = new ChartType[] 
      { 
        ChartType.Column, ChartType.ColumnStacked, ChartType.Bar, ChartType.BarStacked,
        ChartType.AreaStacked, ChartType.StepArea,
        ChartType.LineSymbols, ChartType.XYPlot, ChartType.Pie, ChartType.PieExplodedDoughnut
      };


        public LoadAnimation()
        {
            InitializeComponent();

            NewData();
            chart.Tapped += (s, e) => NewData();
        }

        void NewData()
        {
            chart.BeginUpdate();

            //chart.Data.LoadAnimation = AnimationHelper.CreateAnimation(
            //    (AnimationTransform)rnd.Next(0, 2),
            //    (AnimationOrigin)rnd.Next(0, 2),
            //    (Easing)rnd.Next(0, 12),
            //    true
            //  );

            int nser = rnd.Next(2, 4);
            int npts = rnd.Next(4, 8);

            chart.Data.Children.Clear();
            for (int i = 0; i < nser; i++)
                chart.Data.Children.Add(CreateDataSeries(npts));

            chart.ChartType = chartTypes[rnd.Next(0, chartTypes.Length)];
            chart.EndUpdate();
        }

        public DataSeries CreateDataSeries(int npts, bool invert = false)
        {
            var ds = new XYDataSeries() { SymbolSize = new Size(20, 20) };

            int cnt = npts;
            var x = new double[cnt];
            var y = new double[cnt];

            for (int i = 0; i < cnt; i++)
            {
                x[i] = i; y[i] = rnd.NextDouble();
            }

            if (invert)
            {
                ds.XValuesSource = y; ds.ValuesSource = x;
            }
            else
            {
                ds.XValuesSource = x; ds.ValuesSource = y;
            }
            return ds;
        }
    }
}
