using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Wpf;
using MathNet.Numerics;
using Misc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace FLY.Thick.FilmCasting.UI.UiModule
{
    public class TempScanGraphVmUt : TempScanGraphVm
    {

        bool IsPercent = true;
        bool IsAutoTarget = true;

        public TempScanGraphVmUt()
        {
            SimuData();
        }

        void SimuData() 
        {
            graphparam = new TempScanGraphItemParam();
            graphparam.IsPercent = true;
            graphparam.IsAutoTarget = true;

            profileParam = new Common.FilmCastingProfileParam();
            profileParam.ScanRange = new RangeStruct(10, 110);
            profileParam.DataRange = new RangeStruct(30, 90);
            profileParam.Target = 150;
            profileParam.TolerancePercent = 0.02;

            UpdateSeriesType();

            BoltCnt = 120;

            #region 数据
            double target = profileParam.Target;
            double tolerance = target * profileParam.TolerancePercent;
            double yrangepercent = graphparam.YRangePercent;

            int nbolts = BoltCnt;
            double[] _datas = new double[nbolts];
            Random random = new Random();
            for (int i = 0; i < nbolts; i++)
            {
                _datas[i] = (Math.Sin(i * Math.PI / nbolts) * 3) * tolerance + target + (random.NextDouble() - 0.5) * 1 - 6;
            }

            for (int i = 0; i < profileParam.DataRange.Begin; i++)
            {
                _datas[i] = double.NaN;
            }
            for (int i = profileParam.DataRange.End; i < nbolts; i++)
            {
                _datas[i] = double.NaN;
            }
            datas.AddRange(_datas);

            #endregion
            #region 界面数据

            UpdateX();

            XStep = 10;
            Time = DateTime.Now;
            
            

            Values.Clear();
            Values.AddRange(datas);

            UpdateAverage();

            UpdateY();
            UpdateMaxMinText();
            #endregion


        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
