Example #1
0
        private void DrawBarSerie(VertexHelper vh, SimplifiedBar 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 axisXY     = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x;

            var   barCount      = chart.GetSerieBarRealCount <SimplifiedBar>();
            float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
            float barGap        = chart.GetSerieBarGap <SimplifiedBar>();
            float totalBarWidth = chart.GetSerieTotalWidth <SimplifiedBar>(categoryWidth, barGap, barCount);
            float barWidth      = serie.GetBarWidth(categoryWidth, barCount);
            float offset        = (categoryWidth - totalBarWidth) * 0.5f;
            float barGapWidth   = barWidth + barWidth * barGap;
            float gap           = serie.barGap == -1 ? offset : offset + serie.index * barGapWidth;
            int   maxCount      = serie.maxShow > 0 ?
                                  (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
                                  showData.Count;

            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];
                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;

                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, value, ref pX, ref pY);

                var barHig  = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, categoryWidth, relativedValue);
                var 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, plb.y, prb.x, prt.y);
                serie.context.dataPoints.Add(top);
                DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth,
                              pX, pY, plb, plt, prt, prb, false, m_SerieGrid, areaColor, areaToColor);

                if (serie.animation.CheckDetailBreak(top, isY))
                {
                    break;
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress();
                chart.RefreshPainter(serie);
            }
            if (dataChanging || interacting)
            {
                chart.RefreshPainter(serie);
            }
        }
        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);
            }
        }