Beispiel #1
0
 internal static bool NeedShowSplit(Axis axis)
 {
     if (!axis.show)
     {
         return(false);
     }
     if (axis.IsCategory() && axis.data.Count <= 0)
     {
         return(false);
     }
     else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #2
0
        private float GetDataPoint(Axis xAxis, Axis yAxis, List <SerieData> showData, float yValue, float startX, int i, float scaleWid, float serieHig, ref Vector3 np)
        {
            float yDataHig;

            if (xAxis.IsValue())
            {
                float xValue   = i > showData.Count - 1 ? 0 : showData[i].data[0];
                float pX       = coordinateX + xAxis.axisLine.width;
                float pY       = serieHig + coordinateY + xAxis.axisLine.width;
                float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
                yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
                np       = new Vector3(pX + xDataHig, pY + yDataHig);
            }
            else
            {
                float pX = startX + i * scaleWid;
                float pY = serieHig + coordinateY + yAxis.axisLine.width;
                yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
                np       = new Vector3(pX, pY + yDataHig);
            }
            return(yDataHig);
        }
        internal static void DrawAxisLine(VertexHelper vh, Axis axis, AxisTheme theme, Orient orient,
                                          float startX, float startY, float axisLength)
        {
            var inverse = axis.IsValue() && axis.inverse;
            var offset  = AxisHelper.GetAxisLineArrowOffset(axis);

            var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
            var lineType  = axis.axisLine.GetType(theme.lineType);
            var lineColor = axis.axisLine.GetColor(theme.lineColor);

            if (orient == Orient.Horizonal)
            {
                var left  = new Vector3(startX - lineWidth - (inverse ? offset : 0), startY);
                var right = new Vector3(startX + axisLength + lineWidth + (!inverse ? offset : 0), startY);
                ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, left, right, lineColor);
            }
            else
            {
                var bottom = new Vector3(startX, startY - lineWidth - (inverse ? offset : 0));
                var top    = new Vector3(startX, startY + axisLength + lineWidth + (!inverse ? offset : 0));
                ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, bottom, top, lineColor);
            }
        }
 internal void CheckValueLabelActive(Axis axis, int i, ChartLabel label, Vector3 pos)
 {
     if (!axis.show || !axis.axisLabel.show)
     {
         label.SetTextActive(false);
         return;
     }
     if (axis.IsValue())
     {
         if (orient == Orient.Horizonal)
         {
             if (i == 0)
             {
                 var dist = GetLabelPosition(0, 1).x - pos.x;
                 label.SetTextActive(dist > label.text.GetPreferredWidth());
             }
             else if (i == axis.context.labelValueList.Count - 1)
             {
                 var dist = pos.x - GetLabelPosition(0, i - 1).x;
                 label.SetTextActive(dist > label.text.GetPreferredWidth());
             }
         }
         else
         {
             if (i == 0)
             {
                 var dist = GetLabelPosition(0, 1).y - pos.y;
                 label.SetTextActive(dist > label.text.GetPreferredHeight());
             }
             else if (i == axis.context.labelValueList.Count - 1)
             {
                 var dist = pos.y - GetLabelPosition(0, i - 1).y;
                 label.SetTextActive(dist > label.text.GetPreferredHeight());
             }
         }
     }
 }
        internal static void DrawAxisTick(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
                                          Orient orient, float startX, float startY, float axisLength)
        {
            var lineWidth  = axis.axisLine.GetWidth(theme.lineWidth);
            var tickLength = axis.axisTick.GetLength(theme.tickLength);

            if (AxisHelper.NeedShowSplit(axis))
            {
                var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);

                var current = orient == Orient.Horizonal ?
                              startX :
                              startY;

                for (int i = 0; i < size; i++)
                {
                    var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
                    if (i == 0 && (!axis.axisTick.showStartTick || axis.axisTick.alignWithLabel))
                    {
                        current += scaleWidth;
                        continue;
                    }
                    if (i == size - 1 && !axis.axisTick.showEndTick)
                    {
                        current += scaleWidth;
                        continue;
                    }
                    if (axis.axisTick.show)
                    {
                        if (orient == Orient.Horizonal)
                        {
                            float pX = axis.IsTime() ?
                                       (startX + axis.GetDistance(axis.GetLabelValue(i), axisLength)) :
                                       current;

                            if (axis.boundaryGap && axis.axisTick.alignWithLabel)
                            {
                                pX -= scaleWidth / 2;
                            }

                            var sY = 0f;
                            var eY = 0f;
                            if ((axis.axisTick.inside && axis.IsBottom()) ||
                                (!axis.axisTick.inside && axis.IsTop()))
                            {
                                sY = startY + lineWidth;
                                eY = sY + tickLength;
                            }
                            else
                            {
                                sY = startY - lineWidth;
                                eY = sY - tickLength;
                            }

                            UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY),
                                         axis.axisTick.GetWidth(theme.tickWidth),
                                         axis.axisTick.GetColor(theme.tickColor));
                        }
                        else
                        {
                            float pY = axis.IsTime() ?
                                       (startY + axis.GetDistance(axis.GetLabelValue(i), axisLength)) :
                                       current;

                            if (axis.boundaryGap && axis.axisTick.alignWithLabel)
                            {
                                pY -= scaleWidth / 2;
                            }

                            var sX = 0f;
                            var eX = 0f;
                            if ((axis.axisTick.inside && axis.IsLeft()) ||
                                (!axis.axisTick.inside && axis.IsRight()))
                            {
                                sX = startX + lineWidth;
                                eX = sX + tickLength;
                            }
                            else
                            {
                                sX = startX - lineWidth;
                                eX = sX - tickLength;
                            }

                            UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY),
                                         axis.axisTick.GetWidth(theme.tickWidth),
                                         axis.axisTick.GetColor(theme.tickColor));
                        }
                    }
                    current += scaleWidth;
                }
            }
            if (axis.show && axis.axisLine.show && axis.axisLine.showArrow)
            {
                var lineY     = startY + axis.offset;
                var inverse   = axis.IsValue() && axis.inverse;
                var axisArrow = axis.axisLine.arrow;
                if (orient == Orient.Horizonal)
                {
                    if (inverse)
                    {
                        var startPos = new Vector3(startX + axisLength, lineY);
                        var arrowPos = new Vector3(startX, lineY);
                        UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height,
                                      axisArrow.offset, axisArrow.dent,
                                      axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor)));
                    }
                    else
                    {
                        var arrowPosX = startX + axisLength + lineWidth;
                        var startPos  = new Vector3(startX, lineY);
                        var arrowPos  = new Vector3(arrowPosX, lineY);
                        UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height,
                                      axisArrow.offset, axisArrow.dent,
                                      axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor)));
                    }
                }
                else
                {
                    if (inverse)
                    {
                        var startPos = new Vector3(startX, startY + axisLength);
                        var arrowPos = new Vector3(startX, startY);
                        UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height,
                                      axisArrow.offset, axisArrow.dent,
                                      axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor)));
                    }
                    else
                    {
                        var startPos = new Vector3(startX, startY);
                        var arrowPos = new Vector3(startX, startY + axisLength + lineWidth);
                        UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height,
                                      axisArrow.offset, axisArrow.dent,
                                      axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor)));
                    }
                }
            }
        }
        internal static Vector3 GetLabelPosition(int i, Orient orient, Axis axis, Axis relativedAxis, AxisTheme theme,
                                                 float scaleWid, float axisStartX, float axisStartY, float axisLength, float relativedLength)
        {
            var inside   = axis.axisLabel.inside;
            var fontSize = axis.axisLabel.textStyle.GetFontSize(theme);
            var current  = axis.offset;

            if (axis.IsTime() || axis.IsValue())
            {
                scaleWid = axis.context.minMaxRange != 0 ?
                           axis.GetDistance(axis.GetLabelValue(i), axisLength) :
                           0;
            }

            if (orient == Orient.Horizonal)
            {
                if (axis.axisLabel.onZero && relativedAxis != null)
                {
                    axisStartY += relativedAxis.context.offset;
                }

                if (axis.IsTop())
                {
                    axisStartY += relativedLength;
                }

                if ((inside && axis.IsBottom()) || (!inside && axis.IsTop()))
                {
                    current += axisStartY + axis.axisLabel.distance + fontSize / 2;
                }
                else
                {
                    current += axisStartY - axis.axisLabel.distance - fontSize / 2;
                }

                return(new Vector3(axisStartX + scaleWid, current) + axis.axisLabel.offset);
            }
            else
            {
                if (axis.axisLabel.onZero && relativedAxis != null)
                {
                    axisStartX += relativedAxis.context.offset;
                }

                if (axis.IsRight())
                {
                    axisStartX += relativedLength;
                }

                if ((inside && axis.IsLeft()) || (!inside && axis.IsRight()))
                {
                    current += axisStartX + axis.axisLabel.distance;
                }
                else
                {
                    current += axisStartX - axis.axisLabel.distance;
                }

                return(new Vector3(current, axisStartY + scaleWid) + axis.axisLabel.offset);
            }
        }
        internal void UpdateAxisTickValueList(Axis axis)
        {
            if (axis.IsTime())
            {
                var lastCount = axis.context.labelValueList.Count;
                DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList, (int)axis.context.minValue,
                                                        (int)axis.context.maxValue, axis.splitNumber);

                if (axis.context.labelValueList.Count != lastCount)
                {
                    axis.SetAllDirty();
                }
            }
            else if (axis.IsValue())
            {
                var list      = axis.context.labelValueList;
                var lastCount = list.Count;
                list.Clear();

                var range = axis.context.maxValue - axis.context.minValue;
                if (range <= 0)
                {
                    return;
                }

                double tick = axis.interval;

                if (axis.interval == 0)
                {
                    if (axis.splitNumber > 0)
                    {
                        tick = range / axis.splitNumber;
                    }
                    else
                    {
                        var each = GetTick(range);
                        tick = each;
                        if (range / tick > 8)
                        {
                            tick = 2 * each;
                        }
                        else if (range / tick < 4)
                        {
                            tick = each / 2;
                        }
                    }
                }
                var value = 0d;
                if (Mathf.Approximately((float)(axis.context.minValue % tick), 0))
                {
                    value = axis.context.minValue;
                }
                else
                {
                    list.Add(axis.context.minValue);
                    value = Math.Ceiling(axis.context.minValue / tick) * tick;
                }
                var maxSplitNumber = chart.settings.axisMaxSplitNumber;
                while (value <= axis.context.maxValue)
                {
                    list.Add(value);
                    value += tick;

                    if (maxSplitNumber > 0 && list.Count > maxSplitNumber)
                    {
                        break;
                    }
                }
                if (!ChartHelper.IsEquals(axis.context.maxValue, list[list.Count - 1]))
                {
                    list.Add(axis.context.maxValue);
                }
                if (lastCount != list.Count)
                {
                    axis.SetAllDirty();
                }
            }
        }
        internal void UpdateAxisMinMaxValue(int axisIndex, Axis axis, bool updateChart = true)
        {
            if (!axis.show)
            {
                return;
            }

            if (axis.IsCategory())
            {
                axis.context.minValue    = 0;
                axis.context.maxValue    = SeriesHelper.GetMaxSerieDataCount(chart.series) - 1;
                axis.context.minMaxRange = axis.context.maxValue;
                return;
            }

            double tempMinValue = 0;
            double tempMaxValue = 0;

            chart.GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue);

            if (tempMinValue != axis.context.minValue ||
                tempMaxValue != axis.context.maxValue ||
                m_LastInterval != axis.interval ||
                m_LastSplitNumber != axis.splitNumber)
            {
                m_LastSplitNumber = axis.splitNumber;
                m_LastInterval    = axis.interval;

                axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
                axis.context.offset           = 0;
                axis.context.lastCheckInverse = axis.inverse;
                UpdateAxisTickValueList(axis);

                if (tempMinValue != 0 || tempMaxValue != 0)
                {
                    var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex);
                    if (grid != null && axis is XAxis && axis.IsValue())
                    {
                        axis.context.offset = axis.context.minValue > 0 ?
                                              0 :
                                              (axis.context.maxValue < 0 ?
                                               grid.context.width :
                                               (float)(Math.Abs(axis.context.minValue) * (grid.context.width /
                                                                                          (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue))))
                                              );
                        axis.context.x     = grid.context.x;
                        axis.context.y     = GetAxisLineXOrY();
                        axis.context.zeroY = grid.context.y;
                        axis.context.zeroX = grid.context.x - (float)(axis.context.minValue * grid.context.width / axis.context.minMaxRange);
                    }
                    if (grid != null && axis is YAxis && axis.IsValue())
                    {
                        axis.context.offset = axis.context.minValue > 0 ?
                                              0 :
                                              (axis.context.maxValue < 0 ?
                                               grid.context.height :
                                               (float)(Math.Abs(axis.context.minValue) * (grid.context.height /
                                                                                          (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue))))
                                              );
                        axis.context.x     = GetAxisLineXOrY();
                        axis.context.y     = grid.context.y;
                        axis.context.zeroX = grid.context.x;
                        axis.context.zeroY = grid.context.y - (float)(axis.context.minValue * grid.context.height / axis.context.minMaxRange);
                    }
                }
                var dataZoom = chart.GetDataZoomOfAxis(axis);
                if (dataZoom != null && dataZoom.enable)
                {
                    if (axis is XAxis)
                    {
                        dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
                    }
                    else
                    {
                        dataZoom.SetYAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
                    }
                }
                if (updateChart)
                {
                    UpdateAxisLabelText(axis);
                    chart.RefreshChart();
                }
            }
        }