public static void AvoidLabelOverlap(Serie serie, ComponentTheme theme)
        {
            if (!serie.avoidLabelOverlap)
            {
                return;
            }
            var lastCheckPos = Vector3.zero;
            var data         = serie.data;
            var splitCount   = 0;

            for (int n = 0; n < data.Count; n++)
            {
                var serieData = data[n];
                if (serieData.labelPosition.x != 0 && serieData.labelPosition.x < serie.runtimeCenterPos.x)
                {
                    splitCount = n;
                    break;
                }
            }
            for (int n = 0; n < splitCount; n++)
            {
                CheckSerieDataLabel(serie, data[n], false, theme, ref lastCheckPos);
            }
            lastCheckPos = Vector3.zero;
            for (int n = data.Count - 1; n >= splitCount; n--)
            {
                CheckSerieDataLabel(serie, data[n], true, theme, ref lastCheckPos);
            }
        }
        public virtual void Copy(ComponentTheme theme)
        {
            m_Font                = theme.font;
            m_FontSize            = theme.fontSize;
            m_TextColor           = theme.textColor;
            m_TextBackgroundColor = theme.textBackgroundColor;
#if dUI_TextMeshPro
            m_TMPFont = theme.tmpFont;
#endif
        }
示例#3
0
 public static Color GetTexBackgroundColor(Tooltip tooltip, ComponentTheme theme)
 {
     if (!ChartHelper.IsClearColor(tooltip.textStyle.backgroundColor))
     {
         return(tooltip.textStyle.backgroundColor);
     }
     else
     {
         return(theme.textBackgroundColor);
     }
 }
示例#4
0
 public int GetFontSize(ComponentTheme defaultTheme)
 {
     if (fontSize == 0)
     {
         return(defaultTheme.fontSize);
     }
     else
     {
         return(fontSize);
     }
 }
示例#5
0
        public void SetFontAndSizeAndStyle(TextStyle textStyle, ComponentTheme theme)
        {
#if dUI_TextMeshPro
            if (m_TMPText == null)
            {
                return;
            }
            m_TMPText.font      = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
            m_TMPText.fontSize  = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize;
            m_TMPText.fontStyle = textStyle.tmpFontStyle;
#else
            if (m_Text != null)
            {
                m_Text.font      = textStyle.font == null ? theme.font : textStyle.font;
                m_Text.fontSize  = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize;
                m_Text.fontStyle = textStyle.fontStyle;
            }
#endif
        }
示例#6
0
        public static ChartText AddTextObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
                                              Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme)
        {
            GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);

            txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate);
            var chartText = new ChartText();

#if dUI_TextMeshPro
            RemoveComponent <Text>(txtObj);
            chartText.tmpText                    = GetOrAddComponent <TextMeshProUGUI>(txtObj);
            chartText.tmpText.font               = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
            chartText.tmpText.fontStyle          = textStyle.tmpFontStyle;
            chartText.tmpText.alignment          = textStyle.tmpAlignment;
            chartText.tmpText.richText           = true;
            chartText.tmpText.raycastTarget      = false;
            chartText.tmpText.enableWordWrapping = false;
#else
            chartText.text                    = GetOrAddComponent <Text>(txtObj);
            chartText.text.font               = textStyle.font == null ? theme.font : textStyle.font;
            chartText.text.fontStyle          = textStyle.fontStyle;
            chartText.text.alignment          = textStyle.alignment;
            chartText.text.horizontalOverflow = HorizontalWrapMode.Overflow;
            chartText.text.verticalOverflow   = VerticalWrapMode.Overflow;
            chartText.text.supportRichText    = true;
            chartText.text.raycastTarget      = false;
#endif
            chartText.SetColor(textStyle.GetColor(theme.textColor));
            chartText.SetFontSize(textStyle.fontSize > 0 ? textStyle.fontSize : theme.fontSize);
            chartText.SetText("Text");
            chartText.SetLineSpacing(textStyle.lineSpacing);

            RectTransform rect = GetOrAddComponent <RectTransform>(txtObj);
            rect.localPosition = Vector3.zero;
            rect.sizeDelta     = sizeDelta;
            rect.anchorMin     = anchorMin;
            rect.anchorMax     = anchorMax;
            rect.pivot         = pivot;
            return(chartText);
        }
 public virtual void Reset(ComponentTheme defaultTheme)
 {
     Copy(defaultTheme);
 }
示例#8
0
        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);
        }
        private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ComponentTheme theme,
                                                ref Vector3 lastCheckPos)
        {
            if (!serieData.canShowLabel)
            {
                serieData.SetLabelActive(false);
                return;
            }
            if (!serieData.show)
            {
                return;
            }
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            var fontSize   = serieLabel.textStyle.GetFontSize(theme);

            if (!serieLabel.show)
            {
                return;
            }
            if (serieLabel.position != SerieLabel.Position.Outside)
            {
                return;
            }
            if (lastCheckPos == Vector3.zero)
            {
                lastCheckPos = serieData.labelPosition;
            }
            else if (serieData.labelPosition.x != 0)
            {
                if (lastCheckPos.y - serieData.labelPosition.y < fontSize)
                {
                    var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
                    var y1          = lastCheckPos.y - fontSize;
                    var cy          = serie.runtimeCenterPos.y;
                    var diff        = Mathf.Abs(y1 - cy);
                    var diffX       = labelRadius * labelRadius - diff * diff;
                    diffX = diffX <= 0 ? 0 : diffX;
                    var x1 = serie.runtimeCenterPos.x + Mathf.Sqrt(diffX) * (isLeft ? -1 : 1);
                    serieData.labelPosition = new Vector3(x1, y1);
                }
                lastCheckPos = serieData.labelPosition;
                serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel));
            }
        }