using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using C1.Silverlight.Chart;

namespace AxisAggregation
{
  public partial class CategoryAxis2 : UserControl
  {
    public CategoryAxis2()
    {
      InitializeComponent();
      AggregateByRange();
    }

    void AggregateByRange()
    {
      var keys = new string[] { "<4", "4-8", ">8" };

      for (int i = 0; i < 3; i++)
      {
        var ds = new DataSeries()
        {
          ItemsSource = SampleItem.CreateSampleData(100),
          ValueBinding = new Binding("Value"),
          Aggregate = Aggregate.Count,
          Label = "s" + i,
          AggregateGroupSelector = RangeSelector
        };
        chart.Data.Children.Add(ds);
      }

      chart.Data.ItemNames = keys;
    }

    double RangeSelector(double x, double y, object o)
    {
      var sample = (SampleItem)o;
      if (sample.Value < 4)
        return 0;
      else if (sample.Value <= 8)
        return 1;
      else
        return 2;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      chart.Data.Children.Clear();
      AggregateByRange();
    }
  }
}
