Ejemplo n.º 1
0
        protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
        {
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);

            if (!serieLabel.show)
            {
                return;
            }
            var invert = serie.type == SerieType.Line &&
                         SerieHelper.IsDownPoint(serie, serieData.index) &&
                         !serie.areaStyle.show;
            var centerPos    = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
            var labelHalfWid = serieData.labelObject.GetLabelWidth() / 2;
            var labelHalfHig = serieData.GetLabelHeight() / 2;
            var p1           = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
            var p2           = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
            var p3           = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
            var p4           = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);

            if (serieLabel.rotate > 0)
            {
                p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
                p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
                p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
                p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
            }

            ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);

            if (serieLabel.border)
            {
                ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
                                       serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
            }
        }
        private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                   bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
                                   Vector3 prb, bool isYAxis)
        {
            Color areaColor   = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
            Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);

            DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
            var borderWidth = itemStyle.runtimeBorderWidth;

            if (isYAxis)
            {
                CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip);
                if (borderWidth > 0)
                {
                    var borderColor = itemStyle.borderColor;
                    var itemWidth   = Mathf.Abs(prb.x - plt.x);
                    var itemHeight  = Mathf.Abs(prt.y - plb.y);
                    var center      = new Vector3((plt.x + prb.x) / 2, (prt.y + plb.y) / 2);
                    ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
                }
            }
            else
            {
                CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, serie.clip);
                if (borderWidth > 0)
                {
                    var borderColor = itemStyle.borderColor;
                    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);
                    ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
                }
            }
        }
Ejemplo n.º 3
0
        protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
        {
            var labelHalfWid = serieData.GetLabelWidth() / 2;
            var labelHalfHig = serieData.GetLabelHeight() / 2;
            var serieLabel   = serieData.GetSerieLabel(serie.label);
            var centerPos    = serieData.labelPosition + serieLabel.offset;
            var p1           = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
            var p2           = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
            var p3           = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
            var p4           = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);

            if (serieLabel.rotate > 0)
            {
                p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
                p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
                p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
                p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
            }

            ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);

            if (serieLabel.border)
            {
                ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
                                       serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
            }
        }
Ejemplo n.º 4
0
        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();

            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.data[dimension];
                    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.xValues[0] && j == (int)m_Tooltip.yValues[0]) ||
                                   m_VisualMap.rtSelectedIndex > 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);
                RefreshChart();
            }
        }
Ejemplo n.º 5
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);
                var   borderWidth = itemStyle.runtimeBorderWidth;
                float value       = serieData.GetCurrData(1, dataChangeDuration);
                if (serieData.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);

                if (serie.show)
                {
                    Color areaColor   = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
                    Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
                    DrawBarBackground(vh, serie, serieData, colorIndex, highlight, pX, pY, space, barWidth, false);
                    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 = 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;
            }
        }
Ejemplo n.º 6
0
        protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var yAxis  = m_YAxises[serie.axisIndex];
            var xAxis  = m_XAxises[serie.axisIndex];
            var xCount = xAxis.data.Count;
            var yCount = yAxis.data.Count;
            var xWidth = m_CoordinateWidth / xCount;
            var yWidth = m_CoordinateHeight / yCount;

            var zeroX       = m_CoordinateX;
            var zeroY       = m_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 : 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(m_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 (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 && !ChartHelper.IsClearColor(borderColor))
                    {
                        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 : ChartConst.clearColor32;
                        ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(xCount);
                m_IsPlayingAnimation = true;
                RefreshChart();
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }