private void ConfigureGraph(RetiredColonyData.RetiredColonyStatistic statistic, GameObject layoutBlockGameObject) { GameObject gameObject = Util.KInstantiateUI(lineGraphPrefab, layoutBlockGameObject, true); activeColonyWidgets.Add(statistic.name, gameObject); GraphBase componentInChildren = gameObject.GetComponentInChildren <GraphBase>(); componentInChildren.graphName = statistic.name; componentInChildren.label_title.SetText(componentInChildren.graphName); componentInChildren.axis_x.name = statistic.nameX; componentInChildren.axis_y.name = statistic.nameY; componentInChildren.label_x.SetText(componentInChildren.axis_x.name); componentInChildren.label_y.SetText(componentInChildren.axis_y.name); LineLayer componentInChildren2 = gameObject.GetComponentInChildren <LineLayer>(); componentInChildren.axis_y.min_value = 0f; componentInChildren.axis_y.max_value = statistic.GetByMaxValue().second * 1.2f; componentInChildren.axis_x.min_value = 0f; componentInChildren.axis_x.max_value = statistic.GetByMaxKey().first; componentInChildren.axis_x.guide_frequency = (componentInChildren.axis_x.max_value - componentInChildren.axis_x.min_value) / 10f; componentInChildren.axis_y.guide_frequency = (componentInChildren.axis_y.max_value - componentInChildren.axis_y.min_value) / 10f; componentInChildren.RefreshGuides(); Tuple <float, float>[] value = statistic.value; GraphedLine graphedLine = componentInChildren2.NewLine(value, statistic.id); if (statColors.ContainsKey(statistic.id)) { componentInChildren2.line_formatting[componentInChildren2.line_formatting.Length - 1].color = statColors[statistic.id]; } graphedLine.line_renderer.color = componentInChildren2.line_formatting[componentInChildren2.line_formatting.Length - 1].color; }
public GraphedLine NewLine(Vector2[] points, string ID = "", int compressDataToPointCount = 128, DataScalingType compressType = DataScalingType.DropValues) { GameObject gameObject = Util.KInstantiateUI(prefab_line, line_container, true); if (ID == string.Empty) { ID = lines.Count.ToString(); } gameObject.name = $"line_{ID}"; GraphedLine component = gameObject.GetComponent <GraphedLine>(); if (points.Length > compressDataToPointCount) { Vector2[] array = new Vector2[compressDataToPointCount]; if (compressType == DataScalingType.DropValues) { float num = (float)(points.Length - compressDataToPointCount + 1); float num2 = (float)points.Length / num; int num3 = 0; float num4 = 0f; for (int i = 0; i < points.Length; i++) { num4 += 1f; if (num4 >= num2) { num4 -= num2; } else { array[num3] = points[i]; num3++; } } if (array[compressDataToPointCount - 1] == Vector2.zero) { array[compressDataToPointCount - 1] = array[compressDataToPointCount - 2]; } } else { int num5 = points.Length / compressDataToPointCount; for (int j = 0; j < compressDataToPointCount; j++) { if (j > 0) { float num6 = 0f; switch (compressType) { case DataScalingType.Max: for (int l = 0; l < num5; l++) { num6 = Mathf.Max(num6, points[j * num5 - l].y); } break; case DataScalingType.Average: for (int k = 0; k < num5; k++) { num6 += points[j * num5 - k].y; } num6 /= (float)num5; break; } array[j] = new Vector2(points[j * num5].x, num6); } } } points = array; } component.SetPoints(points); component.line_renderer.color = line_formatting[lines.Count % line_formatting.Length].color; component.line_renderer.LineThickness = (float)line_formatting[lines.Count % line_formatting.Length].thickness; lines.Add(component); return(component); }