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 PlotAreasVertical : UserControl
    {
        public PlotAreasVertical()
        {
            this.InitializeComponent();

            NewData();

            // add panning interation by touch
            chart.GestureSlide = GestureSlideAction.Translate;
            chart.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia;
            chart.ActionUpdateDelay = 0;
        }

        void NewData()
        {
            chart.BeginUpdate();

            chart.View.AxisX.ScrollBar = new AxisScrollBar();
            chart.View.AxisX.Scale = 0.25;

            chart.View.AxisX.Title = "Time";

            chart.View.AxisY.PlotAreaIndex = 1;
            chart.View.AxisY.Title = "Price";

            //chart.View.PlotBackground = new SolidColorBrush(Colors.White);

            chart.View.PlotAreas.Add(new PlotArea()
            {
                Row = 1,
                //        Stroke = new SolidColorBrush(Colors.DarkGray),
                //       StrokeThickness = 0.5,
                      Background = new SolidColorBrush(Colors.White) { Opacity = 0.8 }
            });
            chart.View.PlotAreas.Add(new PlotArea()
            {
                Row = 0,
                //       Stroke = new SolidColorBrush(Colors.DarkGray),
                //        StrokeThickness = 0.5,
                        Background = new SolidColorBrush(Colors.White) { Opacity = 0.3 }
            });

            chart.View.PlotAreas.RowDefinitions.Add(
              new PlotAreaRowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
            chart.View.PlotAreas.RowDefinitions.Add(
              new PlotAreaRowDefinition() { Height = new GridLength(2, GridUnitType.Star) });

            chart.Data.Children.Add(
              new HighLowOpenCloseSeries()
              {
                  Label = "Price",
                  XValueBinding = new Binding() { Path = new PropertyPath("Time") },
                  HighValueBinding = new Binding() { Path = new PropertyPath("High") },
                  LowValueBinding = new Binding() { Path = new PropertyPath("Low") },
                  OpenValueBinding = new Binding() { Path = new PropertyPath("Open") },
                  CloseValueBinding = new Binding() { Path = new PropertyPath("Close") },
                  //          SymbolFill = new SolidColorBrush(Colors.Blue),
                  //          SymbolStroke = new SolidColorBrush(Colors.Blue)
              });

            chart.Data.Children.Add(
              new XYDataSeries()
              {
                  Label = "Volume",
                  AxisY = "Volume",
                  XValueBinding = new Binding() { Path = new PropertyPath("Time") },
                  ValueBinding = new Binding() { Path = new PropertyPath("Volume") },
                  ChartType = ChartType.Column,
                  //          SymbolFill = new SolidColorBrush(Colors.Green)
              });

            chart.View.Axes.Add(new Axis()
            {
                AxisType = AxisType.Y,
                Name = "Volume",
                Title = "Volume",
                PlotAreaIndex = 0,
                MajorGridStroke = chart.View.AxisY.MajorGridStroke
            });

            chart.View.PlotAreas.Add(new PlotArea());

            chart.Data.ItemsSource = SampleFinancialData.Create(60);

            chart.ChartType = ChartType.Candle;
            chart.EndUpdate();
        }

    }
}
