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.Media; using System.Windows.Shapes; namespace PipeGallery.Model { public class CurveGroupInfo : ChartBase { private double _curveStrokeThickness; public double CurveStrokeThickness { get { return _curveStrokeThickness; } set { _curveStrokeThickness = value; } } private List<PointInfo> _curvePointListInfo = new List<PointInfo>(); public List<PointInfo> CurvePointListInfo { get { return _curvePointListInfo; } set { _curvePointListInfo = value; } } private PointCollection _pointCollection = new PointCollection(); private double _yh, _xw, _maxy, _miny, _xMark; private Polyline _polyline; private Point pXStart; /// <summary> /// 画一条曲线组 /// </summary> /// <param name="canvas"></param> public override void DrawGeometricFigure(Canvas canvas, double maxy, double miny, CoordinatesInfoType coordinates) { Coordinates = coordinates; //清空Canvas canvas.Children.Clear(); //坐标轴的左边沿的X坐标点 double xs = 0; //坐标轴的X轴的实际长度 double xw = canvas.ActualWidth; //坐标轴下边沿的Y坐标点 double ys = canvas.ActualHeight; //坐标轴的Y轴的实际长度 double yh = canvas.ActualHeight; //坐标轴的Y轴的起点 Point pYStart = new Point(xs, ys); //X坐标轴的左起点-原点 pXStart = pYStart; Coordinates = coordinates; _xMark = xw / CurvePointListInfo.Count; ; _xw = xw; _yh = yh; _maxy = maxy; _miny = miny; _polyline = new Polyline(); _polyline.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Color)); _polyline.StrokeThickness = CurveStrokeThickness; _polyline.Points = _pointCollection; if (ChartType == ChartType.FilterView) { _polyline.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Color)); } canvas.Children.Add(_polyline); //刷新一条曲线的点 RefreshCurvePointCollection(); } public override void RefreshGeometricFigure() { RefreshCurvePointCollection(); } internal void RefreshCurvePointCollection() { //点集合清空 _pointCollection.Clear(); if (ChartType == ChartType.FilterView) { _pointCollection.Add(pXStart); } for (int i = 0; i < _curvePointListInfo.Count; i++) { //根据Y轴的起点坐标 double py = _yh - (_curvePointListInfo[i].YValue - _miny) * _yh / (_maxy - _miny); Point p = new Point(); double px = Coordinates.GetXPosition(_curvePointListInfo[i].XValue); p.X = px; p.Y = py; _pointCollection.Add(p); if (i == _curvePointListInfo.Count - 1) { if (ChartType == ChartType.FilterView) { Point p_end = new Point(); p_end.X = px; p_end.Y = pXStart.Y; _pointCollection.Add(p_end); _pointCollection.Add(pXStart); } } } } public override double GetMaxValue() { double max = double.MinValue; if (CurvePointListInfo != null && CurvePointListInfo.Count > 0) { double tmpMax = CurvePointListInfo.Max(o => o.YValue); if (max < tmpMax) max = tmpMax; } return max; } public override double GetMinValue() { double min = double.MaxValue; if (CurvePointListInfo != null && CurvePointListInfo.Count > 0) { double tmpMin = CurvePointListInfo.Min(o => o.YValue); if (min > tmpMin) min = tmpMin; } return min; } } }