|
QuantShare
2011-02-09 04:54:34
1
|
|
Best Answer
Here is an example:
bool isNewPair = false;
if(Functions.ClickPositions.Length == 0)
{
Global.SetVariable("count_distance", (double)0);
Global.SetVariable("average_distance", (double)0);
Global.SetVariable("last_click", 0);
return;
}
else if(Math.IEEERemainder(Functions.ClickPositions.Length, 2) == 0)
{
isNewPair = true;
}
string textDis = "";
if(isNewPair)
{
int lastClickIndex = Functions.ClickPositions.Length - 1;
PointPosition p1 = Functions.ClickPositions[lastClickIndex - 1];
PointPosition p2 = Functions.ClickPositions[lastClickIndex];
double distance = Math.Abs(p1.X - p2.X);
double avgDistance = 0;
if((int)Global.GetVariable("last_click") != lastClickIndex)
{
double count = 0;
if(Global.ContainsVariable("average_distance"))
{
count = (double)Global.GetVariable("count_distance");
avgDistance = (double)Global.GetVariable("average_distance");
avgDistance = avgDistance * count; // Calculate total distances
}
count = count + 1;
avgDistance = avgDistance + distance;
avgDistance = avgDistance / count;
Global.SetVariable("count_distance", count);
Global.SetVariable("average_distance", avgDistance);
Global.SetVariable("last_click", lastClickIndex);
}
else
{
avgDistance = (double)Global.GetVariable("average_distance");
}
textDis = "Last Distance: " + distance + " - Average: " + Math.Round(avgDistance, 2);
}
else
{
textDis = "Click on Chart";
}
TextObj text = Functions.PaneObject.DrawText("Distance", textDis, 0, 0.95);
text.UseFractionCoordinate = true;
|
|