using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Temperature_chamber02
{
    /// <summary>
    /// Interaction logic for Graf.xaml
    /// </summary>
    public partial class Graf : Window
    {
        UInt16 refresh = 1;

        public Graf()
        {
            InitializeComponent();
            

            DispatcherTimer timer_aktualizace_graf = new DispatcherTimer();
            timer_aktualizace_graf.Interval = TimeSpan.FromSeconds(refresh);
            timer_aktualizace_graf.Tick += timer_graf_aktualizace_tick;
            timer_aktualizace_graf.Start();


            DispatcherTimer timer_aktualizace_pozice_na_graf = new DispatcherTimer();
            timer_aktualizace_pozice_na_graf.Interval = TimeSpan.FromMilliseconds(10);
            timer_aktualizace_pozice_na_graf.Tick += timer_aktualizace_pozice_na_graf_tick;
            timer_aktualizace_pozice_na_graf.Start();




            Line axisx = new Line();
            axisx.Stroke = System.Windows.Media.Brushes.Black;
            axisx.StrokeThickness = 1;
            axisx.X1 = 0;
            axisx.Y1 = 320;
            axisx.X2 = 600;
            axisx.Y2 = 320;
            canGraph.Children.Add(axisx);

            Line axisy = new Line();
            axisy.Stroke = System.Windows.Media.Brushes.Black;
            axisy.StrokeThickness = 1;
            axisy.X1 = 0;
            axisy.Y1 = 0;
            axisy.X2 = 0;
            axisy.Y2 = 320;
            canGraph.Children.Add(axisy);

            Line axisx2 = new Line();
            axisx2.Stroke = System.Windows.Media.Brushes.Black;
            axisx2.StrokeThickness = 1;
            axisx2.X1 = 0;
            axisx2.Y1 = 0;
            axisx2.X2 = 600;
            axisx2.Y2 = 0;
            canGraph.Children.Add(axisx2);

            Line axisy2 = new Line();
            axisy2.Stroke = System.Windows.Media.Brushes.Black;
            axisy2.StrokeThickness = 1;
            axisy2.X1 = 600;
            axisy2.Y1 = 0;
            axisy2.X2 = 600;
            axisy2.Y2 = 320;
            canGraph.Children.Add(axisy2);

            Line nul_axis = new Line();
            nul_axis.Stroke = System.Windows.Media.Brushes.Black;
            nul_axis.StrokeThickness = 1;
            nul_axis.X1 = 0;
            nul_axis.Y1 = 200;
            nul_axis.X2 = 10;
            nul_axis.Y2 = 200;
            canGraph.Children.Add(nul_axis);


            Line pade_axis = new Line();
            pade_axis.Stroke = System.Windows.Media.Brushes.Black;
            pade_axis.StrokeThickness = 1;
            pade_axis.X1 = 0;
            pade_axis.Y1 = 150;
            pade_axis.X2 = 10;
            pade_axis.Y2 = 150;
            canGraph.Children.Add(pade_axis);

            Line mi_pade_axis = new Line();
            mi_pade_axis.Stroke = System.Windows.Media.Brushes.Black;
            mi_pade_axis.StrokeThickness = 1;
            mi_pade_axis.X1 = 0;
            mi_pade_axis.Y1 = 250;
            mi_pade_axis.X2 = 10;
            mi_pade_axis.Y2 = 250;
            canGraph.Children.Add(mi_pade_axis);

            Line mi_sto_axis = new Line();
            mi_sto_axis.Stroke = System.Windows.Media.Brushes.Black;
            mi_sto_axis.StrokeThickness = 1;
            mi_sto_axis.X1 = 0;
            mi_sto_axis.Y1 = 300;
            mi_sto_axis.X2 = 10;
            mi_sto_axis.Y2 = 300;
            canGraph.Children.Add(mi_sto_axis);

            Line sto_axis = new Line();
            sto_axis.Stroke = System.Windows.Media.Brushes.Black;
            sto_axis.StrokeThickness = 1;
            sto_axis.X1 = 0;
            sto_axis.Y1 = 100;
            sto_axis.X2 = 10;
            sto_axis.Y2 = 100;
            canGraph.Children.Add(sto_axis);

            Line sto_pa_axis = new Line();
            sto_pa_axis.Stroke = System.Windows.Media.Brushes.Black;
            sto_pa_axis.StrokeThickness = 1;
            sto_pa_axis.X1 = 0;
            sto_pa_axis.Y1 = 50;
            sto_pa_axis.X2 = 10;
            sto_pa_axis.Y2 = 50;
            canGraph.Children.Add(sto_pa_axis);

            Line half_axis = new Line();
            half_axis.Stroke = System.Windows.Media.Brushes.Black;
            half_axis.StrokeThickness = 1;
            half_axis.X1 = 300;
            half_axis.Y1 = 320;
            half_axis.X2 = 300;
            half_axis.Y2 = 310;
            canGraph.Children.Add(half_axis);


            //if (data.tep_pozice_historie != 0)
            //{
            //    for (int data_poz = 0; data_poz < data.tep_pozice_historie - 1; data_poz++)
            //    {

            //        Line myLine = new Line();
            //        myLine.Stroke = System.Windows.Media.Brushes.Blue;
            //        myLine.StrokeThickness = 1;
            //        myLine.X1 = data_poz;
            //        myLine.Y1 = (-(data.tep_zmerena[data_poz]) + 200);
            //        myLine.X2 = data_poz + 1;
            //        myLine.Y2 = (-(data.tep_zmerena[data_poz + 1]) + 200);
            //        canGraph.Children.Add(myLine);




            //        Line myLine2 = new Line();
            //        myLine2.Stroke = System.Windows.Media.Brushes.Red;
            //        myLine2.StrokeThickness = 1;
            //        myLine2.X1 = data_poz;
            //        myLine2.Y1 = (-(data.tep_nastavena[data_poz]) + 200);
            //        myLine2.X2 = data_poz + 1;
            //        myLine2.Y2 = (-(data.tep_nastavena[data_poz + 1]) + 200);
            //        canGraph.Children.Add(myLine2);


            //    }
            //}




        }

        private void timer_aktualizace_pozice_na_graf_tick(object sender, EventArgs e)
        {
            string aktual_pozice_temp = "";
            string aktual_pozice_cas = "";

            aktual_pozice_temp = "Teplota: ";
            

            Point p = Mouse.GetPosition(canGraph);
            Point pozice= Mouse.GetPosition(canGraph);

            if (p.X<0 || p.Y<0 || p.Y>320 || p.X>600)
            {
                pozice.X = 0;
                pozice.Y = 0;
            }
            else
            {
                pozice.Y = -p.Y + 200;

                switch (comboBox_refresh.Text)
                {
                    case "Posledních 10 minut":
                        {
                            if(data.tep_pozice_historie>=600)
                            {
                                pozice.X = 600 - p.X;
                                aktual_pozice_cas = "Čas: t-";
                                aktual_pozice_cas += pozice.X.ToString();
                            }
                            else
                            {
                                pozice.X = p.X;
                                aktual_pozice_cas = "Čas: ";
                                aktual_pozice_cas += pozice.X.ToString();
                            }
                            
                            
                            aktual_pozice_cas += " sec";
                            text_pozice_cas.Text = aktual_pozice_cas;
                        }
                        break;
                    case "Poslední 1 hodina":
                        {
                            if (data.tep_pozice_historie >= 3600)
                            {
                                pozice.X = 3600 - p.X * 6;
                                aktual_pozice_cas = "Čas: t-";
                                aktual_pozice_cas += (pozice.X / 60).ToString("F0");
                            }
                            else
                            {
                                pozice.X = p.X * 6;
                                aktual_pozice_cas = "Čas: ";
                                aktual_pozice_cas += (pozice.X / 60).ToString("F0");
                            }


                            aktual_pozice_cas += " min";
                            text_pozice_cas.Text = aktual_pozice_cas;
                        }
                        break;
                    case "Posledních 10 hodin":
                        {
                            if (data.tep_pozice_historie >= 36000)
                            {
                                pozice.X = 36000 - p.X * 60;
                                aktual_pozice_cas = "Čas: t-";
                                aktual_pozice_cas += (pozice.X / 60).ToString("F0");
                            }
                            else
                            {
                                pozice.X = p.X * 60;
                                aktual_pozice_cas = "Čas: ";
                                aktual_pozice_cas += (pozice.X / 60).ToString("F0");
                            }


                            aktual_pozice_cas += " min";
                            text_pozice_cas.Text = aktual_pozice_cas;
                        }
                        break;
                    case "Poslední 1 den":
                        {

                            if (data.tep_pozice_historie >= 86400)
                            {
                                pozice.X = 86400 - p.X * 144;
                                aktual_pozice_cas = "Čas: t-";
                                aktual_pozice_cas += (pozice.X / 3600).ToString("F1");
                            }
                            else
                            {
                                pozice.X = p.X * 144;
                                aktual_pozice_cas = "Čas: ";
                                aktual_pozice_cas += (pozice.X / 3600).ToString("F1");
                            }


                            aktual_pozice_cas += " hod";
                            text_pozice_cas.Text = aktual_pozice_cas;

                        }
                        break;
                  
                }

            }

            aktual_pozice_temp += pozice.Y.ToString();
            aktual_pozice_temp += " °C";
            text_pozice.Text = aktual_pozice_temp;


        }

        private void timer_graf_aktualizace_tick(object sender, EventArgs e)
        {
            int data_poz_help = 0;

            switch (comboBox_refresh.Text)
            {
                case "Posledních 10 minut":
                    {
                        refresh = 1;

                        if (data.tep_pozice_historie > 600)
                        {
                            data_poz_help = (int)data.tep_pozice_historie - 600;
                        }


                        canGraph.Children.Clear();

                        Line axisx = new Line();
                        axisx.Stroke = System.Windows.Media.Brushes.Black;
                        axisx.StrokeThickness = 1;
                        axisx.X1 = 0;
                        axisx.Y1 = 320;
                        axisx.X2 = 600;
                        axisx.Y2 = 320;
                        canGraph.Children.Add(axisx);

                        Line axisy = new Line();
                        axisy.Stroke = System.Windows.Media.Brushes.Black;
                        axisy.StrokeThickness = 1;
                        axisy.X1 = 0;
                        axisy.Y1 = 0;
                        axisy.X2 = 0;
                        axisy.Y2 = 320;
                        canGraph.Children.Add(axisy);

                        Line axisx2 = new Line();
                        axisx2.Stroke = System.Windows.Media.Brushes.Black;
                        axisx2.StrokeThickness = 1;
                        axisx2.X1 = 0;
                        axisx2.Y1 = 0;
                        axisx2.X2 = 600;
                        axisx2.Y2 = 0;
                        canGraph.Children.Add(axisx2);

                        Line axisy2 = new Line();
                        axisy2.Stroke = System.Windows.Media.Brushes.Black;
                        axisy2.StrokeThickness = 1;
                        axisy2.X1 = 600;
                        axisy2.Y1 = 0;
                        axisy2.X2 = 600;
                        axisy2.Y2 = 320;
                        canGraph.Children.Add(axisy2);

                        Line nul_axis = new Line();
                        nul_axis.Stroke = System.Windows.Media.Brushes.Black;
                        nul_axis.StrokeThickness = 1;
                        nul_axis.X1 = 0;
                        nul_axis.Y1 = 200;
                        nul_axis.X2 = 10;
                        nul_axis.Y2 = 200;
                        canGraph.Children.Add(nul_axis);

                        Line pade_axis = new Line();
                        pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        pade_axis.StrokeThickness = 1;
                        pade_axis.X1 = 0;
                        pade_axis.Y1 = 150;
                        pade_axis.X2 = 10;
                        pade_axis.Y2 = 150;
                        canGraph.Children.Add(pade_axis);

                        Line mi_pade_axis = new Line();
                        mi_pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_pade_axis.StrokeThickness = 1;
                        mi_pade_axis.X1 = 0;
                        mi_pade_axis.Y1 = 250;
                        mi_pade_axis.X2 = 10;
                        mi_pade_axis.Y2 = 250;
                        canGraph.Children.Add(mi_pade_axis);

                        Line mi_sto_axis = new Line();
                        mi_sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_sto_axis.StrokeThickness = 1;
                        mi_sto_axis.X1 = 0;
                        mi_sto_axis.Y1 = 300;
                        mi_sto_axis.X2 = 10;
                        mi_sto_axis.Y2 = 300;
                        canGraph.Children.Add(mi_sto_axis);

                        Line sto_axis = new Line();
                        sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_axis.StrokeThickness = 1;
                        sto_axis.X1 = 0;
                        sto_axis.Y1 = 100;
                        sto_axis.X2 = 10;
                        sto_axis.Y2 = 100;
                        canGraph.Children.Add(sto_axis);

                        Line sto_pa_axis = new Line();
                        sto_pa_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_pa_axis.StrokeThickness = 1;
                        sto_pa_axis.X1 = 0;
                        sto_pa_axis.Y1 = 50;
                        sto_pa_axis.X2 = 10;
                        sto_pa_axis.Y2 = 50;
                        canGraph.Children.Add(sto_pa_axis);

                        Line half_axis = new Line();
                        half_axis.Stroke = System.Windows.Media.Brushes.Black;
                        half_axis.StrokeThickness = 1;
                        half_axis.X1 = 300;
                        half_axis.Y1 = 320;
                        half_axis.X2 = 300;
                        half_axis.Y2 = 310;
                        canGraph.Children.Add(half_axis);

                        if (data.tep_pozice_historie != 0)
                        {
                            for (int data_poz = data_poz_help; data_poz < data.tep_pozice_historie - 1; data_poz++)
                            {

                                Line myLine = new Line();
                                myLine.Stroke = System.Windows.Media.Brushes.Blue;
                                myLine.StrokeThickness = 1;
                                myLine.X1 = data_poz - data_poz_help;
                                myLine.Y1 = (-(data.tep_zmerena[data_poz]) + 200);
                                myLine.X2 = data_poz - data_poz_help + 1;
                                myLine.Y2 = (-(data.tep_zmerena[data_poz + 1]) + 200);
                                canGraph.Children.Add(myLine);




                                Line myLine2 = new Line();
                                myLine2.Stroke = System.Windows.Media.Brushes.Red;
                                myLine2.StrokeThickness = 1;
                                myLine2.X1 = data_poz - data_poz_help;
                                myLine2.Y1 = (-(data.tep_nastavena[data_poz]) + 200);
                                myLine2.X2 = data_poz - data_poz_help + 1;
                                myLine2.Y2 = (-(data.tep_nastavena[data_poz + 1]) + 200);
                                canGraph.Children.Add(myLine2);
                            }
                        }
                    }
                    break;

                case "Poslední 1 hodina":
                    {
                        refresh = 3;

                        if (data.tep_pozice_historie > 3600)
                        {
                            data_poz_help = (int)data.tep_pozice_historie - 3600;
                        }


                        canGraph.Children.Clear();

                        Line axisx = new Line();
                        axisx.Stroke = System.Windows.Media.Brushes.Black;
                        axisx.StrokeThickness = 1;
                        axisx.X1 = 0;
                        axisx.Y1 = 320;
                        axisx.X2 = 600;
                        axisx.Y2 = 320;
                        canGraph.Children.Add(axisx);

                        Line axisy = new Line();
                        axisy.Stroke = System.Windows.Media.Brushes.Black;
                        axisy.StrokeThickness = 1;
                        axisy.X1 = 0;
                        axisy.Y1 = 0;
                        axisy.X2 = 0;
                        axisy.Y2 = 320;
                        canGraph.Children.Add(axisy);

                        Line axisx2 = new Line();
                        axisx2.Stroke = System.Windows.Media.Brushes.Black;
                        axisx2.StrokeThickness = 1;
                        axisx2.X1 = 0;
                        axisx2.Y1 = 0;
                        axisx2.X2 = 600;
                        axisx2.Y2 = 0;
                        canGraph.Children.Add(axisx2);

                        Line axisy2 = new Line();
                        axisy2.Stroke = System.Windows.Media.Brushes.Black;
                        axisy2.StrokeThickness = 1;
                        axisy2.X1 = 600;
                        axisy2.Y1 = 0;
                        axisy2.X2 = 600;
                        axisy2.Y2 = 320;
                        canGraph.Children.Add(axisy2);

                        Line nul_axis = new Line();
                        nul_axis.Stroke = System.Windows.Media.Brushes.Black;
                        nul_axis.StrokeThickness = 1;
                        nul_axis.X1 = 0;
                        nul_axis.Y1 = 200;
                        nul_axis.X2 = 10;
                        nul_axis.Y2 = 200;
                        canGraph.Children.Add(nul_axis);

                        Line pade_axis = new Line();
                        pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        pade_axis.StrokeThickness = 1;
                        pade_axis.X1 = 0;
                        pade_axis.Y1 = 150;
                        pade_axis.X2 = 10;
                        pade_axis.Y2 = 150;
                        canGraph.Children.Add(pade_axis);

                        Line mi_pade_axis = new Line();
                        mi_pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_pade_axis.StrokeThickness = 1;
                        mi_pade_axis.X1 = 0;
                        mi_pade_axis.Y1 = 250;
                        mi_pade_axis.X2 = 10;
                        mi_pade_axis.Y2 = 250;
                        canGraph.Children.Add(mi_pade_axis);

                        Line mi_sto_axis = new Line();
                        mi_sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_sto_axis.StrokeThickness = 1;
                        mi_sto_axis.X1 = 0;
                        mi_sto_axis.Y1 = 300;
                        mi_sto_axis.X2 = 10;
                        mi_sto_axis.Y2 = 300;
                        canGraph.Children.Add(mi_sto_axis);

                        Line sto_axis = new Line();
                        sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_axis.StrokeThickness = 1;
                        sto_axis.X1 = 0;
                        sto_axis.Y1 = 100;
                        sto_axis.X2 = 10;
                        sto_axis.Y2 = 100;
                        canGraph.Children.Add(sto_axis);

                        Line sto_pa_axis = new Line();
                        sto_pa_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_pa_axis.StrokeThickness = 1;
                        sto_pa_axis.X1 = 0;
                        sto_pa_axis.Y1 = 50;
                        sto_pa_axis.X2 = 10;
                        sto_pa_axis.Y2 = 50;
                        canGraph.Children.Add(sto_pa_axis);

                        Line half_axis = new Line();
                        half_axis.Stroke = System.Windows.Media.Brushes.Black;
                        half_axis.StrokeThickness = 1;
                        half_axis.X1 = 300;
                        half_axis.Y1 = 320;
                        half_axis.X2 = 300;
                        half_axis.Y2 = 310;
                        canGraph.Children.Add(half_axis);

                        if (data.tep_pozice_historie > 12)
                        {
                            for (int data_poz = data_poz_help; data_poz <= data.tep_pozice_historie - 12; data_poz+=6)
                            {

                                Line myLine = new Line();
                                myLine.Stroke = System.Windows.Media.Brushes.Blue;
                                myLine.StrokeThickness = 1;
                                myLine.X1 = (data_poz - data_poz_help)/6;
                                myLine.Y1 = (-(data.tep_zmerena[data_poz]) + 200);
                                myLine.X2 = (data_poz - data_poz_help)/6 + 1;
                                myLine.Y2 = (-(data.tep_zmerena[(data_poz + 6)]) + 200);
                                canGraph.Children.Add(myLine);




                                Line myLine2 = new Line();
                                myLine2.Stroke = System.Windows.Media.Brushes.Red;
                                myLine2.StrokeThickness = 1;
                                myLine2.X1 = (data_poz - data_poz_help)/6;
                                myLine2.Y1 = (-(data.tep_nastavena[data_poz]) + 200);
                                myLine2.X2 = (data_poz - data_poz_help)/6 + 1;
                                myLine2.Y2 = (-(data.tep_nastavena[(data_poz + 6)]) + 200);
                                canGraph.Children.Add(myLine2);
                            }
                        }

                    }
                    break;

                case "Posledních 10 hodin":
                    {
                        refresh = 5;

                        if (data.tep_pozice_historie > 36000)
                        {
                            data_poz_help = (int)data.tep_pozice_historie - 36000;
                        }


                        canGraph.Children.Clear();

                        Line axisx = new Line();
                        axisx.Stroke = System.Windows.Media.Brushes.Black;
                        axisx.StrokeThickness = 1;
                        axisx.X1 = 0;
                        axisx.Y1 = 320;
                        axisx.X2 = 600;
                        axisx.Y2 = 320;
                        canGraph.Children.Add(axisx);

                        Line axisy = new Line();
                        axisy.Stroke = System.Windows.Media.Brushes.Black;
                        axisy.StrokeThickness = 1;
                        axisy.X1 = 0;
                        axisy.Y1 = 0;
                        axisy.X2 = 0;
                        axisy.Y2 = 320;
                        canGraph.Children.Add(axisy);

                        Line axisx2 = new Line();
                        axisx2.Stroke = System.Windows.Media.Brushes.Black;
                        axisx2.StrokeThickness = 1;
                        axisx2.X1 = 0;
                        axisx2.Y1 = 0;
                        axisx2.X2 = 600;
                        axisx2.Y2 = 0;
                        canGraph.Children.Add(axisx2);

                        Line axisy2 = new Line();
                        axisy2.Stroke = System.Windows.Media.Brushes.Black;
                        axisy2.StrokeThickness = 1;
                        axisy2.X1 = 600;
                        axisy2.Y1 = 0;
                        axisy2.X2 = 600;
                        axisy2.Y2 = 320;
                        canGraph.Children.Add(axisy2);

                        Line nul_axis = new Line();
                        nul_axis.Stroke = System.Windows.Media.Brushes.Black;
                        nul_axis.StrokeThickness = 1;
                        nul_axis.X1 = 0;
                        nul_axis.Y1 = 200;
                        nul_axis.X2 = 10;
                        nul_axis.Y2 = 200;
                        canGraph.Children.Add(nul_axis);

                        Line pade_axis = new Line();
                        pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        pade_axis.StrokeThickness = 1;
                        pade_axis.X1 = 0;
                        pade_axis.Y1 = 150;
                        pade_axis.X2 = 10;
                        pade_axis.Y2 = 150;
                        canGraph.Children.Add(pade_axis);

                        Line mi_pade_axis = new Line();
                        mi_pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_pade_axis.StrokeThickness = 1;
                        mi_pade_axis.X1 = 0;
                        mi_pade_axis.Y1 = 250;
                        mi_pade_axis.X2 = 10;
                        mi_pade_axis.Y2 = 250;
                        canGraph.Children.Add(mi_pade_axis);

                        Line mi_sto_axis = new Line();
                        mi_sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_sto_axis.StrokeThickness = 1;
                        mi_sto_axis.X1 = 0;
                        mi_sto_axis.Y1 = 300;
                        mi_sto_axis.X2 = 10;
                        mi_sto_axis.Y2 = 300;
                        canGraph.Children.Add(mi_sto_axis);

                        Line sto_axis = new Line();
                        sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_axis.StrokeThickness = 1;
                        sto_axis.X1 = 0;
                        sto_axis.Y1 = 100;
                        sto_axis.X2 = 10;
                        sto_axis.Y2 = 100;
                        canGraph.Children.Add(sto_axis);

                        Line sto_pa_axis = new Line();
                        sto_pa_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_pa_axis.StrokeThickness = 1;
                        sto_pa_axis.X1 = 0;
                        sto_pa_axis.Y1 = 50;
                        sto_pa_axis.X2 = 10;
                        sto_pa_axis.Y2 = 50;
                        canGraph.Children.Add(sto_pa_axis);

                        Line half_axis = new Line();
                        half_axis.Stroke = System.Windows.Media.Brushes.Black;
                        half_axis.StrokeThickness = 1;
                        half_axis.X1 = 300;
                        half_axis.Y1 = 320;
                        half_axis.X2 = 300;
                        half_axis.Y2 = 310;
                        canGraph.Children.Add(half_axis);

                        if (data.tep_pozice_historie > 120)
                        {
                            for (int data_poz = data_poz_help; data_poz <= data.tep_pozice_historie - 120; data_poz += 60)
                            {

                                Line myLine = new Line();
                                myLine.Stroke = System.Windows.Media.Brushes.Blue;
                                myLine.StrokeThickness = 1;
                                myLine.X1 = (data_poz - data_poz_help) / 60;
                                myLine.Y1 = (-(data.tep_zmerena[data_poz]) + 200);
                                myLine.X2 = (data_poz - data_poz_help) / 60 + 1;
                                myLine.Y2 = (-(data.tep_zmerena[(data_poz + 60)]) + 200);
                                canGraph.Children.Add(myLine);




                                Line myLine2 = new Line();
                                myLine2.Stroke = System.Windows.Media.Brushes.Red;
                                myLine2.StrokeThickness = 1;
                                myLine2.X1 = (data_poz - data_poz_help) / 60;
                                myLine2.Y1 = (-(data.tep_nastavena[data_poz]) + 200);
                                myLine2.X2 = (data_poz - data_poz_help) / 60 + 1;
                                myLine2.Y2 = (-(data.tep_nastavena[(data_poz + 60)]) + 200);
                                canGraph.Children.Add(myLine2);
                            }
                        }

                    }
                    break;

                case "Poslední 1 den":
                    {
                        refresh = 5;

                        if (data.tep_pozice_historie > 86400)
                        {
                            data_poz_help = (int)data.tep_pozice_historie - 86400;
                        }


                        canGraph.Children.Clear();

                        Line axisx = new Line();
                        axisx.Stroke = System.Windows.Media.Brushes.Black;
                        axisx.StrokeThickness = 1;
                        axisx.X1 = 0;
                        axisx.Y1 = 320;
                        axisx.X2 = 600;
                        axisx.Y2 = 320;
                        canGraph.Children.Add(axisx);

                        Line axisy = new Line();
                        axisy.Stroke = System.Windows.Media.Brushes.Black;
                        axisy.StrokeThickness = 1;
                        axisy.X1 = 0;
                        axisy.Y1 = 0;
                        axisy.X2 = 0;
                        axisy.Y2 = 320;
                        canGraph.Children.Add(axisy);

                        Line axisx2 = new Line();
                        axisx2.Stroke = System.Windows.Media.Brushes.Black;
                        axisx2.StrokeThickness = 1;
                        axisx2.X1 = 0;
                        axisx2.Y1 = 0;
                        axisx2.X2 = 600;
                        axisx2.Y2 = 0;
                        canGraph.Children.Add(axisx2);

                        Line axisy2 = new Line();
                        axisy2.Stroke = System.Windows.Media.Brushes.Black;
                        axisy2.StrokeThickness = 1;
                        axisy2.X1 = 600;
                        axisy2.Y1 = 0;
                        axisy2.X2 = 600;
                        axisy2.Y2 = 320;
                        canGraph.Children.Add(axisy2);

                        Line nul_axis = new Line();
                        nul_axis.Stroke = System.Windows.Media.Brushes.Black;
                        nul_axis.StrokeThickness = 1;
                        nul_axis.X1 = 0;
                        nul_axis.Y1 = 200;
                        nul_axis.X2 = 10;
                        nul_axis.Y2 = 200;
                        canGraph.Children.Add(nul_axis);

                        Line pade_axis = new Line();
                        pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        pade_axis.StrokeThickness = 1;
                        pade_axis.X1 = 0;
                        pade_axis.Y1 = 150;
                        pade_axis.X2 = 10;
                        pade_axis.Y2 = 150;
                        canGraph.Children.Add(pade_axis);

                        Line mi_pade_axis = new Line();
                        mi_pade_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_pade_axis.StrokeThickness = 1;
                        mi_pade_axis.X1 = 0;
                        mi_pade_axis.Y1 = 250;
                        mi_pade_axis.X2 = 10;
                        mi_pade_axis.Y2 = 250;
                        canGraph.Children.Add(mi_pade_axis);

                        Line mi_sto_axis = new Line();
                        mi_sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        mi_sto_axis.StrokeThickness = 1;
                        mi_sto_axis.X1 = 0;
                        mi_sto_axis.Y1 = 300;
                        mi_sto_axis.X2 = 10;
                        mi_sto_axis.Y2 = 300;
                        canGraph.Children.Add(mi_sto_axis);

                        Line sto_axis = new Line();
                        sto_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_axis.StrokeThickness = 1;
                        sto_axis.X1 = 0;
                        sto_axis.Y1 = 100;
                        sto_axis.X2 = 10;
                        sto_axis.Y2 = 100;
                        canGraph.Children.Add(sto_axis);

                        Line sto_pa_axis = new Line();
                        sto_pa_axis.Stroke = System.Windows.Media.Brushes.Black;
                        sto_pa_axis.StrokeThickness = 1;
                        sto_pa_axis.X1 = 0;
                        sto_pa_axis.Y1 = 50;
                        sto_pa_axis.X2 = 10;
                        sto_pa_axis.Y2 = 50;
                        canGraph.Children.Add(sto_pa_axis);

                        Line half_axis = new Line();
                        half_axis.Stroke = System.Windows.Media.Brushes.Black;
                        half_axis.StrokeThickness = 1;
                        half_axis.X1 = 300;
                        half_axis.Y1 = 320;
                        half_axis.X2 = 300;
                        half_axis.Y2 = 310;
                        canGraph.Children.Add(half_axis);

                        if (data.tep_pozice_historie > 288)
                        {
                            for (int data_poz = data_poz_help; data_poz <= data.tep_pozice_historie - 288; data_poz += 144)
                            {

                                Line myLine = new Line();
                                myLine.Stroke = System.Windows.Media.Brushes.Blue;
                                myLine.StrokeThickness = 1;
                                myLine.X1 = (data_poz - data_poz_help) / 144;
                                myLine.Y1 = (-(data.tep_zmerena[data_poz]) + 200);
                                myLine.X2 = (data_poz - data_poz_help) / 144 + 1;
                                myLine.Y2 = (-(data.tep_zmerena[(data_poz + 144)]) + 200);
                                canGraph.Children.Add(myLine);




                                Line myLine2 = new Line();
                                myLine2.Stroke = System.Windows.Media.Brushes.Red;
                                myLine2.StrokeThickness = 1;
                                myLine2.X1 = (data_poz - data_poz_help) / 144;
                                myLine2.Y1 = (-(data.tep_nastavena[data_poz]) + 200);
                                myLine2.X2 = (data_poz - data_poz_help) / 144 + 1;
                                myLine2.Y2 = (-(data.tep_nastavena[(data_poz + 144)]) + 200);
                                canGraph.Children.Add(myLine2);
                            }
                        }

                    }
                    break;
            }//switch








        }//timer

        private void button_Click(object sender, RoutedEventArgs e)
        {
            for(int i=0; i<=600; i++)
            {
                Array.Resize(ref data.tep_nastavena, data.tep_nastavena.Length + 1);
                data.tep_nastavena[data.tep_pozice_historie]=0;
                Array.Resize(ref data.tep_zmerena, data.tep_zmerena.Length + 1);
                data.tep_zmerena[data.tep_pozice_historie]=0;
                data.tep_pozice_historie++;
            }
        }

        private void btn_Export_Click(object sender, RoutedEventArgs e)
        {
            Export Okno_export = new Export();
            Okno_export.Show();
        }
    }


}
