Esempio n. 1
0
        public static void SetLegendBackground(Legend legend, ImageStyle style)
        {
            var background = legend.context.background;

            if (background == null)
            {
                return;
            }
            ChartHelper.SetActive(background, style.show);
            if (!style.show)
            {
                return;
            }
            var rect = background.gameObject.GetComponent <RectTransform>();

            rect.localPosition = legend.context.center;
            rect.sizeDelta     = new Vector2(legend.context.width, legend.context.height);
            ChartHelper.SetBackground(background, style);
        }
 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();
 }
 public void SetBackground(ImageStyle imageStyle)
 {
     ChartHelper.SetBackground(m_Background, imageStyle);
 }