private void DrawMakLineData(VertexHelper vh, MarkLineData data, AnimationStyle animation, Serie serie,
                              GridCoord grid, Color32 serieColor, Vector3 sp, Vector3 ep)
 {
     if (!animation.IsFinish())
     {
         ep = Vector3.Lerp(sp, ep, animation.GetCurrDetail());
     }
     data.runtimeCurrentEndPosition = ep;
     if (sp != Vector3.zero || ep != Vector3.zero)
     {
         m_RefreshLabel = true;
         chart.ClampInChart(ref sp);
         chart.ClampInChart(ref ep);
         var theme     = chart.theme.axis;
         var lineColor = ChartHelper.IsClearColor(data.lineStyle.color) ? serieColor : data.lineStyle.color;
         var lineWidth = data.lineStyle.width == 0 ? theme.lineWidth : data.lineStyle.width;
         ChartDrawer.DrawLineStyle(vh, data.lineStyle, sp, ep, lineWidth, LineStyle.Type.Dashed, lineColor, lineColor);
         if (data.startSymbol != null && data.startSymbol.show)
         {
             DrawMarkLineSymbol(vh, data.startSymbol, serie, grid, chart.theme, sp, sp, lineColor);
         }
         if (data.endSymbol != null && data.endSymbol.show)
         {
             DrawMarkLineSymbol(vh, data.endSymbol, serie, grid, chart.theme, ep, sp, lineColor);
         }
     }
 }
        private void InitMarkLineLabel(Serie serie, MarkLineData data, Color serieColor)
        {
            data.painter          = chart.m_PainterUpper;
            data.refreshComponent = delegate()
            {
                var textName = string.Format("markLine_{0}_{1}", serie.index, data.index);
                var content  = MarkLineHelper.GetFormatterContent(serie, data);
                var label    = ChartHelper.AddChartLabel(textName, m_MarkLineLabelRoot.transform, data.label, chart.theme.axis,
                                                         content, Color.clear, TextAnchor.MiddleCenter);

                label.SetIconActive(false);
                label.SetActive(data.label.show);
                label.SetPosition(MarkLineHelper.GetLabelPosition(data));
                data.runtimeLabel = label;
            };
            data.refreshComponent();
        }
        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.GetTextWidth();
            var labelHeight = data.runtimeLabel == null ? 20 : data.runtimeLabel.GetTextHeight();

            switch (data.label.position)
            {
            case LabelStyle.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 LabelStyle.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);
                }
            }
        }
예제 #4
0
        public override void SetDefaultValue()
        {
            data.Clear();
            var item = new MarkLineData();

            item.name                   = "average";
            item.type                   = MarkLineType.Average;
            item.lineStyle.type         = LineStyle.Type.Dashed;
            item.lineStyle.color        = Color.clear;
            item.startSymbol.show       = true;
            item.startSymbol.type       = SymbolType.Circle;
            item.startSymbol.size       = 4;
            item.endSymbol.show         = true;
            item.endSymbol.type         = SymbolType.Arrow;
            item.endSymbol.size         = 5;
            item.label.show             = true;
            item.label.numericFormatter = "f1";
            item.label.formatter        = "{c}";
            data.Add(item);
        }
        public static string GetFormatterContent(Serie serie, MarkLineData data)
        {
            var serieLabel       = data.label;
            var numericFormatter = serieLabel.numericFormatter;

            if (string.IsNullOrEmpty(serieLabel.formatter))
            {
                var content = ChartCached.NumberToStr(data.runtimeValue, numericFormatter);
                return(serieLabel.formatterFunction == null? content:
                       serieLabel.formatterFunction(data.index, data.runtimeValue, null, content));
            }
            else
            {
                var content = serieLabel.formatter;
                FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, data.runtimeValue,
                                                         0, serie.serieName, data.name, data.name, Color.clear, null);
                return(serieLabel.formatterFunction == null? content:
                       serieLabel.formatterFunction(data.index, data.runtimeValue, null, content));
            }
        }
        private Vector3 GetSinglePos(Axis xAxis, Axis yAxis, GridCoord grid, Serie serie, DataZoom dataZoom, MarkLineData data,
                                     int serieDataCount)
        {
            switch (data.type)
            {
            case MarkLineType.Min:
                var serieData = SerieHelper.GetMinSerieData(serie, data.dimension, dataZoom);
                data.runtimeValue = serieData.GetData(data.dimension);
                var pX = GetAxisPosition(grid, xAxis, dataZoom, serieDataCount, serieData.index);
                var pY = GetAxisPosition(grid, yAxis, dataZoom, serieDataCount, data.runtimeValue);
                return(new Vector3(pX, pY));

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

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

            default:
                return(grid.context.position);
            }
        }