/// <summary> /// Adjusts the graph after a change has been made to the data or size /// </summary> public void AdjustGraph() { //Previous steps int prevXSteps = xSteps, prevYSteps = ySteps; //Calculate data for displaying the graph CalculateIncrements(rectTransform.rect.width, currentGraph.data[(int)GraphData.dataType.pure].Count, true); CalculateIncrements(rectTransform.rect.height, currentGraph.maxYValue, false); currentGraph.CompressData(compressionFactor); #region Text and Dividers //X Axis Titles and Dividers //If there is less titles/dividers than before if (prevXSteps > xSteps) { for (int i = 0; i < prevXSteps; i++) { //If over the new ammount of titles if (i >= xSteps) { //Delete titles GameObject g = xTitles[xSteps]; xTitles.RemoveAt(xSteps); Destroy(g); //Delete dividers g = xAxisDividers[xSteps]; xAxisDividers.RemoveAt(xSteps); Destroy(g); } //Otherwise just move title and dividers to new position else { ModifyXAxisTitle(i); } } } // Else there is now more steps then there used to be or the same amount else { for (int i = 0; i <= xSteps; i++) { //If more create if (i > prevXSteps) { CreateXAxisTitle(i); } //Else move to new postion else { ModifyXAxisTitle(i); } } } //Y Axis Titles and Dividers //If there is less titles/dividers han before if (prevYSteps > ySteps) { for (int i = 0; i < prevYSteps; i++) { //If over the new ammount of titles if (i >= ySteps) { //Delete titles GameObject g = yTitles[ySteps]; yTitles.RemoveAt(ySteps); Destroy(g); //Delete Dividers g = yAxisDividers[ySteps]; yAxisDividers.RemoveAt(ySteps); Destroy(g); } //Otherwise just move title and dividers to new position else { ModifyYAxisTitle(i); } } } // Else there is now more steps then there used to be or the same amount else { for (int i = 0; i <= ySteps; i++) { //If more create if (i > prevYSteps) { CreateYAxisTitle(i); } //Else move to new position else { ModifyYAxisTitle(i); } } } #endregion int pointsOnScreen = Mathf.CeilToInt((rectTransform.rect.width / xGap) / compressionFactor); if (pointsOnScreen > currentGraph.data[currentGraph.dataToDisplay].Count) { pointsOnScreen = currentGraph.data[currentGraph.dataToDisplay].Count; } //Debug.Log("1. Points on screen = " + pointsOnScreen); //Debug.Log("2. rectTransform.rect.width / xGap = " + (rectTransform.rect.width / xGap)); //Debug.Log("3. total points = " + currentGraph.data[currentGraph.dataToDisplay].Count); //Same structure as before just for points and lines //More than last time or same amount if (pointsOnScreen >= points.Count) { for (int i = 0; i < pointsOnScreen; i++) { //if(xGap * i * compressionFactor > rectTransform.rect.width) //{ // GameObject g = points[currentGraph.data[currentGraph.dataToDisplay].Count]; // points.RemoveAt(currentGraph.data[currentGraph.dataToDisplay].Count); // Destroy(g); // g = joiners[currentGraph.data[currentGraph.dataToDisplay].Count]; // joiners.RemoveAt(currentGraph.data[currentGraph.dataToDisplay].Count); // Destroy(g); // continue; //} //Create if (i >= points.Count) { CreatePoint(new Vector2(xGap * i * compressionFactor, yGap * currentGraph.data[currentGraph.dataToDisplay][i])); CreateJoiner(i, false); } //Move else { ModifyPoint(i); ModifyJoiner(i, false); } } } //Less than last time else { for (int i = 0; i < points.Count; i++) { //Remove Points if (i >= pointsOnScreen) { GameObject g = points[pointsOnScreen]; points.RemoveAt(pointsOnScreen); Destroy(g); g = joiners[pointsOnScreen]; joiners.RemoveAt(pointsOnScreen); Destroy(g); } //Move else { ModifyPoint(i); ModifyJoiner(i, false); } } } if (pointsOnScreen < currentGraph.data[currentGraph.dataToDisplay].Count && currentGraph.data[currentGraph.dataToDisplay].Count > 5) { CreateHiddenPoint(new Vector2(xGap * pointsOnScreen * compressionFactor, yGap * currentGraph.data[currentGraph.dataToDisplay][pointsOnScreen])); CreateJoiner(pointsOnScreen, true); } }