Example #1
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);

            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    = coordinateX + i * categoryWidth;
                float zeroY = 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 * 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 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 (!m_Series.IsStack(serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }
Example #2
0
 public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
 {
     return(serie.show && serieData.canShowLabel && !serie.IsIgnoreValue(serieData.GetData(dimesion)));
 }
        protected void DrawCandlestickSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var   showData      = serie.GetDataList(dataZoom);
            var   yAxis         = m_YAxes[serie.yAxisIndex];
            var   xAxis         = m_XAxes[serie.xAxisIndex];
            var   grid          = GetSerieGridOrDefault(serie);
            float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float space         = (categoryWidth - barWidth) / 2;
            int   maxCount      = serie.maxShow > 0
                ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            bool  dataChanging       = false;
            float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            float yMinValue          = yAxis.GetCurrMinValue(dataChangeDuration);
            float yMaxValue          = yAxis.GetCurrMaxValue(dataChangeDuration);
            var   isAllBarEnd        = true;
            var   isYAxis            = false;

            for (int i = serie.minShow; i < maxCount; i++)
            {
                var serieData = showData[i];
                if (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);
                var open        = serieData.GetCurrData(0, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
                var close       = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
                var lowest      = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
                var heighest    = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
                var isRise      = close > open;
                var borderWidth = open == 0 ? 0f
                    : (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth
                    : 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  pY         = zeroY;
                var    barHig     = 0f;
                double valueTotal = yMaxValue - yMinValue;
                var    minCut     = (yMinValue > 0 ? yMinValue : 0);
                if (valueTotal != 0)
                {
                    barHig = (float)((close - open) / valueTotal * grid.runtimeHeight);
                    pY    += (float)((open - minCut) / 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;

                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);
                var areaColor = isRise
                    ? itemStyle.GetColor(m_Theme.serie.candlestickColor)
                    : itemStyle.GetColor0(m_Theme.serie.candlestickColor0);
                var borderColor = isRise
                    ? itemStyle.GetBorderColor(m_Theme.serie.candlestickBorderColor)
                    : itemStyle.GetBorderColor0(m_Theme.serie.candlestickBorderColor0);
                var itemWidth      = Mathf.Abs(prt.x - plb.x);
                var itemHeight     = Mathf.Abs(plt.y - prb.y);
                var center         = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
                var lowPos         = new Vector3(center.x, zeroY + (float)((lowest - minCut) / valueTotal * grid.runtimeHeight));
                var heighPos       = new Vector3(center.x, zeroY + (float)((heighest - minCut) / valueTotal * grid.runtimeHeight));
                var openCenterPos  = new Vector3(center.x, prb.y);
                var closeCenterPos = new Vector3(center.x, prt.y);
                if (barWidth > 2f * borderWidth)
                {
                    if (itemWidth > 0 && itemHeight > 0)
                    {
                        if (ItemStyleHelper.IsNeedCorner(itemStyle))
                        {
                            UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0,
                                                   itemStyle.cornerRadius, isYAxis, 0.5f);
                        }
                        else
                        {
                            Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaColor,
                                                             serie.clip, grid);
                        }
                        UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0,
                                       itemStyle.cornerRadius, isYAxis, 0.5f);
                    }
                }
                else
                {
                    UGL.DrawLine(vh, openCenterPos, closeCenterPos, Mathf.Max(borderWidth, barWidth / 2), borderColor);
                }
                if (isRise)
                {
                    UGL.DrawLine(vh, openCenterPos, lowPos, borderWidth, borderColor);
                    UGL.DrawLine(vh, closeCenterPos, heighPos, borderWidth, borderColor);
                }
                else
                {
                    UGL.DrawLine(vh, closeCenterPos, lowPos, borderWidth, borderColor);
                    UGL.DrawLine(vh, openCenterPos, heighPos, borderWidth, borderColor);
                }
            }
            if (isAllBarEnd)
            {
                serie.animation.AllBarEnd();
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
Example #4
0
        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        = 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;
            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))
                {
                    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 = Internal_GetBarSameStackTotalValue(serie.stack, i, SerieType.Bar);
                    barHig     = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0;
                }
                else
                {
                    if (yAxis.IsLog())
                    {
                        int   minIndex = xAxis.runtimeMinLogIndex;
                        float nowIndex = xAxis.GetLogValue(value);
                        barHig = (nowIndex - minIndex) / xAxis.splitNumber * grid.runtimeWidth;
                    }
                    else
                    {
                        valueTotal = xMaxValue - xMinValue;
                        if (valueTotal != 0)
                        {
                            barHig = (xMinValue > 0 ? value - xMinValue : value)
                                     / valueTotal * grid.runtimeWidth;
                        }
                    }
                }
                serieData.runtimeStackHig = barHig;
                var   isBarEnd = false;
                float currHig  = Internal_CheckBarAnimation(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);
            }
        }