private void PlaceYLabels(YLabelGroup yLabelGroup, float originX, float originY, float chartWidth, float chartHeight) { int nLabels = yLabelGroup.goLabels.Count; double range = yLabelGroup.maxValue - yLabelGroup.minValue; for (int i = 0; i < nLabels; ++i) { double yValue = yLabelGroup.labelValues[i]; float position = (float)(originY + (yValue - yLabelGroup.minValue) / range * chartHeight); var goLabel = yLabelGroup.goLabels[i]; var rectTransform = goLabel.GetComponent <RectTransform>(); rectTransform.anchoredPosition = new Vector2(originX, position); } }
private void UpdateYLabelsSizes(YLabelGroup yLabelGroup) { float maxYLabelWidth = 0; foreach (var goYLabel in yLabelGroup.goLabels) { var goLabel = Common.GetChild(goYLabel, "Label"); var rectTransform = goLabel.GetComponent <RectTransform>(); float labelWidth = rectTransform.rect.width + 10; maxYLabelWidth = Mathf.Max(labelWidth, maxYLabelWidth); goLabel.GetComponent <Text>().color = PanelCharts.CHART_LABEL_COLOR; var goCoordinate = Common.GetChild(goYLabel, "Coordinate"); goCoordinate.GetComponent <Image>().color = PanelCharts.CHART_AXIS_COLOR; } yLabelGroup.maxLabelWidth = maxYLabelWidth; }
private ChartInfo DrawChartFrame(XLabelGroup xLabelGroup, YLabelGroup yLabelGroup) { var rectTransform = this.chartContainer.GetComponent <RectTransform>(); float totalWidth = rectTransform.rect.width; float totalHeight = rectTransform.rect.height; float originX = yLabelGroup.maxLabelWidth; float originY = xLabelGroup.maxLabelHeight; float chartWidth = totalWidth - originX; float chartHeight = totalHeight - originY; var xAxis = DrawXAxis(originX, originY, chartWidth, chartHeight); var yAxis = DrawYAxis(originX, originY, chartWidth, chartHeight); var xPositions = PlaceXLabels(xLabelGroup, originX, originY, chartWidth, chartHeight); PlaceYLabels(yLabelGroup, originX, originY, chartWidth, chartHeight); var tooltip = CreateTooltip(); return(new ChartInfo { originX = originX, originY = originY, chartWidth = chartWidth, chartHeight = chartHeight, xAxis = xAxis, yAxis = yAxis, goXLabels = xLabelGroup.goLabels, xLabels = xLabelGroup.labels, xPositions = xPositions, goYLabels = yLabelGroup.goLabels, yLabelValues = yLabelGroup.labelValues, yValues = yLabelGroup.values, yMinValue = yLabelGroup.minValue, yMaxValue = yLabelGroup.maxValue, tooltip = tooltip, }); }