예제 #1
0
        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);
            }
        }
예제 #2
0
        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)));
                    }
                }
            }
        }
예제 #3
0
        protected void InitAxis(Axis relativedAxis, Orient orient,
                                float axisStartX, float axisStartY, float axisLength, float relativedLength)
        {
            Axis axis = component;

            chart.InitAxisRuntimeData(axis);

            var objName = ChartCached.GetComponentObjectName(axis);
            var axisObj = ChartHelper.AddObject(objName,
                                                chart.transform,
                                                chart.chartMinAnchor,
                                                chart.chartMaxAnchor,
                                                chart.chartPivot,
                                                chart.chartSizeDelta);

            axisObj.SetActive(axis.show);
            axisObj.hideFlags = chart.chartHideFlags;
            ChartHelper.HideAllObject(axisObj);

            axis.gameObject = axisObj;
            axis.context.labelObjectList.Clear();

            if (!axis.show)
            {
                return;
            }

            var axisLabelTextStyle = axis.axisLabel.textStyle;
            var dataZoom           = chart.GetDataZoomOfAxis(axis);
            var splitNumber        = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
            var totalWidth         = 0f;
            var eachWidth          = AxisHelper.GetEachWidth(axis, axisLength, dataZoom);
            var gapWidth           = axis.boundaryGap ? eachWidth / 2 : 0;

            var textWidth = axis.axisLabel.width > 0 ?
                            axis.axisLabel.width :
                            (orient == Orient.Horizonal ?
                             AxisHelper.GetScaleWidth(axis, axisLength, 0, dataZoom) :
                             (axisStartX - chart.chartX)
                            );

            var textHeight = axis.axisLabel.height > 0 ?
                             axis.axisLabel.height :
                             20f;

            var isPercentStack   = SeriesHelper.IsPercentStack <Bar>(chart.series);
            var inside           = axis.axisLabel.inside;
            var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter :
                                   ((inside && axis.IsLeft()) || (!inside && axis.IsRight()) ?
                                    TextAnchor.MiddleLeft :
                                    TextAnchor.MiddleRight);

            if (axis.IsCategory() && axis.boundaryGap)
            {
                splitNumber -= 1;
            }

            for (int i = 0; i < splitNumber; i++)
            {
                var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
                var labelName  = AxisHelper.GetLabelName(axis, axisLength, i,
                                                         axis.context.minValue,
                                                         axis.context.maxValue,
                                                         dataZoom, isPercentStack);

                var label = ChartHelper.AddAxisLabelObject(splitNumber, i,
                                                           ChartCached.GetAxisLabelName(i),
                                                           axisObj.transform,
                                                           new Vector2(textWidth, textHeight),
                                                           axis, chart.theme.axis, labelName,
                                                           Color.clear,
                                                           defaultAlignment);

                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(label.text, labelWidth);
                }

                var pos = GetLabelPosition(totalWidth + gapWidth, i);
                label.SetPosition(pos);
                CheckValueLabelActive(axis, i, label, pos);

                axis.context.labelObjectList.Add(label);

                totalWidth += labelWidth;
            }
            if (axis.axisName.show)
            {
                ChartLabel label         = null;
                var        relativedDist = (relativedAxis == null ? 0 : relativedAxis.context.offset);
                var        zeroPos       = new Vector3(axisStartX, axisStartY + relativedDist);
                var        offset        = axis.axisName.labelStyle.offset;
                var        autoColor     = axis.axisLine.GetColor(chart.theme.axis.lineColor);
                if (orient == Orient.Horizonal)
                {
                    var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex);
                    var posY = !axis.axisName.onZero && grid != null? grid.context.y : GetAxisLineXOrY() + offset.y;
                    switch (axis.axisName.labelStyle.position)
                    {
                    case LabelStyle.Position.Start:

                        label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
                                                          chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleRight);
                        label.SetActive(axis.axisName.labelStyle.show);
                        label.SetPosition(axis.position == Axis.AxisPosition.Top ?
                                          new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset) :
                                          new Vector2(zeroPos.x - offset.x, posY));
                        break;

                    case LabelStyle.Position.Middle:

                        label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
                                                          chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
                        label.SetActive(axis.axisName.labelStyle.show);
                        label.SetPosition(axis.position == Axis.AxisPosition.Top ?
                                          new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset) :
                                          new Vector2(axisStartX + axisLength / 2 + offset.x, posY));
                        break;

                    default:

                        label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
                                                          chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleLeft);
                        label.SetActive(axis.axisName.labelStyle.show);
                        label.SetPosition(axis.position == Axis.AxisPosition.Top ?
                                          new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset) :
                                          new Vector2(axisStartX + axisLength + offset.x, posY));
                        break;
                    }
                }
                else
                {
                    var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex);
                    var posX = !axis.axisName.onZero && grid != null? grid.context.x : GetAxisLineXOrY() + offset.x;
                    switch (axis.axisName.labelStyle.position)
                    {
                    case LabelStyle.Position.Start:

                        label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
                                                          chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
                        label.SetActive(axis.axisName.labelStyle.show);
                        label.SetPosition(axis.position == Axis.AxisPosition.Right ?
                                          new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY - offset.y) :
                                          new Vector2(posX, axisStartY - offset.y));
                        break;

                    case LabelStyle.Position.Middle:

                        label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
                                                          chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
                        label.SetActive(axis.axisName.labelStyle.show);
                        label.SetPosition(axis.position == Axis.AxisPosition.Right ?
                                          new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) :
                                          new Vector2(posX, axisStartY + axisLength / 2 + offset.y));
                        break;

                    default:
                        //LabelStyle.Position
                        label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
                                                          chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
                        label.SetActive(axis.axisName.labelStyle.show);
                        label.SetPosition(axis.position == Axis.AxisPosition.Right ?
                                          new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY + axisLength + offset.y) :
                                          new Vector2(posX, axisStartY + axisLength + offset.y));
                        break;
                    }
                }
            }
        }