Exemplo n.º 1
0
 private Vector3 GetLegendPosition(Legend legend, int i)
 {
     return(legend.location.GetPosition(chartWidth, chartHeight));
 }
Exemplo n.º 2
0
        public static void ResetItemPosition(Legend legend)
        {
            var startX     = 0f;
            var currWidth  = 0f;
            var currHeight = 0f;

            switch (legend.orient)
            {
            case Orient.Vertical:
                switch (legend.location.align)
                {
                case Location.Align.TopCenter:
                    startX     = legend.runtimeWidth / 2;
                    currHeight = 0f;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(-startX + item.width / 2, -currHeight));
                        currHeight += item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.TopLeft:
                    currHeight = 0f;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(0, -currHeight));
                        currHeight += item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.TopRight:
                    currHeight = 0f;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(item.width - legend.runtimeWidth, -currHeight));
                        currHeight += item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.Center:
                    startX     = legend.runtimeWidth / 2;
                    currHeight = legend.runtimeHeight;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
                        currHeight -= item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.CenterLeft:
                    currHeight = legend.runtimeHeight;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(0, currHeight - item.height));
                        currHeight -= item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.CenterRight:
                    currHeight = legend.runtimeHeight;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
                        currHeight -= item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.BottomCenter:
                    startX     = legend.runtimeWidth / 2;
                    currHeight = legend.runtimeHeight;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
                        currHeight -= item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.BottomLeft:
                    currHeight = legend.runtimeHeight;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(0, currHeight - item.height));
                        currHeight -= item.height + legend.itemGap;
                    }
                    break;

                case Location.Align.BottomRight:
                    currHeight = legend.runtimeHeight;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
                        currHeight -= item.height + legend.itemGap;
                    }
                    break;
                }
                break;

            case Orient.Horizonal:
                switch (legend.location.align)
                {
                case Location.Align.TopLeft:
                case Location.Align.CenterLeft:
                case Location.Align.BottomLeft:
                    currWidth = 0f;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(currWidth, 0));
                        currWidth += item.width + legend.itemGap;
                    }
                    break;

                case Location.Align.TopCenter:
                case Location.Align.Center:
                case Location.Align.BottomCenter:
                    startX    = legend.runtimeWidth / 2;
                    currWidth = 0f;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(-startX + item.width / 2 + currWidth, 0));
                        currWidth += item.width + legend.itemGap;
                    }
                    break;

                case Location.Align.TopRight:
                case Location.Align.CenterRight:
                case Location.Align.BottomRight:
                    startX    = -legend.runtimeWidth;
                    currWidth = 0f;
                    foreach (var kv in legend.buttonList)
                    {
                        var item = kv.Value;
                        item.SetPosition(new Vector3(startX + currWidth + item.width, 0));
                        currWidth += item.width + legend.itemGap;
                    }
                    break;
                }
                break;
            }
        }
Exemplo n.º 3
0
        private void InitLegend(Legend legend)
        {
            legend.OnChanged();
            var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, transform, m_ChartMinAnchor,
                                                     m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta);

            legend.gameObject       = legendObject;
            legend.painter          = null; // legend component does not need to paint
            legend.refreshComponent = delegate()
            {
                if (legendObject == null)
                {
                    return;
                }
                legend.OnChanged();
                legendObject.hideFlags = chartHideFlags;
                SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName);
                List <string> datas;
                if (legend.show && legend.data.Count > 0)
                {
                    datas = new List <string>();
                    for (int i = 0; i < m_LegendRealShowName.Count; i++)
                    {
                        if (legend.data.Contains(m_LegendRealShowName[i]))
                        {
                            datas.Add(m_LegendRealShowName[i]);
                        }
                    }
                }
                else
                {
                    datas = 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 = legend.GetFormatterContent(datas[i]);
                    var    readIndex  = m_LegendRealShowName.IndexOf(datas[i]);
                    var    active     = IsActiveByLegend(datas[i]);
                    var    bgColor    = LegendHelper.GetIconColor(legend, readIndex, theme, m_Series, datas[i], active);
                    var    item       = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, m_Theme,
                                                                   legendName, bgColor, active);
                    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(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
                        }
                        else
                        {
                            var btnList = legend.buttonList.Values.ToArray();
                            if (btnList.Length == 1)
                            {
                                OnLegendButtonClick(0, selectedName, !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(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(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(index, selectedName);
                    });
                }
                if (legend.selectedMode == Legend.SelectedMode.Single)
                {
                    for (int n = 0; n < m_LegendRealShowName.Count; n++)
                    {
                        OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false);
                    }
                }
                LegendHelper.ResetItemPosition(legend, m_ChartPosition, m_ChartWidth, m_ChartHeight);
            };
            legend.refreshComponent();
        }