Exemplo n.º 1
0
 public Vector3 ClampInGrid(GridCoord grid, Vector3 pos)
 {
     if (grid.Contains(pos))
     {
         return(pos);
     }
     else
     {
         // var pos = new Vector3(pos.x, pos.y);
         if (pos.x < grid.context.x)
         {
             pos.x = grid.context.x;
         }
         if (pos.x > grid.context.x + grid.context.width)
         {
             pos.x = grid.context.x + grid.context.width;
         }
         if (pos.y < grid.context.y)
         {
             pos.y = grid.context.y;
         }
         if (pos.y > grid.context.y + grid.context.height)
         {
             pos.y = grid.context.y + grid.context.height;
         }
         return(pos);
     }
 }
Exemplo n.º 2
0
        private static void AddLineVertToVertexHelper(VertexHelper vh, Vector3 tp, Vector3 bp,
                                                      Color32 lineColor, bool visualMapGradient, bool lineStyleGradient, VisualMap visualMap,
                                                      LineStyle lineStyle, GridCoord grid, Axis axis, Axis relativedAxis, bool needTriangle,
                                                      bool lastIgnore, bool ignore)
        {
            if (lastIgnore && needTriangle)
            {
                UGL.AddVertToVertexHelper(vh, tp, bp, ColorUtil.clearColor32, true);
            }

            if (visualMapGradient)
            {
                var color1 = VisualMapHelper.GetLineGradientColor(visualMap, tp, grid, axis, relativedAxis, lineColor);
                var color2 = VisualMapHelper.GetLineGradientColor(visualMap, bp, grid, axis, relativedAxis, lineColor);
                UGL.AddVertToVertexHelper(vh, tp, bp, color1, color2, needTriangle);
            }
            else if (lineStyleGradient)
            {
                var color1 = VisualMapHelper.GetLineStyleGradientColor(lineStyle, tp, grid, axis, lineColor);
                var color2 = VisualMapHelper.GetLineStyleGradientColor(lineStyle, bp, grid, axis, lineColor);
                UGL.AddVertToVertexHelper(vh, tp, bp, color1, color2, needTriangle);
            }
            else
            {
                UGL.AddVertToVertexHelper(vh, tp, bp, lineColor, needTriangle);
            }
            if (lastIgnore && !needTriangle)
            {
                UGL.AddVertToVertexHelper(vh, tp, bp, ColorUtil.clearColor32, false);
            }
            if (ignore && needTriangle)
            {
                UGL.AddVertToVertexHelper(vh, tp, bp, ColorUtil.clearColor32, false);
            }
        }
Exemplo n.º 3
0
        private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                   bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
                                   Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor, double value)
        {
            var borderWidth     = itemStyle.runtimeBorderWidth;
            var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false);
            var cornerRadius    = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner() ?
                                  m_CapusleDefaultCornerRadius :
                                  itemStyle.cornerRadius;
            var invert = value < 0;

            if (!ChartHelper.IsClearColor(backgroundColor))
            {
                UGL.DrawRoundRectangle(vh, serieData.context.backgroundRect, backgroundColor, backgroundColor, 0,
                                       cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
            }
            UGL.DrawRoundRectangle(vh, serieData.context.rect, areaColor, areaToColor, 0,
                                   cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
            if (serie.barType == BarType.Capsule)
            {
                UGL.DrawBorder(vh, serieData.context.backgroundRect, borderWidth, itemStyle.borderColor,
                               0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, -borderWidth);
            }
            else
            {
                UGL.DrawBorder(vh, serieData.context.rect, borderWidth, itemStyle.borderColor,
                               0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, itemStyle.borderGap);
            }
        }
        public static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, GridCoord grid, Axis axis,
                                                   Axis relativedAxis, Color32 defaultColor)
        {
            double value = 0;
            double min   = 0;
            double max   = 0;

            if (visualMap.dimension == 0)
            {
                min = axis.context.minValue;
                max = axis.context.maxValue;
                if (axis.IsCategory() && axis.boundaryGap)
                {
                    float startX = grid.context.x + axis.context.scaleWidth / 2;
                    value = (min + (pos.x - startX) / (grid.context.width - axis.context.scaleWidth) * (max - min));
                    if (visualMap.IsPiecewise())
                    {
                        value = (int)value;
                    }
                }
                else
                {
                    value = min + (pos.x - grid.context.x) / grid.context.width * (max - min);
                }
            }
            else
            {
                min = relativedAxis.context.minValue;
                max = relativedAxis.context.maxValue;
                if (relativedAxis.IsCategory() && relativedAxis.boundaryGap)
                {
                    float startY = grid.context.y + relativedAxis.context.scaleWidth / 2;
                    value = (min + (pos.y - startY) / (grid.context.height - relativedAxis.context.scaleWidth) * (max - min));
                    if (visualMap.IsPiecewise())
                    {
                        value = (int)value;
                    }
                }
                else
                {
                    value = min + (pos.y - grid.context.y) / grid.context.height * (max - min);
                }
            }

            var color = visualMap.GetColor(value);

            if (ChartHelper.IsClearColor(color))
            {
                return(defaultColor);
            }
            else
            {
                if (color.a != 0)
                {
                    color.a = defaultColor.a;
                }

                return(color);
            }
        }
 private void DrawMakLineData(VertexHelper vh, MarkLineData data, AnimationStyle animation, Serie serie,
                              GridCoord grid, Color32 serieColor, Vector3 sp, Vector3 ep)
 {
     if (!animation.IsFinish())
     {
         ep = Vector3.Lerp(sp, ep, animation.GetCurrDetail());
     }
     data.runtimeCurrentEndPosition = ep;
     if (sp != Vector3.zero || ep != Vector3.zero)
     {
         m_RefreshLabel = true;
         chart.ClampInChart(ref sp);
         chart.ClampInChart(ref ep);
         var theme     = chart.theme.axis;
         var lineColor = ChartHelper.IsClearColor(data.lineStyle.color) ? serieColor : data.lineStyle.color;
         var lineWidth = data.lineStyle.width == 0 ? theme.lineWidth : data.lineStyle.width;
         ChartDrawer.DrawLineStyle(vh, data.lineStyle, sp, ep, lineWidth, LineStyle.Type.Dashed, lineColor, lineColor);
         if (data.startSymbol != null && data.startSymbol.show)
         {
             DrawMarkLineSymbol(vh, data.startSymbol, serie, grid, chart.theme, sp, sp, lineColor);
         }
         if (data.endSymbol != null && data.endSymbol.show)
         {
             DrawMarkLineSymbol(vh, data.endSymbol, serie, grid, chart.theme, ep, sp, lineColor);
         }
     }
 }
        private float GetDataPoint(bool isY, Axis axis, Axis relativedAxis, GridCoord grid, double xValue,
                                   double yValue, int i, float scaleWid, bool isStack, ref Vector3 np)
        {
            float xPos, yPos;
            var   gridXY = isY ? grid.context.x : grid.context.y;

            if (isY)
            {
                var valueHig = AxisHelper.GetAxisValueDistance(grid, relativedAxis, scaleWid, yValue);
                valueHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, valueHig);

                xPos = gridXY + valueHig;
                yPos = AxisHelper.GetAxisValuePosition(grid, axis, scaleWid, xValue);
            }
            else
            {
                var valueHig = AxisHelper.GetAxisValueDistance(grid, relativedAxis, scaleWid, yValue);
                valueHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, valueHig);

                yPos = gridXY + valueHig;
                xPos = AxisHelper.GetAxisValuePosition(grid, axis, scaleWid, xValue);
            }
            np = new Vector3(xPos, yPos);
            return(yPos);
        }
Exemplo n.º 7
0
        private void DrawZebraBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                  bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
                                  Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 barColor, Color32 barToColor)
        {
            var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false);

            if (!ChartHelper.IsClearColor(backgroundColor))
            {
                UGL.DrawRoundRectangle(vh, serieData.context.backgroundRect, backgroundColor, backgroundColor, 0,
                                       null, isYAxis, chart.settings.cicleSmoothness, false);
            }
            if (isYAxis)
            {
                plt = (plb + plt) / 2;
                prt = (prt + prb) / 2;
                chart.DrawClipZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
                                        barColor, barToColor, serie.clip, grid, grid.context.width);
            }
            else
            {
                plb = (prb + plb) / 2;
                plt = (plt + prt) / 2;
                chart.DrawClipZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
                                        barColor, barToColor, serie.clip, grid, grid.context.height);
            }
        }
Exemplo n.º 8
0
 private void UpdateXYPosition(GridCoord grid, bool isY, Axis axis, Axis relativedAxis, int i, float categoryWidth, float barWidth, bool isStack,
                               double value, ref float pX, ref float pY)
 {
     if (isY)
     {
         if (axis.IsCategory())
         {
             pY = grid.context.y + i * categoryWidth + (axis.boundaryGap ? 0 : -categoryWidth * 0.5f);
         }
         else
         {
             if (axis.context.minMaxRange <= 0)
             {
                 pY = grid.context.y;
             }
             else
             {
                 var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.height;
                 pY = grid.context.y + valueLen - categoryWidth * 0.5f;
             }
         }
         pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
         if (isStack)
         {
             for (int n = 0; n < m_StackSerieData.Count - 1; n++)
             {
                 pX += m_StackSerieData[n][i].context.stackHeight;
             }
         }
     }
     else
     {
         if (axis.IsCategory())
         {
             pX = grid.context.x + i * categoryWidth + (axis.boundaryGap ? 0 : -categoryWidth * 0.5f);
         }
         else
         {
             if (axis.context.minMaxRange <= 0)
             {
                 pX = grid.context.x;
             }
             else
             {
                 var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.width;
                 pX = grid.context.x + valueLen - categoryWidth * 0.5f;
             }
         }
         pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
         if (isStack)
         {
             for (int n = 0; n < m_StackSerieData.Count - 1; n++)
             {
                 pY += m_StackSerieData[n][i].context.stackHeight;
             }
         }
     }
 }
        private void DrawXAxisIndicator(VertexHelper vh, Tooltip tooltip, GridCoord grid)
        {
            var xAxes     = chart.GetChartComponents <XAxis>();
            var lineType  = tooltip.lineStyle.GetType(chart.theme.tooltip.lineType);
            var lineWidth = tooltip.lineStyle.GetWidth(chart.theme.tooltip.lineWidth);

            foreach (var component in xAxes)
            {
                var xAxis = component as XAxis;
                if (xAxis.gridIndex == grid.index)
                {
                    if (double.IsInfinity(xAxis.context.pointerValue))
                    {
                        continue;
                    }
                    var   dataZoom   = chart.GetDataZoomOfAxis(xAxis);
                    int   dataCount  = chart.series.Count > 0 ? chart.series[0].GetDataList(dataZoom).Count : 0;
                    float splitWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, dataCount, dataZoom);
                    switch (tooltip.type)
                    {
                    case Tooltip.Type.Corss:
                    case Tooltip.Type.Line:
                        float pX = grid.context.x;
                        pX += xAxis.IsCategory() ?
                              (float)(xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) :
                              xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width);
                        Vector2 sp        = new Vector2(pX, grid.context.y);
                        Vector2 ep        = new Vector2(pX, grid.context.y + grid.context.height);
                        var     lineColor = TooltipHelper.GetLineColor(tooltip, chart.theme);
                        ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
                        if (tooltip.type == Tooltip.Type.Corss)
                        {
                            sp = new Vector2(grid.context.x, chart.pointerPos.y);
                            ep = new Vector2(grid.context.x + grid.context.width, chart.pointerPos.y);
                            ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
                        }
                        break;

                    case Tooltip.Type.Shadow:
                        if (xAxis.IsCategory() && !double.IsInfinity(xAxis.context.pointerValue))
                        {
                            float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
                            pX = (float)(grid.context.x + splitWidth * xAxis.context.pointerValue -
                                         (xAxis.boundaryGap ? 0 : splitWidth / 2));
                            float   pY = grid.context.y + grid.context.height;
                            Vector3 p1 = new Vector3(pX, grid.context.y);
                            Vector3 p2 = new Vector3(pX, pY);
                            Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
                            Vector3 p4 = new Vector3(pX + tooltipSplitWid, grid.context.y);
                            UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, chart.theme.tooltip.areaColor);
                        }
                        break;
                    }
                }
            }
        }
 public void DrawClipTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color,
                              Color32 color2, Color32 color3, bool clip, GridCoord grid)
 {
     if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3))
     {
         return;
     }
     if (!clip || (clip && (grid.Contains(p1) || grid.Contains(p2) || grid.Contains(p3))))
     {
         UGL.DrawTriangle(vh, p1, p2, p3, color, color2, color3);
     }
 }
 public void DrawClipPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
                             bool clip, bool vertical, GridCoord grid)
 {
     if (!IsInChart(p))
     {
         return;
     }
     if (!clip || (clip && (grid.Contains(p))))
     {
         UGL.DrawSquare(vh, p, radius, color);
     }
 }
 public void DrawClipLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color,
                          bool clip, GridCoord grid)
 {
     if (!IsInChart(p1) || !IsInChart(p2))
     {
         return;
     }
     if (!clip || (clip && (grid.Contains(p1) || grid.Contains(p2))))
     {
         UGL.DrawLine(vh, p1, p2, size, color);
     }
 }
 public void DrawClipSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness,
                            Vector3 pos, Color32 color, Color32 toColor, Color32 emptyColor, Color32 borderColor, float gap,
                            bool clip, float[] cornerRadius, GridCoord grid, Vector3 startPos)
 {
     if (!IsInChart(pos))
     {
         return;
     }
     if (!clip || (clip && (grid.Contains(pos))))
     {
         DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, emptyColor, borderColor,
                    gap, cornerRadius, startPos);
     }
 }
Exemplo n.º 14
0
 private void UpdateRectPosition(GridCoord grid, bool isY, double yValue, float pX, float pY, float gap, float borderWidth,
                                 float barWidth, float currHig,
                                 out Vector3 plb, out Vector3 plt, out Vector3 prt, out Vector3 prb, out Vector3 top)
 {
     if (isY)
     {
         if (yValue < 0)
         {
             plt = new Vector3(pX - borderWidth, pY + gap + barWidth - borderWidth);
             prt = new Vector3(pX + currHig + borderWidth, pY + gap + barWidth - borderWidth);
             prb = new Vector3(pX + currHig + borderWidth, pY + gap + borderWidth);
             plb = new Vector3(pX - borderWidth, pY + gap + borderWidth);
         }
         else
         {
             plt = new Vector3(pX + borderWidth, pY + gap + barWidth - borderWidth);
             prt = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth - borderWidth);
             prb = new Vector3(pX + currHig - borderWidth, pY + gap + borderWidth);
             plb = new Vector3(pX + borderWidth, pY + gap + borderWidth);
         }
         top = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth / 2);
     }
     else
     {
         if (yValue < 0)
         {
             plb = new Vector3(pX + gap + borderWidth, pY - borderWidth);
             plt = new Vector3(pX + gap + borderWidth, pY + currHig + borderWidth);
             prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig + borderWidth);
             prb = new Vector3(pX + gap + barWidth - borderWidth, pY - borderWidth);
         }
         else
         {
             plb = new Vector3(pX + gap + borderWidth, pY + borderWidth);
             plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth);
             prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth);
             prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth);
         }
         top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth);
     }
     if (serie.clip)
     {
         plb = chart.ClampInGrid(grid, plb);
         plt = chart.ClampInGrid(grid, plt);
         prt = chart.ClampInGrid(grid, prt);
         prb = chart.ClampInGrid(grid, prb);
         top = chart.ClampInGrid(grid, top);
     }
 }
 private void GetStartEndPos(Axis xAxis, Axis yAxis, GridCoord grid, double value, ref Vector3 sp, ref Vector3 ep)
 {
     if (xAxis.IsCategory())
     {
         var pY = AxisHelper.GetAxisPosition(grid, yAxis, value);
         sp = new Vector3(grid.context.x, pY);
         ep = new Vector3(grid.context.x + grid.context.width, pY);
     }
     else
     {
         var pX = AxisHelper.GetAxisPosition(grid, xAxis, value);
         sp = new Vector3(pX, grid.context.y);
         ep = new Vector3(pX, grid.context.y + grid.context.height);
     }
 }
Exemplo n.º 16
0
 public static double GetAxisPositionValue(GridCoord grid, Axis axis, Vector3 pos)
 {
     if (axis is YAxis)
     {
         return(GetAxisPositionValue(pos.y, grid.context.height, axis.context.minMaxRange, grid.context.y, axis.context.offset));
     }
     else if (axis is XAxis)
     {
         return(GetAxisPositionValue(pos.x, grid.context.width, axis.context.minMaxRange, grid.context.x, axis.context.offset));
     }
     else
     {
         return(0);
     }
 }
 private void GetSerieDataIndexByItem(Serie serie, Axis axis, GridCoord grid, int dimension = 0)
 {
     if (serie.context.pointerItemDataIndex >= 0)
     {
         axis.context.axisTooltipValue = serie.GetSerieData(serie.context.pointerItemDataIndex).GetData(dimension);
     }
     else if (component.type == Tooltip.Type.Corss)
     {
         axis.context.axisTooltipValue = axis.context.pointerValue;
     }
     else
     {
         axis.context.axisTooltipValue = 0;
     }
 }
Exemplo n.º 18
0
        public static int GetDataAverageRate(Serie serie, GridCoord grid, int maxCount, bool isYAxis)
        {
            var sampleDist = serie.sampleDist;
            var rate       = 0;
            var width      = isYAxis ? grid.context.height : grid.context.width;

            if (sampleDist > 0)
            {
                rate = (int)((maxCount - serie.minShow) / (width / sampleDist));
            }
            if (rate < 1)
            {
                rate = 1;
            }
            return(rate);
        }
Exemplo n.º 19
0
 private Vector3 GetPosition(Axis xAxis, Axis yAxis, GridCoord grid, double value, bool start)
 {
     if (yAxis.IsCategory())
     {
         var pX = AxisHelper.GetAxisPosition(grid, xAxis, value);
         return(start ?
                new Vector3(pX, grid.context.y + grid.context.height) :
                new Vector3(pX, grid.context.y));
     }
     else
     {
         var pY = AxisHelper.GetAxisPosition(grid, yAxis, value);
         return(start ?
                new Vector3(grid.context.x, pY + grid.context.height) :
                new Vector3(grid.context.x + grid.context.width, pY));
     }
 }
Exemplo n.º 20
0
        private float GetDataPoint(bool isY, Axis axis, Axis relativedAxis, GridCoord grid, double xValue,
                                   double yValue, int i, float scaleWid, bool isStack, ref Vector3 np)
        {
            float xPos, yPos;
            var   gridXY   = isY ? grid.context.x : grid.context.y;
            var   valueHig = 0f;

            if (isY)
            {
                valueHig = AxisHelper.GetAxisValueDistance(grid, relativedAxis, scaleWid, yValue);
                valueHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, valueHig);

                xPos = gridXY + valueHig;
                yPos = AxisHelper.GetAxisValuePosition(grid, axis, scaleWid, xValue);

                if (isStack)
                {
                    for (int n = 0; n < m_StackSerieData.Count - 1; n++)
                    {
                        xPos += m_StackSerieData[n][i].context.stackHeight;
                    }
                }
            }
            else
            {
                valueHig = AxisHelper.GetAxisValueDistance(grid, relativedAxis, scaleWid, yValue);
                valueHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, valueHig);

                yPos = gridXY + valueHig;
                xPos = AxisHelper.GetAxisValuePosition(grid, axis, scaleWid, xValue);

                if (isStack)
                {
                    for (int n = 0; n < m_StackSerieData.Count - 1; n++)
                    {
                        yPos += m_StackSerieData[n][i].context.stackHeight;
                    }
                }
            }
            np = new Vector3(xPos, yPos);
            return(valueHig);
        }
Exemplo n.º 21
0
 private void UpdateXYPosition(GridCoord grid, bool isY, Axis axis, Axis relativedAxis, int i, float categoryWidth, float barWidth,
                               double value, ref float pX, ref float pY)
 {
     if (isY)
     {
         if (axis.IsCategory())
         {
             pY = grid.context.y + i * categoryWidth + (axis.boundaryGap ? 0 : -categoryWidth * 0.5f);
         }
         else
         {
             if (axis.context.minMaxRange <= 0)
             {
                 pY = grid.context.y;
             }
             else
             {
                 pY = grid.context.y + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
             }
         }
         pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
     }
     else
     {
         if (axis.IsCategory())
         {
             pX = grid.context.x + i * categoryWidth + (axis.boundaryGap ? 0 : -categoryWidth * 0.5f);
         }
         else
         {
             if (axis.context.minMaxRange <= 0)
             {
                 pX = grid.context.x;
             }
             else
             {
                 pX = grid.context.x + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
             }
         }
         pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
     }
 }
 public void DrawClipPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
                             Color32 startColor, Color32 toColor, bool clip, GridCoord grid)
 {
     ClampInChart(ref p1);
     ClampInChart(ref p2);
     ClampInChart(ref p3);
     ClampInChart(ref p4);
     if (clip)
     {
         p1 = ClampInGrid(grid, p1);
         p2 = ClampInGrid(grid, p2);
         p3 = ClampInGrid(grid, p3);
         p4 = ClampInGrid(grid, p4);
     }
     if (!clip || (clip && (grid.Contains(p1) && grid.Contains(p2) && grid.Contains(p3) &&
                            grid.Contains(p4))))
     {
         UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, startColor, toColor);
     }
 }
Exemplo n.º 23
0
        private static float GetAxisPositionInternal(GridCoord grid, Axis axis, float scaleWidth, double value, bool includeGridXY, bool realLength)
        {
            var isY        = axis is YAxis;
            var gridHeight = isY ? grid.context.height : grid.context.width;
            var gridXY     = isY ? grid.context.y : grid.context.x;

            if (axis.IsLog())
            {
                int   minIndex = axis.GetLogMinIndex();
                float nowIndex = axis.GetLogValue(value);
                return(includeGridXY ?
                       gridXY + (nowIndex - minIndex) / axis.splitNumber * gridHeight :
                       (nowIndex - minIndex) / axis.splitNumber * gridHeight);
            }
            else if (axis.IsCategory())
            {
                var categoryIndex = (int)value;
                return(includeGridXY ?
                       gridXY + (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex :
                       (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex);
            }
            else
            {
                var yDataHig = 0f;
                if (axis.context.minMaxRange != 0)
                {
                    if (realLength)
                    {
                        yDataHig = (float)(value * gridHeight / axis.context.minMaxRange);
                    }
                    else
                    {
                        yDataHig = (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
                    }
                }
                return(includeGridXY ?
                       gridXY + yDataHig :
                       yDataHig);
            }
        }
        private Vector3 GetSinglePos(Axis xAxis, Axis yAxis, GridCoord grid, Serie serie, DataZoom dataZoom, MarkLineData data,
                                     int serieDataCount)
        {
            switch (data.type)
            {
            case MarkLineType.Min:
                var serieData = SerieHelper.GetMinSerieData(serie, data.dimension, dataZoom);
                data.runtimeValue = serieData.GetData(data.dimension);
                var pX = GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, serieData.index);
                var pY = GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.runtimeValue);
                return(new Vector3(pX, pY));

            case MarkLineType.Max:
                serieData         = SerieHelper.GetMaxSerieData(serie, data.dimension, dataZoom);
                data.runtimeValue = serieData.GetData(data.dimension);
                pX = GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, serieData.index);
                pY = GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.runtimeValue);
                return(new Vector3(pX, pY));

            case MarkLineType.None:
                if (data.zeroPosition)
                {
                    data.runtimeValue = 0;
                    return(grid.context.position);
                }
                else
                {
                    pX = data.xPosition != 0 ? grid.context.x + data.xPosition :
                         GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, data.xValue);
                    pY = data.yPosition != 0 ? grid.context.y + data.yPosition :
                         GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.yValue);
                    data.runtimeValue = data.yValue;
                    return(new Vector3(pX, pY));
                }

            default:
                return(grid.context.position);
            }
        }
Exemplo n.º 25
0
        public static float GetAxisPosition(GridCoord grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null)
        {
            var gridHeight = axis is YAxis ? grid.context.height : grid.context.width;
            var gridXY     = axis is YAxis ? grid.context.y : grid.context.x;

            if (axis.IsCategory())
            {
                if (dataCount == 0)
                {
                    dataCount = axis.data.Count;
                }
                var   categoryIndex = (int)value;
                var   scaleWid      = AxisHelper.GetDataWidth(axis, gridHeight, dataCount, dataZoom);
                float startY        = gridXY + (axis.boundaryGap ? scaleWid / 2 : 0);
                return(startY + scaleWid * categoryIndex);
            }
            else
            {
                var yDataHig = (axis.context.minMaxRange == 0) ? 0f :
                               (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
                return(gridXY + yDataHig);
            }
        }
        public GridCoord GetGridOfDataZoom(DataZoom dataZoom)
        {
            GridCoord grid = null;

            if (dataZoom.xAxisIndexs != null && dataZoom.xAxisIndexs.Count > 0)
            {
                var xAxis = GetChartComponent <XAxis>(dataZoom.xAxisIndexs[0]);
                grid = GetChartComponent <GridCoord>(xAxis.gridIndex);
            }
            else if (dataZoom.yAxisIndexs != null && dataZoom.yAxisIndexs.Count > 0)
            {
                var yAxis = GetChartComponent <YAxis>(dataZoom.yAxisIndexs[0]);
                grid = GetChartComponent <GridCoord>(yAxis.gridIndex);
            }
            if (grid == null)
            {
                return(GetChartComponent <GridCoord>());
            }
            else
            {
                return(grid);
            }
        }
Exemplo n.º 27
0
        private void DrawLineSerie(VertexHelper vh, Line serie)
        {
            if (!serie.show)
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            serie.context.vertCount = vh.currentVertCount;

            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress();
                serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize));
                chart.RefreshPainter(serie);
            }
        }
Exemplo n.º 28
0
        private Vector3 GetPosition(MarkAreaData data, Serie serie, DataZoom dataZoom, XAxis xAxis, YAxis yAxis,
                                    GridCoord grid, List <SerieData> showData, bool start)
        {
            var pos = Vector3.zero;

            switch (data.type)
            {
            case MarkAreaType.Min:
                data.runtimeValue = SerieHelper.GetMinData(serie, data.dimension, dataZoom);
                return(GetPosition(xAxis, yAxis, grid, data.runtimeValue, start));

            case MarkAreaType.Max:
                data.runtimeValue = SerieHelper.GetMaxData(serie, data.dimension, dataZoom);
                return(GetPosition(xAxis, yAxis, grid, data.runtimeValue, start));

            case MarkAreaType.Average:
                data.runtimeValue = SerieHelper.GetAverageData(serie, data.dimension, dataZoom);
                return(GetPosition(xAxis, yAxis, grid, data.runtimeValue, start));

            case MarkAreaType.Median:
                data.runtimeValue = SerieHelper.GetMedianData(serie, data.dimension, dataZoom);
                return(GetPosition(xAxis, yAxis, grid, data.runtimeValue, start));

            case MarkAreaType.None:
                if (data.xPosition != 0 || data.yPosition != 0)
                {
                    var pX = grid.context.x + data.xPosition;
                    var pY = grid.context.y + data.yPosition;
                    return(new Vector3(pX, pY));
                }
                else if (data.yValue != 0)
                {
                    data.runtimeValue = data.yValue;
                    if (yAxis.IsCategory())
                    {
                        var pY = AxisHelper.GetAxisPosition(grid, yAxis, data.yValue, showData.Count, dataZoom);
                        return(start ?
                               new Vector3(grid.context.x, pY) :
                               new Vector3(grid.context.x + grid.context.width, pY));
                    }
                    else
                    {
                        return(GetPosition(xAxis, yAxis, grid, data.runtimeValue, start));
                    }
                }
                else
                {
                    data.runtimeValue = data.xValue;
                    if (xAxis.IsCategory())
                    {
                        var pX = AxisHelper.GetAxisPosition(grid, xAxis, data.xValue, showData.Count, dataZoom);
                        return(start ? new Vector3(pX, grid.context.y + grid.context.height) :
                               new Vector3(pX, grid.context.y));
                    }
                    else
                    {
                        return(GetPosition(xAxis, yAxis, grid, data.xValue, start));
                    }
                }

            default:
                break;
            }
            return(pos);
        }
Exemplo n.º 29
0
        private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                   bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
                                   Vector3 prb, bool isYAxis, GridCoord grid, Color32 areaColor, Color32 areaToColor)
        {
            var borderWidth = itemStyle.runtimeBorderWidth;

            if (isYAxis)
            {
                if (serie.clip)
                {
                    prb = chart.ClampInGrid(grid, prb);
                    plb = chart.ClampInGrid(grid, plb);
                    plt = chart.ClampInGrid(grid, plt);
                    prt = chart.ClampInGrid(grid, prt);
                }
                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);
                if (itemWidth > 0 && itemHeight > 0)
                {
                    var invert = center.x < plb.x;
                    if (itemStyle.IsNeedCorner())
                    {
                        UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
                                               itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
                    }
                    else
                    {
                        chart.DrawClipPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid);
                    }
                    UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
                                   itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
                }
            }
            else
            {
                if (serie.clip)
                {
                    prb = chart.ClampInGrid(grid, prb);
                    plb = chart.ClampInGrid(grid, plb);
                    plt = chart.ClampInGrid(grid, plt);
                    prt = chart.ClampInGrid(grid, prt);
                }
                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);
                if (itemWidth > 0 && itemHeight > 0)
                {
                    var invert = center.y < plb.y;
                    if (itemStyle.IsNeedCorner())
                    {
                        UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
                                               itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
                    }
                    else
                    {
                        chart.DrawClipPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor,
                                              serie.clip, grid);
                    }
                    UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
                                   itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
                }
            }
        }
Exemplo n.º 30
0
        private void DrawBarSerie(VertexHelper vh, SimplifiedBar serie, int colorIndex)
        {
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }

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

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

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

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

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

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

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

            bool   dataChanging       = false;
            float  dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            double yMinValue          = relativedAxis.context.minValue;
            double yMaxValue          = relativedAxis.context.maxValue;

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

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

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

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

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

                var pX = 0f;
                var pY = 0f;
                UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, barWidth, value, ref pX, ref pY);

                var barHig  = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, categoryWidth, relativedValue);
                var currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);

                Vector3 plb, plt, prt, prb, top;
                UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, gap, borderWidth, barWidth, currHig,
                                   out plb, out plt, out prt, out prb, out top);
                serieData.context.stackHeight = barHig;
                serieData.context.position    = top;
                serieData.context.rect        = Rect.MinMaxRect(plb.x, plb.y, prb.x, prt.y);
                serie.context.dataPoints.Add(top);
                DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth,
                              pX, pY, plb, plt, prt, prb, false, m_SerieGrid, areaColor, areaToColor);

                if (serie.animation.CheckDetailBreak(top, isY))
                {
                    break;
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress();
                chart.RefreshPainter(serie);
            }
            if (dataChanging || interacting)
            {
                chart.RefreshPainter(serie);
            }
        }