Пример #1
0
        /// <summary>
        /// Whether to show serie and legend.
        /// </summary>
        /// <param name="serieIndex">the index of serie</param>
        /// <param name="active">Active or not</param>
        public virtual void SetActive(int serieIndex, bool active)
        {
            m_Series.SetActive(serieIndex, active);
            var serie = m_Series.GetSerie(serieIndex);

            if (serie != null && !string.IsNullOrEmpty(serie.name))
            {
                var bgColor1 = active ? m_ThemeInfo.GetColor(serie.index) : m_ThemeInfo.legendUnableColor;
                m_Legend.UpdateButtonColor(serie.name, bgColor1);
            }
        }
Пример #2
0
        public static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
        {
            var color = Color.clear;

            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
                if (itemStyleEmphasis != null && itemStyleEmphasis.color != Color.clear)
                {
                    color    = itemStyleEmphasis.color;
                    color.a *= itemStyleEmphasis.opacity;
                    return(color);
                }
            }
            if (serie.lineStyle.color != Color.clear)
            {
                color = serie.lineStyle.GetColor();
            }
            else if (serie.itemStyle.color != Color.clear)
            {
                color = serie.itemStyle.GetColor();
            }
            if (color == Color.clear)
            {
                color   = (Color)theme.GetColor(index);
                color.a = serie.lineStyle.opacity;
            }
            if (highlight)
            {
                color *= color;
            }
            return(color);
        }
Пример #3
0
        internal static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
        {
            if (serie == null)
            {
                return(ChartConst.clearColor32);
            }
            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
                if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
                {
                    var color = itemStyleEmphasis.color;
                    ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
                    return(color);
                }
            }
            var itemStyle = GetItemStyle(serie, serieData);

            if (!ChartHelper.IsClearColor(itemStyle.color))
            {
                return(itemStyle.GetColor());
            }
            else
            {
                var color = theme.GetColor(index);
                if (highlight)
                {
                    color = ChartHelper.GetHighlightColor(color);
                }
                ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
                return(color);
            }
        }
Пример #4
0
        internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
        {
            var itemStyle = GetItemStyle(serie, serieData);

            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
                if (itemStyleEmphasis != null && itemStyleEmphasis.color != Color.clear)
                {
                    var color = itemStyleEmphasis.color;
                    color.a *= itemStyleEmphasis.opacity;
                    return(color);
                }
            }
            if (itemStyle.color != Color.clear)
            {
                var color = itemStyle.color;
                if (highlight)
                {
                    color *= color;
                }
                color.a *= itemStyle.opacity;
                return(color);
            }
            else
            {
                var color = (Color)theme.GetColor(index);
                if (highlight)
                {
                    color *= color;
                }
                color.a *= itemStyle.opacity;
                return(color);
            }
        }
Пример #5
0
        protected override void OnThemeChanged()
        {
            base.OnThemeChanged();
            foreach (var radar in m_Radars)
            {
                radar.splitArea.color.Clear();
                switch (m_ThemeInfo.theme)
                {
                case Theme.Dark:
                    radar.splitArea.color.Add(ThemeInfo.GetColor("#6f6f6f"));
                    radar.splitArea.color.Add(ThemeInfo.GetColor("#606060"));
                    break;

                case Theme.Default:
                    radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6"));
                    radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7"));
                    break;

                case Theme.Light:
                    radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6"));
                    radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7"));
                    break;
                }
            }
            m_RadarsDirty = true;
        }
Пример #6
0
        internal static Color32 GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
        {
            Color32 color = ChartConst.clearColor32;

            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
                if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
                {
                    color = itemStyleEmphasis.color;
                    ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
                    return(color);
                }
            }
            if (!ChartHelper.IsClearColor(serie.lineStyle.color))
            {
                color = serie.lineStyle.GetColor();
            }
            else if (!ChartHelper.IsClearColor(serie.itemStyle.color))
            {
                color = serie.itemStyle.GetColor();
            }
            if (ChartHelper.IsClearColor(color))
            {
                color = theme.GetColor(index);
                ChartHelper.SetColorOpacity(ref color, serie.lineStyle.opacity);
            }
            if (highlight)
            {
                color = ChartHelper.GetHighlightColor(color);
            }
            return(color);
        }
Пример #7
0
        private void InitSerieLabel()
        {
            var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, m_ChartMinAnchor,
                                                    m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta);

            SerieLabelPool.ReleaseAll(labelObject.transform);
            int count = 0;

            for (int i = 0; i < m_Series.Count; i++)
            {
                var serie = m_Series.list[i];
                SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight);
                for (int j = 0; j < serie.data.Count; j++)
                {
                    var serieData  = serie.data[j];
                    var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
                    if (!serieLabel.show && j > 100)
                    {
                        continue;
                    }
                    var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
                    var color    = Color.grey;
                    if (serie.type == SerieType.Pie)
                    {
                        color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white :
                                (Color)m_ThemeInfo.GetColor(count);
                    }
                    else
                    {
                        color = serieLabel.color != Color.clear ? serieLabel.color :
                                (Color)m_ThemeInfo.GetColor(i);
                    }
                    var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, m_ThemeInfo.font, color,
                                                      serieData.iconStyle.width, serieData.iconStyle.height);
                    var iconImage = labelObj.transform.Find("Icon").GetComponent <Image>();
                    serieData.SetIconImage(iconImage);

                    var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
                    serieData.InitLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
                    serieData.SetLabelActive(false);
                    count++;
                }
            }
            SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
        }
Пример #8
0
        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);

            if (serie.IsPerformanceMode())
            {
                return;
            }
            if (!serieLabel.show)
            {
                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_ThemeInfo.GetColor(count);
            }
            else
            {
                color = !ChartHelper.IsClearColor(serieLabel.color) ? serieLabel.color :
                        (Color)m_ThemeInfo.GetColor(serie.index);
            }
            var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, m_ThemeInfo.font, color,
                                              serieData.iconStyle.width, serieData.iconStyle.height);
            var iconImage  = labelObj.transform.Find("Icon").GetComponent <Image>();
            var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
            var item       = new LabelObject();

            item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
            item.SetIcon(iconImage);
            item.SetIconActive(false);
            serieData.labelObject = item;
        }
Пример #9
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;
     }
 }
Пример #10
0
 public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
 {
     if (serie.label.color != Color.clear)
     {
         return(serie.label.color);
     }
     else
     {
         return(themeInfo.GetColor(index));
     }
 }
Пример #11
0
 public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
 {
     if (!ChartHelper.IsClearColor(serie.label.color))
     {
         return(serie.label.color);
     }
     else
     {
         return(themeInfo.GetColor(index));
     }
 }
Пример #12
0
        private void InitLegend()
        {
            m_Legend.OnChanged();
            ChartHelper.HideAllObject(transform, s_LegendObjectName);
            TextAnchor anchor    = m_Legend.location.textAnchor;
            Vector2    anchorMin = m_Legend.location.anchorMin;
            Vector2    anchorMax = m_Legend.location.anchorMax;
            Vector2    pivot     = m_Legend.location.pivot;

            var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax,
                                                     pivot, new Vector2(chartWidth, chartHeight));

            legendObject.transform.localPosition = m_Legend.location.GetPosition(chartWidth, chartHeight);
            ChartHelper.HideAllObject(legendObject, s_LegendObjectName);

            for (int i = 0; i < m_Legend.data.Count; i++)
            {
                Button btn = ChartHelper.AddButtonObject(s_LegendObjectName + "_" + i, legendObject.transform,
                                                         m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
                                                         anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));

                m_Legend.SetButton(i, btn);
                m_Legend.SetActive(i, IsActive(i));
                m_Legend.UpdateButtonColor(i, m_ThemeInfo.GetColor(i), m_ThemeInfo.legendUnableColor);
                btn.GetComponentInChildren <Text>().text = m_Legend.data[i];
                ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
                {
                    int count = (data as PointerEventData).clickCount;
                    int index = int.Parse(data.selectedObject.name.Split('_')[1]);
                    SetActive(index, !m_Legend.IsActive(index));
                    m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index),
                                               m_ThemeInfo.legendUnableColor);
                    OnYMaxValueChanged();
                    OnLegendButtonClicked();
                    RefreshChart();
                });
            }
        }
Пример #13
0
        internal static Color GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
        {
            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
                if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.toColor))
                {
                    var color = itemStyleEmphasis.toColor;
                    color.a *= itemStyleEmphasis.opacity;
                    return(color);
                }
            }
            var itemStyle = GetItemStyle(serie, serieData, highlight);

            if (itemStyle == null)
            {
                itemStyle = serieData.itemStyle;
            }
            if (!ChartHelper.IsClearColor(itemStyle.toColor))
            {
                var color = itemStyle.toColor;
                if (highlight)
                {
                    color *= color;
                }
                color.a *= itemStyle.opacity;
                return(color);
            }
            if (!ChartHelper.IsClearColor(itemStyle.color))
            {
                var color = itemStyle.color;
                if (highlight)
                {
                    color *= color;
                }
                color.a *= itemStyle.opacity;
                return(color);
            }
            else
            {
                var color = (Color)theme.GetColor(index);
                if (highlight)
                {
                    color *= color;
                }
                color.a *= itemStyle.opacity;
                return(color);
            }
        }
        IEnumerator ComponentVisualMap()
        {
            chart.title.subText = "VisualMap 视觉映射:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";

            chart.visualMap.enable     = true;
            chart.visualMap.show       = true;
            chart.visualMap.orient     = Orient.Vertical;
            chart.visualMap.calculable = true;
            chart.visualMap.min        = 0;
            chart.visualMap.max        = 100;
            chart.visualMap.range[0]   = 0;
            chart.visualMap.range[1]   = 100;

            var colors = new List <string> {
                "#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
                "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"
            };

            chart.visualMap.inRange.Clear();
            foreach (var str in colors)
            {
                chart.visualMap.inRange.Add(ThemeInfo.GetColor(str));
            }
            chart.grid.left   = 80;
            chart.grid.bottom = 100;
            chart.RefreshChart();

            yield return(new WaitForSeconds(1f));

            while (chart.visualMap.rangeMin < 40)
            {
                chart.visualMap.rangeMin += speed * Time.deltaTime;
                chart.RefreshChart();
                yield return(null);
            }
            while (chart.visualMap.rangeMax > 60)
            {
                chart.visualMap.rangeMax -= speed * Time.deltaTime;
                chart.RefreshChart();
                yield return(null);
            }
            while (chart.visualMap.rangeMin > 0 || chart.visualMap.rangeMax < 100)
            {
                chart.visualMap.rangeMin -= speed * Time.deltaTime;
                chart.visualMap.rangeMax += speed * Time.deltaTime;
                chart.RefreshChart();
                yield return(null);
            }
        }
Пример #15
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;
 }
Пример #16
0
        internal Color GetAreaColor(ThemeInfo theme, int index, bool highlight)
        {
            var color = areaStyle.color != Color.clear ? areaStyle.color : (Color)theme.GetColor(index);

            if (highlight)
            {
                if (areaStyle.highlightColor != Color.clear)
                {
                    color = areaStyle.highlightColor;
                }
                else
                {
                    color *= color;
                }
            }
            color.a *= areaStyle.opacity;
            return(color);
        }
 public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, bool active)
 {
     if (active)
     {
         if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
         {
             return((Color)themeInfo.GetColor(readIndex));
         }
         else
         {
             return(Color.white);
         }
     }
     else
     {
         return((Color)themeInfo.legendUnableColor);
     }
 }
Пример #18
0
        internal Color32 GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
        {
            Color32 color;

            if (!ChartHelper.IsClearColor(itemStyle.color))
            {
                return(itemStyle.GetColor());
            }
            for (int i = 0; i < runtimeStageAngle.Count; i++)
            {
                if (angle < runtimeStageAngle[i])
                {
                    color = axisLine.stageColor[i].color;
                    ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
                    return(color);
                }
            }
            color = theme.GetColor(serieIndex);
            ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
            return(color);
        }
Пример #19
0
        internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
                                                     bool highlight, bool useDefault = true)
        {
            var color = Color.clear;

            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
                if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor))
                {
                    color    = itemStyleEmphasis.backgroundColor;
                    color.a *= itemStyleEmphasis.opacity;
                    return(color);
                }
            }
            var itemStyle = GetItemStyle(serie, serieData);

            if (!ChartHelper.IsClearColor(itemStyle.backgroundColor))
            {
                color = itemStyle.backgroundColor;
                if (highlight)
                {
                    color *= color;
                }
                color.a *= itemStyle.opacity;
                return(color);
            }
            else if (useDefault)
            {
                color = (Color)theme.GetColor(index);
                if (highlight)
                {
                    color *= color;
                }
                color.a = 0.2f;
                return(color);
            }
            return(color);
        }
Пример #20
0
        internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
                                                       bool highlight, bool useDefault = true)
        {
            var color = ChartConst.clearColor32;

            if (highlight)
            {
                var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
                if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor))
                {
                    color = itemStyleEmphasis.backgroundColor;
                    ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
                    return(color);
                }
            }
            var itemStyle = GetItemStyle(serie, serieData);

            if (!ChartHelper.IsClearColor(itemStyle.backgroundColor))
            {
                color = itemStyle.backgroundColor;
                if (highlight)
                {
                    color = ChartHelper.GetHighlightColor(color);
                }
                ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
                return(color);
            }
            else if (useDefault)
            {
                color = theme.GetColor(index);
                if (highlight)
                {
                    color = ChartHelper.GetHighlightColor(color);
                }
                color.a = 50;
                return(color);
            }
            return(color);
        }
Пример #21
0
 internal static Color GetItemColor(Serie serie, ThemeInfo theme, int index, bool highlight)
 {
     if (serie.itemStyle.color != Color.clear)
     {
         var color = serie.itemStyle.color;
         if (highlight)
         {
             color *= color;
         }
         color.a *= serie.itemStyle.opacity;
         return(color);
     }
     else
     {
         var color = (Color)theme.GetColor(index);
         if (highlight)
         {
             color *= color;
         }
         color.a *= serie.itemStyle.opacity;
         return(color);
     }
 }
Пример #22
0
        protected override void OnThemeChanged()
        {
            base.OnThemeChanged();
            m_Radar.backgroundColorList.Clear();
            switch (m_Theme)
            {
            case Theme.Dark:
                m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#6f6f6f"));
                m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#606060"));
                break;

            case Theme.Default:
                m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
                m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
                break;

            case Theme.Light:
                m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
                m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
                break;
            }
            InitIndicator();
        }
Пример #23
0
 public Color GetLineColor(ThemeInfo theme, int index, bool highlight)
 {
     if (lineStyle.color != Color.clear)
     {
         var color = lineStyle.color;
         if (highlight)
         {
             color *= color;
         }
         color.a *= lineStyle.opactiy;
         return(color);
     }
     else
     {
         var color = (Color)theme.GetColor(index);
         if (highlight)
         {
             color *= color;
         }
         color.a *= lineStyle.opactiy;
         return(color);
     }
 }
Пример #24
0
        internal Color GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
        {
            Color color;

            if (!ChartHelper.IsClearColor(axisTick.lineStyle.color))
            {
                color    = axisTick.lineStyle.color;
                color.a *= axisTick.lineStyle.opacity;
                return(color);
            }
            for (int i = 0; i < runtimeStageAngle.Count; i++)
            {
                if (angle < runtimeStageAngle[i])
                {
                    color    = axisLine.stageColor[i].color;
                    color.a *= axisTick.lineStyle.opacity;
                    return(color);
                }
            }
            color    = theme.GetColor(serieIndex);
            color.a *= axisTick.lineStyle.opacity;
            return(color);
        }
Пример #25
0
        internal Color GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
        {
            Color color;

            if (itemStyle.color != Color.clear)
            {
                color    = itemStyle.color;
                color.a *= itemStyle.opacity;
                return(color);
            }
            for (int i = 0; i < runtimeStageAngle.Count; i++)
            {
                if (angle < runtimeStageAngle[i])
                {
                    color    = axisLine.stageColor[i].color;
                    color.a *= itemStyle.opacity;
                    return(color);
                }
            }
            color    = theme.GetColor(serieIndex);
            color.a *= itemStyle.opacity;
            return(color);
        }
Пример #26
0
 public Color GetSymbolColor(ThemeInfo theme, int index, bool highlight)
 {
     if (symbol.color != Color.clear)
     {
         var color = symbol.color;
         if (highlight)
         {
             color *= color;
         }
         color.a *= symbol.opacity;
         return(color);
     }
     else
     {
         var color = (Color)theme.GetColor(index);
         if (highlight)
         {
             color *= color;
         }
         color.a *= symbol.opacity;
         return(color);
     }
 }
Пример #27
0
        protected override void Reset()
        {
            base.Reset();
            m_Title.text   = "HeatmapChart";
            m_Tooltip.type = Tooltip.Type.None;
            m_Grid.left    = 100;
            m_Grid.right   = 60;
            m_Grid.bottom  = 60;

            m_XAxises[0].type        = Axis.AxisType.Category;
            m_XAxises[0].boundaryGap = false;
            m_YAxises[0].type        = Axis.AxisType.Category;
            m_YAxises[0].boundaryGap = false;
            m_XAxises[0].splitNumber = 10;
            m_YAxises[0].splitNumber = 10;
            RemoveData();
            var serie          = AddSerie(SerieType.Heatmap, "serie1");
            var heatmapGridWid = 10f;
            int xSplitNumber   = (int)(coordinateWidth / heatmapGridWid);
            int ySplitNumber   = (int)(coordinateHeight / heatmapGridWid);

            serie.itemStyle.show                 = true;
            serie.itemStyle.borderWidth          = 1;
            serie.itemStyle.borderColor          = Color.clear;
            serie.emphasis.show                  = true;
            serie.emphasis.itemStyle.show        = true;
            serie.emphasis.itemStyle.borderWidth = 1;
            serie.emphasis.itemStyle.borderColor = Color.black;

            m_VisualMap.enable          = true;
            m_VisualMap.max             = 10;
            m_VisualMap.range[0]        = 0f;
            m_VisualMap.range[1]        = 10f;
            m_VisualMap.orient          = Orient.Vertical;
            m_VisualMap.calculable      = true;
            m_VisualMap.location.align  = Location.Align.BottomLeft;
            m_VisualMap.location.bottom = 100;
            m_VisualMap.location.left   = 30;
            var colors = new List <string> {
                "#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
                "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"
            };

            m_VisualMap.inRange.Clear();
            foreach (var str in colors)
            {
                m_VisualMap.inRange.Add(ThemeInfo.GetColor(str));
            }
            for (int i = 0; i < xSplitNumber; i++)
            {
                m_XAxises[0].data.Add((i + 1).ToString());
            }
            for (int i = 0; i < ySplitNumber; i++)
            {
                m_YAxises[0].data.Add((i + 1).ToString());
            }
            for (int i = 0; i < xSplitNumber; i++)
            {
                for (int j = 0; j < ySplitNumber; j++)
                {
                    var value = 0f;
                    var rate  = Random.Range(0, 101);
                    if (rate > 70)
                    {
                        value = Random.Range(8f, 10f);
                    }
                    else
                    {
                        value = Random.Range(1f, 8f);
                    }
                    var list = new List <float> {
                        i, j, value
                    };
                    AddData(0, list);
                }
            }
        }
Пример #28
0
        public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis)
        {
            if (string.IsNullOrEmpty(tooltip.formatter))
            {
                var sb = ChartHelper.sb;
                sb.Length = 0;
                var title       = tooltip.titleFormatter;
                var formatTitle = !string.IsNullOrEmpty(title);
                if ("{i}".Equals(tooltip.titleFormatter))
                {
                    title       = string.Empty;
                    formatTitle = false;
                }
                else if (string.IsNullOrEmpty(title))
                {
                    var angle = angleAxis.clockwise ? tooltip.runtimeAngle : 360 - tooltip.runtimeAngle;
                    title = ChartCached.FloatToStr(angle);
                }
                foreach (var serie in series.list)
                {
                    if (serie.show && IsSelectedSerie(tooltip, serie.index))
                    {
                        if (formatTitle)
                        {
                            FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, themeInfo, null, null);
                        }
                        var dataIndexList = tooltip.runtimeSerieIndex[serie.index];

                        for (int i = 0; i < dataIndexList.Count; i++)
                        {
                            var   dataIndex = dataIndexList[i];
                            var   serieData = serie.GetSerieData(dataIndex);
                            var   itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                            var   numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
                            float xValue, yValue;
                            serie.GetXYData(dataIndex, null, out xValue, out yValue);
                            if (string.IsNullOrEmpty(itemFormatter))
                            {
                                sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
                                if (!string.IsNullOrEmpty(serie.name))
                                {
                                    sb.Append(serie.name).Append(": ");
                                }
                                sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
                                if (i != dataIndexList.Count - 1)
                                {
                                    sb.Append(FormatterHelper.PH_NN);
                                }
                            }
                            else
                            {
                                string content = itemFormatter;
                                FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, null, null);
                                var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : serie.index;
                                sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
                                sb.Append(content);
                            }
                        }
                        sb.Append(FormatterHelper.PH_NN);
                    }
                }
                if (string.IsNullOrEmpty(title))
                {
                    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, 0, tooltip.numericFormatter, null, series, themeInfo, null, null);
                return(content);
            }
        }
Пример #29
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, 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 < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             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, category, themeInfo, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, 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, series, themeInfo, category, dataZoom);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(FormatterHelper.PH_NN);
                     }
                 }
             }
             else if (IsNeedTooltipSerie(serie, tooltip))
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var 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, series, themeInfo, category, 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, category, themeInfo, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, 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(themeInfo.GetColor(dotColorIndex)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(FormatterHelper.TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory && !titleIsIgnroe)
             {
                 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, series, themeInfo, category, dataZoom);
         return(content);
     }
 }
Пример #30
0
        private void InitLegend()
        {
            m_Legend.OnChanged();
            TextAnchor anchor    = m_Legend.location.textAnchor;
            Vector2    anchorMin = m_Legend.location.anchorMin;
            Vector2    anchorMax = m_Legend.location.anchorMax;
            Vector2    pivot     = m_Legend.location.pivot;

            var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax,
                                                     pivot, new Vector2(chartWidth, chartHeight));

            legendObject.transform.localPosition = m_Legend.location.GetPosition(chartWidth, chartHeight);
            ChartHelper.DestoryAllChilds(legendObject.transform);
            if (!m_Legend.show)
            {
                return;
            }
            var           serieNameList = m_Series.GetSerieNameList();
            List <string> datas;

            if (m_Legend.data.Count > 0)
            {
                datas = new List <string>();
                for (int i = 0; i < m_Legend.data.Count; i++)
                {
                    var category = m_Legend.data[i];
                    if (serieNameList.Contains(category))
                    {
                        datas.Add(category);
                    }
                }
            }
            else
            {
                datas = serieNameList;
            }
            m_Legend.RemoveButton();
            for (int i = 0; i < datas.Count; i++)
            {
                string legendName = datas[i];
                Button btn        = ChartHelper.AddButtonObject(s_LegendObjectName + "_" + i + "_" + legendName, legendObject.transform,
                                                                m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
                                                                anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
                var bgColor = IsActiveByLegend(legendName) ? m_ThemeInfo.GetColor(i) : m_ThemeInfo.legendUnableColor;
                m_Legend.SetButton(legendName, btn, datas.Count);
                m_Legend.UpdateButtonColor(legendName, bgColor);
                btn.GetComponentInChildren <Text>().text = legendName;
                ChartHelper.ClearEventListener(btn.gameObject);
                ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
                {
                    if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None)
                    {
                        return;
                    }
                    var temp            = data.selectedObject.name.Split('_');
                    string selectedName = temp[2];
                    int clickedIndex    = int.Parse(temp[1]);
                    if (m_Legend.selectedMode == Legend.SelectedMode.Multiple)
                    {
                        OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
                    }
                    else
                    {
                        var btnList = m_Legend.buttonList.Values.ToArray();
                        for (int n = 0; n < btnList.Length; n++)
                        {
                            temp         = btnList[n].name.Split('_');
                            selectedName = temp[2];
                            var index    = int.Parse(temp[1]);
                            OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false);
                        }
                    }
                });
                ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) =>
                {
                    if (btn == null)
                    {
                        return;
                    }
                    var temp            = btn.name.Split('_');
                    string selectedName = temp[2];
                    int index           = int.Parse(temp[1]);
                    OnLegendButtonEnter(index, selectedName);
                });
                ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) =>
                {
                    if (btn == null)
                    {
                        return;
                    }
                    var temp            = btn.name.Split('_');
                    string selectedName = temp[2];
                    int index           = int.Parse(temp[1]);
                    OnLegendButtonExit(index, selectedName);
                });
            }
            if (m_Legend.selectedMode == Legend.SelectedMode.Single)
            {
                for (int n = 0; n < datas.Count; n++)
                {
                    OnLegendButtonClick(n, datas[n], n == 0 ? true : false);
                }
            }
        }