Newer
Older
Correlator / PipeGallery / Model / ColumnGroupInfo.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;

namespace PipeGallery.Model
{
    [Serializable]
    public class ColumnGroupInfo : ChartBase
    {

        private List<ColumnInfo> _columnListInfo = new List<ColumnInfo>();

        public List<ColumnInfo> ColumnListInfo
        {
            get { return _columnListInfo; }
            set { _columnListInfo = value; }
        }

        private Canvas _canvas = null;
        private double _maxy;
        private double _miny;

        public override void DrawGeometricFigure(Canvas canvas, double maxy, double miny, CoordinatesInfoType coordinates)
        {
            _canvas = canvas;
            _maxy = maxy;
            _miny = miny;

            Coordinates = coordinates;

            RefreshGeometricFigure();
        }

        public override void RefreshGeometricFigure()
        {
            //清空canvas
            _canvas.Children.Clear();
            _canvas.Visibility = Visibility.Hidden;
            /* 线程优化1  
            System.Threading.ThreadStart start = delegate ()
            {
                //Thread.Sleep(500);
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    _canvas.Visibility = Visibility.Visible;
                }), DispatcherPriority.Normal);
            };
            Thread t = new System.Threading.Thread(start);
            t.IsBackground = true;
            t.Start();
             * */
            Task t = new Task(()=> {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    _canvas.Visibility = Visibility.Visible;
                }), DispatcherPriority.Normal);
            });


            //坐标轴的左边沿的X坐标点
            double xs = 0;
            //坐标轴的X轴的实际长度
            double xw = _canvas.ActualWidth;
            //坐标轴下边沿的Y坐标点
            double ys = _canvas.ActualHeight;
            //坐标轴的Y轴的实际长度
            double yh = _canvas.ActualHeight;
            //坐标起点
            Point pStart = new Point(xs, ys);

            //得到X轴刻度的实际长度

            //遍历KLine图表
            for (int i = 0; i < _columnListInfo.Count; i++)
            {
                double xStart = Coordinates.GetXPosition(_columnListInfo[i].XValue);
                _columnListInfo[i].DrawColumn(this, _canvas, xStart, 3, yh, _maxy, _miny);
            }
        }


        public override double GetMaxValue()
        {
            double max = double.MinValue;

            if (_columnListInfo != null && _columnListInfo.Count > 0)
            {
                double tmpMax = _columnListInfo.Max(o => o.StartValue);
                if (max < tmpMax)
                    max = tmpMax;
                tmpMax = _columnListInfo.Max(o => o.EndValue);
                if (max < tmpMax)
                    max = tmpMax;
            }
            return max;
        }

        public override double GetMinValue()
        {
            double min = double.MaxValue;

            if (_columnListInfo != null && _columnListInfo.Count > 0)
            {
                double tmpMin = _columnListInfo.Min(o => o.StartValue);
                if (min > tmpMin)
                    min = tmpMin;
                tmpMin = _columnListInfo.Min(o => o.EndValue);
                if (min > tmpMin)
                    min = tmpMin;
            }

            return min;
        }
    }
}