protected void OnInit()
        {
            RemoveAllChartComponent();
            OnBeforeSerialize();
            AddChartComponentWhenNoExist <Title>();
            AddChartComponentWhenNoExist <Tooltip>();

            GetChartComponent <Title>().text = GetType().Name;

            if (m_Theme.sharedTheme != null)
            {
                m_Theme.sharedTheme.CopyTheme(ThemeType.Default);
            }
            else
            {
                m_Theme.sharedTheme = XCThemeMgr.GetTheme(ThemeType.Default);
            }

            var sizeDelta = rectTransform.sizeDelta;

            if (sizeDelta.x < 580 && sizeDelta.y < 300)
            {
                rectTransform.sizeDelta = new Vector2(580, 300);
            }
            ChartHelper.HideAllObject(transform);
            if (m_OnInit != null)
            {
                m_OnInit();
            }
        }
        private void InitTooltip(Tooltip tooltip)
        {
            tooltip.painter          = chart.m_PainterUpper;
            tooltip.refreshComponent = delegate()
            {
                var objName = ChartCached.GetComponentObjectName(tooltip);
                tooltip.gameObject = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
                                                           chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
                var tooltipObject = tooltip.gameObject;
                tooltipObject.transform.localPosition = Vector3.zero;
                tooltipObject.hideFlags = chart.chartHideFlags;
                var parent = tooltipObject.transform;
                ChartHelper.HideAllObject(tooltipObject.transform);

                tooltip.view = TooltipView.CreateView(tooltip, chart.theme, parent);
                tooltip.SetActive(false);

                m_LabelRoot = ChartHelper.AddObject("label", tooltip.gameObject.transform, chart.chartMinAnchor,
                                                    chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
                ChartHelper.HideAllObject(m_LabelRoot);
                m_IndicatorLabels.Clear();
                for (int i = 0; i < 2; i++)
                {
                    var labelName = "label_" + i;
                    var item      = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
                                                                         chart.theme, TextAnchor.MiddleCenter);
                    item.SetActive(false);
                    m_IndicatorLabels.Add(item);
                }
            };
            tooltip.refreshComponent();
        }
        private void InitRadarCoord(RadarCoord radar)
        {
            float txtHig = 20;

            radar.painter          = chart.GetPainter(radar.index);
            radar.refreshComponent = delegate()
            {
                radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
                var radarObject = ChartHelper.AddObject("Radar" + radar.index, chart.transform, chart.chartMinAnchor,
                                                        chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
                radar.gameObject           = radarObject;
                radar.gameObject.hideFlags = chart.chartHideFlags;
                ChartHelper.HideAllObject(radarObject.transform, INDICATOR_TEXT);
                for (int i = 0; i < radar.indicatorList.Count; i++)
                {
                    var indicator = radar.indicatorList[i];
                    var pos       = radar.GetIndicatorPosition(i);
                    var objName   = INDICATOR_TEXT + "_" + i;

                    var label = ChartHelper.AddChartLabel(objName, radarObject.transform, radar.axisName.labelStyle,
                                                          chart.theme.common, radar.GetFormatterIndicatorContent(i), Color.clear, TextAnchor.MiddleCenter);
                    label.SetActive(radar.indicator && radar.axisName.labelStyle.show);
                    AxisHelper.AdjustCircleLabelPos(label, pos, radar.context.center, txtHig, radar.axisName.labelStyle.offset);
                }
                chart.RefreshBasePainter();
            };
            radar.refreshComponent.Invoke();
        }
Esempio n. 4
0
        public override void InitComponent()
        {
            var comment = component;

            comment.painter          = null;
            comment.refreshComponent = delegate()
            {
                var objName    = ChartCached.GetComponentObjectName(comment);
                var commentObj = ChartHelper.AddObject(objName,
                                                       chart.transform,
                                                       chart.chartMinAnchor,
                                                       chart.chartMaxAnchor,
                                                       chart.chartPivot,
                                                       chart.chartSizeDelta);

                commentObj.SetActive(comment.show);
                commentObj.hideFlags = chart.chartHideFlags;
                ChartHelper.HideAllObject(commentObj);
                for (int i = 0; i < comment.items.Count; i++)
                {
                    var item       = comment.items[i];
                    var labelStyle = comment.GetLabelStyle(i);
                    var label      = ChartHelper.AddChartLabel(s_CommentObjectName + i, commentObj.transform, labelStyle, chart.theme.common,
                                                               GetContent(item), Color.clear, TextAnchor.MiddleCenter);
                    label.SetActive(comment.show && item.show);
                    label.SetPosition(item.position + labelStyle.offset);
                }
            };
            comment.refreshComponent();
        }
Esempio n. 5
0
 public override void InitComponent()
 {
     m_MarkLineLabelRoot = ChartHelper.AddObject("markarea" + component.index, chart.transform, chart.chartMinAnchor,
                                                 chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
     m_MarkLineLabelRoot.hideFlags = chart.chartHideFlags;
     ChartHelper.HideAllObject(m_MarkLineLabelRoot);
     InitMarkArea(component);
 }
        private void InitRadiusAxis(RadiusAxis axis)
        {
            var polar = chart.GetChartComponent <PolarCoord>(axis.index);

            if (polar == null)
            {
                return;
            }

            var angleAxis = ComponentHelper.GetAngleAxis(chart.components, polar.index);

            if (angleAxis == null)
            {
                return;
            }

            PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            axis.context.labelObjectList.Clear();
            var radius  = polar.context.radius;
            var objName = component.GetType().Name + axis.index;
            var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
                                                chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);

            axisObj.transform.localPosition = Vector3.zero;
            axisObj.SetActive(axis.show && axis.axisLabel.show);
            axisObj.hideFlags = chart.chartHideFlags;
            ChartHelper.HideAllObject(axisObj);
            var textStyle   = axis.axisLabel.textStyle;
            var splitNumber = AxisHelper.GetScaleNumber(axis, radius, null);
            var totalWidth  = 0f;
            var txtHig      = textStyle.GetFontSize(chart.theme.axis) + 2;

            for (int i = 0; i < splitNumber; i++)
            {
                var labelWidth     = AxisHelper.GetScaleWidth(axis, radius, i + 1, null);
                var inside         = axis.axisLabel.inside;
                var isPercentStack = SeriesHelper.IsPercentStack <Bar>(chart.series);
                var labelName      = AxisHelper.GetLabelName(axis, radius, i, axis.context.minValue, axis.context.maxValue,
                                                             null, isPercentStack);
                var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
                                                           new Vector2(labelWidth, txtHig), axis, chart.theme.axis, labelName, Color.clear);

                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(label.text, labelWidth);
                }

                label.text.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
                label.SetText(labelName);
                label.SetPosition(GetLabelPosition(polar, axis, angleAxis.context.startAngle, totalWidth));
                label.SetActive(true);
                label.SetTextActive(true);

                axis.context.labelObjectList.Add(label);

                totalWidth += labelWidth;
            }
        }
Esempio n. 7
0
        private void InitAngleAxis(AngleAxis axis)
        {
            var polar = chart.GetChartComponent <PolarCoord>(axis.polarIndex);

            if (polar == null)
            {
                return;
            }
            PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            var radius = polar.context.radius;

            axis.context.labelObjectList.Clear();
            axis.context.startAngle = 90 - axis.startAngle;

            string objName = component.GetType().Name + axis.index;
            var    axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
                                                   chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);

            axisObj.transform.localPosition = Vector3.zero;
            axisObj.SetActive(axis.show);
            axisObj.hideFlags = chart.chartHideFlags;
            ChartHelper.HideAllObject(axisObj);
            var splitNumber    = AxisHelper.GetSplitNumber(axis, radius, null);
            var totalAngle     = axis.context.startAngle;
            var total          = 360;
            var cenPos         = polar.context.center;
            var txtHig         = axis.axisLabel.textStyle.GetFontSize(chart.theme.axis) + 2;
            var margin         = axis.axisLabel.distance + axis.axisTick.GetLength(chart.theme.axis.tickLength);
            var isCategory     = axis.IsCategory();
            var isPercentStack = SeriesHelper.IsPercentStack <Bar>(chart.series);

            for (int i = 0; i < splitNumber; i++)
            {
                float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i + 1, null);
                bool  inside     = axis.axisLabel.inside;
                var   labelName  = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue,
                                                           null, isPercentStack);
                var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
                                                           new Vector2(scaleAngle, txtHig), axis,
                                                           chart.theme.axis, labelName, Color.clear);
                label.text.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
                var pos = ChartHelper.GetPos(cenPos, radius + margin,
                                             isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
                AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero);
                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(label.text, scaleAngle);
                }
                axis.context.labelObjectList.Add(label);

                totalAngle += scaleAngle;
            }
        }
 private void UpdateTooltipIndicatorLabelText(Tooltip tooltip)
 {
     if (!tooltip.show)
     {
         return;
     }
     if (tooltip.type == Tooltip.Type.None)
     {
         return;
     }
     if (m_PointerContainer != null)
     {
         if (tooltip.type == Tooltip.Type.Corss)
         {
             var labelCount = 0;
             if (m_PointerContainer is GridCoord)
             {
                 var grid = m_PointerContainer as GridCoord;
                 ChartHelper.HideAllObject(m_LabelRoot);
                 foreach (var component in chart.components)
                 {
                     if (component is XAxis || component is YAxis)
                     {
                         var axis = component as Axis;
                         if (axis.gridIndex == grid.index)
                         {
                             var label = GetIndicatorLabel(labelCount++);
                             SetTooltipIndicatorLabel(tooltip, axis, label);
                         }
                     }
                 }
             }
             else if (m_PointerContainer is PolarCoord)
             {
                 var polar = m_PointerContainer as PolarCoord;
                 ChartHelper.HideAllObject(m_LabelRoot);
                 foreach (var component in chart.components)
                 {
                     if (component is AngleAxis || component is RadiusAxis)
                     {
                         var axis = component as Axis;
                         if (axis.polarIndex == polar.index)
                         {
                             var label = GetIndicatorLabel(labelCount++);
                             SetTooltipIndicatorLabel(tooltip, axis, label);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
        public override void InitComponent()
        {
            var dataZoom = component;

            dataZoom.painter          = chart.m_PainterUpper;
            dataZoom.refreshComponent = delegate()
            {
                var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom + dataZoom.index, chart.transform,
                                                           chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
                dataZoom.gameObject      = dataZoomObject;
                dataZoomObject.hideFlags = chart.chartHideFlags;
                ChartHelper.HideAllObject(dataZoomObject);

                var startLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "start", dataZoomObject.transform,
                                                           dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleRight);
                startLabel.gameObject.SetActive(true);

                var endLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "end", dataZoomObject.transform,
                                                         dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleLeft);
                endLabel.gameObject.SetActive(true);

                dataZoom.SetStartLabel(startLabel);
                dataZoom.SetEndLabel(endLabel);
                dataZoom.SetLabelActive(false);

                foreach (var index in dataZoom.xAxisIndexs)
                {
                    var xAxis = chart.GetChartComponent <XAxis>(index);
                    if (xAxis != null)
                    {
                        xAxis.UpdateFilterData(dataZoom);
                    }
                }

                foreach (var serie in chart.series)
                {
                    SerieHelper.UpdateFilterData(serie, dataZoom);
                }
            };
            dataZoom.refreshComponent();
        }
Esempio n. 10
0
        public override void InitComponent()
        {
            var title = component;

            title.painter          = null;
            title.refreshComponent = delegate()
            {
                title.OnChanged();
                var anchorMin   = title.location.runtimeAnchorMin;
                var anchorMax   = title.location.runtimeAnchorMax;
                var pivot       = title.location.runtimePivot;
                var objName     = ChartCached.GetComponentObjectName(title);
                var titleObject = ChartHelper.AddObject(objName, chart.transform, anchorMin, anchorMax,
                                                        pivot, chart.chartSizeDelta);
                title.gameObject = titleObject;
                title.gameObject.transform.SetSiblingIndex(chart.m_PainterUpper.transform.GetSiblingIndex() + 1);
                anchorMin = title.location.runtimeAnchorMin;
                anchorMax = title.location.runtimeAnchorMax;
                pivot     = title.location.runtimePivot;
                var fontSize = title.labelStyle.textStyle.GetFontSize(chart.theme.title);
                ChartHelper.UpdateRectTransform(titleObject, anchorMin, anchorMax, pivot, new Vector2(chart.chartWidth, chart.chartHeight));
                var titlePosition    = chart.GetTitlePosition(title);
                var subTitlePosition = -new Vector3(0, fontSize + title.itemGap, 0);

                titleObject.transform.localPosition = titlePosition;
                titleObject.hideFlags = chart.chartHideFlags;
                ChartHelper.HideAllObject(titleObject);

                m_LabelObject = ChartHelper.AddChartLabel(s_TitleObjectName, titleObject.transform, title.labelStyle, chart.theme.title,
                                                          GetTitleText(title), Color.clear, title.location.runtimeTextAlignment);
                m_LabelObject.SetActive(title.show && title.labelStyle.show);

                m_SubLabelObject = ChartHelper.AddChartLabel(s_SubTitleObjectName, titleObject.transform, title.subLabelStyle, chart.theme.subTitle,
                                                             GetSubTitleText(title), Color.clear, title.location.runtimeTextAlignment);
                m_SubLabelObject.SetActive(title.show && title.subLabelStyle.show);
                m_SubLabelObject.transform.localPosition = subTitlePosition + title.subLabelStyle.offset;
            };
            title.refreshComponent();
        }
 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();
 }