using C1.Xaml.Chart;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace DrillDown
{
    public partial class ColumnPieSample : Page
    {
        private DrillDownViewModel _vm;
        public ColumnPieSample()
        {
            InitializeComponent();
            _vm = new DrillDownViewModel();
            this.DataContext = _vm;

            this.Loaded += (o, e) =>
            {
                cbAggregate.SelectedIndex = 0;
                cbChartTypes.SelectedIndex = 0;
            };

            this.barChart.Tapped += Chart_Tapped;
            this.pieChart.Tapped += Chart_Tapped;
        }

        private void Chart_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var flexChart = sender as FlexChartBase;
            var hitInfo = flexChart.HitTest(e.GetPosition(flexChart));
            if (hitInfo != null && hitInfo.Distance < 2)
            {
                _vm.DataLayer.DrillDown(hitInfo.PointIndex);
            }
        }
    }
}
