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;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace SalesDashboard
{
    public sealed partial class SalesByPartner : UserControl
    {
        SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb(255, 2, 186, 2));
        SolidColorBrush brush2 = new SolidColorBrush(Color.FromArgb(255, 2, 140, 186));
        SolidColorBrush brush3 = new SolidColorBrush(Color.FromArgb(255, 2, 78, 186));
        SolidColorBrush[] customPalette = new SolidColorBrush[3];

        public SalesByPartner()
        {
            this.InitializeComponent();
            
            // set custom palette
            customPalette[0] = brush1;
            customPalette[1] = brush2;
            customPalette[2] = brush3;
            c1Chart1.CustomPalette = customPalette;
        }

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            // chart settings
            c1Chart1.BeginUpdate();

            c1Chart1.Data.SelectionAction = C1.Xaml.Chart.SelectionAction.Tap;

            c1Chart1.View.AxisX.AxisLine = new Windows.UI.Xaml.Shapes.Line() { StrokeThickness = 0 };
            c1Chart1.View.AxisY.AxisLine = new Windows.UI.Xaml.Shapes.Line() { StrokeThickness = 0 };
            c1Chart1.View.AxisX.Foreground = new SolidColorBrush(Colors.Transparent);
            c1Chart1.View.AxisY.MajorGridStrokeThickness = 0;
            c1Chart1.View.AxisY.MinorGridStrokeThickness = 0;

            // hide tick marks
            c1Chart1.View.AxisX.MajorTickThickness = 0;
            c1Chart1.View.AxisX.MinorTickThickness = 0;
            c1Chart1.View.AxisY.MajorTickThickness = 0;
            c1Chart1.View.AxisY.MinorTickThickness = 0;
            
            c1Chart1.View.AxisY.FontSize = 16;
            c1Chart1.View.AxisY.Reversed = true;

            // set ItemNames in code because issue with XAML binding
            Data.SampleDataSource dataSource = this.DataContext as Data.SampleDataSource;
            if (dataSource != null)
            {
                // set data source to CollectionView for selection support
                c1Chart1.Data.ItemsSource = new C1.Xaml.C1CollectionView(dataSource.SalesByPartner);
                c1Chart1.Data.ItemNames = dataSource.Partners;
            }

            c1Chart1.EndUpdate();
        }
    }
}
