using C1.Xaml.Sparkline;
using System;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ControlExplorer.Controls.Sparkline
{
    public sealed partial class SparklineSample : UserControl
    {
        private SampleData sampleData = new SampleData();
        Random rnd = new Random();

        public SparklineSample()
        {
            this.InitializeComponent();
            sparklineType.ItemsSource = Enum.GetValues(typeof(SparklineType));
            sparklineType.SelectedItem = sparkline.SparklineType;
            sparkline.Data = sampleData.DefaultData;
            sparkline.SeriesColor = Colors.MediumPurple;
            sparkline.ShowHigh = true;
            sparkline.ShowLow = true;
        }

        private void sparklineType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.SparklineType = (SparklineType)sparklineType.SelectedItem;
        }

        private void checkBox_Click(object sender, RoutedEventArgs e)
        {
            if (checkBox.IsChecked.Value)
            {
                sparkline.DateAxisData = sampleData.DefaultDateAxisData;
                sparkline.DisplayXAxis = true;
            }
            else if (sparkline.DateAxisData != null)
            {
                sparkline.DisplayXAxis = false;
                sparkline.DateAxisData = null;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int cnt = 12;
            double[] vals = new double[cnt];
            for (int i = 0; i < cnt; i++)
            {
                vals[i] = rnd.Next(-50, 50);
            }
            sparkline.Data = vals;
        }
    }
}
