protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var   xAxis         = m_XAxes[serie.xAxisIndex];
            var   yAxis         = m_YAxes[serie.yAxisIndex];
            var   grid          = GetSerieGridOrDefault(serie);
            var   showData      = serie.GetDataList(dataZoom);
            float categoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + GetBarIndex(serie) * barGapWidth;
            var   isStack       = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar);

            m_StackSerieData.Clear();
            if (isStack)
            {
                SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData);
            }

            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;
            var   isPercentStack     = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
            bool  dataChanging       = false;
            float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            float xMinValue          = xAxis.GetCurrMinValue(dataChangeDuration);
            float xMaxValue          = xAxis.GetCurrMaxValue(dataChangeDuration);
            var   isAllBarEnd        = true;

            for (int i = serie.minShow; i < maxCount; i++)
            {
                var serieData = showData[i];
                if (serie.IsIgnoreValue(serieData.GetData(1)))
                {
                    serie.dataPoints.Add(Vector3.zero);
                    continue;
                }
                var highlight = (tooltip.show && tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);

                serieData.canShowLabel = true;
                float value       = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue);
                float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
                if (showData[i].IsDataChanged())
                {
                    dataChanging = true;
                }
                float axisLineWidth = value == 0 ? 0
                    : ((value < 0 ? -1 : 1) * yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth));

                float pY = grid.runtimeY + i * categoryWidth;
                if (!yAxis.boundaryGap)
                {
                    pY -= categoryWidth / 2;
                }
                float pX = grid.runtimeX + xAxis.runtimeZeroXOffset + axisLineWidth;
                if (isStack)
                {
                    for (int n = 0; n < m_StackSerieData.Count - 1; n++)
                    {
                        pX += m_StackSerieData[n][i].runtimeStackHig;
                    }
                }

                var barHig     = 0f;
                var valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal = GetSameStackTotalValue(serie.stack, i);
                    barHig     = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0;
                }
                else
                {
                    valueTotal = xMaxValue - xMinValue;
                    if (valueTotal != 0)
                    {
                        barHig = (xMinValue > 0 ? value - xMinValue : value)
                                 / valueTotal * grid.runtimeWidth;
                    }
                }
                serieData.runtimeStackHig = barHig;
                var   isBarEnd = false;
                float currHig  = CheckAnimation(serie, i, barHig, out isBarEnd);
                if (!isBarEnd)
                {
                    isAllBarEnd = false;
                }
                Vector3 plt, prt, prb, plb, top;
                if (value < 0)
                {
                    plt = new Vector3(pX - borderWidth, pY + space + barWidth - borderWidth);
                    prt = new Vector3(pX + currHig + borderWidth, pY + space + barWidth - borderWidth);
                    prb = new Vector3(pX + currHig + borderWidth, pY + space + borderWidth);
                    plb = new Vector3(pX - borderWidth, pY + space + borderWidth);
                }
                else
                {
                    plt = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth);
                    prt = new Vector3(pX + currHig - borderWidth, pY + space + barWidth - borderWidth);
                    prb = new Vector3(pX + currHig - borderWidth, pY + space + borderWidth);
                    plb = new Vector3(pX + borderWidth, pY + space + borderWidth);
                }
                top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2);
                plt = ClampInGrid(grid, plt);
                prt = ClampInGrid(grid, prt);
                prb = ClampInGrid(grid, prb);
                plb = ClampInGrid(grid, plb);
                top = ClampInGrid(grid, top);
                serie.dataPoints.Add(top);
                if (serie.show)
                {
                    switch (serie.barType)
                    {
                    case BarType.Normal:
                        DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                      pX, pY, plb, plt, prt, prb, true, grid);
                        break;

                    case BarType.Zebra:
                        DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                     pX, pY, plb, plt, prt, prb, true, grid);
                        break;

                    case BarType.Capsule:
                        DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                       pX, pY, plb, plt, prt, prb, true, grid);
                        break;
                    }
                }
            }
            if (isAllBarEnd)
            {
                serie.animation.AllBarEnd();
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
        protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            var yAxis = m_YAxises[serie.axisIndex];
            var xAxis = m_XAxises[serie.axisIndex];
            var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);

            color.a *= serie.symbol.opacity;
            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
                : serie.dataCount;

            serie.animation.InitProgress(1, 0, 1);
            var rate           = serie.animation.GetCurrRate();
            var updateDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging   = false;

            for (int n = serie.minShow; n < maxCount; n++)
            {
                var   serieData = serie.GetDataList(m_DataZoom)[n];
                float xValue    = serieData.GetCurrData(0, updateDuration);
                float yValue    = serieData.GetCurrData(1, updateDuration);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX       = coordinateX + xAxis.axisLine.width;
                float pY       = coordinateY + yAxis.axisLine.width;
                float xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
                float yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
                var   pos      = new Vector3(pX + xDataHig, pY + yDataHig);

                var   datas      = serie.data[n].data;
                float symbolSize = 0;
                if (serie.highlighted || serieData.highlighted)
                {
                    symbolSize = serie.symbol.GetSelectedSize(datas);
                }
                else
                {
                    symbolSize = serie.symbol.GetSize(datas);
                }
                symbolSize *= rate;
                if (symbolSize > 100)
                {
                    symbolSize = 100;
                }
                if (serie.type == SerieType.EffectScatter)
                {
                    for (int count = 0; count < serie.symbol.animationSize.Count; count++)
                    {
                        var nowSize = serie.symbol.animationSize[count];
                        color.a = (symbolSize - nowSize) / symbolSize;
                        DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color);
                    }
                    RefreshChart();
                }
                else
                {
                    DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
                }
            }
            if (!serie.animation.IsFinish())
            {
                float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
                float speed    = 1 / duration;
                serie.animation.CheckProgress(Time.deltaTime * speed);
                m_IsPlayingStartAnimation = true;
                RefreshChart();
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }
Ejemplo n.º 3
0
        protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            if (!serie.show)
            {
                return;
            }
            var yAxis    = m_YAxises[serie.axisIndex];
            var xAxis    = m_XAxises[serie.axisIndex];
            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
                : serie.dataCount;

            serie.animation.InitProgress(1, 0, 1);
            var rate = serie.animation.GetCurrRate();
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging       = false;

            for (int n = serie.minShow; n < maxCount; n++)
            {
                var serieData = serie.GetDataList(m_DataZoom)[n];
                var symbol    = SerieHelper.GetSerieSymbol(serie, serieData);
                if (!symbol.ShowSymbol(n, maxCount))
                {
                    continue;
                }
                var   highlight    = serie.highlighted || serieData.highlighted;
                var   color        = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
                var   toColor      = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
                var   symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight);
                var   cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
                float xValue       = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
                float yValue       = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX       = m_CoordinateX + xAxis.axisLine.width;
                float pY       = m_CoordinateY + yAxis.axisLine.width;
                float xDataHig = GetDataHig(xAxis, xValue, m_CoordinateWidth);
                float yDataHig = GetDataHig(yAxis, yValue, m_CoordinateHeight);
                var   pos      = new Vector3(pX + xDataHig, pY + yDataHig);
                serie.dataPoints.Add(pos);
                serieData.runtimePosition = pos;
                var   datas      = serie.data[n].data;
                float symbolSize = 0;
                if (serie.highlighted || serieData.highlighted)
                {
                    symbolSize = symbol.GetSelectedSize(datas);
                }
                else
                {
                    symbolSize = symbol.GetSize(datas);
                }
                symbolSize *= rate;
                if (symbolSize > 100)
                {
                    symbolSize = 100;
                }
                if (serie.type == SerieType.EffectScatter)
                {
                    for (int count = 0; count < symbol.animationSize.Count; count++)
                    {
                        var nowSize = symbol.animationSize[count];
                        color.a = (symbolSize - nowSize) / symbolSize;
                        DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
                    }
                    RefreshChart();
                }
                else
                {
                    DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(1);
                m_IsPlayingAnimation = true;
                RefreshChart();
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }
        protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            var yAxis  = m_YAxises[serie.axisIndex];
            var xAxis  = m_XAxises[serie.axisIndex];
            var xCount = xAxis.data.Count;
            var yCount = yAxis.data.Count;
            var xWidth = coordinateWidth / xCount;
            var yWidth = coordinateHeight / yCount;

            var zeroX       = coordinateX;
            var zeroY       = coordinateY;
            var dataList    = serie.GetDataList();
            var rangeMin    = m_VisualMap.rangeMin;
            var rangeMax    = m_VisualMap.rangeMax;
            var color       = m_ThemeInfo.GetColor(serie.index);
            var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
            var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : Color.clear;

            borderColor.a *= serie.itemStyle.opacity;
            serie.dataPoints.Clear();
            serie.animation.InitProgress(1, 0, xCount);
            var animationIndex = serie.animation.GetCurrIndex();
            var updateDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging   = false;

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var dataIndex = i * yCount + j;
                    if (dataIndex >= dataList.Count)
                    {
                        continue;
                    }
                    var serieData = dataList[dataIndex];
                    var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
                                    serieData.data.Count - 1;
                    var value = serieData.GetCurrData(dimension, updateDuration);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
                    serie.dataPoints.Add(pos);
                    serieData.canShowLabel = false;
                    if (value == 0)
                    {
                        continue;
                    }
                    if (m_VisualMap.enable)
                    {
                        if ((value < rangeMin && rangeMin != m_VisualMap.min) ||
                            (value > rangeMax && rangeMax != m_VisualMap.max))
                        {
                            continue;
                        }
                        if (!m_VisualMap.IsInSelectedValue(value))
                        {
                            continue;
                        }
                        color = m_VisualMap.GetColor(value);
                    }
                    if (animationIndex >= 0 && i > animationIndex)
                    {
                        continue;
                    }
                    serieData.canShowLabel = true;
                    var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.runtimeXValues[0] && j == (int)m_Tooltip.runtimeYValues[0]) ||
                                   m_VisualMap.runtimeSelectedIndex > 0;
                    var rectWid = xWidth - 2 * borderWidth;
                    var rectHig = yWidth - 2 * borderWidth;
                    ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color);
                    if (borderWidth > 0 && borderColor != Color.clear)
                    {
                        ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
                    }
                    if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
                    {
                        var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
                        var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : Color.clear;
                        ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
                float speed    = xCount / duration;
                serie.animation.CheckProgress(Time.deltaTime * speed);
                m_IsPlayingStartAnimation = true;
                RefreshChart();
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }
        protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            var showData = serie.GetDataList(m_DataZoom);
            var yAxis    = m_YAxises[serie.axisIndex];
            var xAxis    = m_XAxises[serie.axisIndex];

            if (!xAxis.show)
            {
                xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
            }
            float categoryWidth = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
            int   maxCount      = serie.maxShow > 0 ?
                                  (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            if (seriesHig.Count < serie.minShow)
            {
                for (int i = 0; i < serie.minShow; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = serie.minShow; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value = showData[i].data[1];
                float pX    = coordinateX + i * categoryWidth;
                float zeroY = coordinateY + yAxis.zeroYOffset;
                if (!xAxis.boundaryGap)
                {
                    pX -= categoryWidth / 2;
                }
                float pY     = seriesHig[i] + zeroY + xAxis.axisLine.width;
                float barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value)
                               / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
                seriesHig[i] += barHig;

                float currHig = CheckAnimation(serie, i, barHig);

                Vector3 p1 = new Vector3(pX + space, pY);
                Vector3 p2 = new Vector3(pX + space, pY + currHig);
                Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig);
                Vector3 p4 = new Vector3(pX + space + barWidth, pY);
                serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig));
                var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;

                if (serie.show)
                {
                    Color areaColor   = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
                    Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
                    ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
                }
            }
            if (!m_Series.IsStack(serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }
Ejemplo n.º 6
0
        private void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount,
                                   Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            var xAxis = m_XAxises[serie.axisIndex];
            var yAxis = m_YAxises[serie.axisIndex];

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }

            float categoryWidth = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;

            var showData = serie.GetDataList(m_DataZoom);
            int maxCount = maxShowDataNumber > 0 ?
                           (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
                : showData.Count;

            if (seriesHig.Count < minShowDataNumber)
            {
                for (int i = 0; i < minShowDataNumber; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = minShowDataNumber; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value = showData[i].data[1];
                float pX    = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width;
                float pY    = coordinateY + +i * categoryWidth;
                if (!yAxis.boundaryGap)
                {
                    pY -= categoryWidth / 2;
                }
                float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
                               / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
                seriesHig[i] += barHig;
                Vector3 p1        = new Vector3(pX, pY + space + barWidth);
                Vector3 p2        = new Vector3(pX + barHig, pY + space + barWidth);
                Vector3 p3        = new Vector3(pX + barHig, pY + space);
                Vector3 p4        = new Vector3(pX, pY + space);
                var     highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                    serie.data[i].highlighted ||
                                    serie.highlighted;
                if (serie.show)
                {
                    Color areaColor   = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
                    Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
                    ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, areaColor, areaToColor);
                }
            }
            if (!m_Series.IsStack(serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }
Ejemplo n.º 7
0
        private void DrawYLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref List <float> seriesHig)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            var     showData    = serie.GetDataList(m_DataZoom);
            Vector3 lp          = Vector3.zero;
            Vector3 np          = Vector3.zero;
            Vector3 nnp         = Vector3.zero;
            Color   lineColor   = serie.GetLineColor(m_ThemeInfo, serieIndex, false);
            Color   areaColor   = serie.GetAreaColor(m_ThemeInfo, serieIndex, false);
            Color   areaToColor = serie.GetAreaToColor(m_ThemeInfo, serieIndex, false);
            var     xAxis       = m_XAxises[serie.axisIndex];
            var     yAxis       = m_YAxises[serie.axisIndex];
            var     zeroPos     = new Vector3(coordinateX + xAxis.zeroXOffset, coordinateY);
            var     lastSerie   = m_Series.GetSerie(serieIndex - 1);
            var     isStack     = m_Series.IsStack(serie.stack, SerieType.Line);

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }
            float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
            float startY   = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
            int   maxCount = maxShowDataNumber > 0 ?
                             (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
                : showData.Count;

            if (seriesHig.Count < minShowDataNumber)
            {
                for (int i = 0; i < minShowDataNumber; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = minShowDataNumber; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value   = showData[i].data[1];
                float pY      = startY + i * scaleWid;
                float pX      = seriesHig[i] + coordinateX + yAxis.axisLine.width;
                float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
                np = new Vector3(pX + dataHig, pY);
                serie.dataPoints.Add(np);
                seriesHig[i] += dataHig;
                lp            = np;
            }

            lp = serie.dataPoints[0];
            for (int i = 1; i < serie.dataPoints.Count; i++)
            {
                np = serie.dataPoints[i];
                serie.ClearSmoothList(i);
                switch (serie.lineType)
                {
                case LineType.Normal:
                    nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
                    DrawNormalLine(vh, serieIndex, serie, yAxis, lp, np, nnp, i, lineColor, areaColor, areaToColor, zeroPos);
                    break;

                case LineType.Smooth:
                    DrawSmoothLine(vh, serieIndex, serie, yAxis, lp, np, i, lineColor, areaColor, areaToColor, isStack, zeroPos);
                    break;

                case LineType.StepStart:
                case LineType.StepMiddle:
                case LineType.StepEnd:
                    DrawStepLine(vh, serieIndex, serie, yAxis, lp, np, i, lineColor, areaColor, zeroPos);
                    break;
                }
                lp = np;
            }
        }
Ejemplo n.º 8
0
        protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            var xAxis = m_XAxises[serie.axisIndex];
            var yAxis = m_YAxises[serie.axisIndex];

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }

            var   showData      = serie.GetDataList(m_DataZoom);
            float categoryWidth = yAxis.GetDataWidth(coordinateHeight, showData.Count, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;


            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            if (seriesHig.Count < serie.minShow)
            {
                for (int i = 0; i < serie.minShow; i++)
                {
                    seriesHig.Add(0);
                }
            }
            var   isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
            bool  dataChanging   = false;
            float updateDuration = serie.animation.GetUpdateAnimationDuration();
            float xMinValue      = xAxis.GetCurrMinValue(updateDuration);
            float xMaxValue      = xAxis.GetCurrMaxValue(updateDuration);

            for (int i = serie.minShow; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                var serieData = showData[i];
                serieData.canShowLabel = true;
                float value = showData[i].GetCurrData(1, updateDuration);
                if (showData[i].IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + yAxis.axisLine.width;
                float pY = coordinateY + +i * categoryWidth;
                if (!yAxis.boundaryGap)
                {
                    pY -= categoryWidth / 2;
                }

                var barHig     = 0f;
                var valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal    = GetSameStackTotalValue(serie.stack, i);
                    barHig        = valueTotal != 0 ? (value / valueTotal * coordinateWidth) : 0;
                    seriesHig[i] += barHig;
                }
                else
                {
                    valueTotal = xMaxValue - xMinValue;
                    if (valueTotal != 0)
                    {
                        barHig = (xMinValue > 0 ? value - xMinValue : value)
                                 / valueTotal * coordinateWidth;
                    }
                    seriesHig[i] += barHig;
                }

                float currHig = CheckAnimation(serie, i, barHig);

                Vector3 p1 = new Vector3(pX, pY + space + barWidth);
                Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth);
                Vector3 p3 = new Vector3(pX + currHig, pY + space);
                Vector3 p4 = new Vector3(pX, pY + space);
                serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2));
                var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                if (serie.show)
                {
                    Color areaColor   = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
                    Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
                    if (serie.barType == BarType.Zebra)
                    {
                        p1 = (p4 + p1) / 2;
                        p2 = (p2 + p3) / 2;
                        ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
                    }
                    else
                    {
                        ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
                    }
                }
            }
            if (!m_Series.IsStack(serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }
        protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var yAxis  = m_YAxes[serie.yAxisIndex];
            var xAxis  = m_XAxes[serie.xAxisIndex];
            var grid   = GetSerieGridOrDefault(serie);
            var xCount = xAxis.data.Count;
            var yCount = yAxis.data.Count;
            var xWidth = grid.runtimeWidth / xCount;
            var yWidth = grid.runtimeHeight / yCount;

            var zeroX       = grid.runtimeX;
            var zeroY       = grid.runtimeY;
            var dataList    = serie.GetDataList();
            var rangeMin    = visualMap.rangeMin;
            var rangeMax    = visualMap.rangeMax;
            var color       = m_Theme.GetColor(serie.index);
            var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
            var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;

            borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
            serie.dataPoints.Clear();
            serie.animation.InitProgress(1, 0, xCount);
            var animationIndex     = serie.animation.GetCurrIndex();
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging       = false;

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var dataIndex = i * yCount + j;
                    if (dataIndex >= dataList.Count)
                    {
                        continue;
                    }
                    var serieData = dataList[dataIndex];
                    var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
                    if (serie.IsIgnoreIndex(dataIndex, dimension))
                    {
                        serie.dataPoints.Add(Vector3.zero);
                        continue;
                    }
                    var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
                    serie.dataPoints.Add(pos);
                    serieData.canShowLabel = false;
                    if (value == 0)
                    {
                        continue;
                    }
                    if (visualMap.enable)
                    {
                        if ((value < rangeMin && rangeMin != visualMap.min) ||
                            (value > rangeMax && rangeMax != visualMap.max))
                        {
                            continue;
                        }
                        if (!visualMap.IsInSelectedValue(value))
                        {
                            continue;
                        }
                        color = visualMap.GetColor(value);
                    }
                    if (animationIndex >= 0 && i > animationIndex)
                    {
                        continue;
                    }
                    serieData.canShowLabel = true;
                    var emphasis = (tooltip.show && i == (int)tooltip.runtimeXValues[0] && j == (int)tooltip.runtimeYValues[0]) ||
                                   visualMap.runtimeSelectedIndex > 0;
                    var rectWid = xWidth - 2 * borderWidth;
                    var rectHig = yWidth - 2 * borderWidth;
                    UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
                    if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
                    {
                        UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
                    }
                    if (visualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
                    {
                        var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
                        var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
                        UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(xCount);
                m_IsPlayingAnimation = true;
                RefreshPainter(serie);
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
Ejemplo n.º 10
0
        private void DrawXLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref List <float> seriesHig)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            var showData = serie.GetDataList(m_DataZoom);

            if (showData.Count <= 0)
            {
                return;
            }
            Color   lineColor = serie.GetLineColor(m_ThemeInfo, serieIndex, false);
            Color   areaColor = serie.GetAreaColor(m_ThemeInfo, serieIndex, false);
            Color   areaToColor = serie.GetAreaToColor(m_ThemeInfo, serieIndex, false);
            Vector3 lp = Vector3.zero, np = Vector3.zero, nnp = Vector3.zero;
            var     yAxis     = m_YAxises[serie.axisIndex];
            var     xAxis     = m_XAxises[serie.axisIndex];
            var     zeroPos   = new Vector3(coordinateX, coordinateY + yAxis.zeroYOffset);
            var     lastSerie = m_Series.GetSerie(serie.index - 1);
            var     isStack   = m_Series.IsStack(serie.stack, SerieType.Line);

            if (!xAxis.show)
            {
                xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
            }
            float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
            float startX   = coordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
            int   maxCount = maxShowDataNumber > 0 ?
                             (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
                : showData.Count;

            if (seriesHig.Count < minShowDataNumber)
            {
                for (int i = 0; i < minShowDataNumber; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = minShowDataNumber; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float yValue = showData[i].data[1];
                seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np);
                serie.dataPoints.Add(np);
                lp = np;
            }
            if (serie.dataPoints.Count <= 0)
            {
                return;
            }
            lp = serie.dataPoints[0];
            for (int i = 1; i < serie.dataPoints.Count; i++)
            {
                np = serie.dataPoints[i];
                serie.ClearSmoothList(i);
                switch (serie.lineType)
                {
                case LineType.Normal:
                    nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
                    DrawNormalLine(vh, serieIndex, serie, xAxis, lp, np, nnp, i, lineColor, areaColor, areaToColor, zeroPos);
                    break;

                case LineType.Smooth:
                    DrawSmoothLine(vh, serieIndex, serie, xAxis, lp, np, i, lineColor, areaColor, areaToColor, isStack, zeroPos);
                    break;

                case LineType.StepStart:
                case LineType.StepMiddle:
                case LineType.StepEnd:
                    DrawStepLine(vh, serieIndex, serie, xAxis, lp, np, i, lineColor, areaColor, zeroPos);
                    break;
                }
                lp = np;
            }
        }
Ejemplo n.º 11
0
        protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var showData = serie.GetDataList(m_DataZoom);
            var yAxis    = m_YAxises[serie.axisIndex];
            var xAxis    = m_XAxises[serie.axisIndex];

            if (!xAxis.show)
            {
                xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
            }

            float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
            int   maxCount      = serie.maxShow > 0 ?
                                  (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            if (seriesHig.Count < serie.minShow)
            {
                for (int i = 0; i < serie.minShow; i++)
                {
                    seriesHig.Add(0);
                }
            }

            var   isPercentStack     = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
            bool  dataChanging       = false;
            float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            float yMinValue          = yAxis.GetCurrMinValue(dataChangeDuration);
            float yMaxValue          = yAxis.GetCurrMaxValue(dataChangeDuration);

            for (int i = serie.minShow; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                var serieData = showData[i];
                if (serie.IsIgnoreValue(serieData.GetData(1)))
                {
                    serie.dataPoints.Add(Vector3.zero);
                    continue;
                }
                var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                var   itemStyle   = SerieHelper.GetItemStyle(serie, serieData, highlight);
                float value       = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
                float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX    = m_CoordinateX + i * categoryWidth;
                float zeroY = m_CoordinateY + yAxis.runtimeZeroYOffset;
                if (!xAxis.boundaryGap)
                {
                    pX -= categoryWidth / 2;
                }
                float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.width;
                float pY            = seriesHig[i] + zeroY + axisLineWidth;

                var barHig     = 0f;
                var valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal    = GetSameStackTotalValue(serie.stack, i);
                    barHig        = valueTotal != 0 ? (value / valueTotal * m_CoordinateHeight) : 0;
                    seriesHig[i] += barHig;
                }
                else
                {
                    valueTotal = yMaxValue - yMinValue;
                    if (valueTotal != 0)
                    {
                        barHig = (yMinValue > 0 ? value - yMinValue : value)
                                 / valueTotal * m_CoordinateHeight;
                    }
                    seriesHig[i] += barHig;
                }
                float   currHig = CheckAnimation(serie, i, barHig);
                Vector3 plb, plt, prt, prb, top;
                if (value < 0)
                {
                    plb = new Vector3(pX + space + borderWidth, pY - borderWidth);
                    plt = new Vector3(pX + space + borderWidth, pY + currHig + borderWidth - axisLineWidth);
                    prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig + borderWidth - axisLineWidth);
                    prb = new Vector3(pX + space + barWidth - borderWidth, pY - borderWidth);
                }
                else
                {
                    plb = new Vector3(pX + space + borderWidth, pY + borderWidth);
                    plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth - axisLineWidth);
                    prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth - axisLineWidth);
                    prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth);
                }
                top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
                if (serie.clip)
                {
                    plb = ClampInCoordinate(plb);
                    plt = ClampInCoordinate(plt);
                    prt = ClampInCoordinate(prt);
                    prb = ClampInCoordinate(prb);
                    top = ClampInCoordinate(top);
                }
                serie.dataPoints.Add(top);
                if (serie.show)
                {
                    switch (serie.barType)
                    {
                    case BarType.Normal:
                        DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                      pX, pY, plb, plt, prt, prb, false);
                        break;

                    case BarType.Zebra:
                        DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                     pX, pY, plb, plt, prt, prb, false);
                        break;

                    case BarType.Capsule:
                        DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                       pX, pY, plb, plt, prt, prb, false);
                        break;
                    }
                }
            }
            if (dataChanging)
            {
                RefreshChart();
            }
            if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }
        protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var yAxis    = m_YAxes[serie.yAxisIndex];
            var xAxis    = m_XAxes[serie.xAxisIndex];
            var grid     = GetSerieGridOrDefault(serie);
            var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
            var showData = serie.GetDataList(dataZoom);
            var isStack  = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar);

            m_StackSerieData.Clear();
            if (isStack)
            {
                SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData);
            }
            float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom);
            float barGap        = Internal_GetBarGap(SerieType.Bar);
            float totalBarWidth = Internal_GetBarTotalWidth(categoryWidth, barGap, SerieType.Bar);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + Internal_GetBarIndex(serie, SerieType.Bar) * barGapWidth;
            int   maxCount      = serie.maxShow > 0
                ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            var    isPercentStack     = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
            bool   dataChanging       = false;
            float  dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            double yMinValue          = yAxis.GetCurrMinValue(dataChangeDuration);
            double yMaxValue          = yAxis.GetCurrMaxValue(dataChangeDuration);
            var    isAllBarEnd        = true;

            for (int i = serie.minShow; i < maxCount; i++)
            {
                var serieData = showData[i];
                if (!serieData.show || serie.IsIgnoreValue(serieData))
                {
                    serie.dataPoints.Add(Vector3.zero);
                    continue;
                }
                var highlight = (tooltip.show && tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                var    itemStyle   = SerieHelper.GetItemStyle(serie, serieData, highlight);
                double value       = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
                float  borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX    = grid.runtimeX + i * categoryWidth;
                float zeroY = grid.runtimeY + yAxis.runtimeZeroYOffset;
                if (!xAxis.boundaryGap)
                {
                    pX -= categoryWidth / 2;
                }
                float axisLineWidth = value == 0 ? 0 :
                                      ((value < 0 ? -1 : 1) * xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth));
                float pY = zeroY + axisLineWidth;
                if (isStack)
                {
                    for (int n = 0; n < m_StackSerieData.Count - 1; n++)
                    {
                        pY += m_StackSerieData[n][i].runtimeStackHig;
                    }
                }

                var    barHig     = 0f;
                double valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal = Internal_GetBarSameStackTotalValue(serie.stack, i, SerieType.Bar);
                    barHig     = valueTotal != 0 ? (float)(value / valueTotal * grid.runtimeHeight) : 0;
                }
                else
                {
                    valueTotal = (double)(yMaxValue - yMinValue);
                    if (valueTotal != 0)
                    {
                        if (yAxis.IsLog())
                        {
                            int minIndex = yAxis.runtimeMinLogIndex;
                            var nowIndex = yAxis.GetLogValue(value);
                            barHig = (nowIndex - minIndex) / yAxis.splitNumber * grid.runtimeHeight;
                        }
                        else
                        {
                            barHig = (float)((yMinValue > 0 ? value - yMinValue : value) / valueTotal * grid.runtimeHeight);
                        }
                    }
                }
                serieData.runtimeStackHig = barHig;
                var   isBarEnd = false;
                float currHig  = Internal_CheckBarAnimation(serie, i, barHig, out isBarEnd);
                if (!isBarEnd)
                {
                    isAllBarEnd = false;
                }
                Vector3 plb, plt, prt, prb, top;
                if (value < 0)
                {
                    plb = new Vector3(pX + space + borderWidth, pY - borderWidth);
                    plt = new Vector3(pX + space + borderWidth, pY + currHig + borderWidth);
                    prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig + borderWidth);
                    prb = new Vector3(pX + space + barWidth - borderWidth, pY - borderWidth);
                }
                else
                {
                    plb = new Vector3(pX + space + borderWidth, pY + borderWidth);
                    plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth);
                    prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth);
                    prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth);
                }
                top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
                if (serie.clip)
                {
                    plb = ClampInGrid(grid, plb);
                    plt = ClampInGrid(grid, plt);
                    prt = ClampInGrid(grid, prt);
                    prb = ClampInGrid(grid, prb);
                    top = ClampInGrid(grid, top);
                }
                serie.dataPoints.Add(top);
                if (serie.show && currHig != 0)
                {
                    switch (serie.barType)
                    {
                    case BarType.Normal:
                        DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                      pX, pY, plb, plt, prt, prb, false, grid);
                        break;

                    case BarType.Zebra:
                        DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                     pX, pY, plb, plt, prt, prb, false, grid);
                        break;

                    case BarType.Capsule:
                        DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                       pX, pY, plb, plt, prt, prb, false, grid);
                        break;
                    }
                }
            }
            if (isAllBarEnd)
            {
                serie.animation.AllBarEnd();
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
Ejemplo n.º 13
0
        private void DrawYLineSerie(VertexHelper vh, int serieIndex, Color lineColor, Serie serie, ref List <float> seriesHig)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            var     showData  = serie.GetDataList(m_DataZoom);
            Vector3 lp        = Vector3.zero;
            Vector3 np        = Vector3.zero;
            Color   areaColor = new Color(lineColor.r, lineColor.g, lineColor.b, lineColor.a * 0.75f);
            var     xAxis     = m_XAxises[serie.axisIndex];
            var     yAxis     = m_YAxises[serie.axisIndex];
            var     lastSerie = m_Series.GetSerie(serieIndex - 1);
            var     isStack   = m_Series.IsStack(serie.stack);

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }
            float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
            float startY   = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
            int   maxCount = maxShowDataNumber > 0 ?
                             (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
                : showData.Count;

            if (seriesHig.Count < minShowDataNumber)
            {
                for (int i = 0; i < minShowDataNumber; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = minShowDataNumber; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value   = showData[i].data[1];
                float pY      = startY + i * scaleWid;
                float pX      = seriesHig[i] + coordinateX + yAxis.axisLine.width;
                float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
                np = new Vector3(pX + dataHig, pY);
                if (i > 0)
                {
                    if (m_Line.step)
                    {
                        Vector2 middle1, middle2;
                        switch (m_Line.stepTpe)
                        {
                        case Line.StepType.Start:
                            middle1 = new Vector2(np.x, lp.y);
                            middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
                            ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
                            ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
                            if (m_Line.area)
                            {
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle1.y), middle1, np,
                                                        new Vector2(coordinateX, np.y), areaColor);
                            }
                            break;

                        case Line.StepType.Middle:
                            middle1 = new Vector2(lp.x, (lp.y + np.y) / 2 + m_Line.tickness);
                            middle2 = new Vector2(np.x, (lp.y + np.y) / 2 - m_Line.tickness);
                            ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
                            ChartHelper.DrawLine(vh, new Vector2(middle1.x, middle1.y - m_Line.tickness),
                                                 new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, lineColor);
                            ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
                            if (m_Line.area)
                            {
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), lp, middle1,
                                                        new Vector2(coordinateX, middle1.y), areaColor);
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle2.y + 2 * m_Line.tickness),
                                                        new Vector2(middle2.x, middle2.y + 2 * m_Line.tickness), np,
                                                        new Vector2(coordinateX, np.y), areaColor);
                            }
                            break;

                        case Line.StepType.End:
                            middle1 = new Vector2(np.x, lp.y);
                            middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
                            ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
                            ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
                            if (m_Line.area)
                            {
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), middle1,
                                                        new Vector2(np.x, np.y),
                                                        new Vector2(coordinateX, np.y), areaColor);
                            }
                            break;
                        }
                    }
                    else if (m_Line.smooth)
                    {
                        DrawSmoothAreaPoints(vh, serieIndex, serie, yAxis, lp, np, i, lineColor, areaColor, isStack);
                    }
                    else
                    {
                        ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, lineColor);
                        if (m_Line.area)
                        {
                            Vector3 alp   = new Vector3(lp.x, lp.y);
                            Vector3 anp   = new Vector3(np.x, np.y);
                            var     cross = ChartHelper.GetIntersection(lp, np, new Vector3(coordinateX, coordinateY),
                                                                        new Vector3(coordinateX, coordinateY + coordinateHig));
                            if (cross == Vector3.zero)
                            {
                                Vector3 tnp = serieIndex > 0 ?
                                              new Vector3(lastSerie.dataPoints[i].x + yAxis.axisLine.width, lastSerie.dataPoints[i].y) :
                                              new Vector3(coordinateX + yAxis.axisLine.width, np.y);
                                Vector3 tlp = serieIndex > 0 ?
                                              new Vector3(lastSerie.dataPoints[i - 1].x + yAxis.axisLine.width, lastSerie.dataPoints[i - 1].y) :
                                              new Vector3(coordinateX + yAxis.axisLine.width, lp.y);
                                ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
                            }
                            else
                            {
                                Vector3 cross1 = new Vector3(cross.x + (alp.x > coordinateX ? yAxis.axisLine.width : -yAxis.axisLine.width), cross.y);
                                Vector3 cross2 = new Vector3(cross.x + (anp.x > coordinateX ? yAxis.axisLine.width : -yAxis.axisLine.width), cross.y);
                                Vector3 xp1    = new Vector3(coordinateX + (alp.x > coordinateX ? yAxis.axisLine.width : -yAxis.axisLine.width), alp.y);
                                Vector3 xp2    = new Vector3(coordinateX + (anp.x > coordinateX ? yAxis.axisLine.width : -yAxis.axisLine.width), anp.y);
                                ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
                                ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
                            }
                        }
                    }
                }
                serie.dataPoints.Add(np);
                seriesHig[i] += dataHig;
                lp            = np;
            }
        }
Ejemplo n.º 14
0
        private void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount,
                                   Serie serie, Color color, ref List <float> seriesHig)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            var xAxis = m_XAxises[serie.axisIndex];
            var yAxis = m_YAxises[serie.axisIndex];

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }
            float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
            float barWid   = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
            float offset   = m_Bar.inSameBar ?
                             (scaleWid - barWid - m_Bar.space * (stackCount - 1)) / 2 :
                             (scaleWid - barWid * stackCount - m_Bar.space * (stackCount - 1)) / 2;
            var showData = serie.GetDataList(m_DataZoom);
            int maxCount = maxShowDataNumber > 0 ?
                           (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
                : showData.Count;

            if (seriesHig.Count < minShowDataNumber)
            {
                for (int i = 0; i < minShowDataNumber; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = minShowDataNumber; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value = showData[i].data[1];
                float pX    = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width;
                float pY    = coordinateY + +i * scaleWid;
                if (!yAxis.boundaryGap)
                {
                    pY -= scaleWid / 2;
                }
                float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
                               / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
                float space = m_Bar.inSameBar ? offset :
                              offset + serieIndex * (barWid + m_Bar.space);
                seriesHig[i] += barHig;
                Vector3 p1 = new Vector3(pX, pY + space + barWid);
                Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
                Vector3 p3 = new Vector3(pX + barHig, pY + space);
                Vector3 p4 = new Vector3(pX, pY + space);
                if ((m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                    serie.data[i].highlighted ||
                    serie.highlighted)
                {
                    color *= 1.05f;
                }
                if (serie.show)
                {
                    ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
                }
            }
        }
Ejemplo n.º 15
0
        protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var showData = serie.GetDataList(m_DataZoom);
            var yAxis    = m_YAxises[serie.axisIndex];
            var xAxis    = m_XAxises[serie.axisIndex];

            if (!xAxis.show)
            {
                xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
            }

            float categoryWidth = xAxis.GetDataWidth(coordinateWidth, showData.Count, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
            int   maxCount      = serie.maxShow > 0 ?
                                  (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            if (seriesHig.Count < serie.minShow)
            {
                for (int i = 0; i < serie.minShow; i++)
                {
                    seriesHig.Add(0);
                }
            }

            var   isPercentStack     = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
            bool  dataChanging       = false;
            float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            float yMinValue          = yAxis.GetCurrMinValue(dataChangeDuration);
            float yMaxValue          = yAxis.GetCurrMaxValue(dataChangeDuration);
            float borderWidth        = serie.itemStyle.runtimeBorderWidth;

            for (int i = serie.minShow; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value = showData[i].GetCurrData(1, dataChangeDuration);
                if (showData[i].IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX    = coordinateX + i * categoryWidth;
                float zeroY = coordinateY + yAxis.runtimeZeroYOffset;
                if (!xAxis.boundaryGap)
                {
                    pX -= categoryWidth / 2;
                }
                float pY = seriesHig[i] + zeroY + xAxis.axisLine.width;

                var barHig     = 0f;
                var valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal    = GetSameStackTotalValue(serie.stack, i);
                    barHig        = valueTotal != 0 ? (value / valueTotal * coordinateHeight) : 0;
                    seriesHig[i] += barHig;
                }
                else
                {
                    valueTotal = yMaxValue - yMinValue;
                    if (valueTotal != 0)
                    {
                        barHig = (yMinValue > 0 ? value - yMinValue : value)
                                 / valueTotal * coordinateHeight;
                    }
                    seriesHig[i] += barHig;
                }

                float   currHig = CheckAnimation(serie, i, barHig);
                Vector3 p1      = new Vector3(pX + space + borderWidth, pY + borderWidth);
                Vector3 p2      = new Vector3(pX + space + borderWidth, pY + currHig - 2 * borderWidth);
                Vector3 p3      = new Vector3(pX + space + barWidth, pY + currHig - 2 * borderWidth);
                Vector3 p4      = new Vector3(pX + space + barWidth, pY + borderWidth);
                Vector3 top     = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
                p1  = ClampInCoordinate(p1);
                p2  = ClampInCoordinate(p2);
                p3  = ClampInCoordinate(p3);
                p4  = ClampInCoordinate(p4);
                top = ClampInCoordinate(top);
                serie.dataPoints.Add(top);
                var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                if (serie.show)
                {
                    Color areaColor   = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
                    Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
                    if (serie.barType == BarType.Zebra)
                    {
                        p1 = (p4 + p1) / 2;
                        p2 = (p2 + p3) / 2;
                        CheckClipAndDrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
                                                  areaColor, serie.clip);
                    }
                    else
                    {
                        CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, areaColor, areaToColor, serie.clip);
                        if (borderWidth > 0)
                        {
                            var borderColor = serie.itemStyle.borderColor;
                            var itemWidth   = Mathf.Abs(p3.x - p1.x);
                            var itemHeight  = Mathf.Abs(p2.y - p4.y);
                            var center      = new Vector3((p1.x + p3.x) / 2, (p2.y + p4.y) / 2);
                            ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
                        }
                    }
                }
            }
            if (dataChanging)
            {
                RefreshChart();
            }
            if (!m_Series.IsStack(serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }