Profile Picture

How do I prevent Custom Series from printing on axis?

Posted By Harry Kindle 8 Years Ago
Author
Message
Harry Kindle
Posted 8 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 2, Visits: 12
Thanks, that helped me find the correct form for clipping.
I recognized the "Bezier" example from the post that taught me how to use custom series.


Nevron Support
Posted 8 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Harry,

   /// <summary>
   /// Performs custom painting
   /// </summary>
   /// <param name="context"></param>
   /// <param name="graphics"></param>
   public void Paint2D(NChartRenderingContext2D context, NGraphics graphics)
   {
    NVector3DF vecView = new NVector3DF();
    NVector3DF vecModel = new NVector3DF();
    NScaleRuler rulerX = m_Chart.Axis(m_Series.HorizontalAxes[0]).Scale.Ruler;
    NScaleRuler rulerY = m_Chart.Axis(m_Series.VerticalAxes[0]).Scale.Ruler;

    // current number of accumulated Bezier points
    int bpCount = 0;

    // accumulated Bezier points
    PointF[] bezierPoints = new PointF[4];

    NRange1DD xRange = m_Chart.Axis(StandardAxis.PrimaryX).Scale.RulerRange;
    NRange1DD yRange = m_Chart.Axis(StandardAxis.PrimaryY).Scale.RulerRange;

    NScale2DToViewTransformation transform = new NScale2DToViewTransformation(m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);

    NPointF viewLeftTop = NPointF.Empty;
    NPointF viewRightBottom = NPointF.Empty;
    transform.Transform(new NVector2DD(xRange.Begin, yRange.Begin), ref viewLeftTop);
    transform.Transform(new NVector2DD(xRange.End, yRange.End), ref viewRightBottom);

    NRectangleF clipRect = new NRectangleF(viewLeftTop.X, viewLeftTop.Y, viewRightBottom.X - viewLeftTop.X, viewRightBottom.Y - viewLeftTop.Y);
    clipRect.Normalize();

    using (Region clipRegion = new Region(clipRect.ToRectangleF()))
    {
     Region oldCilp = graphics.DeviceGraphics.Clip;
     try
     {
      graphics.DeviceGraphics.Clip = clipRegion;

      for (int i = 0; i < Points.Length; i++)
      {
       // Transform values to chart model coorinates
       vecModel.X = rulerX.LogicalToScale(Points[i].X);
       vecModel.Y = rulerY.LogicalToScale(Points[i].Y);

       // Transform model coordinates to view coordinates
       m_Chart.TransformModelToClient(context, vecModel, ref vecView);

       // Draw the current point
       bool isControlPoint = (i % 3) != 0;
       if (isControlPoint)
       {
        NRectangleF rect = new NRectangleF(vecView.X - 3, vecView.Y - 3, 6, 6);
        graphics.PaintEllipse(ControlPointFill, null, rect);
       }
       else
       {
        NRectangleF rect = new NRectangleF(vecView.X - 5, vecView.Y - 5, 10, 10);
        graphics.PaintEllipse(PointFill, null, rect);
       }

       // Accumulate Bezier point
       bezierPoints[bpCount] = new PointF(vecView.X, vecView.Y);
       bpCount++;

       if (bpCount == 4)
       {
        // Draw tangents
        graphics.DrawLine(TangentStroke, new NPointF(bezierPoints[0]), new NPointF(bezierPoints[1]));
        graphics.DrawLine(TangentStroke, new NPointF(bezierPoints[2]), new NPointF(bezierPoints[3]));

        // Draw Bezier line
        GraphicsPath path = new GraphicsPath();
        path.AddBezier(bezierPoints[0], bezierPoints[1], bezierPoints[2], bezierPoints[3]);
        graphics.PaintPath(null, BezierStroke, path);
        path.Dispose();

        // Update accumultaed points
        bezierPoints[0] = bezierPoints[3];
        bpCount = 1;
       }
      }
     }
     finally
     {
      graphics.DeviceGraphics.Clip = oldCilp;
     }
     
    }
   }

The relevant code is:

    NRange1DD xRange = m_Chart.Axis(StandardAxis.PrimaryX).Scale.RulerRange;
    NRange1DD yRange = m_Chart.Axis(StandardAxis.PrimaryY).Scale.RulerRange;

    NScale2DToViewTransformation transform = new NScale2DToViewTransformation(m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);

    NPointF viewLeftTop = NPointF.Empty;
    NPointF viewRightBottom = NPointF.Empty;
    transform.Transform(new NVector2DD(xRange.Begin, yRange.Begin), ref viewLeftTop);
    transform.Transform(new NVector2DD(xRange.End, yRange.End), ref viewRightBottom);

    NRectangleF clipRect = new NRectangleF(viewLeftTop.X, viewLeftTop.Y, viewRightBottom.X - viewLeftTop.X, viewRightBottom.Y - viewLeftTop.Y);
    clipRect.Normalize();

    using (Region clipRegion = new Region(clipRect.ToRectangleF()))
    {
     Region oldCilp = graphics.DeviceGraphics.Clip;
     try
     {
      graphics.DeviceGraphics.Clip = clipRegion;

      // Painting goes here  
     }
     finally
     {
      graphics.DeviceGraphics.Clip = oldCilp;
     }
     
    }

Hope this helps - let us know if you have any questions or meet any problems.


Best Regards,
Nevron Support Team



Harry Kindle
Question Posted 8 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 2, Visits: 12
I am using a custom series to paint polygons on a chart, but the paint (green) covers the entire chart.
How do I use custom series to paint within the chart area only?  -400 to 400 on both axis below.  Leaving the axis labels white.
https://www.nevron.com/forum/uploads/images/d6f5e9a0-cc36-4ac9-97e0-7fc6.jpg

My guess is that there is some way to clip the custom series drawing area so it only paints on the chart area and not on the chart axis notations, but have not stumbled upon such a method in the documentation or the forum.
Any help is appreciated.
Thanks,
Harry Kindle




Similar Topics


Reading This Topic