using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

using C1.Xaml.Chart;

namespace ChartSamples
{
  public sealed partial class ComplexChart : UserControl
  {
    Random rnd = new Random();
//    Brush[] brushes = new Brush[]
//    {
//      new SolidColorBrush(Color.FromArgb(255, 21, 72, 123) ),
//      CreateBrush( Color.FromArgb(255, 21, 72, 123) ),
//      new SolidColorBrush(Color.FromArgb(255, 239, 239, 231)),
//      CreateBrush( Color.FromArgb(255, 239, 239, 231)),
//      new SolidColorBrush(Color.FromArgb(255, 74, 130, 189)),
//      CreateBrush( Color.FromArgb(255, 74, 130, 189)),
//      new SolidColorBrush(Color.FromArgb(255, 198, 80, 74)),
//      CreateBrush( Color.FromArgb(255, 198, 80, 74)),
//      new SolidColorBrush(Color.FromArgb(255, 156, 186, 90)),
//      CreateBrush( Color.FromArgb(255, 156, 186, 90)),
//    };

    public ComplexChart()
    {
      this.InitializeComponent();

      chart.Data.ItemNames = new string[] { "Cat.1", "Cat.2", "Cat.3", "Cat.4", "Cat.5" };
      CreateData();
    }

    void CreateData()
    {
      chart.Data.Children.Clear();

      for (int i = 0; i < 10; i++)
      {
        DataSeries ds = new DataSeries() { ValuesSource = CreateRandomArray(5), Label = "series " + i };
//        ds.SymbolFill = brushes[i];

        BarColumnOptions.SetStackGroup(ds, i % 2);
        chart.Data.Children.Add(ds);
      }

      chart.Data.Children.Add(new DataSeries()
      {
        ChartType = ChartType.LineSymbols,
        ValuesSource = CreateRandomArray(5),
        ConnectionStrokeThickness = 5,
        Label = "series 10"
//        ConnectionStroke = new SolidColorBrush(Colors.Red)
      });
    }

    double[] CreateRandomArray(int cnt)
    {
      double[] vals = new double[cnt];

      for (int i = 0; i < cnt; i++)
        vals[i] = rnd.Next(10, 100);

      return vals;
    }

//    static LinearGradientBrush CreateBrush(Color clr)
//    {
//      LinearGradientBrush lgb = new LinearGradientBrush()
//      {
//        EndPoint = new Point(2, 2),
//        MappingMode = BrushMappingMode.Absolute,
//        SpreadMethod = GradientSpreadMethod.Reflect
//      };
//      lgb.GradientStops = new GradientStopCollection()
//      {
//        new GradientStop() { Color= clr, Offset = 0},
//        new GradientStop() { Color= Color.FromArgb(64,255,255,255), Offset = 1},
//      };

//      return lgb;
//    }
  }
}
