public static void SetGaugeLabelText(Serie serie)
        {
            var serieData = serie.GetSerieData(0);

            if (serieData == null)
            {
                return;
            }
            if (serieData.labelObject == null)
            {
                return;
            }
            var label = SerieHelper.GetSerieLabel(serie, serieData);

            if (label == null)
            {
                return;
            }
            var value   = serieData.GetData(1);
            var total   = serie.max;
            var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);

            serieData.labelObject.SetText(content);
            serieData.labelObject.SetPosition(serie.context.center + label.offset);
            if (!ChartHelper.IsClearColor(label.textStyle.color))
            {
                serieData.labelObject.text.SetColor(label.textStyle.color);
            }
        }
 private void GetSerieDataIndexByItem(Serie serie, Axis axis, GridCoord grid, int dimension = 0)
 {
     if (serie.context.pointerItemDataIndex >= 0)
     {
         axis.context.axisTooltipValue = serie.GetSerieData(serie.context.pointerItemDataIndex).GetData(dimension);
     }
     else if (component.type == Tooltip.Type.Corss)
     {
         axis.context.axisTooltipValue = axis.context.pointerValue;
     }
     else
     {
         axis.context.axisTooltipValue = 0;
     }
 }
예제 #3
0
        private void DrawLinePoint(VertexHelper vh, Serie serie)
        {
            if (!serie.show || serie.IsPerformanceMode())
            {
                return;
            }

            if (m_SerieGrid == null)
            {
                return;
            }

            var count               = serie.context.dataPoints.Count;
            var clip                = SeriesHelper.IsAnyClipSerie(chart.series);
            var theme               = chart.theme;
            var interacting         = false;
            var lineArrow           = serie.lineArrow;
            var visualMap           = chart.GetVisualMapOfSerie(serie);
            var isVisualMapGradient = VisualMapHelper.IsNeedLineGradient(visualMap);

            Axis axis;
            Axis relativedAxis;
            var  isY = chart.GetSerieGridCoordAxis(serie, out axis, out relativedAxis);

            for (int i = 0; i < count; i++)
            {
                var serieData = serie.GetSerieData(i);
                if (serieData == null)
                {
                    continue;
                }
                if (serieData.context.isClip)
                {
                    continue;
                }

                var symbol = SerieHelper.GetSerieSymbol(serie, serieData);

                if (!symbol.show || !symbol.ShowSymbol(i, count))
                {
                    continue;
                }

                var pos = serie.context.dataPoints[i];
                if (lineArrow != null && lineArrow.show)
                {
                    if (lineArrow.position == LineArrow.Position.Start && i == 0)
                    {
                        continue;
                    }
                    if (lineArrow.position == LineArrow.Position.End && i == count - 1)
                    {
                        continue;
                    }
                }

                if (ChartHelper.IsIngore(pos))
                {
                    continue;
                }

                var highlight  = serie.data[i].context.highlight || serie.highlight;
                var symbolSize = highlight ?
                                 theme.serie.lineSymbolSelectedSize :
                                 theme.serie.lineSymbolSize;
                if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
                {
                    symbolSize = highlight ?
                                 symbol.GetSelectedSize(serieData.data, symbolSize) :
                                 symbol.GetSize(serieData.data, symbolSize);
                    serieData.interact.SetValue(ref interacting, symbolSize);
                    symbolSize = serie.animation.GetSysmbolSize(symbolSize);
                }
                var symbolColor      = SerieHelper.GetItemColor(serie, serieData, theme, serie.index, highlight);
                var symbolToColor    = SerieHelper.GetItemToColor(serie, serieData, theme, serie.index, highlight);
                var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, theme, serie.index, highlight, false);

                if (isVisualMapGradient)
                {
                    symbolColor   = VisualMapHelper.GetLineGradientColor(visualMap, pos, m_SerieGrid, axis, relativedAxis, symbolColor);
                    symbolToColor = symbolColor;
                }
                var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, theme, highlight);
                var borderColor  = SerieHelper.GetSymbolBorderColor(serie, serieData, theme, highlight);
                var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
                chart.DrawClipSymbol(vh, symbol.type, symbolSize, symbolBorder, pos,
                                     symbolColor, symbolToColor, symbolEmptyColor, borderColor, symbol.gap, clip, cornerRadius, m_SerieGrid,
                                     i > 0 ? serie.context.dataPoints[i - 1] : m_SerieGrid.context.position);
            }
            if (interacting)
            {
                if (SeriesHelper.IsStack(chart.series))
                {
                    chart.RefreshTopPainter();
                }
                else
                {
                    chart.RefreshPainter(serie);
                }
            }
        }
        /// <summary>
        /// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。
        /// </summary>
        /// <param name="content">要替换的字符串</param>
        /// <param name="dataIndex">选中的数据项serieData索引</param>
        /// <param name="numericFormatter">默认的数字格式化</param>
        /// <param name="serie">选中的serie</param>
        /// <param name="series">所有serie</param>
        /// <param name="theme">用来获取指定index的颜色</param>
        /// <param name="category">选中的类目,一般用在折线图和柱状图</param>
        /// <param name="dataZoom">dataZoom</param>
        /// <returns></returns>
        public static bool ReplaceContent(ref string content, int dataIndex, string numericFormatter, Serie serie,
                                          BaseChart chart, DataZoom dataZoom = null)
        {
            var foundDot = false;
            var mc       = s_Regex.Matches(content);

            foreach (var m in mc)
            {
                var old       = m.ToString();
                var args      = s_RegexSub.Matches(m.ToString());
                var argsCount = args.Count;
                if (argsCount <= 0)
                {
                    continue;
                }
                int  targetIndex = 0;
                char p           = GetSerieIndex(args[0].ToString(), ref targetIndex);
                if (targetIndex >= 0)
                {
                    serie = chart.GetSerie(targetIndex);
                    if (serie == null)
                    {
                        continue;
                    }
                }
                else if (serie != null)
                {
                    targetIndex = serie.index;
                }
                else
                {
                    serie       = chart.GetSerie(0);
                    targetIndex = 0;
                }
                if (serie == null)
                {
                    continue;
                }
                if (p == '.')
                {
                    var bIndex = targetIndex;
                    if (argsCount >= 2)
                    {
                        var args1Str = args[1].ToString();
                        if (s_RegexN.IsMatch(args1Str))
                        {
                            bIndex = int.Parse(args1Str);
                        }
                    }
                    content  = content.Replace(old, ChartCached.ColorToDotStr(chart.theme.GetColor(bIndex)));
                    foundDot = true;
                }
                else if (p == 'a' || p == 'A')
                {
                    if (argsCount == 1)
                    {
                        content = content.Replace(old, serie.serieName);
                    }
                }
                else if (p == 'b' || p == 'B' || p == 'e' || p == 'E')
                {
                    var bIndex = dataIndex;
                    if (argsCount >= 2)
                    {
                        var args1Str = args[1].ToString();
                        if (s_RegexN.IsMatch(args1Str))
                        {
                            bIndex = int.Parse(args1Str);
                        }
                    }
                    var needCategory = (p != 'e' && p != 'E') && (serie is Line || serie is Bar);
                    if (needCategory)
                    {
                        var category = chart.GetTooltipCategory(dataIndex, serie, dataZoom);
                        content = content.Replace(old, category);
                    }
                    else
                    {
                        var serieData = serie.GetSerieData(bIndex, dataZoom);
                        content = content.Replace(old, serieData.name);
                    }
                }
                else if (p == 'g' || p == 'G')
                {
                    content = content.Replace(old, ChartCached.NumberToStr(serie.dataCount, ""));
                }
                else if (p == 'c' || p == 'C' || p == 'd' || p == 'D' || p == 'f' || p == 'f')
                {
                    var isPercent      = p == 'd' || p == 'D';
                    var isTotal        = p == 'f' || p == 'f';
                    var bIndex         = dataIndex;
                    var dimensionIndex = -1;
                    if (argsCount >= 2)
                    {
                        var args1Str = args[1].ToString();
                        if (s_RegexFn.IsMatch(args1Str))
                        {
                            numericFormatter = args1Str;
                        }
                        else if (s_RegexN_N.IsMatch(args1Str))
                        {
                            var temp = args1Str.Split('-');
                            bIndex         = int.Parse(temp[0]);
                            dimensionIndex = int.Parse(temp[1]);
                        }
                        else if (s_RegexN.IsMatch(args1Str))
                        {
                            dimensionIndex = int.Parse(args1Str);
                        }
                        else
                        {
                            Debug.LogError("unmatch:" + args1Str);
                            continue;
                        }
                    }
                    if (argsCount >= 3)
                    {
                        numericFormatter = args[2].ToString();
                    }
                    if (dimensionIndex == -1)
                    {
                        dimensionIndex = 1;
                    }
                    if (numericFormatter == string.Empty)
                    {
                        numericFormatter = SerieHelper.GetNumericFormatter(serie, serie.GetSerieData(bIndex), "");
                    }
                    var value = serie.GetData(bIndex, dimensionIndex, dataZoom);
                    if (isPercent)
                    {
                        var total   = serie.GetDataTotal(dimensionIndex, serie.GetSerieData(bIndex));
                        var percent = total == 0 ? 0 : value / serie.yTotal * 100;
                        content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter));
                    }
                    else if (isTotal)
                    {
                        var total = serie.GetDataTotal(dimensionIndex, serie.GetSerieData(bIndex));
                        content = content.Replace(old, ChartCached.FloatToStr(total, numericFormatter));
                    }
                    else
                    {
                        content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
                    }
                }
            }
            content = s_RegexNewLine.Replace(content, PH_NN);
            return(foundDot);
        }
        private void GetSerieDataIndexByAxis(Serie serie, Axis axis, GridCoord grid, int dimension = 0)
        {
            var currValue       = 0d;
            var lastValue       = 0d;
            var nextValue       = 0d;
            var axisValue       = axis.context.pointerValue;
            var isTimeAxis      = axis.IsTime();
            var dataCount       = serie.dataCount;
            var themeSymbolSize = chart.theme.serie.scatterSymbolSize;
            var data            = serie.data;

            if (!isTimeAxis)
            {
                serie.context.sortedData.Clear();
                for (int i = 0; i < dataCount; i++)
                {
                    var serieData = serie.data[i];
                    serieData.index = i;
                    serie.context.sortedData.Add(serieData);
                }
                serie.context.sortedData.Sort(delegate(SerieData a, SerieData b)
                {
                    return(a.GetData(dimension).CompareTo(b.GetData(dimension)));
                });
                data = serie.context.sortedData;
            }
            serie.context.pointerAxisDataIndexs.Clear();
            for (int i = 0; i < dataCount; i++)
            {
                var serieData = data[i];
                currValue = serieData.GetData(dimension);
                if (i == 0)
                {
                    nextValue = data[i + 1].GetData(dimension);
                    if (axisValue <= currValue + (nextValue - currValue) / 2)
                    {
                        serie.context.pointerAxisDataIndexs.Add(serieData.index);
                        break;
                    }
                }
                else if (i == dataCount - 1)
                {
                    if (axisValue > lastValue + (currValue - lastValue) / 2)
                    {
                        serie.context.pointerAxisDataIndexs.Add(serieData.index);
                        break;
                    }
                }
                else
                {
                    nextValue = data[i + 1].GetData(dimension);
                    if (axisValue > (currValue - (currValue - lastValue) / 2) && axisValue <= currValue + (nextValue - currValue) / 2)
                    {
                        serie.context.pointerAxisDataIndexs.Add(serieData.index);
                        break;
                    }
                }
                lastValue = currValue;
            }
            if (serie.context.pointerAxisDataIndexs.Count > 0)
            {
                var index = serie.context.pointerAxisDataIndexs[0];
                serie.context.pointerItemDataIndex = index;
                axis.context.axisTooltipValue      = serie.GetSerieData(index).GetData(dimension);
            }
            else
            {
                serie.context.pointerItemDataIndex = -1;
                axis.context.axisTooltipValue      = 0;
            }
        }