voidfindPointsForPage(doubleposition,outintstart,outintend)// given a page position , find the right most and left most indices in the data for that page.
{
intindex=FindClosestIndex(position);// use binary search to find the closest position to the current scroll point
doubleendPosition=position+PageSizeFactor;
doublestartPosition=position-PageSizeFactor;
//starting from the current index , we find the page boundries
for(start=index;start>0;start--)
{
if(mData[start].x<startPosition)// take the first point that is out of the page. so the graph doesn't break at the edge
break;
}
for(end=index;end<mData.Count;end++)
{
if(mData[end].x>endPosition)// take the first point that is out of the page
break;
}
}
voidLoadPage(doublepagePosition)
{
if(graph!=null)
{
Debug.Log("Loading page :"+pagePosition);
graph.DataSource.StartBatch();// call start batch
graph.DataSource.HorizontalViewOrigin=0;
intstart,end;
findPointsForPage(pagePosition,outstart,outend);// get the page edges
graph.DataSource.ClearCategory("Player 2");// clear the cateogry
if(DownSampleToPoints<=0)
LoadWithoutDownSampling(start,end);
else
LoadWithDownSampling(start,end);
graph.DataSource.EndBatch();
graph.HorizontalScrolling=pagePosition;
}
currentPagePosition=pagePosition;
}
publicvoidSetData(List<DoubleVector2>data)
{
if(data==null)
data=newList<DoubleVector2>();// set up an empty list instead of null
if(VerifySorted(data)==false)
{
Debug.LogWarning("The data used with large data feed must be sorted acoording to the x value, aborting operation");
return;
}
mData=data;
LoadPage(currentPagePosition);// load the page at position 0