Ejemplo n.º 1
0
        public static string GetFormatterContent(Serie serie, SerieData serieData,
                                                 float dataValue, float dataTotal, SerieLabel serieLabel = null)
        {
            if (serieLabel == null)
            {
                serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            }
            var numericFormatter = GetLabelNumericFormatter(serie, serieData);
            var serieName        = serie.name;
            var dataName         = serieData != null ? serieData.name : null;

            if (string.IsNullOrEmpty(serieLabel.formatter))
            {
                return(ChartCached.NumberToStr(dataValue, numericFormatter));
            }
            else
            {
                var content = serieLabel.formatter.Replace("{a}", serieName);
                content = content.Replace("{b}", dataName);
                content = content.Replace("{c}", ChartCached.NumberToStr(dataValue, numericFormatter));
                content = content.Replace("{c:f0}", ChartCached.IntToStr((int)Mathf.Round(dataValue)));
                content = content.Replace("{c:f1}", ChartCached.FloatToStr(dataValue, string.Empty, 1));
                content = content.Replace("{c:f2}", ChartCached.FloatToStr(dataValue, string.Empty, 2));
                var percent = dataValue == 0 && dataTotal == 0 ? 0 : dataValue / dataTotal * 100;
                content = content.Replace("{d}", ChartCached.NumberToStr(percent, numericFormatter));
                content = content.Replace("{d:f0}", ChartCached.IntToStr((int)Mathf.Round(percent)));
                content = content.Replace("{d:f1}", ChartCached.FloatToStr(percent, string.Empty, 1));
                content = content.Replace("{d:f2}", ChartCached.FloatToStr(percent, string.Empty, 2));
                content = content.Replace("\\n", "\n");
                content = content.Replace("<br/>", "\n");
                return(content);
            }
        }
Ejemplo n.º 2
0
        public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color,
                                     float iconWidth, float iconHeight)
        {
            GameObject element;

            if (m_Stack.Count == 0 || !Application.isPlaying)
            {
                element = CreateSerieLabel(name, parent, label, font, color, iconWidth, iconHeight);
            }
            else
            {
                element = m_Stack.Pop();
                if (element == null)
                {
                    element = CreateSerieLabel(name, parent, label, font, color, iconWidth, iconHeight);
                }
                m_ReleaseDic.Remove(element.GetInstanceID());
                element.name = name;
                element.transform.SetParent(parent);
                element.transform.localEulerAngles = new Vector3(0, 0, label.rotate);
                var text = element.GetComponentInChildren <Text>();
                text.color     = color;
                text.font      = font;
                text.fontSize  = label.fontSize;
                text.fontStyle = label.fontStyle;
                ChartHelper.SetActive(element, true);
            }
            return(element);
        }
Ejemplo n.º 3
0
        public static GameObject Get(string name, Transform parent, SerieLabel label, Color color,
                                     float iconWidth, float iconHeight, ChartTheme theme)
        {
            GameObject element;

            if (m_Stack.Count == 0 || !Application.isPlaying)
            {
                element = CreateSerieLabel(name, parent, label, color, iconWidth, iconHeight, theme);
            }
            else
            {
                element = m_Stack.Pop();
                if (element == null)
                {
                    element = CreateSerieLabel(name, parent, label, color, iconWidth, iconHeight, theme);
                }
                m_ReleaseDic.Remove(element.GetInstanceID());
                element.name = name;
                element.transform.SetParent(parent);
                element.transform.localEulerAngles = new Vector3(0, 0, label.textStyle.rotate);
                var text = new ChartText(element);
                text.SetColor(color);
                text.SetFontAndSizeAndStyle(label.textStyle, theme.common);
                ChartHelper.SetActive(element, true);
            }
            return(element);
        }
        public static string GetFormatterContent(Serie serie, SerieData serieData,
                                                 double dataValue, double dataTotal, SerieLabel serieLabel, Color color)
        {
            if (serieLabel == null)
            {
                serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            }
            var numericFormatter = serieLabel == null ? serie.label.numericFormatter : serieLabel.numericFormatter;
            var serieName        = serie.name;
            var dataName         = serieData != null ? serieData.name : null;

            if (serieLabel.formatterFunction != null)
            {
                return(serieLabel.formatterFunction(serieData.index, dataValue));
            }
            if (string.IsNullOrEmpty(serieLabel.formatter))
            {
                return(ChartCached.NumberToStr(dataValue, numericFormatter));
            }
            else
            {
                var content = serieLabel.formatter;
                FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue,
                                                         dataTotal, serieName, dataName, color);
                return(content);
            }
        }
Ejemplo n.º 5
0
        public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, SerieData serieData)
        {
            GameObject element;

            if (m_Stack.Count == 0)
            {
                element = ChartHelper.AddSerieLabel(name, parent, font,
                                                    color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
                                                    label.backgroundWidth, label.backgroundHeight);
                ChartHelper.AddIcon("Icon", element.transform, serieData.iconWidth, serieData.iconHeight);
            }
            else
            {
                element = m_Stack.Pop();

                //天讯修改,栈堆取出来的值可能会为空,导致空引用报错,因此新增if判断
                if (element == null)
                {
                    element = ChartHelper.AddSerieLabel(name, parent, font,
                                                        color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
                                                        label.backgroundWidth, label.backgroundHeight);
                    ChartHelper.AddIcon("Icon", element.transform, serieData.iconWidth, serieData.iconHeight);
                }
                else
                {
                    element.name = name;
                    element.transform.SetParent(parent);
                    ChartHelper.SetActive(element, true);
                }
            }
            return(element);
        }
Ejemplo n.º 6
0
        public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, float iconWidth, float iconHeight)
        {
            GameObject element;

            if (m_Stack.Count == 0 || !Application.isPlaying)
            {
                element = ChartHelper.AddSerieLabel(name, parent, font,
                                                    color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
                                                    label.backgroundWidth, label.backgroundHeight);
                ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
            }
            else
            {
                element      = m_Stack.Pop();
                element.name = name;
                element.transform.SetParent(parent);
                element.transform.localEulerAngles = new Vector3(0, 0, label.rotate);
                var text = element.GetComponentInChildren <Text>();
                text.color     = color;
                text.font      = font;
                text.fontSize  = label.fontSize;
                text.fontStyle = label.fontStyle;
                ChartHelper.SetActive(element, true);
            }
            return(element);
        }
Ejemplo n.º 7
0
        private static GameObject CreateSerieLabel(string name, Transform parent, SerieLabel label, Color color,
                                                   float iconWidth, float iconHeight, ChartTheme theme)
        {
            var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight,
                                                    color, label.textStyle, theme);

            ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
            return(element);
        }
Ejemplo n.º 8
0
 public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
 {
     if (serieData.labelText)
     {
         serieData.labelText.color = label.color != Color.clear ? label.color :
                                     (Color)themeInfo.GetColor(colorIndex);
         serieData.labelText.fontSize  = label.fontSize;
         serieData.labelText.fontStyle = label.fontStyle;
     }
 }
Ejemplo n.º 9
0
        private static GameObject CreateSerieLabel(string name, Transform parent, SerieLabel label, Font font, Color color,
                                                   float iconWidth, float iconHeight)
        {
            var element = ChartHelper.AddSerieLabel(name, parent, font,
                                                    color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
                                                    label.backgroundWidth, label.backgroundHeight, 1);

            ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
            return(element);
        }
Ejemplo n.º 10
0
 public SerieLabel GetSerieLabel(SerieLabel parentLabel)
 {
     if (enableLabel)
     {
         return(label);
     }
     else
     {
         return(parentLabel);
     }
 }
Ejemplo n.º 11
0
 public static void ResetLabel(ChartText labelObject, SerieLabel label, ChartTheme theme, int colorIndex)
 {
     if (labelObject == null)
     {
         return;
     }
     labelObject.SetColor(!ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color :
                          (Color)theme.GetColor(colorIndex));
     labelObject.SetFontSize(label.textStyle.GetFontSize(theme.common));
     labelObject.SetFontStyle(label.textStyle.fontStyle);
 }
Ejemplo n.º 12
0
 public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
 {
     if (serieData.labelObject == null)
     {
         return;
     }
     if (serieData.labelObject.label == null)
     {
         return;
     }
     serieData.labelObject.label.color = !ChartHelper.IsClearColor(label.color) ? label.color :
                                         (Color)themeInfo.GetColor(colorIndex);
     serieData.labelObject.label.fontSize  = label.fontSize;
     serieData.labelObject.label.fontStyle = label.fontStyle;
 }
Ejemplo n.º 13
0
 internal static Vector3 GetRealLabelPosition(SerieData serieData, SerieLabel label)
 {
     if (label.position == SerieLabel.Position.Outside && label.lineType != SerieLabel.LineType.HorizontalLine)
     {
         var currAngle = serieData.runtimePieHalfAngle;
         var offset    = label.lineLength2 + serieData.labelObject.GetLabelWidth() / 2;
         if (currAngle > 180)
         {
             return(serieData.labelPosition + new Vector3(-offset, 0, 0));
         }
         else
         {
             return(serieData.labelPosition + new Vector3(offset, 0, 0));
         }
     }
     else
     {
         return(serieData.labelPosition);
     }
 }
Ejemplo n.º 14
0
        public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, SerieData serieData)
        {
            GameObject element;

            if (m_Stack.Count == 0 || !Application.isPlaying)
            {
                element = ChartHelper.AddSerieLabel(name, parent, font,
                                                    color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
                                                    label.backgroundWidth, label.backgroundHeight);
                ChartHelper.AddIcon("Icon", element.transform, serieData.iconStyle.width, serieData.iconStyle.height);
            }
            else
            {
                element      = m_Stack.Pop();
                element.name = name;
                element.transform.SetParent(parent);
                ChartHelper.SetActive(element, true);
            }
            return(element);
        }
Ejemplo n.º 15
0
        public static string GetFormatterContent(Serie serie, SerieData serieData,
                                                 float dataValue, float dataTotal, SerieLabel serieLabel = null)
        {
            if (serieLabel == null)
            {
                serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            }
            var numericFormatter = GetLabelNumericFormatter(serie, serieData);
            var serieName        = serie.name;
            var dataName         = serieData != null ? serieData.name : null;

            if (string.IsNullOrEmpty(serieLabel.formatter))
            {
                return(ChartCached.NumberToStr(dataValue, numericFormatter));
            }
            else
            {
                var content = serieLabel.formatter;
                FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue,
                                                         dataTotal, serieName, dataName);
                return(content);
            }
        }
Ejemplo n.º 16
0
 public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
 {
     return(serie.show && serieData.canShowLabel && !serie.IsIgnoreValue(serieData.GetData(dimesion)));
 }
Ejemplo n.º 17
0
 private static void ImportLabelColor(SerieLabel label, List <Color32> colorList)
 {
     label.backgroundColor = colorList[0];
     label.borderColor     = colorList[1];
 }