Profile Picture

Chart (type FastPoint) with Y-axis as NLogarithmicScaleConfigurator using custom Paint function

Posted By joern kunze 6 Years Ago

Chart (type FastPoint) with Y-axis as NLogarithmicScaleConfigurator...

Author
Message
joern kunze
Problem Posted 6 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 86, Visits: 221
Hi Experts,

I have a FastPoint Chart with Y axis as a NLogarithmicScaleConfigurator. The plotting of the points is done in Paint2D.
When I use the code with a Linear axis everything is working fine. But when I switch the axis to NLogarithmicScale, the following doesnt work anymore:
      NScale axisScaleY = m_Chart.Axis(m_Series.VerticalAxes[0]).Scale;
      axisScaleY.Ruler.GetScaleAndOffset(out scaleY, out offsetY);

=> the out values scaleY and offsetY are always 0. 

So what must be changed in the following code that it also is working for logarithmic axis ?

Thanks for your help,
Best regards,
Joern

 Code which is working for Linear axis::

  public void Paint2D(NChartRenderingContext2D context, NGraphics graphics)
   {
    unsafe {
      if (graphics == null || graphics.DeviceGraphics == null) return;

      if (m_XValues.Length < 1 || m_YValues.Length < 1) return;

      NScale axisScaleX = m_Chart.Axis(m_Series.HorizontalAxes[0]).Scale;
      NScale axisScaleY = m_Chart.Axis(m_Series.VerticalAxes[0]).Scale;
      NScaleRuler rulerX = axisScaleX.Ruler;
      NScaleRuler rulerY = axisScaleY.Ruler;
     // cache values need to be transformed from logical to scale
      double[] xValues = m_XValues;
      double[] yValues = m_YValues;

      int count = xValues.Length;
      float modelScaleX = (float)1.0;  
      float modelScaleY = (float)1.0;  

      GraphicsState state = graphics.DeviceGraphics.Save();

      context.ActivateCamera(m_Chart);

      double scaleX = 0.0;
      double offsetX = 0.0;

      rulerX.GetScaleAndOffset(out scaleX, out offsetX);
      scaleX *= modelScaleX;
      offsetX *= modelScaleX;

      double scaleY = 0.0;
      double offsetY = 0.0;

      try {
       rulerY.GetScaleAndOffset(out scaleY, out offsetY);
      }
      catch (Exception) {
       //throw;
      }

      scaleY *= modelScaleY;
      offsetY *= modelScaleY;


      NRange1DD viewXRange = axisScaleX.RulerRange;
      NRange1DD viewYRange = axisScaleY.RulerRange;


      double viewX1 = viewXRange.GetValueInRange(m_XRange.Begin);
      double viewX2 = viewXRange.GetValueInRange(m_XRange.End);
      double viewY1 = viewYRange.GetValueInRange(m_YRange.Begin);
      double viewY2 = viewYRange.GetValueInRange(m_YRange.End);

      if (double.IsNaN(viewX1) || double.IsInfinity(viewX1)) return;
      if (double.IsNaN(viewX2) || double.IsInfinity(viewX2)) return;
      if (double.IsNaN(viewY1) || double.IsInfinity(viewY1)) return;
      if (double.IsNaN(viewY2) || double.IsInfinity(viewY2)) return;

      int pointSize = (int)context.Device.LengthConverter.ConvertNLengthToLength(new NLength(m_PointSize, NGraphicsUnit.Point));
      int pointSizeDiv2 = pointSize / 2;

      int pointOffsetX = pointSize;
      int pointOffsetY = pointSize;

      float x1 = (float)(viewX1 * scaleX + offsetX);
      float y1 = (float)(viewY1 * scaleY + offsetY);

....

      graphics.DeviceGraphics.DrawImage(drawBitmap
                  , new Rectangle((int)x1
                  , (int)y2
                  , drawBitmap.Width
                  , drawBitmap.Height)
                  , new Rectangle(0, 0, drawBitmap.Width, drawBitmap.Height)
                  , GraphicsUnit.Pixel);
       Point[] points = new Point[] { new Point((int)x1, (int)y2) };

       graphics.DeviceGraphics.Transform.TransformPoints(points);
       m_SelectionOrigin = points[0];



Nevron Support
Posted 6 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: Last Week
Posts: 3,054, Visits: 4,009
Hi Joern,

The GetScaleOffset method will not work because the logarithmic function is not linear and cannot be defined with a scale/offset parameter. In order to transform the coordinates from logical to scale you need to use the LogicalToScale method. Let us know if you meet any problems - we'll gladly help.

Best Regards,
Nevron Support Team



joern kunze
Posted 6 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 86, Visits: 221
... thanks for the hint using LogicalToScale. But  I could not manage to produce a result using this function. As far as I understand the Scale philosophy according to the NevronHelp (which unfortunatly does not go to much into detail concerning scaling...), there are 3 different spaces for data representation:
Logical (the original x/y data values)
Scale (some internal Nevron specific coordinate system ??)
           for example:
           float y1_Scale = axisScaleY.Ruler.LogicalToScale(fYValues[i]);
View (Bitmap related coordinate system ??)
           for example:
           NScale2DToViewTransformation scaleToView = new NScale2DToViewTransformation(m_Chart,
                          (int)StandardAxis.PrimaryX, m_Chart.Axis(m_Series.VerticalAxes[0]).AxisId);
           NPointF pointView = new NPointF();
            scaleToView.Transform(new NVector2DD(xValue, yValue)
                   , ref pointView);

And now I dont know how to transform the scale-value for the Logarithmic axis to the View (Bitmap) coordinate value. Is there a little example somewhere which demonstrates how this can be done ?

Thanks for your help,
Best regards,
Joern



Nevron Support
Posted 6 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: Last Week
Posts: 3,054, Visits: 4,009
Hi Joern,

Can you post an application that replicates this problem for review. The problem in this case is that the bitmap coordinates are not exactly view coordinates in this case so we would like a working example which we can modify / correct and post back to you...

Best Regards,
Nevron Support Team



joern kunze
Posted 6 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 86, Visits: 221
... I just have prepaired a little example - but since this example contains also some code which should not be disclosed: Can I send you this code so that it is not available for the public ?

Thanks again,
Best regards,
Joern

Nevron Support
Posted 6 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: Last Week
Posts: 3,054, Visits: 4,009
Hi Joern,
Sure - please mail it to support@nevron.com it will be treated as confidential.

Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic