protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     Pen pen = new Pen(LineBrush, 1);
     GuidelineSet gs = new GuidelineSet();
     gs.GuidelinesX.Clear();
     gs.GuidelinesY.Clear();
     gs.GuidelinesY.Add(_lastPoint.Y - 0.5);
     gs.GuidelinesY.Add(_lastPoint.Y + 0.5);
     drawingContext.PushGuidelineSet(gs.Clone());
     drawingContext.DrawLine(pen, new Point(0, _lastPoint.Y), new Point(ActualWidth, _lastPoint.Y));
     drawingContext.PushGuidelineSet(gs.Clone());
     gs.GuidelinesX.Clear();
     gs.GuidelinesY.Clear();
     gs.GuidelinesX.Add(_lastPoint.X - 0.5);
     gs.GuidelinesX.Add(_lastPoint.X + 0.5);
     drawingContext.PushGuidelineSet(gs.Clone());
     drawingContext.DrawLine(pen, new Point(_lastPoint.X, 0), new Point(_lastPoint.X, ActualHeight));
     drawingContext.PushGuidelineSet(gs.Clone());
 }
        /// <summary>
        /// OnRender method.
        /// </summary>
        /// <param name="drawingContext">Drawing context.</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (TimeAxis.ZoomMode == ZoomMode.FrameLevel)
            {
                GuidelineSet gs = new GuidelineSet();
                Pen pen = new Pen(Brushes.LightGray, 1);
                double halfPen = pen.Thickness / 2;
                
                // draw time line for each frame
                for (int i = 0; i <= ActualWidth / ViewHelper.TimespanToPixel(TimeAxis.SampleInterval, TimeAxis.ZoomScale); ++i)
                {
                    double x = ViewHelper.TimespanToPixel(TimeAxis.SampleInterval * (double)i, TimeAxis.ZoomScale);
                    gs.GuidelinesX.Clear();
                    gs.GuidelinesX.Add(x - halfPen);
                    gs.GuidelinesX.Add(x + halfPen);
                    drawingContext.PushGuidelineSet(gs.Clone());
                    drawingContext.DrawLine(pen, new Point(x, 0), new Point(x, Height));
                    drawingContext.Pop();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Overrides OnRender method to draw ruler.
        /// </summary>
        /// <param name="drawingContext">Drawing context.</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (RulerHeight == 0 || ActualHeight < 1 || DataContext == null)
            {
                return;
            }

            drawingContext.PushClip(ClipRect);
            _rulerArea.Margin = new Thickness(0, 0, 0, 0);
            _renderMinorTick = MinorTick / ViewHelper.AdjustFactor(RulerHeight / ActualHeight);

            GuidelineSet gs = new GuidelineSet();
            double halfRulerPen = rulerStroke.Thickness / 2;
            double xOffset = IsRulerLeft ? RulerWidth : 0;
            gs.GuidelinesX.Add(xOffset - halfRulerPen);
            gs.GuidelinesX.Add(xOffset + halfRulerPen);
            drawingContext.PushGuidelineSet(gs.Clone());
            drawingContext.DrawLine(rulerStroke,
                new Point(xOffset, OriginOffset),
                new Point(xOffset, RulerHeight + OriginOffset));
            drawingContext.Pop();
            if (GraduationCount > 0)
            {
                int startGradIndex = checked((int)Math.Floor((RulerHeight + OriginOffset - ActualHeight) / GraduationHeight));
                int stopGradIndex = checked((int)Math.Floor((RulerHeight + OriginOffset) / GraduationHeight));

                // Draw scale and label.
                for (int gradIndex = startGradIndex; gradIndex <= stopGradIndex; ++gradIndex)
                {
                    double gradY = (GraduationHeight * gradIndex) - OriginOffset;
                    double gradValue = Min + (gradIndex * _renderMinorTick);
                    double graduationLength = MinorTickLength;

                    if ((GraduationCount - gradIndex) % MajorStep == 0)
                    {
                        graduationLength = MajorGraduationLength;
                        FormattedText text = new FormattedText(gradValue.ToString(),
                            CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
                            new Typeface(FontFamilyName), 8, Brushes.Black);
                        Point lableLocation = new Point(LabelMargin,
                            RulerHeight - (gradY + (text.Height / 2)));
                        if (gradIndex == GraduationCount)
                        {
                            lableLocation.Y = OriginOffset;
                        }
                        else if (gradIndex == 0)
                        {
                            lableLocation.Y = OriginOffset + RulerHeight - text.Height - 1;
                        }

                        if (IsRulerLeft)
                        {
                            lableLocation.X = RulerWidth - text.Width - LabelMargin;
                        }

                        drawingContext.DrawText(text, lableLocation);
                    }

                    double lineHeight = RulerHeight - gradY;
                    gs.GuidelinesX.Clear();
                    gs.GuidelinesY.Clear();
                    gs.GuidelinesY.Add(lineHeight - halfRulerPen);
                    gs.GuidelinesY.Add(lineHeight + halfRulerPen);
                    drawingContext.PushGuidelineSet(gs.Clone());
                    if (IsRulerLeft)
                    {
                        drawingContext.DrawLine(rulerStroke,
                            new Point(ActualWidth, lineHeight),
                           new Point(RulerWidth - graduationLength, lineHeight));
                    }
                    else
                    {
                        drawingContext.DrawLine(rulerStroke, new Point(0, lineHeight),
                           new Point(graduationLength, lineHeight));
                    }

                    drawingContext.Pop();
                }
            }

            drawingContext.Pop();
        }
Ejemplo n.º 4
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     if (_durations != null && _durations.TimeAxis.ZoomMode == ZoomMode.FrameLevel)
     {
         GuidelineSet gs = new GuidelineSet();
         Point start = new Point();
         Point end = new Point();
         start.Y = TopMargin;
         end.Y = ActualHeight - BottomMargin;
         Pen pen = new Pen(Brushes.Blue, _lineWidth);
         pen.DashStyle = DashStyles.Dash;
         double halfPen = pen.Thickness / 2;
         int n = _durations.Durations.Count;
         double offset = -ViewHelper.TimespanToPixel(_durations.TimeAxis.StartingTime, _durations.TimeAxis.ZoomScale);
         for (int i = 0; i < n - 1; i++)
         {
             offset += ViewHelper.TimespanToPixel(_durations.Durations[i], _durations.TimeAxis.ZoomScale);
             if (offset > 0 && offset < ActualWidth)
             {
                 start.X = end.X = offset;
                 gs.GuidelinesX.Clear();
                 gs.GuidelinesX.Add(start.X - halfPen);
                 gs.GuidelinesX.Add(start.X + halfPen);
                 drawingContext.PushGuidelineSet(gs.Clone());
                 drawingContext.DrawLine(pen, start, end);
                 drawingContext.Pop();
             }
         }
     }
 }
        /// <summary>
        /// Render in constant interpolation.
        /// </summary>
        /// <param name="drawingContext">Drawing context.</param>
        private void RenderConstantInterpolation(DrawingContext drawingContext)
        {
            int sampleRate = CalculateSampleRate();
            Collection<double> sampleValue = Resample(_samples.Samples, sampleRate);
            Collection<double> deviations = null;
            if (_samples.Deviations != null)
            {
                deviations = Resample(_samples.Deviations, sampleRate);
            }

            Pen pen = new Pen(CurveStroke, CurveStrokeThickness);
            Pen rectPen = new Pen(DeviationStroke, CurveStrokeThickness);
            double halfPen = CurveStrokeThickness / 2;
            GuidelineSet gs = new GuidelineSet();
            for (int pointIndex = (int)Math.Ceiling(_samples.TimeAxis.StartingTime / _samples.TimeAxis.SampleInterval);
                pointIndex < sampleValue.Count; ++pointIndex)
            {
                double value = sampleValue[pointIndex];
                if (IsValidSampleValue(value))
                {
                    Point startPoint = CreatePoint(pointIndex, sampleRate, value);
                    Point endPoint = CreatePoint(pointIndex + 1, sampleRate, value);
                    endPoint.Y = startPoint.Y;
                    if (startPoint.X > Width)
                    {
                        break;
                    }

                    if (deviations != null)
                    {
                        value = deviations[pointIndex];
                        if (IsValidSampleValue(value))
                        {
                            Rect rect = new Rect();
                            rect.Width = ViewHelper.TimespanToPixel(_samples.TimeAxis.SampleInterval * (double)sampleRate, _horizontalScale);
                            double deviation = value * RenderHeightPixel / (_samples.YAxis.RenderRange.Max - _samples.YAxis.RenderRange.Min);
                            rect.Height = deviation * 2;
                            rect.X = startPoint.X;
                            rect.Y = startPoint.Y - deviation;
                            gs.GuidelinesX.Clear();
                            gs.GuidelinesX.Add(rect.X - halfPen);
                            gs.GuidelinesX.Add(rect.X + halfPen);
                            gs.GuidelinesX.Add(rect.Right - halfPen);
                            gs.GuidelinesX.Add(rect.Right + halfPen);
                            gs.GuidelinesY.Clear();
                            gs.GuidelinesY.Add(rect.Y - halfPen);
                            gs.GuidelinesY.Add(rect.Y + halfPen);
                            gs.GuidelinesY.Add(rect.Bottom - halfPen);
                            gs.GuidelinesY.Add(rect.Bottom + halfPen);
                            drawingContext.PushGuidelineSet(gs.Clone());
                            if (pointIndex == _hoverFrame)
                            {
                                drawingContext.DrawRectangle(Brushes.Yellow, new Pen(Brushes.Red, CurveStrokeThickness), rect);
                            }
                            else
                            {
                                drawingContext.DrawRectangle(DeviationFill, rectPen, rect);
                            }

                            drawingContext.Pop();
                        }
                    }

                    gs.GuidelinesX.Clear();
                    gs.GuidelinesY.Clear();
                    gs.GuidelinesY.Add(startPoint.Y - halfPen);
                    gs.GuidelinesY.Add(startPoint.Y + halfPen);
                    drawingContext.PushGuidelineSet(gs.Clone());
                    drawingContext.DrawLine(pen, startPoint, endPoint);
                    drawingContext.Pop();
                }
            }
        }