예제 #1
0
        public virtual void UpdateLegendColor(string legendName, bool active)
        {
            var legendIndex = m_LegendRealShowName.IndexOf(legendName);

            if (legendIndex >= 0)
            {
                foreach (var component in m_Components)
                {
                    if (component is Legend)
                    {
                        var legend       = component as Legend;
                        var iconColor    = LegendHelper.GetIconColor(this, legend, legendIndex, legendName, active);
                        var contentColor = LegendHelper.GetContentColor(this, legendIndex, legendName, legend, m_Theme, active);
                        legend.UpdateButtonColor(legendName, iconColor);
                        legend.UpdateContentColor(legendName, contentColor);
                    }
                }
            }
        }
 private void InitLegend(Legend legend)
 {
     legend.painter          = null;
     legend.refreshComponent = delegate()
     {
         legend.OnChanged();
         var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, chart.transform, chart.chartMinAnchor,
                                                  chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
         legend.gameObject      = legendObject;
         legendObject.hideFlags = chart.chartHideFlags;
         SeriesHelper.UpdateSerieNameList(chart, ref chart.m_LegendRealShowName);
         legend.context.background = ChartHelper.AddIcon("background", legendObject.transform, 0, 0);
         legend.context.background.transform.SetSiblingIndex(0);
         ChartHelper.SetBackground(legend.context.background, legend.background);
         List <string> datas;
         if (legend.show && legend.data.Count > 0)
         {
             datas = new List <string>();
             foreach (var data in legend.data)
             {
                 if (chart.m_LegendRealShowName.Contains(data) || chart.IsSerieName(data))
                 {
                     datas.Add(data);
                 }
             }
         }
         else
         {
             datas = chart.m_LegendRealShowName;
         }
         int totalLegend = 0;
         for (int i = 0; i < datas.Count; i++)
         {
             if (!SeriesHelper.IsLegalLegendName(datas[i]))
             {
                 continue;
             }
             totalLegend++;
         }
         legend.RemoveButton();
         ChartHelper.HideAllObject(legendObject);
         if (!legend.show)
         {
             return;
         }
         for (int i = 0; i < datas.Count; i++)
         {
             if (!SeriesHelper.IsLegalLegendName(datas[i]))
             {
                 continue;
             }
             string legendName = GetFormatterContent(legend, i, datas[i]);
             var    readIndex  = chart.m_LegendRealShowName.IndexOf(datas[i]);
             var    active     = chart.IsActiveByLegend(datas[i]);
             var    bgColor    = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active);
             bgColor.a = legend.itemOpacity;
             var item = LegendHelper.AddLegendItem(chart, legend, i, datas[i], legendObject.transform, chart.theme,
                                                   legendName, bgColor, active, readIndex);
             legend.SetButton(legendName, item, totalLegend);
             ChartHelper.ClearEventListener(item.button.gameObject);
             ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
             {
                 if (data.selectedObject == null || legend.selectedMode == Legend.SelectedMode.None)
                 {
                     return;
                 }
                 var temp            = data.selectedObject.name.Split('_');
                 string selectedName = temp[1];
                 int clickedIndex    = int.Parse(temp[0]);
                 if (legend.selectedMode == Legend.SelectedMode.Multiple)
                 {
                     OnLegendButtonClick(legend, clickedIndex, selectedName, !chart.IsActiveByLegend(selectedName));
                 }
                 else
                 {
                     var btnList = legend.context.buttonList.Values.ToArray();
                     if (btnList.Length == 1)
                     {
                         OnLegendButtonClick(legend, 0, selectedName, !chart.IsActiveByLegend(selectedName));
                     }
                     else
                     {
                         for (int n = 0; n < btnList.Length; n++)
                         {
                             temp         = btnList[n].name.Split('_');
                             selectedName = btnList[n].legendName;
                             var index    = btnList[n].index;
                             OnLegendButtonClick(legend, n, selectedName, index == clickedIndex ? true : false);
                         }
                     }
                 }
             });
             ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) =>
             {
                 if (item.button == null)
                 {
                     return;
                 }
                 var temp            = item.button.name.Split('_');
                 string selectedName = temp[1];
                 int index           = int.Parse(temp[0]);
                 OnLegendButtonEnter(legend, index, selectedName);
             });
             ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) =>
             {
                 if (item.button == null)
                 {
                     return;
                 }
                 var temp            = item.button.name.Split('_');
                 string selectedName = temp[1];
                 int index           = int.Parse(temp[0]);
                 OnLegendButtonExit(legend, index, selectedName);
             });
         }
         LegendHelper.ResetItemPosition(legend, chart.chartPosition, chart.chartWidth, chart.chartHeight);
     };
     legend.refreshComponent();
 }