private void InitAxisLabel() { if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Gauge)) { return; } var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, chart.transform, chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); labelObject.hideFlags = chart.chartHideFlags; SerieLabelPool.ReleaseAll(labelObject.transform); for (int i = 0; i < chart.series.Count; i++) { var serie = chart.series.list[i]; var serieLabel = serie.gaugeAxis.axisLabel; var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1); var startAngle = serie.startAngle; serie.gaugeAxis.ClearLabelObject(); SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); for (int j = 0; j < count; j++) { var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j); var color = Color.grey; var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, color, 100, 100, chart.theme); var iconImage = labelObj.transform.Find("Icon").GetComponent <Image>(); var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; var item = new ChartLabel(); item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); item.SetIcon(iconImage); item.SetIconActive(false); serie.gaugeAxis.AddLabelObject(item); } UpdateAxisLabel(serie); } }
protected void AddSerieLabel(Serie serie, SerieData serieData, int count = -1) { if (m_SerieLabelRoot == null) { return; } if (count == -1) { count = serie.dataCount; } var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); var iconStyle = SerieHelper.GetIconStyle(serie, serieData); if (serie.IsPerformanceMode()) { return; } if (!serieLabel.show && !iconStyle.show) { return; } if (serie.animation.enable && serie.animation.HasFadeOut()) { return; } var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index); var color = Color.grey; if (serie.type == SerieType.Pie) { color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white : (Color)m_Theme.GetColor(count); } else { color = !ChartHelper.IsClearColor(serieLabel.textStyle.color) ? serieLabel.textStyle.color : (Color)m_Theme.GetColor(serie.index); } var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, color, iconStyle.width, iconStyle.height, theme); var iconImage = labelObj.transform.Find("Icon").GetComponent <Image>(); var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; var item = new ChartLabel(); item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); item.SetIcon(iconImage); item.SetIconActive(iconStyle.show); serieData.labelObject = item; }
private void InitMarkLineLabel(Serie serie, MarkLineData data, Color serieColor) { data.painter = chart.m_PainterTop; data.refreshComponent = delegate() { var label = data.label; var textName = string.Format("markLine_{0}_{1}", serie.index, data.index); var color = !ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color : chart.theme.axis.textColor; var element = ChartHelper.AddSerieLabel(textName, m_MarkLineLabelRoot.transform, label.backgroundWidth, label.backgroundHeight, color, label.textStyle, chart.theme); var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0; var item = new ChartLabel(); item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom); item.SetIconActive(false); item.SetActive(data.label.show); item.SetPosition(MarkLineHelper.GetLabelPosition(data)); item.SetText(MarkLineHelper.GetFormatterContent(serie, data)); data.runtimeLabel = item; }; data.refreshComponent(); }
public static ChartLabel AddAxisLabelObject(int total, int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme, string content) { var textStyle = axis.axisLabel.textStyle; var iconStyle = axis.iconStyle; var label = new ChartLabel(); label.gameObject = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); // TODO: 为了兼容旧版本,这里后面版本可以去掉 var oldText = label.gameObject.GetComponent <Text>(); if (oldText != null) { GameObject.DestroyImmediate(oldText); } var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0); if (labelShow) { if (!axis.axisLabel.showStartLabel && index == 0) { labelShow = false; } else if (!axis.axisLabel.showEndLabel && index == total - 1) { labelShow = false; } } label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme); label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height); label.SetAutoSize(false); label.UpdateIcon(iconStyle, axis.GetIcon(index)); label.label.SetActive(labelShow); label.SetText(content); return(label); }
public static void AdjustCircleLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) { var txtWidth = txt.label.GetPreferredWidth(); var sizeDelta = new Vector2(txtWidth, txt.label.GetPreferredHeight()); txt.label.SetSizeDelta(sizeDelta); var diff = pos.x - cenPos.x; if (diff < -1f) //left { pos = new Vector3(pos.x - txtWidth / 2, pos.y); } else if (diff > 1f) //right { pos = new Vector3(pos.x + txtWidth / 2, pos.y); } else { float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2; pos = new Vector3(pos.x, y); } txt.SetPosition(pos + offset); }
internal void CheckValueLabelActive(Axis axis, int i, ChartLabel label, Vector3 pos) { if (!axis.show || !axis.axisLabel.show) { label.SetTextActive(false); return; } if (axis.IsValue()) { if (orient == Orient.Horizonal) { if (i == 0) { var dist = GetLabelPosition(0, 1).x - pos.x; label.SetTextActive(dist > label.text.GetPreferredWidth()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.x - GetLabelPosition(0, i - 1).x; label.SetTextActive(dist > label.text.GetPreferredWidth()); } } else { if (i == 0) { var dist = GetLabelPosition(0, 1).y - pos.y; label.SetTextActive(dist > label.text.GetPreferredHeight()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.y - GetLabelPosition(0, i - 1).y; label.SetTextActive(dist > label.text.GetPreferredHeight()); } } } }
public void AddLabelObject(ChartLabel label) { m_RuntimeLabelList.Add(label); }
protected void InitAxis(Axis relativedAxis, Orient orient, float axisStartX, float axisStartY, float axisLength, float relativedLength) { Axis axis = component; chart.InitAxisRuntimeData(axis); var objName = ChartCached.GetComponentObjectName(axis); var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); axisObj.SetActive(axis.show); axisObj.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(axisObj); axis.gameObject = axisObj; axis.context.labelObjectList.Clear(); if (!axis.show) { return; } var axisLabelTextStyle = axis.axisLabel.textStyle; var dataZoom = chart.GetDataZoomOfAxis(axis); var splitNumber = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom); var totalWidth = 0f; var eachWidth = AxisHelper.GetEachWidth(axis, axisLength, dataZoom); var gapWidth = axis.boundaryGap ? eachWidth / 2 : 0; var textWidth = axis.axisLabel.width > 0 ? axis.axisLabel.width : (orient == Orient.Horizonal ? AxisHelper.GetScaleWidth(axis, axisLength, 0, dataZoom) : (axisStartX - chart.chartX) ); var textHeight = axis.axisLabel.height > 0 ? axis.axisLabel.height : 20f; var isPercentStack = SeriesHelper.IsPercentStack <Bar>(chart.series); var inside = axis.axisLabel.inside; var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter : ((inside && axis.IsLeft()) || (!inside && axis.IsRight()) ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight); if (axis.IsCategory() && axis.boundaryGap) { splitNumber -= 1; } for (int i = 0; i < splitNumber; i++) { var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom); var labelName = AxisHelper.GetLabelName(axis, axisLength, i, axis.context.minValue, axis.context.maxValue, dataZoom, isPercentStack); var label = ChartHelper.AddAxisLabelObject(splitNumber, i, ChartCached.GetAxisLabelName(i), axisObj.transform, new Vector2(textWidth, textHeight), axis, chart.theme.axis, labelName, Color.clear, defaultAlignment); if (i == 0) { axis.axisLabel.SetRelatedText(label.text, labelWidth); } var pos = GetLabelPosition(totalWidth + gapWidth, i); label.SetPosition(pos); CheckValueLabelActive(axis, i, label, pos); axis.context.labelObjectList.Add(label); totalWidth += labelWidth; } if (axis.axisName.show) { ChartLabel label = null; var relativedDist = (relativedAxis == null ? 0 : relativedAxis.context.offset); var zeroPos = new Vector3(axisStartX, axisStartY + relativedDist); var offset = axis.axisName.labelStyle.offset; var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor); if (orient == Orient.Horizonal) { var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); var posY = !axis.axisName.onZero && grid != null? grid.context.y : GetAxisLineXOrY() + offset.y; switch (axis.axisName.labelStyle.position) { case LabelStyle.Position.Start: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleRight); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset) : new Vector2(zeroPos.x - offset.x, posY)); break; case LabelStyle.Position.Middle: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset) : new Vector2(axisStartX + axisLength / 2 + offset.x, posY)); break; default: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleLeft); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset) : new Vector2(axisStartX + axisLength + offset.x, posY)); break; } } else { var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); var posX = !axis.axisName.onZero && grid != null? grid.context.x : GetAxisLineXOrY() + offset.x; switch (axis.axisName.labelStyle.position) { case LabelStyle.Position.Start: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY - offset.y) : new Vector2(posX, axisStartY - offset.y)); break; case LabelStyle.Position.Middle: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) : new Vector2(posX, axisStartY + axisLength / 2 + offset.y)); break; default: //LabelStyle.Position label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY + axisLength + offset.y) : new Vector2(posX, axisStartY + axisLength + offset.y)); break; } } } }