Nevron Forum

Distance factor for sampling and clustering

https://www.nevron.com/Forum/Topic5993.aspx

By Leonardo Rocha 1 - Wednesday, December 28, 2011

Hi,

I am trying to set up the sampling distance and also the clustering distance in order to render each point without overlap, i.e., all point are draw, excepting the points that will have the same (x,y) coordinates in the screen. This should take in account the axes ranges.

Rgds,

Leo

By Nevron Support - Friday, December 30, 2011

Hi Leo,

For this purpose you will have to determine how the logical units map to actual screen pixels. The following code snippet shows how to acheive this:

nChartControl1.Document.Calculate();
nChartControl1.Document.RecalcLayout(nChartControl1.View.Context);

NChart chart1 = nChartControl1.Charts[0];
NAxis xAxis = chart.Axis(StandardAxis.PrimaryX);
NAxis yAxis = chart.Axis(StandardAxis.PrimaryY);

NRange1DD xRulerRange = xAxis.Scale.RulerRange;
NRange1DD yRulerRange = yAxis.Scale.RulerRange;

NRange1DF xModelRange = xAxis.Scale.Ruler.LogicalToScale(xRulerRange);
NRange1DF yModelRange = yAxis.Scale.Ruler.LogicalToScale(yRulerRange);

float xPixelsPerUnit = (float)(xModelRange.GetLength() / xRulerRange.GetLength());
float yPixelsPerUnit = (float)(yModelRange.GetLength() / yRulerRange.GetLength());

m_Point.ClusterDistanceFactor = 0.5 / Math.Max(xPixelsPerUnit, yPixelsPerUnit);

If the number of data points is too large there is a more efficient implementation and it is to resample the data using a bitmap of some sort. This will always perform with linear speed instead of n log (n) speed which is the case with the cluster at the expense of more memory in the general case.

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