private List <float> PlaceXLabels(XLabelGroup xLabelGroup, float originX, float originY, float chartWidth, float chartHeight) { const float MARGIN_RATIO = 0.5f; // 左右分别留出 0.5 个单位长度 int nLabels = xLabelGroup.goLabels.Count; float unitWidth = chartWidth / (nLabels - 1 + MARGIN_RATIO * 2); List <float> xPositions = new List <float>(); float beginPosition = originX + MARGIN_RATIO * unitWidth; for (int i = 0; i < nLabels; ++i) { float currPosition = beginPosition + i * unitWidth; xPositions.Add(currPosition); var goLabel = xLabelGroup.goLabels[i]; if (goLabel == null) { continue; } var rectTransform = goLabel.GetComponent <RectTransform>(); rectTransform.anchoredPosition = new Vector2(currPosition, originY); } return(xPositions); }
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, }); }
private void UpdateXLabelsSizes(XLabelGroup xLabelGroup) { float maxXLabelHeight = 0; foreach (var goXLabel in xLabelGroup.goLabels) { if (goXLabel == null) { continue; } var goLabel = Common.GetChild(goXLabel, "Label"); var rectTransform = goLabel.GetComponent <RectTransform>(); float labelHeight = 5 + (rectTransform.rect.width + rectTransform.rect.height) * 0.707106f; maxXLabelHeight = Mathf.Max(labelHeight, maxXLabelHeight); goLabel.GetComponent <Text>().color = PanelCharts.CHART_LABEL_COLOR; var goCoordinate = Common.GetChild(goXLabel, "Coordinate"); goCoordinate.GetComponent <Image>().color = PanelCharts.CHART_AXIS_COLOR; } xLabelGroup.maxLabelHeight = maxXLabelHeight; }