コード例 #1
0
        /// <summary>
        /// 绘制当前时间进度
        /// </summary>
        private void DrawTimeProcess(bool isSyncProcess = false)
        {
            if (_XAxis == null)
            {
                return;
            }
            if (_TimeProcessUI != null && _TimeProcessUI.Count > 0)
            {
                _TimeProcessUI.ForEach(u => _Container.Children.Remove(u));
                _TimeProcessUI.Clear();
            }
            processButtonGrid.Children.Clear();

            bool     isOverMin, isOverMax;
            DateTime time = DateTime.Now;//DateTime.Now.Date.AddHours(9);//
            double   x    = _XAxis.LocalTransform(time, out isOverMin, out isOverMax);

            GradientStopCollection GradientStops = new GradientStopCollection();
            LinearGradientBrush    bgBrush;
            Border processBorder;
            double TicStartY   = StartPoint.Y + _drawHeight * TicLabelHeightPercent;
            double TicEndY     = TicStartY + _drawHeight * TicAreaHeightPercent;
            double leftMargin  = -6;
            double rightMargin = 6;

            if (!isOverMin)
            {
                //LinearGradientBrush bgBrush = new LinearGradientBrush(Color.FromRgb(0x65, 0xD3, 0xAC), Color.FromRgb(0x29, 0xB9, 0xB6), new Point(0, 0), new Point(0, 1));

                GradientStops.Add(new GradientStop(Color.FromRgb(0x65, 0xD3, 0xAC), 0.0));
                GradientStops.Add(new GradientStop(Color.FromRgb(0x59, 0xE6, 0xCB), 0.3));
                GradientStops.Add(new GradientStop(Color.FromRgb(0x45, 0xD9, 0xC7), 0.7));
                GradientStops.Add(new GradientStop(Color.FromRgb(0x29, 0xB9, 0xB6), 1.0));
                bgBrush = new LinearGradientBrush(GradientStops, new Point(0, 0), new Point(0, 1));

                processBorder        = new Border();
                processBorder.Width  = x - AxisStartPoint.X - leftMargin + rightMargin;
                processBorder.Height = _drawHeight * TicAreaHeightPercent;
                processBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                processBorder.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                processBorder.CornerRadius        = new CornerRadius(5);
                processBorder.Background          = bgBrush;
                processBorder.Margin = new Thickness(AxisStartPoint.X + leftMargin, TicStartY, 0, 0);
                //processBorder.Opacity = 0.5;
                _Container.Children.Add(processBorder);
                _TimeProcessUI.Add(processBorder);
            }

            DrawRescueTimes(TicStartY);  //绘制抢救时间段

            if (time < _XAxis.MaxTime)
            {
                GradientStops = new GradientStopCollection();
                GradientStops.Add(new GradientStop(Color.FromRgb(0x31, 0xAA, 0xCE), 0.0));
                GradientStops.Add(new GradientStop(Color.FromRgb(0x38, 0xBD, 0xE3), 0.3));
                GradientStops.Add(new GradientStop(Color.FromRgb(0x38, 0xBC, 0xE2), 0.7));
                GradientStops.Add(new GradientStop(Color.FromRgb(0x37, 0xAD, 0xD1), 1.0));
                bgBrush              = new LinearGradientBrush(GradientStops, new Point(0, 0), new Point(0, 1));
                processBorder        = new Border();
                processBorder.Width  = _XAxis.MaxPix - x;
                processBorder.Height = _drawHeight * TicAreaHeightPercent;
                processBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                processBorder.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                processBorder.CornerRadius        = new CornerRadius(5);
                processBorder.Background          = bgBrush;
                processBorder.Margin = new Thickness(x, TicStartY, 0, 0);
                _Container.Children.Add(processBorder);
                _TimeProcessUI.Add(processBorder);

                //拉杆
                if (!isOverMin && !isOverMax)
                {
                    double width          = processBorder.Height * 0.8;
                    double ContainerWidth = width * 2.5;
                    processButtonPopup.Width  = ContainerWidth * 1.2;
                    processButtonPopup.Height = ContainerWidth * 1.2;
                    processButtonPopup.Margin = new Thickness(x, 0, 0, 0);
                    Point startP = new Point(ContainerWidth / 2, ContainerWidth / 2);

                    Path Circle3 = GetProcessButton(startP, new Size(width * 2.5, width * 2.5), Color.FromRgb(0xE5, 0xF6, 0xF5), Color.FromRgb(0xE5, 0xF6, 0xF5));
                    Circle3.Opacity = 0.7;
                    processButtonGrid.Children.Add(Circle3);

                    Path Circle2 = GetProcessButton(startP, new Size(width * 1.8, width * 1.8), Color.FromRgb(0xFF, 0xFF, 0xFF), Color.FromRgb(0xFF, 0xFF, 0xFF));
                    processButtonGrid.Children.Add(Circle2);

                    Path Circle1 = GetProcessButton(startP, new Size(width, width), Color.FromRgb(0x00, 0xD8, 0xAE), Color.FromRgb(0x00, 0xD8, 0xAE));
                    processButtonGrid.Children.Add(Circle1);

                    double y = TicStartY + processBorder.Height / 2 - ContainerWidth / 2;
                    processButtonPopup.PlacementRectangle = new Rect(x - ContainerWidth / 2, y, ContainerWidth, ContainerWidth);
                    processButtonPopup.IsOpen             = true;
                }
            }

            if (isSyncProcess && DrawTimeProcessAction != null)
            {
                DrawTimeProcessAction(time);
            }
        }
コード例 #2
0
        public void InsertDataPoint(DateTime time, double value, object Tag, MouseEventHandler MouseEnterHandler, MouseEventHandler MouseLeaveHandler, ref DataPoint point, SymbolType symbolType = SymbolType.Point)
        {
            bool isOverMin, isOverMax;
            var  x = _XAxis.LocalTransform(time, out isOverMin, out isOverMax);

            if (isOverMin || isOverMax) //超过x轴范围返回
            {
                return;
            }
            double drawValue = value;

            if (drawValue > _YAxis.Max)
            {
                drawValue = _YAxis.Max;
            }
            else if (drawValue < _YAxis.Min)
            {
                drawValue = _YAxis.Min;
            }
            var         y              = _drawHeight - _YAxis.LocalTransform(drawValue);
            LineSegment lineSegment    = null;
            PathFigure  figure         = null;
            var         currentFigures = _pathGeometry.Figures[_index];

            DataPoint point1 = _points.Find(x1 => x1.Time == time.AddMinutes(-5));
            DataPoint point2 = _points.Find(x2 => x2.Time == time.AddMinutes(5));

            if (point1 != null && point2 == null)
            {
                lineSegment       = new LineSegment();
                lineSegment.Point = new Point(x, y);
                for (int i = _points.IndexOf(point1); i >= 0; i--)
                {
                    if (_points[i].Figure != null)
                    {
                        currentFigures = _points[i].Figure;
                        break;
                    }
                }
                currentFigures.Segments.Add(lineSegment);
            }
            else if (point1 != null && point2 != null)
            {
                lineSegment       = new LineSegment();
                lineSegment.Point = new Point(x, y);
                for (int i = _points.IndexOf(point1); i >= 0; i--)
                {
                    if (_points[i].Figure != null)
                    {
                        currentFigures = _points[i].Figure;
                        break;
                    }
                }
                currentFigures.Segments.Add(lineSegment);
                point2.Figure            = null;
                point2.LineSegment       = new LineSegment();
                point2.LineSegment.Point = new Point(point2.X, point2.Y);
                for (int i = _points.IndexOf(point2); i < _points.Count; i++)
                {
                    if (_points[i].Figure != null)
                    {
                        break;
                    }
                    currentFigures.Segments.Add(_points[i].LineSegment);
                }
            }
            else if (point1 == null && point2 != null)
            {
                figure = point2.Figure;
                figure.Segments.Clear();
                figure.StartPoint        = new Point(x, y);
                point2.Figure            = null;
                point2.LineSegment       = new LineSegment();
                point2.LineSegment.Point = new Point(point2.X, point2.Y);
                for (int i = _points.IndexOf(point2); i < _points.Count; i++)
                {
                    if (_points[i].Figure != null)
                    {
                        break;
                    }
                    figure.Segments.Add(_points[i].LineSegment);
                }
            }
            else if (point1 == null && point2 == null)
            {
                figure          = new PathFigure();
                figure.Segments = new PathSegmentCollection();
                _pathGeometry.Figures.Add(figure);
                _index++;
                figure.StartPoint = new Point(x, y);
            }

            Path path = Symbol.MakePath(symbolType, new Point(x, y), new Size(_pointWidth, _pointHeight), LineColor, Colors.White);

            path.Tag             = Tag;
            path.StrokeThickness = 1.5;
            //path.RenderTransform = new TranslateTransform(1, 1);
            path.MouseEnter += MouseEnterHandler;
            path.MouseMove  += MouseEnterHandler;
            path.MouseLeave += MouseLeaveHandler;

            Path path2 = Symbol.MakePath(SymbolType.CustomRectangle, new Point(x, y), new Size(_pointWidth, _pointHeight), LineColor, Colors.White);

            path2.Tag             = Tag;
            path2.StrokeThickness = 1.5;
            //path.RenderTransform = new TranslateTransform(1, 1);
            path2.MouseEnter += MouseEnterHandler;
            path2.MouseMove  += MouseEnterHandler;
            path2.MouseLeave += MouseLeaveHandler;
            point             = new DataPoint(time, value, x, y, new List <FrameworkElement>()
            {
                path, path2
            }, figure, lineSegment);
            _points.Add(point);
            _points = _points.OrderBy(p => p.Time).ToList();
        }