void PrepareAxisLAbels(DataGraph.Axis axis, List <RectTransform> textBoxes) { for (int i = 0; i < axis.majorMarkerList.Count; i++) { GameObject obj = GameObject.Instantiate(textObj); obj.name = textObj.name + "_" + textBoxes.Count.ToString(); obj.transform.SetParent(this.gameObject.transform); textBoxes.Add(obj.GetComponent <RectTransform>()); } }
string UpdateLabels(DataGraph.Axis axis, List <RectTransform> textBoxes) { float unitAdjustement = 0; if (!float.IsInfinity(axis.axisValueMinMax.y)) { if (Mathf.Abs(axis.axisValueMinMax.y) > 10 || (Mathf.Abs(axis.axisValueMinMax.y) < 1)) { while (Mathf.Abs(axis.axisValueMinMax.y) * Mathf.Pow(10f, -unitAdjustement) > 10) { unitAdjustement++; } while (Mathf.Abs(axis.axisValueMinMax.y) * Mathf.Pow(10f, -unitAdjustement) < 1) { unitAdjustement--; } } } for (int i = 0; i < dataPlot.horizontalAxis.majorMarkerList.Count; i++) { float width = Mathf.Abs(textBoxes[i].offsetMax.x - textBoxes[i].offsetMin.x); float height = Mathf.Abs(textBoxes[i].offsetMax.y - textBoxes[i].offsetMin.y); float posX = (axis.majorMarkerList[i].markerPosition) * (axis.stop.x - axis.start.x) + axis.start.x; float posY = (axis.majorMarkerList[i].markerPosition) * (axis.stop.y - axis.start.y) + axis.start.y; TextMeshProUGUI textMeshProUGUI = textBoxes[i].GetComponent <TextMeshProUGUI>(); if ((axis.stop.x - axis.start.x) > (axis.stop.y - axis.start.y)) { textBoxes[i].anchoredPosition = new Vector2(posX * parentWidth, posY * parentHeight - height) + horizontalOffset; textMeshProUGUI.alignment = TextAlignmentOptions.Left; } else { textBoxes[i].anchoredPosition = new Vector2(posX * parentWidth - width, posY * parentHeight - height / 2f) + verticalOffset; textMeshProUGUI.alignment = TextAlignmentOptions.Center; } double result = 0; //if (unitAdjustement < -20) //{ // result = 0; //} //else if (unitAdjustement > 20) //{ // result = 0; //} //else //{ result = Math.Round(Math.Pow(10f, -unitAdjustement) * ((double)(axis.majorMarkerList[i].markerPosition) * (double)(axis.axisValueMinMax.y - axis.axisValueMinMax.x) + (double)axis.axisValueMinMax.x) * 100.0) / 100.0; //} if (!double.IsNaN(result)) { string str = String.Format("{0:F2}", result); textMeshProUGUI.text = str; } else { textMeshProUGUI.text = ""; } } String unit = "10" + "<sup>" + unitAdjustement.ToString() + "</sup>"; return(unit); }