Example #1
0
 public GraphControl()
 {
    mTraceBoxes = new List<TracingBox>();
    mPointTrans = new PointTranslater()
    {
       ZoomX = ZOOM_DEFAULT,
       ZoomY = ZOOM_DEFAULT
    };
 }
Example #2
0
      internal void Draw(DrawingContext dc, PointTranslater pt,
         GraphDrawingOptions op)
      {
         IPlotDataSource plotData = PlotData;
         if (plotData == null)
            return;

         double plotDataBegin = plotData.GetSegmentBegin();
         double plotDataEnd = plotData.GetSegmentEnd();
         double from = Math.Max(Math.Max(op.From, SegmentBegin), plotDataBegin);
         double to = Math.Min(Math.Min(op.To, SegmentEnd), plotDataEnd);
         if (from >= to)
            return;

         //plotData.SetZoom(pt.Zoom);
         plotData.SetSegment(from, to);
         var pointsToDraw = plotData.GetPoints();
         if (pointsToDraw == null)
            return;

         if (pointsToDraw.Count <= 1)
            return;

         var graphPen = new Pen(StrokeBrush, StrokeThickness);
         int startIndex = plotData.GetStartIndex();
         if (startIndex < 0)
            return;

         Rect rect = op.GraphRect;
         rect.X = pt.TransalteX(from);
         rect.Width = pt.TransalteX(to) - rect.X;
         Point next = pt.Translate(pointsToDraw[startIndex]);

         Point boundPoint;
         if (IsInterpolationEnabled)
            boundPoint = plotData.Interpolate(from);
         else
            boundPoint = pointsToDraw[startIndex];

         boundPoint = pt.Translate(boundPoint);
         if (IsInterpolationEnabled)
            dc.DrawLine(graphPen, boundPoint, next);

         if (rect.Left > op.GraphRect.Left)
         {
            dc.DrawEllipse(StrokeBrush, null, boundPoint,
               BOUND_POINT_RADOUS, BOUND_POINT_RADOUS);
         }

         int endIndex = plotData.GetEndIndex();
         for (int i = startIndex; i <= endIndex; i++)
         {
            Point prev = next;
            next = pt.Translate(pointsToDraw[i]);
            if (!(rect.Contains(prev) || rect.Contains(next)))
               continue;

            dc.DrawLine(graphPen, prev, next);
         }

         if (IsInterpolationEnabled)
            boundPoint = plotData.Interpolate(to);
         else
            boundPoint = pointsToDraw[endIndex];

         boundPoint = pt.Translate(boundPoint);
         if (IsInterpolationEnabled)
            dc.DrawLine(graphPen, next, boundPoint);

         if (rect.Right < op.GraphRect.Right)
         {
            dc.DrawEllipse(StrokeBrush, null, boundPoint,
               BOUND_POINT_RADOUS, BOUND_POINT_RADOUS);
         }
      }