public static Serie AddDefaultCategoryGanttSerie(BaseChart chart, string serieName, int dataCount = 0, int min = 0, int max = 0)
        {
            var serie = chart.AddSerie(SerieType.Gantt, serieName);

            serie.showDataName      = true;
            serie.showDataDimension = 2;
            for (int i = 0; i < dataCount; i++)
            {
                var start = Random.Range(min, max);
                var end   = Random.Range(start + 1, max);
                serie.AddXYData(start, end, "task-" + (i + 1));
            }
            return(serie);
        }
        public static string CheckChart(BaseChart chart)
        {
            var sb = ChartHelper.sb;

            sb.Length = 0;
            CheckName(chart, sb);
            CheckSize(chart, sb);
            CheckTheme(chart, sb);
            CheckTitle(chart, sb);
            CheckLegend(chart, sb);
            CheckGrid(chart, sb);
            CheckSerie(chart, sb);
            return(sb.ToString());
        }
Esempio n. 3
0
        public void AddChart(BaseChart chart)
        {
            var sameNameChart = GetChart(chart.chartName);

            if (sameNameChart != null)
            {
                var path = ChartHelper.GetFullName(sameNameChart.transform);
                Debug.LogError("A chart named `" + chart.chartName + "` already exists:" + path);
            }
            if (!ContainsChart(chart))
            {
                m_ChartList.Add(chart);
            }
        }
Esempio n. 4
0
        public static string CheckChart(BaseChart chart)
        {
            var sb = ChartHelper.sb;

            sb.Length = 0;
            //sb.AppendFormat("version:{0}_{1}\n", XChartsMgr.version, XChartsMgr.date);
            CheckSize(chart, sb);
            CheckTheme(chart, sb);
            CheckTitle(chart, sb);
            CheckLegend(chart, sb);
            CheckGrid(chart, sb);
            CheckSerie(chart, sb);
            return(sb.ToString());
        }
Esempio n. 5
0
        public static int AddDefaultCandlestickSerie(BaseChart chart, string serieName)
        {
            var serie            = chart.AddSerie(SerieType.Candlestick, serieName);
            var defaultDataCount = 5;

            for (int i = 0; i < defaultDataCount; i++)
            {
                var open     = Random.Range(20, 60);
                var close    = Random.Range(40, 90);
                var lowest   = Random.Range(0, 50);
                var heighest = Random.Range(50, 100);
                chart.AddData(serie.index, open, close, lowest, heighest);
            }
            return(defaultDataCount);
        }
Esempio n. 6
0
        public static Serie AddDefaultTimeGanttSerie(BaseChart chart, string serieName, int dataCount = 0)
        {
            var serie = chart.AddSerie(SerieType.Gantt, serieName);

            serie.showDataName      = true;
            serie.showDataDimension = 2;
            var timestamp = DateTimeUtil.GetTimestamp();

            for (int i = 0; i < dataCount; i++)
            {
                var start = timestamp + Random.Range(1, 6) * 3600 * 24;
                var end   = start + Random.Range(1, 10) * 3600 * 24;
                serie.AddXYData(start, end, "task-" + (i + 1));
            }
            return(serie);
        }
Esempio n. 7
0
        protected virtual void OnEnable()
        {
            m_Target    = (BaseChart)target;
            m_Script    = serializedObject.FindProperty("m_Script");
            m_Theme     = serializedObject.FindProperty("m_Theme");
            m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo");
            m_Title     = serializedObject.FindProperty("m_Title");
            m_Legend    = serializedObject.FindProperty("m_Legend");
            m_Tooltip   = serializedObject.FindProperty("m_Tooltip");
            m_Series    = serializedObject.FindProperty("m_Series");

            m_Large              = serializedObject.FindProperty("m_Large");
            m_MinShowDataNumber  = serializedObject.FindProperty("m_MinShowDataNumber");
            m_MaxShowDataNumber  = serializedObject.FindProperty("m_MaxShowDataNumber");
            m_MaxCacheDataNumber = serializedObject.FindProperty("m_MaxCacheDataNumber");
        }
Esempio n. 8
0
        public static void AddDefaultLiquidSerie(BaseChart chart, string serieName)
        {
            if (chart.vessels.Count == 0)
            {
                chart.AddVessel(Vessel.defaultVessel);
            }
            var serie = chart.AddSerie(SerieType.Liquid, serieName);

            serie.min        = 0;
            serie.max        = 100;
            serie.label.show = true;
            serie.label.textStyle.fontSize = 40;
            serie.label.formatter          = "{d}%";
            serie.label.textStyle.color    = new Color32(70, 70, 240, 255);
            chart.AddData(serie.index, UnityEngine.Random.Range(0, 100));
        }
Esempio n. 9
0
        public static void SwitchTheme(BaseChart chart, string themeName)
        {
#if UNITY_EDITOR
            if (XChartsMgr.Instance.m_ThemeDict.Count == 0)
            {
                ReloadThemeList();
            }
#endif
            if (!XChartsMgr.Instance.m_ThemeDict.ContainsKey(themeName))
            {
                Debug.LogError("SwitchTheme ERROR: not exist theme:" + themeName);
                return;
            }
            var target = XChartsMgr.Instance.m_ThemeDict[themeName];
            chart.UpdateTheme(target);
        }
        protected virtual void OnEnable()
        {
            m_Target      = (BaseChart)target;
            m_Script      = serializedObject.FindProperty("m_Script");
            m_ChartWidth  = serializedObject.FindProperty("m_ChartWidth");
            m_ChartHeight = serializedObject.FindProperty("m_ChartHeight");
            m_Theme       = serializedObject.FindProperty("m_Theme");
            m_ThemeInfo   = serializedObject.FindProperty("m_ThemeInfo");
            m_Title       = serializedObject.FindProperty("m_Title");
            m_Legend      = serializedObject.FindProperty("m_Legend");
            m_Tooltip     = serializedObject.FindProperty("m_Tooltip");
            m_Series      = serializedObject.FindProperty("m_Series");

            m_Large    = serializedObject.FindProperty("m_Large");
            m_Settings = serializedObject.FindProperty("m_Settings");
        }
Esempio n. 11
0
        private string[] GetChartSerieTypeNames(BaseChart chart)
        {
            var list = System.Enum.GetNames(typeof(SerieType));

            for (int i = 0; i < list.Length; i++)
            {
                if (list[i].Equals("Custom"))
                {
                    var customName = chart.GetCustomSerieTypeName();
                    if (!string.IsNullOrEmpty(customName))
                    {
                        list[i] = customName;
                    }
                }
            }
            return(list);
        }
Esempio n. 12
0
        public static void AddDefaultRingSerie(BaseChart chart, string serieName)
        {
            var serie = chart.AddSerie(SerieType.Ring, serieName);

            serie.roundCap                    = true;
            serie.radius                      = new float[] { 0.3f, 0.35f };
            serie.titleStyle.show             = false;
            serie.titleStyle.textStyle.offset = new Vector2(0, 30);
            serie.label.show                  = true;
            serie.label.position              = SerieLabel.Position.Center;
            serie.label.formatter             = "{d:f0}%";
            serie.label.textStyle.fontSize    = 28;
            var value = Random.Range(30, 90);
            var max   = 100;

            chart.AddData(serie.index, value, max, "data1");
        }
Esempio n. 13
0
        private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                               BaseChart chart, DataZoom dataZoom = null, bool isCartesian = false,
                                               Radar radar = null)
        {
            switch (serie.type)
            {
            case SerieType.Line:
            case SerieType.Bar:
            case SerieType.Candlestick:
                InitCoordinateTooltip(ref sb, tooltip, serie, index, chart.theme, isCartesian, dataZoom);
                break;

            case SerieType.Scatter:
            case SerieType.EffectScatter:
                InitScatterTooltip(ref sb, tooltip, serie, index, chart.theme);
                break;

            case SerieType.Radar:
                InitRadarTooltip(ref sb, tooltip, serie, radar, chart.theme);
                break;

            case SerieType.Pie:
                InitPieTooltip(ref sb, tooltip, serie, index, chart.theme);
                break;

            case SerieType.Ring:
                InitRingTooltip(ref sb, tooltip, serie, index, chart.theme);
                break;

            case SerieType.Heatmap:
                break;

            case SerieType.Gauge:
                InitGaugeTooltip(ref sb, tooltip, serie, index, chart.theme);
                break;

            case SerieType.Gantt:
                InitGanttTooltip(ref sb, tooltip, serie, index, chart.theme);
                break;

            case SerieType.Custom:
                chart.InitCustomSerieTooltip(ref sb, serie, index);
                break;
            }
        }
Esempio n. 14
0
 public static Color GetIconColor(BaseChart chart, int readIndex, string legendName, bool active)
 {
     if (active)
     {
         var legend = chart.legend;
         if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
         {
             return(SeriesHelper.GetNameColor(chart, readIndex, legendName));
         }
         else
         {
             return(Color.white);
         }
     }
     else
     {
         return(chart.theme.legend.unableColor);
     }
 }
Esempio n. 15
0
        public static void AddDefaultRadarSerie(BaseChart chart, string serieName)
        {
            if (chart.radars.Count == 0)
            {
                chart.AddRadar(Radar.defaultRadar);
            }
            var serie = chart.AddSerie(SerieType.Radar, serieName);

            serie.symbol.show         = true;
            serie.symbol.type         = SerieSymbolType.EmptyCircle;
            serie.symbol.size         = 4;
            serie.symbol.selectedSize = 6;
            serie.showDataName        = true;
            List <float> data = new List <float>();

            for (int i = 0; i < 5; i++)
            {
                data.Add(Random.Range(20, 90));
            }
            chart.AddData(serie.index, data, "legendName");
        }
Esempio n. 16
0
        private static void CheckTitle(BaseChart chart, StringBuilder sb)
        {
            var title = chart.title;

            if (!title.show)
            {
                return;
            }
            if (string.IsNullOrEmpty(title.text))
            {
                sb.Append("warning:title->text is null\n");
            }
            if (IsColorAlphaZero(title.textStyle.color))
            {
                sb.Append("warning:title->textStyle->color alpha is 0\n");
            }
            if (IsColorAlphaZero(title.subTextStyle.color))
            {
                sb.Append("warning:title->subTextStyle->color alpha is 0\n");
            }
        }
Esempio n. 17
0
 /// <summary>
 /// 获得所有系列名,不包含空名字。
 /// </summary>
 /// <returns></returns>
 public static void UpdateSerieNameList(BaseChart chart, ref List <string> serieNameList)
 {
     serieNameList.Clear();
     for (int n = 0; n < chart.series.list.Count; n++)
     {
         var serie = chart.series.GetSerie(n);
         if (serie.type == SerieType.Pie ||
             serie.type == SerieType.Radar ||
             serie.type == SerieType.Ring ||
             (serie.type == SerieType.Custom && chart.GetCustomSerieDataNameForColor()))
         {
             for (int i = 0; i < serie.data.Count; i++)
             {
                 if (serie.type == SerieType.Pie && serie.IsIgnoreValue(serie.data[i]))
                 {
                     continue;
                 }
                 if (string.IsNullOrEmpty(serie.data[i].name))
                 {
                     serieNameList.Add(ChartCached.IntToStr(i));
                 }
                 else if (!serieNameList.Contains(serie.data[i].name))
                 {
                     serieNameList.Add(serie.data[i].name);
                 }
             }
         }
         else
         {
             if (string.IsNullOrEmpty(serie.name))
             {
                 serieNameList.Add(ChartCached.IntToStr(n));
             }
             else if (!serieNameList.Contains(serie.name))
             {
                 serieNameList.Add(serie.name);
             }
         }
     }
 }
Esempio n. 18
0
        public static Color GetNameColor(BaseChart chart, int index, string name)
        {
            Serie     destSerie     = null;
            SerieData destSerieData = null;
            var       series        = chart.series;

            for (int n = 0; n < series.list.Count; n++)
            {
                var serie = series.GetSerie(n);
                if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ||
                    (serie.type == SerieType.Custom && chart.GetCustomSerieDataNameForColor()))
                {
                    bool found = false;
                    for (int i = 0; i < serie.data.Count; i++)
                    {
                        if (name.Equals(serie.data[i].name))
                        {
                            destSerie     = serie;
                            destSerieData = serie.data[i];
                            found         = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                else
                {
                    if (name.Equals(serie.name))
                    {
                        destSerie     = serie;
                        destSerieData = null;
                        break;
                    }
                }
            }
            return(SerieHelper.GetItemColor(destSerie, destSerieData, chart.theme, index, false));
        }
Esempio n. 19
0
 private static void CheckTitle(BaseChart chart, StringBuilder sb)
 {
     foreach (var title in chart.titles)
     {
         if (!title.show)
         {
             return;
         }
         if (string.IsNullOrEmpty(title.text))
         {
             sb.AppendFormat("warning:title{0}->text is null\n", title.index);
         }
         if (IsColorAlphaZero(title.textStyle.color))
         {
             sb.AppendFormat("warning:title{0}->textStyle->color alpha is 0\n", title.index);
         }
         if (IsColorAlphaZero(title.subTextStyle.color))
         {
             sb.AppendFormat("warning:title{0}->subTextStyle->color alpha is 0\n", title.index);
         }
     }
 }
Esempio n. 20
0
        public static void AddDefaultGaugeSerie(BaseChart chart, string serieName)
        {
            var serie = chart.AddSerie(SerieType.Gauge, serieName);

            serie.min         = 0;
            serie.max         = 100;
            serie.startAngle  = -125;
            serie.endAngle    = 125;
            serie.center[0]   = 0.5f;
            serie.center[1]   = 0.5f;
            serie.radius[0]   = 80;
            serie.splitNumber = 5;
            serie.animation.dataChangeEnable  = true;
            serie.titleStyle.show             = true;
            serie.titleStyle.textStyle.offset = new Vector2(0, 20);
            serie.label.show                 = true;
            serie.label.offset               = new Vector3(0, -30);
            serie.itemStyle.show             = true;
            serie.gaugeAxis.axisLabel.show   = true;
            serie.gaugeAxis.axisLabel.margin = 18;
            chart.AddData(serie.index, UnityEngine.Random.Range(10, 90), "title");
        }
Esempio n. 21
0
        public static void SwitchTheme(BaseChart chart, string themeName)
        {
            Debug.Log("SwitchTheme:" + themeName);
            if (chart.theme.themeName.Equals(themeName))
            {
                return;
            }
#if UNITY_EDITOR
            if (Instance.m_ThemeDict.Count == 0)
            {
                Instance.LoadThemesFromResources();
            }
#endif
            if (!Instance.m_ThemeDict.ContainsKey(themeName))
            {
                Debug.LogError("SwitchTheme ERROR: not exist theme:" + themeName);
                return;
            }
            var target = Instance.m_ThemeDict[themeName];
            chart.theme.CopyTheme(target);
            chart.RefreshAllComponent();
        }
Esempio n. 22
0
 void Awake()
 {
     chart = gameObject.GetComponent <BaseChart>();
 }
Esempio n. 23
0
 public DrawSeriePie(BaseChart chart)
 {
     this.chart = chart;
 }
Esempio n. 24
0
        private static void CheckSerie(BaseChart chart, StringBuilder sb)
        {
            var allDataIsEmpty = true;
            var allDataIsZero  = true;
            var allSerieIsHide = true;

            foreach (var serie in chart.series.list)
            {
                if (serie.show)
                {
                    allSerieIsHide = false;
                }
                if (serie.dataCount > 0)
                {
                    allDataIsEmpty = false;
                    for (int i = 0; i < serie.dataCount; i++)
                    {
                        var serieData = serie.GetSerieData(i);
                        for (int j = 1; j < serieData.data.Count; j++)
                        {
                            if (serieData.GetData(j) != 0)
                            {
                                allDataIsZero = false;
                                break;
                            }
                        }
                    }
                    var dataCount = serie.GetSerieData(0).data.Count;
                    if (serie.showDataDimension > 1 && serie.showDataDimension != dataCount)
                    {
                        sb.AppendFormat("warning:serie {0} serieData.data.count[{1}] not match showDataDimension[{2}]\n", serie.index, dataCount, serie.showDataDimension);
                    }
                }
                else
                {
                    sb.AppendFormat("warning:serie {0} no data\n", serie.index);
                }
                if (IsColorAlphaZero(serie.itemStyle.color))
                {
                    sb.AppendFormat("warning:serie {0} itemStyle->color alpha is 0\n", serie.index);
                }
                if (serie.itemStyle.opacity == 0)
                {
                    sb.AppendFormat("warning:serie {0} itemStyle->opacity is 0\n", serie.index);
                }
                if (serie.itemStyle.borderWidth != 0 && IsColorAlphaZero(serie.itemStyle.borderColor))
                {
                    sb.AppendFormat("warning:serie {0} itemStyle->borderColor alpha is 0\n", serie.index);
                }
                switch (serie.type)
                {
                case SerieType.Line:
                    if (serie.lineStyle.width == 0)
                    {
                        sb.AppendFormat("warning:serie {0} lineStyle->width is 0\n", serie.index);
                    }
                    if (serie.lineStyle.opacity == 0)
                    {
                        sb.AppendFormat("warning:serie {0} lineStyle->opacity is 0\n", serie.index);
                    }
                    if (IsColorAlphaZero(serie.lineStyle.color))
                    {
                        sb.AppendFormat("warning:serie {0} lineStyle->color alpha is 0\n", serie.index);
                    }
                    break;

                case SerieType.Bar:
                    if (serie.barWidth == 0)
                    {
                        sb.AppendFormat("warning:serie {0} barWidth is 0\n", serie.index);
                    }
                    break;

                case SerieType.Pie:
                    if (serie.radius.Length >= 2 && serie.radius[1] == 0)
                    {
                        sb.AppendFormat("warning:serie {0} radius[1] is 0\n", serie.index);
                    }
                    break;

                case SerieType.Scatter:
                case SerieType.EffectScatter:
                    if (!serie.symbol.show)
                    {
                        sb.AppendFormat("warning:serie {0} symbol type is None\n", serie.index);
                    }
                    break;
                }
            }
            if (allDataIsEmpty)
            {
                sb.Append("warning:all serie data is empty\n");
            }
            if (!allDataIsEmpty && allDataIsZero)
            {
                sb.Append("warning:all serie data is 0\n");
            }
            if (allSerieIsHide)
            {
                sb.Append("warning:all serie is hide\n");
            }
        }
Esempio n. 25
0
        private static void CheckTheme(BaseChart chart, StringBuilder sb)
        {
            var themeInfo = chart.themeInfo;

            themeInfo.CheckWarning(sb);
        }
Esempio n. 26
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, BaseChart chart, DataZoom dataZoom = null,
                                          bool isCartesian = false, Radar radar = null)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb            = ChartHelper.sb;
         var title         = tooltip.titleFormatter;
         var formatTitle   = !string.IsNullOrEmpty(title);
         var titleIsIgnroe = false;
         var needCategory  = false;
         var first         = true;
         var isScatter     = false;
         sb.Length = 0;
         if ("{i}".Equals(tooltip.titleFormatter))
         {
             title         = string.Empty;
             formatTitle   = false;
             titleIsIgnroe = true;
         }
         for (int i = 0; i < chart.series.Count; i++)
         {
             var serie = chart.series.GetSerie(i);
             if (tooltip.runtimeGridIndex >= 0 && serie.runtimeGridIndex != tooltip.runtimeGridIndex)
             {
                 continue;
             }
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter = GetItemFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(FormatterHelper.PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, chart.theme, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, chart, dataZoom);
                         sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         string content  = itemFormatter;
                         var    foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, chart, dataZoom);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(FormatterHelper.PH_NN);
                     }
                 }
             }
             else if (IsNeedTooltipSerie(serie, tooltip))
             {
                 var itemFormatter = string.Empty;
                 if (serie.type == SerieType.Gauge)
                 {
                     var serieData = serie.GetSerieData(0, dataZoom);
                     if (serieData == null)
                     {
                         continue;
                     }
                     itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 }
                 else
                 {
                     var serieData = serie.GetSerieData(dataIndex, dataZoom);
                     if (serieData == null)
                     {
                         continue;
                     }
                     itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 }
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, chart, dataZoom);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar)
                     {
                         if (!first)
                         {
                             sb.Append(FormatterHelper.PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, chart.theme, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, chart, dataZoom);
                     if (!first)
                     {
                         sb.Append(FormatterHelper.PH_NN);
                     }
                     var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar ||
                                         serie.type == SerieType.Ring ? dataIndex : i;
                     sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(dotColorIndex)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(FormatterHelper.TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory && !titleIsIgnroe)
             {
                 var category = (chart as CoordinateChart).GetTooltipCategory(dataIndex, dataZoom);
                 return(category + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
             }
             else
             {
                 return(FormatterHelper.TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = FormatterHelper.TrimAndReplaceLine(title);
             return(title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, chart, dataZoom);
         return(content);
     }
 }
Esempio n. 27
0
 public bool ContainsChart(BaseChart chart)
 {
     return(m_ChartList.Contains(chart));
 }
Esempio n. 28
0
 public VisualMapHandler(BaseChart chart)
 {
     this.chart = chart;
 }
 public DrawSerieGauge(BaseChart chart)
 {
     this.chart = chart;
 }
Esempio n. 30
0
 public DrawSerieRadar(BaseChart chart)
 {
     this.chart = chart;
 }