예제 #1
0
 public static Color GetIconColor(BaseChart chart, Legend legend, int readIndex, string legendName, bool active)
 {
     if (active)
     {
         if (legend.itemAutoColor)
         {
             return(SeriesHelper.GetNameColor(chart, readIndex, legendName));
         }
         else
         {
             return(legend.GetColor(readIndex));
         }
     }
     else
     {
         return(chart.theme.legend.unableColor);
     }
 }
예제 #2
0
        public override void DrawSerie(VertexHelper vh)
        {
            if (serie.IsUseCoord <PolarCoord>())
            {
                DrawPolarLine(vh, serie);
                DrawPolarLineSymbol(vh);
            }
            else if (serie.IsUseCoord <GridCoord>())
            {
                DrawLineSerie(vh, serie);

                if (!SeriesHelper.IsStack(chart.series))
                {
                    DrawLinePoint(vh, serie);
                    DrawLineArrow(vh, serie);
                }
            }
        }
예제 #3
0
 public virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue)
 {
     if (IsAllAxisValue())
     {
         if (axis is XAxis)
         {
             SeriesHelper.GetXMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue);
         }
         else
         {
             SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue);
         }
     }
     else
     {
         SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue);
     }
     AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
 }
 public void InsertSerie(Serie serie, int index = -1, bool addToHead = false)
 {
     serie.AnimationRestart();
     AnimationStyleHelper.UpdateSerieAnimation(serie);
     if (addToHead)
     {
         m_Series.Insert(0, serie);
     }
     else if (index >= 0)
     {
         m_Series.Insert(index, serie);
     }
     else
     {
         m_Series.Add(serie);
     }
     ResetSeriesIndex();
     SeriesHelper.UpdateSerieNameList(this, ref m_LegendRealShowName);
 }
예제 #5
0
        public static Color GetContentColor(BaseChart chart, int legendIndex, string legendName, Legend legend, ThemeStyle theme, bool active)
        {
            var textStyle = legend.labelStyle.textStyle;

            if (active)
            {
                if (legend.labelStyle.textStyle.autoColor)
                {
                    return(SeriesHelper.GetNameColor(chart, legendIndex, legendName));
                }
                else
                {
                    return(!ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor);
                }
            }
            else
            {
                return(theme.legend.unableColor);
            }
        }
        public override void CheckComponent(System.Text.StringBuilder sb)
        {
            var legend = component;

            if (ChartHelper.IsColorAlphaZero(legend.labelStyle.textStyle.color))
            {
                sb.AppendFormat("warning:legend{0}->textStyle->color alpha is 0\n", legend.index);
            }
            var serieNameList = SeriesHelper.GetLegalSerieNameList(chart.series);

            if (serieNameList.Count == 0)
            {
                sb.AppendFormat("warning:legend{0} need serie.serieName or serieData.name not empty\n", legend.index);
            }
            foreach (var category in legend.data)
            {
                if (!serieNameList.Contains(category))
                {
                    sb.AppendFormat("warning:legend{0} [{1}] is invalid, must be one of serie.serieName or serieData.name\n",
                                    legend.index, category);
                }
            }
        }
 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();
 }
예제 #8
0
        private void DrawVerticalDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
        {
            if (!dataZoom.enable || !dataZoom.supportSlider)
            {
                return;
            }

            var p1              = new Vector3(dataZoom.context.x, dataZoom.context.y);
            var p2              = new Vector3(dataZoom.context.x, dataZoom.context.y + dataZoom.context.height);
            var p3              = new Vector3(dataZoom.context.x + dataZoom.context.width, dataZoom.context.y + dataZoom.context.height);
            var p4              = new Vector3(dataZoom.context.x + dataZoom.context.width, dataZoom.context.y);
            var lineColor       = dataZoom.lineStyle.GetColor(chart.theme.dataZoom.dataLineColor);
            var lineWidth       = dataZoom.lineStyle.GetWidth(chart.theme.dataZoom.dataLineWidth);
            var borderWidth     = dataZoom.borderWidth == 0 ? chart.theme.dataZoom.borderWidth : dataZoom.borderWidth;
            var borderColor     = dataZoom.GetBorderColor(chart.theme.dataZoom.borderColor);
            var backgroundColor = dataZoom.GetBackgroundColor(chart.theme.dataZoom.backgroundColor);
            var areaColor       = dataZoom.areaStyle.GetColor(chart.theme.dataZoom.dataAreaColor);

            UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor);
            var centerPos = new Vector3(dataZoom.context.x + dataZoom.context.width / 2,
                                        dataZoom.context.y + dataZoom.context.height / 2);

            UGL.DrawBorder(vh, centerPos, dataZoom.context.width, dataZoom.context.height, borderWidth, borderColor);

            if (dataZoom.showDataShadow && chart.series.Count > 0)
            {
                Serie   serie    = chart.series[0];
                Axis    axis     = chart.GetChartComponent <YAxis>(0);
                var     showData = serie.GetDataList(null);
                float   scaleWid = dataZoom.context.height / (showData.Count - 1);
                Vector3 lp       = Vector3.zero;
                Vector3 np       = Vector3.zero;
                double  minValue = 0;
                double  maxValue = 0;
                SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue);
                AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);

                int rate       = 1;
                var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
                var maxCount   = showData.Count;
                if (sampleDist > 0)
                {
                    rate = (int)((maxCount - serie.minShow) / (dataZoom.context.height / sampleDist));
                }
                if (rate < 1)
                {
                    rate = 1;
                }

                var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
                                   DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
                var dataChanging = false;

                for (int i = 0; i < maxCount; i += rate)
                {
                    double value = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
                                                          serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
                    float pY      = dataZoom.context.y + i * scaleWid;
                    float dataHig = (maxValue - minValue) == 0 ? 0 :
                                    (float)((value - minValue) / (maxValue - minValue) * dataZoom.context.width);
                    np = new Vector3(chart.chartX + chart.chartWidth - dataZoom.right - dataHig, pY);
                    if (i > 0)
                    {
                        UGL.DrawLine(vh, lp, np, lineWidth, lineColor);
                        Vector3 alp = new Vector3(lp.x, lp.y - lineWidth);
                        Vector3 anp = new Vector3(np.x, np.y - lineWidth);

                        Vector3 tnp = new Vector3(np.x, chart.chartY + dataZoom.bottom + lineWidth);
                        Vector3 tlp = new Vector3(lp.x, chart.chartY + dataZoom.bottom + lineWidth);
                        UGL.DrawQuadrilateral(vh, alp, anp, tnp, tlp, areaColor);
                    }
                    lp = np;
                }
                if (dataChanging)
                {
                    chart.RefreshTopPainter();
                }
            }
            switch (dataZoom.rangeMode)
            {
            case DataZoom.RangeMode.Percent:
                var start       = dataZoom.context.y + dataZoom.context.height * dataZoom.start / 100;
                var end         = dataZoom.context.y + dataZoom.context.height * dataZoom.end / 100;
                var fillerColor = dataZoom.GetFillerColor(chart.theme.dataZoom.fillerColor);

                p1 = new Vector2(dataZoom.context.x, start);
                p2 = new Vector2(dataZoom.context.x + dataZoom.context.width, start);
                p3 = new Vector2(dataZoom.context.x + dataZoom.context.width, end);
                p4 = new Vector2(dataZoom.context.x, end);
                UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, fillerColor);
                UGL.DrawLine(vh, p1, p2, lineWidth, fillerColor);
                UGL.DrawLine(vh, p3, p4, lineWidth, fillerColor);
                break;
            }
        }
예제 #9
0
        public static void GetMinMaxValue(List <Serie> series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
                                          bool inverse, bool yValue, out double minVaule, out double maxValue, bool isPolar = false)
        {
            double min            = double.MaxValue;
            double max            = double.MinValue;
            var    isPercentStack = SeriesHelper.IsPercentStack <Bar>(series);

            if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue))
            {
                for (int i = 0; i < series.Count; i++)
                {
                    var serie = series[i];
                    if ((isPolar && serie.polarIndex != axisIndex) ||
                        (!isPolar && serie.yAxisIndex != axisIndex) ||
                        !serie.show)
                    {
                        continue;
                    }
                    var updateDuration = serie.animation.enable?serie.animation.dataChangeDuration : 0;
                    if (isPercentStack && SeriesHelper.IsPercentStack <Bar>(series, serie.serieName))
                    {
                        if (100 > max)
                        {
                            max = 100;
                        }
                        if (0 < min)
                        {
                            min = 0;
                        }
                    }
                    else
                    {
                        var showData = serie.GetDataList(dataZoom);
                        foreach (var data in showData)
                        {
                            if (serie is Candlestick)
                            {
                                var dataMin = data.GetMinData(inverse);
                                var dataMax = data.GetMaxData(inverse);
                                if (dataMax > max)
                                {
                                    max = dataMax;
                                }
                                if (dataMin < min)
                                {
                                    min = dataMin;
                                }
                            }
                            else
                            {
                                //var currData = data.GetData(yValue ? 1 : 0, inverse);
                                var currData = data.GetCurrData(yValue ? 1 : 0, updateDuration, inverse);
                                if (!serie.IsIgnoreValue(currData))
                                {
                                    if (currData > max)
                                    {
                                        max = currData;
                                    }
                                    if (currData < min)
                                    {
                                        min = currData;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax);
                foreach (var ss in _stackSeriesForMinMax)
                {
                    _serieTotalValueForMinMax.Clear();
                    for (int i = 0; i < ss.Value.Count; i++)
                    {
                        var serie = ss.Value[i];
                        if ((isPolar && serie.polarIndex != axisIndex) ||
                            (!isPolar && serie.yAxisIndex != axisIndex) ||
                            !serie.show)
                        {
                            continue;
                        }
                        var showData = serie.GetDataList(dataZoom);
                        if (SeriesHelper.IsPercentStack <Bar>(series, serie.stack))
                        {
                            for (int j = 0; j < showData.Count; j++)
                            {
                                _serieTotalValueForMinMax[j] = 100;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < showData.Count; j++)
                            {
                                if (!_serieTotalValueForMinMax.ContainsKey(j))
                                {
                                    _serieTotalValueForMinMax[j] = 0;
                                }
                                double currData = 0;
                                if (serie is Candlestick)
                                {
                                    currData = showData[j].GetMaxData(false);
                                }
                                else
                                {
                                    currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
                                }
                                if (inverse)
                                {
                                    currData = -currData;
                                }
                                if (!serie.IsIgnoreValue(currData))
                                {
                                    _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
                                }
                            }
                        }
                    }
                    double tmax = double.MinValue;
                    double tmin = double.MaxValue;
                    foreach (var tt in _serieTotalValueForMinMax)
                    {
                        if (tt.Value > tmax)
                        {
                            tmax = tt.Value;
                        }
                        if (tt.Value < tmin)
                        {
                            tmin = tt.Value;
                        }
                    }
                    if (tmax > max)
                    {
                        max = tmax;
                    }
                    if (tmin < min)
                    {
                        min = tmin;
                    }
                }
            }
            if (max == double.MinValue && min == double.MaxValue)
            {
                minVaule = 0;
                maxValue = 0;
            }
            else
            {
                minVaule = min > 1 ? Math.Floor(min) : min;
                maxValue = max > 1 ? Math.Ceiling(max) : max;
            }
        }
        private void UpdateSeriePolarContext()
        {
            if (m_SeriePolar == null)
            {
                return;
            }

            var needCheck = (chart.isPointerInChart && m_SeriePolar.IsPointerEnter()) || m_LegendEnter;
            var lineWidth = 0f;

            if (!needCheck)
            {
                if (m_LastCheckContextFlag != needCheck)
                {
                    var needAnimation1 = false;
                    lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
                    m_LastCheckContextFlag             = needCheck;
                    serie.context.pointerItemDataIndex = -1;
                    serie.context.pointerEnter         = false;
                    serie.interact.SetValue(ref needAnimation1, lineWidth, false);
                    foreach (var serieData in serie.data)
                    {
                        var symbol     = SerieHelper.GetSerieSymbol(serie, serieData);
                        var symbolSize = symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
                        serieData.context.highlight = false;
                        serieData.interact.SetValue(ref needAnimation1, symbolSize);
                    }
                    if (needAnimation1)
                    {
                        if (SeriesHelper.IsStack(chart.series))
                        {
                            chart.RefreshTopPainter();
                        }
                        else
                        {
                            chart.RefreshPainter(serie);
                        }
                    }
                }
                return;
            }
            m_LastCheckContextFlag = needCheck;
            var themeSymbolSize         = chart.theme.serie.lineSymbolSize;
            var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize;

            lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);

            var needInteract = false;

            if (m_LegendEnter)
            {
                serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData          = serie.data[i];
                    var symbol             = SerieHelper.GetSerieSymbol(serie, serieData);
                    var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize);

                    serieData.context.highlight = true;
                    serieData.interact.SetValue(ref needInteract, symbolSelectedSize);
                }
            }
            else
            {
                serie.context.pointerItemDataIndex = -1;
                serie.context.pointerEnter         = false;
                var dir          = chart.pointerPos - new Vector2(m_SeriePolar.context.center.x, m_SeriePolar.context.center.y);
                var pointerAngle = ChartHelper.GetAngle360(Vector2.up, dir);
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData = serie.data[i];
                    var angle0    = serieData.context.angle;
                    var angle1    = i >= serie.dataCount - 1 ? angle0 : serie.data[i + 1].context.angle;

                    if (pointerAngle >= angle0 && pointerAngle < angle1)
                    {
                        serie.context.pointerItemDataIndex = i;
                        serie.context.pointerEnter         = true;
                        serieData.context.highlight        = true;
                    }
                    else
                    {
                        serieData.context.highlight = false;
                    }
                }
            }
            if (needInteract)
            {
                if (SeriesHelper.IsStack(chart.series))
                {
                    chart.RefreshTopPainter();
                }
                else
                {
                    chart.RefreshPainter(serie);
                }
            }
        }
예제 #11
0
        private void UpdateSerieGridContext()
        {
            if (m_SerieGrid == null)
            {
                return;
            }
            var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
            var needCheck = (chart.isPointerInChart && m_SerieGrid.IsPointerEnter()) || m_LegendEnter;

            if (!needCheck)
            {
                if (m_LastCheckContextFlag != needCheck)
                {
                    m_LastCheckContextFlag             = needCheck;
                    serie.context.pointerItemDataIndex = -1;
                    serie.context.pointerEnter         = false;
                    serie.highlight = false;
                    serie.ResetInteract();
                    foreach (var serieData in serie.data)
                    {
                        serieData.context.highlight = false;
                    }
                    if (SeriesHelper.IsStack(chart.series))
                    {
                        chart.RefreshTopPainter();
                    }
                    else
                    {
                        chart.RefreshPainter(serie);
                    }
                }
                return;
            }
            m_LastCheckContextFlag = needCheck;
            var themeSymbolSize         = chart.theme.serie.lineSymbolSize;
            var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize;
            var needInteract            = false;

            if (m_LegendEnter)
            {
                serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData          = serie.data[i];
                    var symbol             = SerieHelper.GetSerieSymbol(serie, serieData);
                    var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize);

                    serieData.context.highlight = true;
                    serieData.interact.SetValue(ref needInteract, symbolSelectedSize);
                }
            }
            else if (serie.context.isTriggerByAxis)
            {
                serie.context.pointerEnter = true;
                serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData          = serie.data[i];
                    var symbol             = SerieHelper.GetSerieSymbol(serie, serieData);
                    var symbolSize         = symbol.GetSize(serieData.data, themeSymbolSize);
                    var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize);

                    if (i == serie.context.pointerItemDataIndex)
                    {
                        serieData.context.highlight = true;
                        serieData.interact.SetValue(ref needInteract, symbolSelectedSize);
                    }
                    else
                    {
                        serieData.context.highlight = false;
                        serieData.interact.SetValue(ref needInteract, symbolSize);
                    }
                }
            }
            else
            {
                serie.context.pointerItemDataIndex = -1;
                serie.context.pointerEnter         = false;
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData = serie.data[i];
                    serieData.index = i;
                    var dist               = Vector3.Distance(chart.pointerPos, serieData.context.position);
                    var symbol             = SerieHelper.GetSerieSymbol(serie, serieData);
                    var symbolSize         = symbol.GetSize(serieData.data, themeSymbolSize);
                    var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize);
                    if (dist <= symbolSelectedSize)
                    {
                        serie.context.pointerItemDataIndex = serieData.index;
                        serie.context.pointerEnter         = true;
                        serie.interact.SetValue(ref needInteract, lineWidth, true);
                        serieData.context.highlight = true;
                        serieData.interact.SetValue(ref needInteract, symbolSelectedSize);
                    }
                    else
                    {
                        serieData.context.highlight = false;
                        serieData.interact.SetValue(ref needInteract, symbolSize);
                    }
                }
            }
            if (needInteract)
            {
                if (SeriesHelper.IsStack(chart.series))
                {
                    chart.RefreshTopPainter();
                }
                else
                {
                    chart.RefreshPainter(serie);
                }
            }
        }
예제 #12
0
        private void DrawLineSerie(VertexHelper vh, Line serie)
        {
            if (!serie.show)
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }

            Axis axis;
            Axis relativedAxis;
            var  isY = chart.GetSerieGridCoordAxis(serie, out axis, out relativedAxis);

            if (axis == null)
            {
                return;
            }
            if (relativedAxis == null)
            {
                return;
            }

            m_SerieGrid = chart.GetChartComponent <GridCoord>(axis.gridIndex);
            if (m_SerieGrid == null)
            {
                return;
            }
            if (m_EndLabel != null && !m_SerieGrid.context.endLabelList.Contains(m_EndLabel))
            {
                m_SerieGrid.context.endLabelList.Add(m_EndLabel);
            }

            var visualMap = chart.GetVisualMapOfSerie(serie);
            var dataZoom  = chart.GetDataZoomOfAxis(axis);
            var showData  = serie.GetDataList(dataZoom);

            if (showData.Count <= 0)
            {
                return;
            }

            var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width;
            var scaleWid   = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);

            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
                           showData.Count;
            int rate         = LineHelper.GetDataAverageRate(serie, m_SerieGrid, maxCount, false);
            var totalAverage = serie.sampleAverage > 0 ?
                               serie.sampleAverage :
                               DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
            var dataChanging       = false;
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();

            var interacting = false;
            var lineWidth   = LineHelper.GetLineWidth(ref interacting, serie, chart.theme.serie.lineWidth);

            axis.context.scaleWidth    = scaleWid;
            serie.containerIndex       = m_SerieGrid.index;
            serie.containterInstanceId = m_SerieGrid.instanceId;

            Serie lastSerie = null;
            var   isStack   = SeriesHelper.IsStack <Line>(chart.series, serie.stack);

            if (isStack)
            {
                lastSerie = SeriesHelper.GetLastStackSerie(chart.series, serie);
                SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData);
            }
            var lp = Vector3.zero;

            for (int i = serie.minShow; i < maxCount; i += rate)
            {
                var serieData = showData[i];
                var isIgnore  = serie.IsIgnoreValue(serieData);
                if (isIgnore)
                {
                    serieData.context.stackHeight = 0;
                    serieData.context.position    = Vector3.zero;
                    if (serie.ignoreLineBreak && serie.context.dataIgnores.Count > 0)
                    {
                        serie.context.dataIgnores[serie.context.dataIgnores.Count - 1] = true;
                    }
                }
                else
                {
                    var np             = Vector3.zero;
                    var xValue         = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse);
                    var relativedValue = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow,
                                                                maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, relativedAxis);

                    serieData.context.stackHeight = GetDataPoint(isY, axis, relativedAxis, m_SerieGrid, xValue, relativedValue,
                                                                 i, scaleWid, isStack, ref np);
                    serieData.context.isClip = false;
                    if (serie.clip && !m_SerieGrid.Contains(np))
                    {
                        if (m_SerieGrid.BoundaryPoint(lp, np, ref np))
                        {
                            serieData.context.isClip = true;
                        }
                    }
                    serie.context.dataIgnores.Add(false);
                    serieData.context.position = np;
                    serie.context.dataPoints.Add(np);
                    lp = np;
                }
            }

            if (dataChanging || interacting)
            {
                chart.RefreshPainter(serie);
            }

            if (serie.context.dataPoints.Count <= 0)
            {
                return;
            }

            serie.animation.InitProgress(serie.context.dataPoints, isY);

            VisualMapHelper.AutoSetLineMinMax(visualMap, serie, isY, axis, relativedAxis);
            LineHelper.UpdateSerieDrawPoints(serie, chart.settings, chart.theme, visualMap, lineWidth, isY);
            LineHelper.DrawSerieLineArea(vh, serie, lastSerie, chart.theme, visualMap, isY, axis, relativedAxis, m_SerieGrid);
            LineHelper.DrawSerieLine(vh, chart.theme, serie, visualMap, m_SerieGrid, axis, relativedAxis, lineWidth);

            serie.context.vertCount = vh.currentVertCount;

            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress();
                serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize));
                chart.RefreshPainter(serie);
            }
        }
예제 #13
0
        private void DrawLinePoint(VertexHelper vh, Serie serie)
        {
            if (!serie.show || serie.IsPerformanceMode())
            {
                return;
            }

            if (m_SerieGrid == null)
            {
                return;
            }

            var count               = serie.context.dataPoints.Count;
            var clip                = SeriesHelper.IsAnyClipSerie(chart.series);
            var theme               = chart.theme;
            var interacting         = false;
            var lineArrow           = serie.lineArrow;
            var visualMap           = chart.GetVisualMapOfSerie(serie);
            var isVisualMapGradient = VisualMapHelper.IsNeedLineGradient(visualMap);

            Axis axis;
            Axis relativedAxis;
            var  isY = chart.GetSerieGridCoordAxis(serie, out axis, out relativedAxis);

            for (int i = 0; i < count; i++)
            {
                var serieData = serie.GetSerieData(i);
                if (serieData == null)
                {
                    continue;
                }
                if (serieData.context.isClip)
                {
                    continue;
                }

                var symbol = SerieHelper.GetSerieSymbol(serie, serieData);

                if (!symbol.show || !symbol.ShowSymbol(i, count))
                {
                    continue;
                }

                var pos = serie.context.dataPoints[i];
                if (lineArrow != null && lineArrow.show)
                {
                    if (lineArrow.position == LineArrow.Position.Start && i == 0)
                    {
                        continue;
                    }
                    if (lineArrow.position == LineArrow.Position.End && i == count - 1)
                    {
                        continue;
                    }
                }

                if (ChartHelper.IsIngore(pos))
                {
                    continue;
                }

                var highlight  = serie.data[i].context.highlight || serie.highlight;
                var symbolSize = highlight ?
                                 theme.serie.lineSymbolSelectedSize :
                                 theme.serie.lineSymbolSize;
                if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
                {
                    symbolSize = highlight ?
                                 symbol.GetSelectedSize(serieData.data, symbolSize) :
                                 symbol.GetSize(serieData.data, symbolSize);
                    serieData.interact.SetValue(ref interacting, symbolSize);
                    symbolSize = serie.animation.GetSysmbolSize(symbolSize);
                }
                var symbolColor      = SerieHelper.GetItemColor(serie, serieData, theme, serie.index, highlight);
                var symbolToColor    = SerieHelper.GetItemToColor(serie, serieData, theme, serie.index, highlight);
                var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, theme, serie.index, highlight, false);

                if (isVisualMapGradient)
                {
                    symbolColor   = VisualMapHelper.GetLineGradientColor(visualMap, pos, m_SerieGrid, axis, relativedAxis, symbolColor);
                    symbolToColor = symbolColor;
                }
                var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, highlight);
                var borderColor  = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, highlight);
                var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
                chart.DrawClipSymbol(vh, symbol.type, symbolSize, symbolBorder, pos,
                                     symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, clip, cornerRadius, m_SerieGrid,
                                     i > 0 ? serie.context.dataPoints[i - 1] : m_SerieGrid.context.position);
            }
            if (interacting)
            {
                if (SeriesHelper.IsStack(chart.series))
                {
                    chart.RefreshTopPainter();
                }
                else
                {
                    chart.RefreshPainter(serie);
                }
            }
        }
예제 #14
0
        private void DrawBarSerie(VertexHelper vh, Bar serie, int colorIndex)
        {
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }

            Axis axis;
            Axis relativedAxis;
            var  isY = chart.GetSerieGridCoordAxis(serie, out axis, out relativedAxis);

            m_SerieGrid = chart.GetChartComponent <GridCoord>(axis.gridIndex);

            if (axis == null)
            {
                return;
            }
            if (relativedAxis == null)
            {
                return;
            }
            if (m_SerieGrid == null)
            {
                return;
            }
            var dataZoom = chart.GetDataZoomOfAxis(axis);
            var showData = serie.GetDataList(dataZoom);

            if (showData.Count <= 0)
            {
                return;
            }

            var axisLength          = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width;
            var relativedAxisLength = isY ? m_SerieGrid.context.width : m_SerieGrid.context.height;
            var axisXY = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x;

            var isStack = SeriesHelper.IsStack <Bar>(chart.series, serie.stack);

            if (isStack)
            {
                SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData);
            }

            var   barCount       = chart.GetSerieBarRealCount <Bar>();
            float categoryWidth  = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
            float barGap         = chart.GetSerieBarGap <Bar>();
            float totalBarWidth  = chart.GetSerieTotalWidth <Bar>(categoryWidth, barGap, barCount);
            float barWidth       = serie.GetBarWidth(categoryWidth, barCount);
            float offset         = (categoryWidth - totalBarWidth) * 0.5f;
            var   serieReadIndex = chart.GetSerieIndexIfStack <Bar>(serie);
            float gap            = serie.barGap == -1 ? offset : offset + chart.GetSerieTotalGap <Bar>(categoryWidth, barGap, serieReadIndex);
            int   maxCount       = serie.maxShow > 0 ?
                                   (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
                                   showData.Count;
            var    isPercentStack     = SeriesHelper.IsPercentStack <Bar>(chart.series, serie.stack);
            bool   dataChanging       = false;
            float  dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            double yMinValue          = relativedAxis.context.minValue;
            double yMaxValue          = relativedAxis.context.maxValue;

            var areaColor   = ColorUtil.clearColor32;
            var areaToColor = ColorUtil.clearColor32;
            var interacting = false;

            serie.containerIndex       = m_SerieGrid.index;
            serie.containterInstanceId = m_SerieGrid.instanceId;
            serie.animation.InitProgress(axisXY, axisXY + axisLength);
            for (int i = serie.minShow; i < maxCount; i++)
            {
                var serieData = showData[i];
                serieData.index = i;
                if (!serieData.show || serie.IsIgnoreValue(serieData))
                {
                    serie.context.dataPoints.Add(Vector3.zero);
                    continue;
                }

                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }

                var highlight         = serieData.context.highlight || serie.highlight;
                var itemStyle         = SerieHelper.GetItemStyle(serie, serieData, highlight);
                var value             = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse);
                var relativedValue    = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue);
                var borderWidth       = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth;
                var borderGap         = relativedValue == 0 ? 0 : itemStyle.borderGap;
                var borderGapAndWidth = borderWidth + borderGap;

                if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting))
                {
                    areaColor   = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, highlight);
                    areaToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, highlight);
                    serieData.interact.SetColor(ref interacting, areaColor, areaToColor);
                }

                var pX = 0f;
                var pY = 0f;
                UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, barWidth, isStack, value, ref pX, ref pY);
                var barHig = 0f;
                if (isPercentStack)
                {
                    var valueTotal = chart.GetSerieSameStackTotalValue <Bar>(serie.stack, i);
                    barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * relativedAxisLength) : 0;
                }
                else
                {
                    barHig = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, categoryWidth, relativedValue);
                }

                float   currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);
                Vector3 plb, plt, prt, prb, top;
                UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, gap, borderWidth, barWidth, currHig,
                                   out plb, out plt, out prt, out prb, out top);
                serieData.context.stackHeight = barHig;
                serieData.context.position    = top;
                serieData.context.rect        = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth,
                                                                prt.x - borderGapAndWidth, prt.y - borderGapAndWidth);
                serieData.context.backgroundRect = isY ?
                                                   Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y) :
                                                   Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength);

                if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top)))
                {
                    serie.context.dataPoints.Add(top);
                }
                else
                {
                    continue;
                }

                if (serie.show && currHig != 0 && !serie.placeHolder)
                {
                    switch (serie.barType)
                    {
                    case BarType.Normal:
                    case BarType.Capsule:
                        DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth,
                                      pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor, relativedValue);
                        break;

                    case BarType.Zebra:
                        DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth,
                                     pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor);
                        break;
                    }
                }
                if (serie.animation.CheckDetailBreak(top, isY))
                {
                    break;
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress();
                chart.RefreshPainter(serie);
            }
            if (dataChanging || interacting)
            {
                chart.RefreshPainter(serie);
            }
        }