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); }