コード例 #1
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);
            }
        }
コード例 #2
0
        private void DrawRectVessel(VertexHelper vh, Vessel vessel)
        {
            var serie       = SeriesHelper.GetSerieByVesselIndex(chart.series, vessel.index);
            var vesselColor = VesselHelper.GetColor(vessel, serie, chart.theme, chart.m_LegendRealShowName);

            if (vessel.gap != 0)
            {
                UGL.DrawBorder(vh, vessel.runtimeCenterPos, vessel.runtimeWidth,
                               vessel.runtimeHeight, vessel.gap, vessel.backgroundColor, 0, vessel.cornerRadius);
            }
            UGL.DrawBorder(vh, vessel.runtimeCenterPos, vessel.runtimeWidth + 2 * vessel.gap,
                           vessel.runtimeHeight + 2 * vessel.gap, vessel.shapeWidth, vesselColor, 0, vessel.cornerRadius);
        }
コード例 #3
0
        public void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
        {
            if (serieData == null || serieData.labelObject == null)
            {
                return;
            }
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);

            if (!serieLabel.show)
            {
                return;
            }
            var invert = serieLabel.autoOffset &&
                         serie.type == SerieType.Line &&
                         SerieHelper.IsDownPoint(serie, serieData.index) &&
                         !serie.areaStyle.show;
            var centerPos = Vector3.zero;

            if (serie.type == SerieType.Pie)
            {
                centerPos = SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel);
            }
            else
            {
                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.textStyle.rotate > 0)
            {
                p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.textStyle.rotate);
                p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.textStyle.rotate);
                p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.textStyle.rotate);
                p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.textStyle.rotate);
            }

            UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, serieLabel.textStyle.backgroundColor);

            if (serieLabel.border)
            {
                UGL.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
                               serieLabel.borderWidth, serieLabel.borderColor, serieLabel.textStyle.rotate);
            }
        }
コード例 #4
0
 public override void DrawUpper(VertexHelper vh)
 {
     for (int i = 0; i < component.items.Count; i++)
     {
         var item      = component.items[i];
         var markStyle = component.GetMarkStyle(i);
         if (!markStyle.show)
         {
             continue;
         }
         var color = ChartHelper.IsClearColor(markStyle.lineStyle.color) ?
                     chart.theme.axis.splitLineColor :
                     markStyle.lineStyle.color;
         var width = markStyle.lineStyle.width == 0 ? 1 : markStyle.lineStyle.width;
         UGL.DrawBorder(vh, item.markRect, width, color);
     }
 }
コード例 #5
0
        private Rect DrawGanttBar(VertexHelper vh, Grid grid, Serie serie, SerieData serieData, ItemStyle itemStyle,
                                  Color32 color, float pX, float pY, float space, float barWidth, float xStart, float xEnd)
        {
            var borderWidth = itemStyle.borderWidth;
            var plb         = new Vector3(xStart + borderWidth, pY + space + borderWidth);
            var plt         = new Vector3(xStart + borderWidth, pY + space + barWidth - borderWidth);
            var prt         = new Vector3(xEnd - borderWidth, pY + space + barWidth - borderWidth);
            var prb         = new Vector3(xEnd - borderWidth, pY + space + borderWidth);
            var center      = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
            var itemWidth   = Mathf.Abs(prt.x - plb.x);
            var itemHeight  = Mathf.Abs(plt.y - prb.y);

            if (serie.clip)
            {
                plb    = ClampInGrid(grid, plb);
                plt    = ClampInGrid(grid, plt);
                prt    = ClampInGrid(grid, prt);
                prb    = ClampInGrid(grid, prb);
                center = ClampInGrid(grid, center);
            }
            if (ItemStyleHelper.IsNeedCorner(itemStyle))
            {
                UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, color, color, 0,
                                       itemStyle.cornerRadius, true, 0.5f);
            }
            else
            {
                CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color,
                                        serie.clip, grid);
            }
            if (borderWidth != 0)
            {
                UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor, 0,
                               itemStyle.cornerRadius, true, 0.5f);
            }
            return(new Rect(plb.x, plb.y, xEnd - xStart, barWidth));
        }
コード例 #6
0
ファイル: UGLExample.cs プロジェクト: zezejss/XUGL
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Vector3 sp, cp, ep;

            vh.Clear();

            //背景边框
            UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor);
            UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 10, Color.green, 0, m_BorderRadius);

            //点
            UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor);

            //直线
            sp = new Vector3(m_LeftTopPos.x + 50, m_LeftTopPos.y - 20);
            ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 20);
            UGL.DrawLine(vh, sp, ep, 3, m_DrawColor);

            //3点确定的折线
            sp = new Vector3(m_LeftTopPos.x + 20, m_LeftTopPos.y - 100);
            cp = new Vector3(m_LeftTopPos.x + 200, m_LeftTopPos.y - 40);
            ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 80);
            UGL.DrawLine(vh, sp, cp, ep, 5, m_DrawColor);
        }
コード例 #7
0
 private void DrawCoord(VertexHelper vh, GridCoord grid)
 {
     if (!grid.show)
     {
         return;
     }
     if (!ChartHelper.IsClearColor(grid.backgroundColor))
     {
         var p1 = new Vector2(grid.context.x, grid.context.y);
         var p2 = new Vector2(grid.context.x, grid.context.y + grid.context.height);
         var p3 = new Vector2(grid.context.x + grid.context.width, grid.context.y + grid.context.height);
         var p4 = new Vector2(grid.context.x + grid.context.width, grid.context.y);
         UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, grid.backgroundColor);
     }
     if (grid.showBorder)
     {
         var borderWidth = grid.borderWidth == 0 ? chart.theme.axis.lineWidth * 2 : grid.borderWidth;
         var borderColor = ChartHelper.IsClearColor(grid.borderColor) ?
                           chart.theme.axis.lineColor :
                           grid.borderColor;
         UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
                        grid.context.height - borderWidth, borderWidth, borderColor);
     }
 }
コード例 #8
0
        private void DrawCandlestickSerie(VertexHelper vh, SimplifiedCandlestick serie)
        {
            if (!serie.show)
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            XAxis     xAxis;
            YAxis     yAxis;
            GridCoord grid;

            if (!chart.TryGetChartComponent <XAxis>(out xAxis, serie.xAxisIndex))
            {
                return;
            }
            if (!chart.TryGetChartComponent <YAxis>(out yAxis, serie.yAxisIndex))
            {
                return;
            }
            if (!chart.TryGetChartComponent <GridCoord>(out grid, xAxis.gridIndex))
            {
                return;
            }
            var   theme         = chart.theme;
            var   dataZoom      = chart.GetDataZoomOfAxis(xAxis);
            var   showData      = serie.GetDataList(dataZoom);
            float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, showData.Count, dataZoom);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float gap           = (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();
            double yMinValue          = yAxis.context.minValue;
            double yMaxValue          = yAxis.context.maxValue;
            var    isYAxis            = false;
            var    itemStyle          = serie.itemStyle;

            serie.containerIndex       = grid.index;
            serie.containterInstanceId = grid.instanceId;

            for (int i = serie.minShow; i < maxCount; i++)
            {
                var serieData = showData[i];
                if (serie.IsIgnoreValue(serieData))
                {
                    serie.context.dataPoints.Add(Vector3.zero);
                    continue;
                }
                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 = yAxis.inverse ? close <open : close> open;
                var borderWidth = open == 0 ? 0f :
                                  (itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth :
                                   itemStyle.runtimeBorderWidth);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX    = grid.context.x + i * categoryWidth;
                float zeroY = grid.context.y + yAxis.context.offset;
                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.context.height);
                    pY    += (float)((open - minCut) / valueTotal * grid.context.height);
                }
                serieData.context.stackHeight = barHig;
                float   currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);
                Vector3 plb, plt, prt, prb, top;

                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);
                // }
                serie.context.dataPoints.Add(top);
                var areaColor = isRise ?
                                itemStyle.GetColor(theme.serie.candlestickColor) :
                                itemStyle.GetColor0(theme.serie.candlestickColor0);
                var borderColor = isRise ?
                                  itemStyle.GetBorderColor(theme.serie.candlestickBorderColor) :
                                  itemStyle.GetBorderColor0(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.context.height));
                var heighPos       = new Vector3(center.x, zeroY + (float)((heighest - minCut) / valueTotal * grid.context.height));
                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 (itemStyle.IsNeedCorner())
                        {
                            UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0,
                                                   itemStyle.cornerRadius, isYAxis, 0.5f);
                        }
                        else
                        {
                            chart.DrawClipPolygon(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);
                    }
                    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);
                    }
                }
                else
                {
                    UGL.DrawLine(vh, openCenterPos, closeCenterPos, Mathf.Max(borderWidth, barWidth / 2), borderColor);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress();
            }
            if (dataChanging)
            {
                chart.RefreshPainter(serie);
            }
        }
コード例 #9
0
        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, Grid grid)
        {
            var areaColor   = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
            var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);

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

            if (isYAxis)
            {
                if (serie.clip)
                {
                    prb = ClampInGrid(grid, prb);
                    plb = ClampInGrid(grid, plb);
                    plt = ClampInGrid(grid, plt);
                    prt = 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)
                {
                    if (ItemStyleHelper.IsNeedCorner(itemStyle))
                    {
                        UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
                                               itemStyle.cornerRadius, isYAxis);
                    }
                    else
                    {
                        Internal_CheckClipAndDrawPolygon(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);
                }
            }
            else
            {
                if (serie.clip)
                {
                    prb = ClampInGrid(grid, prb);
                    plb = ClampInGrid(grid, plb);
                    plt = ClampInGrid(grid, plt);
                    prt = 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)
                {
                    if (ItemStyleHelper.IsNeedCorner(itemStyle))
                    {
                        UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
                                               itemStyle.cornerRadius, isYAxis);
                    }
                    else
                    {
                        Internal_CheckClipAndDrawPolygon(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);
                }
            }
        }
コード例 #10
0
        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.GetData(1)))
                {
                    serie.dataPoints.Add(Vector3.zero);
                    continue;
                }
                var highlight = (tooltip.show && tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                var itemStyle   = SerieHelper.GetItemStyle(serie, serieData, highlight);
                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;
                var   valueTotal = yMaxValue - yMinValue;
                var   minCut     = (yMinValue > 0 ? yMinValue : 0);
                if (valueTotal != 0)
                {
                    barHig = (close - open) / valueTotal * grid.runtimeHeight;
                    pY    += (open - minCut) / valueTotal * grid.runtimeHeight;
                }
                serieData.runtimeStackHig = barHig;
                var   isBarEnd = false;
                float currHig  = CheckAnimation(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 + (lowest - minCut) / valueTotal * grid.runtimeHeight);
                var heighPos       = new Vector3(center.x, zeroY + (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
                        {
                            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);
            }
        }
コード例 #11
0
        private void DrawVerticalDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
        {
            if (!dataZoom.enable || !dataZoom.supportSlider)
            {
                return;
            }

            var p1              = new Vector3(dataZoom.context.x, dataZoom.context.y);
            var p2              = new Vector3(dataZoom.context.x, dataZoom.context.y + dataZoom.context.height);
            var p3              = new Vector3(dataZoom.context.x + dataZoom.context.width, dataZoom.context.y + dataZoom.context.height);
            var p4              = new Vector3(dataZoom.context.x + dataZoom.context.width, dataZoom.context.y);
            var lineColor       = dataZoom.lineStyle.GetColor(chart.theme.dataZoom.dataLineColor);
            var lineWidth       = dataZoom.lineStyle.GetWidth(chart.theme.dataZoom.dataLineWidth);
            var borderWidth     = dataZoom.borderWidth == 0 ? chart.theme.dataZoom.borderWidth : dataZoom.borderWidth;
            var borderColor     = dataZoom.GetBorderColor(chart.theme.dataZoom.borderColor);
            var backgroundColor = dataZoom.GetBackgroundColor(chart.theme.dataZoom.backgroundColor);
            var areaColor       = dataZoom.areaStyle.GetColor(chart.theme.dataZoom.dataAreaColor);

            UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, backgroundColor);
            var centerPos = new Vector3(dataZoom.context.x + dataZoom.context.width / 2,
                                        dataZoom.context.y + dataZoom.context.height / 2);

            UGL.DrawBorder(vh, centerPos, dataZoom.context.width, dataZoom.context.height, borderWidth, borderColor);

            if (dataZoom.showDataShadow && chart.series.Count > 0)
            {
                Serie   serie    = chart.series[0];
                Axis    axis     = chart.GetChartComponent <YAxis>(0);
                var     showData = serie.GetDataList(null);
                float   scaleWid = dataZoom.context.height / (showData.Count - 1);
                Vector3 lp       = Vector3.zero;
                Vector3 np       = Vector3.zero;
                double  minValue = 0;
                double  maxValue = 0;
                SeriesHelper.GetYMinMaxValue(chart.series, null, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue);
                AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);

                int rate       = 1;
                var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
                var maxCount   = showData.Count;
                if (sampleDist > 0)
                {
                    rate = (int)((maxCount - serie.minShow) / (dataZoom.context.height / sampleDist));
                }
                if (rate < 1)
                {
                    rate = 1;
                }

                var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
                                   DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
                var dataChanging = false;

                for (int i = 0; i < maxCount; i += rate)
                {
                    double value = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
                                                          serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
                    float pY      = dataZoom.context.y + i * scaleWid;
                    float dataHig = (maxValue - minValue) == 0 ? 0 :
                                    (float)((value - minValue) / (maxValue - minValue) * dataZoom.context.width);
                    np = new Vector3(chart.chartX + chart.chartWidth - dataZoom.right - dataHig, pY);
                    if (i > 0)
                    {
                        UGL.DrawLine(vh, lp, np, lineWidth, lineColor);
                        Vector3 alp = new Vector3(lp.x, lp.y - lineWidth);
                        Vector3 anp = new Vector3(np.x, np.y - lineWidth);

                        Vector3 tnp = new Vector3(np.x, chart.chartY + dataZoom.bottom + lineWidth);
                        Vector3 tlp = new Vector3(lp.x, chart.chartY + dataZoom.bottom + lineWidth);
                        UGL.DrawQuadrilateral(vh, alp, anp, tnp, tlp, areaColor);
                    }
                    lp = np;
                }
                if (dataChanging)
                {
                    chart.RefreshTopPainter();
                }
            }
            switch (dataZoom.rangeMode)
            {
            case DataZoom.RangeMode.Percent:
                var start       = dataZoom.context.y + dataZoom.context.height * dataZoom.start / 100;
                var end         = dataZoom.context.y + dataZoom.context.height * dataZoom.end / 100;
                var fillerColor = dataZoom.GetFillerColor(chart.theme.dataZoom.fillerColor);

                p1 = new Vector2(dataZoom.context.x, start);
                p2 = new Vector2(dataZoom.context.x + dataZoom.context.width, start);
                p3 = new Vector2(dataZoom.context.x + dataZoom.context.width, end);
                p4 = new Vector2(dataZoom.context.x, end);
                UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, fillerColor);
                UGL.DrawLine(vh, p1, p2, lineWidth, fillerColor);
                UGL.DrawLine(vh, p3, p4, lineWidth, fillerColor);
                break;
            }
        }
コード例 #12
0
        protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var yAxis = m_YAxes[serie.yAxisIndex];
            var xAxis = m_XAxes[serie.xAxisIndex];

            xAxis.boundaryGap = true;
            yAxis.boundaryGap = true;
            var grid   = GetSerieGridOrDefault(serie);
            var xCount = xAxis.data.Count;
            var yCount = yAxis.data.Count;
            var xWidth = grid.runtimeWidth / xCount;
            var yWidth = grid.runtimeHeight / yCount;

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

            borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
            var borderToColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderToColor : ChartConst.clearColor32;

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

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var dataIndex = i * yCount + j;
                    if (dataIndex >= dataList.Count)
                    {
                        continue;
                    }
                    var serieData = dataList[dataIndex];
                    var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
                    if (serie.IsIgnoreIndex(dataIndex, dimension))
                    {
                        serie.dataPoints.Add(Vector3.zero);
                        continue;
                    }
                    var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse,
                                                      yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    var pos = new Vector3(zeroX + (i + (xAxis.boundaryGap ? 0.5f : 0)) * xWidth,
                                          zeroY + (j + (yAxis.boundaryGap ? 0.5f : 0)) * yWidth);
                    serie.dataPoints.Add(pos);
                    serieData.canShowLabel = false;
                    if (value == 0)
                    {
                        continue;
                    }
                    if (visualMap.enable)
                    {
                        if ((value < rangeMin && rangeMin != visualMap.min) ||
                            (value > rangeMax && rangeMax != visualMap.max))
                        {
                            continue;
                        }
                        if (!visualMap.IsInSelectedValue(value))
                        {
                            continue;
                        }
                        color = visualMap.GetColor(value);
                    }
                    if (animationIndex >= 0 && i > animationIndex)
                    {
                        continue;
                    }
                    serieData.canShowLabel = true;
                    var emphasis = (tooltip.show &&
                                    i == (int)tooltip.runtimeXValues[0] &&
                                    j == (int)tooltip.runtimeYValues[0]) ||
                                   visualMap.runtimeSelectedIndex > 0;
                    var rectWid = xWidth - 2 * borderWidth;
                    var rectHig = yWidth - 2 * borderWidth;
                    UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
                    if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
                    {
                        UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor);
                    }
                    if (visualMap.hoverLink && emphasis && serie.emphasis.show &&
                        serie.emphasis.itemStyle.borderWidth > 0)
                    {
                        var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
                        var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0
                            ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
                        var emphasisBorderToColor = serie.emphasis.itemStyle.opacity > 0
                            ? serie.emphasis.itemStyle.borderToColor : ChartConst.clearColor32;
                        UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor,
                                       emphasisBorderToColor);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(xCount);
                m_IsPlayingAnimation = true;
                RefreshPainter(serie);
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
コード例 #13
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);
                }
            }
        }
コード例 #14
0
        private void DrawHeatmapSerie(VertexHelper vh, Heatmap serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            XAxis xAxis;
            YAxis yAxis;

            if (!chart.TryGetChartComponent <XAxis>(out xAxis, serie.xAxisIndex))
            {
                return;
            }
            if (!chart.TryGetChartComponent <YAxis>(out yAxis, serie.yAxisIndex))
            {
                return;
            }
            m_SerieGrid       = chart.GetChartComponent <GridCoord>(xAxis.gridIndex);
            xAxis.boundaryGap = true;
            yAxis.boundaryGap = true;
            var visualMap         = chart.GetVisualMapOfSerie(serie);
            var emphasisItemStyle = serie.emphasisItemStyle;
            var xCount            = xAxis.data.Count;
            var yCount            = yAxis.data.Count;
            var xWidth            = m_SerieGrid.context.width / xCount;
            var yWidth            = m_SerieGrid.context.height / yCount;

            var zeroX       = m_SerieGrid.context.x;
            var zeroY       = m_SerieGrid.context.y;
            var rangeMin    = visualMap.rangeMin;
            var rangeMax    = visualMap.rangeMax;
            var color       = chart.theme.GetColor(serie.index);
            var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
            var rectWid     = xWidth - 2 * borderWidth;
            var rectHig     = yWidth - 2 * borderWidth;

            var borderColor = serie.itemStyle.opacity > 0 ?
                              serie.itemStyle.borderColor :
                              ChartConst.clearColor32;

            borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);

            var borderToColor = serie.itemStyle.opacity > 0 ?
                                serie.itemStyle.borderToColor :
                                ChartConst.clearColor32;

            borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity);

            serie.context.dataPoints.Clear();
            serie.animation.InitProgress(0, xCount);
            var animationIndex     = serie.animation.GetCurrIndex();
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging       = false;

            serie.containerIndex       = m_SerieGrid.index;
            serie.containterInstanceId = m_SerieGrid.instanceId;
            for (int n = 0; n < serie.dataCount; n++)
            {
                var serieData = serie.data[n];
                serieData.index = n;
                var i         = (int)serieData.GetData(0);
                var j         = (int)serieData.GetData(1);
                var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
                if (serie.IsIgnoreValue(serieData, dimension))
                {
                    serie.context.dataPoints.Add(Vector3.zero);
                    continue;
                }
                var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse,
                                                  yAxis.context.minValue, yAxis.context.maxValue);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                var pos = new Vector3(zeroX + (i + (xAxis.boundaryGap ? 0.5f : 0)) * xWidth,
                                      zeroY + (j + (yAxis.boundaryGap ? 0.5f : 0)) * yWidth);
                serie.context.dataPoints.Add(pos);
                serieData.context.position = pos;

                serieData.context.canShowLabel = false;
                serieData.context.rect         = new Rect(pos.x - rectWid / 2, pos.y - rectHig / 2, rectWid, rectHig);
                if (value == 0)
                {
                    continue;
                }
                if ((value < rangeMin && rangeMin != visualMap.min) ||
                    (value > rangeMax && rangeMax != visualMap.max))
                {
                    continue;
                }
                if (!visualMap.IsInSelectedValue(value))
                {
                    continue;
                }
                if (animationIndex >= 0 && i > animationIndex)
                {
                    continue;
                }
                color = visualMap.GetColor(value);
                if (serieData.context.highlight)
                {
                    color = ChartHelper.GetHighlightColor(color);
                }

                serieData.context.canShowLabel = true;
                serieData.context.color        = color;

                var highlight = (serieData.context.highlight) ||
                                visualMap.context.pointerIndex > 0;

                //UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
                UGL.DrawRectangle(vh, serieData.context.rect, color);

                if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
                {
                    UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor);
                }
                if (visualMap.hoverLink && highlight && emphasisItemStyle != null &&
                    emphasisItemStyle.borderWidth > 0)
                {
                    var emphasisBorderWidth = emphasisItemStyle.borderWidth;
                    var emphasisBorderColor = emphasisItemStyle.opacity > 0 ?
                                              emphasisItemStyle.borderColor : ChartConst.clearColor32;
                    var emphasisBorderToColor = emphasisItemStyle.opacity > 0 ?
                                                emphasisItemStyle.borderToColor : ChartConst.clearColor32;
                    UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor,
                                   emphasisBorderToColor);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(xCount);
                chart.RefreshPainter(serie);
            }
            if (dataChanging)
            {
                chart.RefreshPainter(serie);
            }
        }
コード例 #15
0
        public static void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness,
                                      Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
                                      Color32 emptyColor, Color32 backgroundColor, Color32 borderColor, float smoothness, Vector3 startPos)
        {
            switch (type)
            {
            case SymbolType.None:
                break;

            case SymbolType.Circle:
                if (gap > 0)
                {
                    UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness);
                }
                else
                {
                    if (tickness > 0)
                    {
                        UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + tickness, borderColor, borderColor, color, smoothness);
                    }
                    else
                    {
                        UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
                    }
                }
                break;

            case SymbolType.EmptyCircle:
                if (gap > 0)
                {
                    UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
                    UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
                }
                else
                {
                    UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
                }
                break;

            case SymbolType.Rect:
                if (gap > 0)
                {
                    UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawSquare(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    if (tickness > 0)
                    {
                        UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
                        UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius);
                    }
                    else
                    {
                        UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
                    }
                }
                break;

            case SymbolType.EmptyRect:
                if (gap > 0)
                {
                    UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color);
                }
                else
                {
                    UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color);
                }
                break;

            case SymbolType.Triangle:
                if (gap > 0)
                {
                    UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SymbolType.Diamond:
                if (gap > 0)
                {
                    UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SymbolType.Arrow:
                var arrowWidth  = symbolSize * 2;
                var arrowHeight = arrowWidth * 1.5f;
                var arrowOffset = 0;
                var arrowDent   = arrowWidth / 3.3f;
                UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight,
                              arrowOffset, arrowDent, color);
                break;
            }
        }