Пример #1
0
 private void DrawMakLineData(VertexHelper vh, MarkLineData data, SerieAnimation animation, Serie serie,
                              Grid 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, lineColor, lineWidth, LineStyle.Type.Dashed);
         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);
         }
     }
 }
Пример #2
0
        public static Vector3 GetLabelPosition(MarkLineData data)
        {
            if (!data.label.show)
            {
                return(Vector3.zero);
            }
            var dir         = (data.runtimeEndPosition - data.runtimeStartPosition).normalized;
            var horizontal  = Mathf.Abs(Vector3.Dot(dir, Vector3.right)) == 1;
            var labelWidth  = data.runtimeLabel == null ? 50 : data.runtimeLabel.GetLabelWidth();
            var labelHeight = data.runtimeLabel == null ? 20 : data.runtimeLabel.GetLabelHeight();

            switch (data.label.position)
            {
            case SerieLabel.Position.Start:
                if (horizontal)
                {
                    return(data.runtimeStartPosition + data.label.offset + labelWidth / 2 * Vector3.left);
                }
                else
                {
                    return(data.runtimeStartPosition + data.label.offset + labelHeight / 2 * Vector3.down);
                }

            case SerieLabel.Position.Middle:
                var center = (data.runtimeStartPosition + data.runtimeCurrentEndPosition) / 2;
                if (horizontal)
                {
                    return(center + data.label.offset + labelHeight / 2 * Vector3.up);
                }
                else
                {
                    return(center + data.label.offset + labelWidth / 2 * Vector3.right);
                }

            default:
                if (horizontal)
                {
                    return(data.runtimeCurrentEndPosition + data.label.offset + labelWidth / 2 * Vector3.right);
                }
                else
                {
                    return(data.runtimeCurrentEndPosition + data.label.offset + labelHeight / 2 * Vector3.up);
                }
            }
        }
Пример #3
0
        public static string GetFormatterContent(Serie serie, MarkLineData data)
        {
            var serieLabel       = data.label;
            var numericFormatter = serieLabel.numericFormatter;

            if (serieLabel.formatterFunction != null)
            {
                return(serieLabel.formatterFunction(data.index, data.runtimeValue));
            }
            if (string.IsNullOrEmpty(serieLabel.formatter))
            {
                return(ChartCached.NumberToStr(data.runtimeValue, numericFormatter));
            }
            else
            {
                var content = serieLabel.formatter;
                FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, data.runtimeValue,
                                                         0, serie.name, data.name, Color.clear);
                return(content);
            }
        }
Пример #4
0
 private void InitMarkLineLabel(Serie serie, MarkLineData data, Color serieColor)
 {
     data.painter          = chart.m_PainterTop;
     data.refreshComponent = delegate()
     {
         var label    = data.label;
         var textName = string.Format("markLine_{0}_{1}", serie.index, data.index);
         var color    = !ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color : chart.theme.axis.textColor;
         var element  = ChartHelper.AddSerieLabel(textName, m_MarkLineLabelRoot.transform, label.backgroundWidth,
                                                  label.backgroundHeight, color, label.textStyle, chart.theme);
         var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0;
         var item       = new ChartLabel();
         item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom);
         item.SetIconActive(false);
         item.SetActive(data.label.show);
         item.SetPosition(MarkLineHelper.GetLabelPosition(data));
         item.SetText(MarkLineHelper.GetFormatterContent(serie, data));
         data.runtimeLabel = item;
     };
     data.refreshComponent();
 }
Пример #5
0
        private Vector3 GetSinglePos(Axis xAxis, Axis yAxis, Grid 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.runtimePosition);
                }
                else
                {
                    pX = data.xPosition != 0 ? grid.runtimeX + data.xPosition :
                         GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, data.xValue);
                    pY = data.yPosition != 0 ? grid.runtimeY + data.yPosition :
                         GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.yValue);
                    data.runtimeValue = data.yValue;
                    return(new Vector3(pX, pY));
                }

            default:
                return(grid.runtimePosition);
            }
        }