コード例 #1
0
        /// <summary>
        /// 获得分割段宽度
        /// </summary>
        /// <param name="coordinateWidth"></param>
        /// <param name="dataZoom"></param>
        /// <returns></returns>
        internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
        {
            if (index < 0)
            {
                return(0);
            }
            int num      = GetScaleNumber(axis, coordinateWidth, dataZoom);
            int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);

            if (num <= 0)
            {
                num = 1;
            }
            if (axis.type == Axis.AxisType.Value && axis.interval > 0)
            {
                if (axis.runtimeMinMaxRange <= 0)
                {
                    return(0);
                }
                if (index >= splitNum)
                {
                    return(coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange);
                }
                else
                {
                    return(axis.interval * coordinateWidth / axis.runtimeMinMaxRange);
                }
            }
            else
            {
                if (axis.IsCategory() && axis.data.Count > 0)
                {
                    int tick  = Mathf.RoundToInt(axis.data.Count * 1f / splitNum);
                    var count = axis.boundaryGap ? axis.data.Count : axis.data.Count - 1;
                    if (count <= 0)
                    {
                        return(0);
                    }
                    var each = coordinateWidth / count;
                    if (index >= num - 1)
                    {
                        if (axis.axisTick.alignWithLabel)
                        {
                            return(each * tick);
                        }
                        else
                        {
                            return(coordinateWidth - each * tick * (index - 1));
                        }
                    }
                    else
                    {
                        return(each * tick);
                    }
                }
                else
                {
                    if (splitNum <= 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(coordinateWidth / splitNum);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Tooltip.cs プロジェクト: FZY173/Unity3dProject
 public string GetFormatterContent(int dataIndex, Series series, string category, DataZoom dataZoom = null)
 {
     if (string.IsNullOrEmpty(m_Formatter))
     {
         return("");
     }
     else
     {
         string content = m_Formatter;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.show)
             {
                 var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
                 var serieData    = serie.GetSerieData(dataIndex, dataZoom);
                 if (i == 0)
                 {
                     content = content.Replace("{a}", serie.name);
                     content = content.Replace("{b}", needCategory ? category : serieData.name);
                     content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1)));
                     //if (serie.type == SerieType.Pie)
                     {
                         var percent = serieData.GetData(1) / serie.yTotal * 100;
                         content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                     }
                 }
                 content = content.Replace("{a" + i + "}", serie.name);
                 content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name);
                 content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1)));
                 //if (serie.type == SerieType.Pie)
                 {
                     var percent = serieData.GetData(1) / serie.yTotal * 100;
                     content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
                 }
             }
         }
         content = content.Replace("\\n", "\n");
         content = content.Replace("<br/>", "\n");
         return(content);
     }
 }
コード例 #3
0
        /// <summary>
        /// 获得指定维数的最大最小值
        /// </summary>
        /// <param name="dimension"></param>
        /// <param name="dataZoom"></param>
        /// <returns></returns>
        public void GetMinMaxData(int dimension, out float minValue, out float maxValue, DataZoom dataZoom = null)
        {
            var   dataList = GetDataList(dataZoom);
            float max      = float.MinValue;
            float min      = float.MaxValue;

            for (int i = 0; i < dataList.Count; i++)
            {
                var serieData = dataList[i];
                if (serieData.data.Count > dimension)
                {
                    var value = serieData.data[dimension];
                    if (value > max)
                    {
                        max = value;
                    }
                    if (value < min)
                    {
                        min = value;
                    }
                }
            }
            maxValue = max;
            minValue = min;
        }
コード例 #4
0
 private void OnDragSlider(DataZoom dataZoom, float deltaPercent)
 {
     if (Input.touchCount > 1)
     {
         return;
     }
     if (!dataZoom.supportSlider)
     {
         return;
     }
     if (dataZoom.runtimeStartDrag)
     {
         dataZoom.start += deltaPercent;
         if (dataZoom.start > dataZoom.end)
         {
             dataZoom.start            = dataZoom.end;
             dataZoom.runtimeEndDrag   = true;
             dataZoom.runtimeStartDrag = false;
         }
         if (dataZoom.realtime)
         {
             RefreshDataZoomLabel();
             chart.RefreshChart();
         }
     }
     else if (dataZoom.runtimeEndDrag)
     {
         dataZoom.end += deltaPercent;
         if (dataZoom.end < dataZoom.start)
         {
             dataZoom.end = dataZoom.start;
             dataZoom.runtimeStartDrag = true;
             dataZoom.runtimeEndDrag   = false;
         }
         if (dataZoom.realtime)
         {
             RefreshDataZoomLabel();
             chart.RefreshChart();
         }
     }
     else if (dataZoom.runtimeDrag)
     {
         if (deltaPercent > 0)
         {
             if (dataZoom.end + deltaPercent > 100)
             {
                 deltaPercent = 100 - dataZoom.end;
             }
         }
         else
         {
             if (dataZoom.start + deltaPercent < 0)
             {
                 deltaPercent = -dataZoom.start;
             }
         }
         dataZoom.start += deltaPercent;
         dataZoom.end   += deltaPercent;
         if (dataZoom.realtime)
         {
             RefreshDataZoomLabel();
             chart.RefreshChart();
         }
     }
 }
コード例 #5
0
        internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
                                            bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false)
        {
            float min            = int.MaxValue;
            float max            = int.MinValue;
            var   isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar);

            if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue))
            {
                for (int i = 0; i < series.list.Count; i++)
                {
                    var serie = series.GetSerie(i);
                    if ((isPolar && serie.polarIndex != axisIndex) ||
                        (!isPolar && serie.yAxisIndex != axisIndex))
                    {
                        continue;
                    }
                    if (series.IsActive(i))
                    {
                        if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
                        {
                            if (100 > max)
                            {
                                max = 100;
                            }
                            if (0 < min)
                            {
                                min = 0;
                            }
                        }
                        else
                        {
                            var showData = serie.GetDataList(dataZoom);
                            foreach (var data in showData)
                            {
                                if (serie.type == SerieType.Candlestick)
                                {
                                    var dataMin = data.min;
                                    var dataMax = data.max;
                                    if (dataMax > max)
                                    {
                                        max = dataMax;
                                    }
                                    if (dataMin < min)
                                    {
                                        min = dataMin;
                                    }
                                }
                                else
                                {
                                    var currData = data.GetData(yValue ? 1 : 0, inverse);
                                    if (currData > max)
                                    {
                                        max = currData;
                                    }
                                    if (currData < min)
                                    {
                                        min = currData;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax);
                foreach (var ss in _stackSeriesForMinMax)
                {
                    _serieTotalValueForMinMax.Clear();
                    for (int i = 0; i < ss.Value.Count; i++)
                    {
                        var serie = ss.Value[i];
                        if ((isPolar && serie.polarIndex != axisIndex) ||
                            (!isPolar && serie.yAxisIndex != axisIndex) ||
                            !series.IsActive(i))
                        {
                            continue;
                        }
                        var showData = serie.GetDataList(dataZoom);
                        if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar))
                        {
                            for (int j = 0; j < showData.Count; j++)
                            {
                                _serieTotalValueForMinMax[j] = 100;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < showData.Count; j++)
                            {
                                if (!_serieTotalValueForMinMax.ContainsKey(j))
                                {
                                    _serieTotalValueForMinMax[j] = 0;
                                }
                                var currData = 0f;
                                if (serie.type == SerieType.Candlestick)
                                {
                                    currData = showData[j].max;
                                }
                                else
                                {
                                    currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
                                }
                                if (inverse)
                                {
                                    currData = -currData;
                                }
                                _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
                            }
                        }
                    }
                    float tmax = int.MinValue;
                    float tmin = int.MaxValue;
                    foreach (var tt in _serieTotalValueForMinMax)
                    {
                        if (tt.Value > tmax)
                        {
                            tmax = tt.Value;
                        }
                        if (tt.Value < tmin)
                        {
                            tmin = tt.Value;
                        }
                    }
                    if (tmax > max)
                    {
                        max = tmax;
                    }
                    if (tmin < min)
                    {
                        min = tmin;
                    }
                }
            }
            if (max == int.MinValue && min == int.MaxValue)
            {
                minVaule = 0;
                maxValue = 0;
            }
            else
            {
                minVaule = min > 1 ? Mathf.FloorToInt(min) : min;
                maxValue = max > 1 ? Mathf.CeilToInt(max) : max;
            }
        }
コード例 #6
0
ファイル: Axis.cs プロジェクト: inquick/unity-ugui-XCharts
        public float GetDataWidth(float coordinateWidth, DataZoom dataZoom)
        {
            var dataCount = GetDataNumber(dataZoom);

            return(coordinateWidth / (m_BoundaryGap ? dataCount : dataCount - 1));
        }
コード例 #7
0
        private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                               string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null, bool isCartesian = false)
        {
            switch (serie.type)
            {
            case SerieType.Line:
            case SerieType.Bar:
                InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom);
                break;

            case SerieType.Scatter:
            case SerieType.EffectScatter:
                InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo);
                break;

            case SerieType.Radar:
                break;

            case SerieType.Pie:
                InitPieTooltip(ref sb, tooltip, serie, index, themeInfo);
                break;

            case SerieType.Ring:
                InitRingTooltip(ref sb, tooltip, serie, index, themeInfo);
                break;

            case SerieType.Heatmap:
                break;

            case SerieType.Gauge:
                break;
            }
        }
コード例 #8
0
        public void GetMinMaxValue(DataZoom dataZoom, out int minVaule, out int maxValue)
        {
            float min = int.MaxValue;
            float max = int.MinValue;

            if (IsStack())
            {
                var stackSeries = GetStackSeries();
                foreach (var ss in stackSeries)
                {
                    var seriesTotalValue = new Dictionary <int, float>();
                    for (int i = 0; i < ss.Value.Count; i++)
                    {
                        var serie    = ss.Value[i];
                        var showData = serie.GetData(dataZoom);
                        for (int j = 0; j < showData.Count; j++)
                        {
                            if (!seriesTotalValue.ContainsKey(j))
                            {
                                seriesTotalValue[j] = 0;
                            }
                            seriesTotalValue[j] = seriesTotalValue[j] + showData[j];
                        }
                    }
                    float tmax = int.MinValue;
                    float tmin = int.MaxValue;
                    foreach (var tt in seriesTotalValue)
                    {
                        if (tt.Value > tmax)
                        {
                            tmax = tt.Value;
                        }
                        if (tt.Value < tmin)
                        {
                            tmin = tt.Value;
                        }
                    }
                    if (tmax > max)
                    {
                        max = tmax;
                    }
                    if (tmin < min)
                    {
                        min = tmin;
                    }
                }
            }
            else
            {
                for (int i = 0; i < m_Series.Count; i++)
                {
                    if (IsActive(i))
                    {
                        if (dataZoom != null && dataZoom.show)
                        {
                            var showData = m_Series[i].GetData(dataZoom);
                            foreach (var data in showData)
                            {
                                if (data > max)
                                {
                                    max = data;
                                }
                                if (data < min)
                                {
                                    min = data;
                                }
                            }
                        }
                        else
                        {
                            if (m_Series[i].Max > max)
                            {
                                max = m_Series[i].Max;
                            }
                            if (m_Series[i].Min < min)
                            {
                                min = m_Series[i].Min;
                            }
                        }
                    }
                }
            }
            if (max == int.MinValue && min == int.MaxValue)
            {
                minVaule = 0;
                maxValue = 100;
            }
            else
            {
                minVaule = (int)min;
                maxValue = (int)max;
            }
        }
コード例 #9
0
 /// <summary>
 /// 获得类目数据个数
 /// </summary>
 /// <param name="dataZoom"></param>
 /// <returns></returns>
 internal int GetDataNumber(DataZoom dataZoom)
 {
     return(GetDataList(dataZoom).Count);
 }
コード例 #10
0
        /// <summary>
        /// 获得指定维数的最大最小值
        /// </summary>
        /// <param name="dimension"></param>
        /// <param name="dataZoom"></param>
        /// <returns></returns>
        public static void GetDimensionMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null)
        {
            var   dataList = serie.GetDataList(dataZoom);
            float max      = float.MinValue;
            float min      = float.MaxValue;

            for (int i = 0; i < dataList.Count; i++)
            {
                var serieData = dataList[i];
                if (serieData.show && serieData.data.Count > dimension)
                {
                    var value = serieData.data[dimension];
                    if (value > max)
                    {
                        max = value;
                    }
                    if (value < min)
                    {
                        min = value;
                    }
                }
            }
            serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
            serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
        }
コード例 #11
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, DataZoom dataZoom = null, bool isCartesian = false)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb           = ChartHelper.sb;
         var title        = tooltip.titleFormatter;
         var formatTitle  = !string.IsNullOrEmpty(title);
         var needCategory = false;
         var first        = true;
         var isScatter    = false;
         sb.Length = 0;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter    = GetItemFormatter(tooltip, serie, null);
                     var numericFormatter = GetItemNumericFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         ReplaceContent(ref itemTitle, dataIndex, tooltip, serie, null, themeInfo, category, dataZoom, isCartesian);
                         sb.Append(itemTitle).Append(PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         string content  = itemFormatter;
                         var    foundDot = ReplaceContent(ref content, tempIndex, tooltip, serie, null, themeInfo, category, dataZoom, isCartesian);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(PH_NN);
                     }
                 }
             }
             else
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     ReplaceContent(ref title, dataIndex, tooltip, null, series, themeInfo, category, dataZoom, isCartesian);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     ReplaceContent(ref content, dataIndex, tooltip, serie, null, themeInfo, category, dataZoom, isCartesian);
                     if (!first)
                     {
                         sb.Append(PH_NN);
                     }
                     sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory)
             {
                 return(category + PH_NN + TrimAndReplaceLine(sb));
             }
             else
             {
                 return(TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = s_RegexNewLine.Replace(title, PH_NN);
             return(title + PH_NN + TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         ReplaceContent(ref content, dataIndex, tooltip, null, series, themeInfo, category, dataZoom, isCartesian);
         return(content);
     }
 }
コード例 #12
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, DataZoom dataZoom = null, bool isCartesian = false, Radar radar = null)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb            = ChartHelper.sb;
         var title         = tooltip.titleFormatter;
         var formatTitle   = !string.IsNullOrEmpty(title);
         var titleIsIgnroe = false;
         var needCategory  = false;
         var first         = true;
         var isScatter     = false;
         sb.Length = 0;
         if ("{i}".Equals(tooltip.titleFormatter))
         {
             title         = string.Empty;
             formatTitle   = false;
             titleIsIgnroe = true;
         }
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter = GetItemFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(FormatterHelper.PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                         sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         string content  = itemFormatter;
                         var    foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(FormatterHelper.PH_NN);
                     }
                 }
             }
             else if (IsNeedTooltipSerie(serie, tooltip))
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar)
                     {
                         if (!first)
                         {
                             sb.Append(FormatterHelper.PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                     if (!first)
                     {
                         sb.Append(FormatterHelper.PH_NN);
                     }
                     var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : i;
                     sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(FormatterHelper.TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory && !titleIsIgnroe)
             {
                 return(category + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
             }
             else
             {
                 return(FormatterHelper.TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = FormatterHelper.TrimAndReplaceLine(title);
             return(title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, themeInfo, category, dataZoom);
         return(content);
     }
 }
コード例 #13
0
        private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                                  ChartTheme theme, bool isCartesian, DataZoom dataZoom = null)
        {
            string key = serie.name;
            float  xValue, yValue;

            serie.GetXYData(index, dataZoom, out xValue, out yValue);
            var isIngore         = serie.IsIgnorePoint(index);
            var serieData        = serie.GetSerieData(index, dataZoom);
            var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);

            if (isCartesian)
            {
                if (serieData != null && serieData.highlighted)
                {
                    sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
                    sb.Append("[").Append(ChartCached.FloatToStr(xValue, numericFormatter)).Append(",")
                    .Append(ChartCached.FloatToStr(yValue, numericFormatter)).Append("]");
                }
            }
            else if (!isIngore || (isIngore && tooltip.ignoreDataShow))
            {
                var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
                               ChartCached.FloatToStr(yValue, numericFormatter);
                sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
                if (serie.type == SerieType.Candlestick)
                {
                    sb.Append(key).Append(FormatterHelper.PH_NN);
                    var data     = serieData.data;
                    var open     = ChartCached.FloatToStr(data[0], numericFormatter);
                    var close    = ChartCached.FloatToStr(data[1], numericFormatter);
                    var lowest   = ChartCached.FloatToStr(data[2], numericFormatter);
                    var heighest = ChartCached.FloatToStr(data[3], numericFormatter);
                    sb.Append("   open: ").Append(open).Append(FormatterHelper.PH_NN);
                    sb.Append("   close: ").Append(close).Append(FormatterHelper.PH_NN);
                    sb.Append("   lowest: ").Append(lowest).Append(FormatterHelper.PH_NN);
                    sb.Append("   heighest: ").Append(heighest).Append(FormatterHelper.PH_NN);
                }
                else
                {
                    sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
                    sb.Append(valueTxt);
                }
            }
        }
コード例 #14
0
 /// <summary>
 /// 获得维度X的最大最小值
 /// </summary>
 /// <param name="dataZoom"></param>
 /// <param name="axisIndex"></param>
 /// <param name="minVaule"></param>
 /// <param name="maxValue"></param>
 public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis,
                             out int minVaule, out int maxValue)
 {
     GetMinMaxValue(dataZoom, axisIndex, isValueAxis, false, out minVaule, out maxValue);
 }
コード例 #15
0
ファイル: Axis.cs プロジェクト: inquick/unity-ugui-XCharts
 public float GetSplitWidth(float coordinateWidth, DataZoom dataZoom)
 {
     return(coordinateWidth / (m_BoundaryGap ? GetSplitNumber(dataZoom) : GetSplitNumber(dataZoom) - 1));
 }
コード例 #16
0
        /// <summary>
        /// 获得标签显示的名称
        /// </summary>
        /// <param name="index"></param>
        /// <param name="minValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="dataZoom"></param>
        /// <returns></returns>
        internal string GetLabelName(float coordinateWidth, int index, float minValue, float maxValue,
                                     DataZoom dataZoom, bool forcePercent)
        {
            int split = GetSplitNumber(coordinateWidth, dataZoom);

            if (m_Type == AxisType.Value)
            {
                if (minValue == 0 && maxValue == 0)
                {
                    return(string.Empty);
                }
                float value = 0;
                if (forcePercent)
                {
                    maxValue = 100;
                }
                if (m_Interval > 0)
                {
                    if (index == split - 1)
                    {
                        value = maxValue;
                    }
                    else
                    {
                        value = minValue + index * m_Interval;
                    }
                }
                else
                {
                    value = (minValue + (maxValue - minValue) * index / (split - 1));
                }
                if (forcePercent)
                {
                    return(string.Format("{0}%", (int)value));
                }
                else
                {
                    return(m_AxisLabel.GetFormatterContent(value, minValue, maxValue));
                }
            }
            else if (m_Type == AxisType.Log)
            {
                float value = m_LogBaseE ? Mathf.Exp(runtimeMinLogIndex + index) :
                              Mathf.Pow(m_LogBase, runtimeMinLogIndex + index);
                return(m_AxisLabel.GetFormatterContent(value, minValue, maxValue, true));
            }
            var showData  = GetDataList(dataZoom);
            int dataCount = showData.Count;

            if (dataCount <= 0)
            {
                return("");
            }

            if (index == split - 1 && !m_BoundaryGap)
            {
                return(m_AxisLabel.GetFormatterContent(showData[dataCount - 1]));
            }
            else
            {
                float rate = dataCount / split;
                if (rate < 1)
                {
                    rate = 1;
                }
                int offset   = m_BoundaryGap ? (int)(rate / 2) : 0;
                int newIndex = (int)(index * rate >= dataCount - 1 ?
                                     dataCount - 1 : offset + index * rate);
                return(m_AxisLabel.GetFormatterContent(showData[newIndex]));
            }
        }
コード例 #17
0
ファイル: Axis.cs プロジェクト: inquick/unity-ugui-XCharts
 public int GetDataNumber(DataZoom dataZoom)
 {
     return(GetData(dataZoom).Count);
 }
コード例 #18
0
        /// <summary>
        /// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}。
        /// </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="themeInfo">用来获取指定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, Series series,
                                          ThemeInfo themeInfo, string category = null, 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 = series.GetSerie(targetIndex);
                    if (serie == null)
                    {
                        continue;
                    }
                }
                else if (serie != null)
                {
                    targetIndex = serie.index;
                }
                else
                {
                    serie       = series.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(themeInfo.GetColor(bIndex)));
                    foundDot = true;
                }
                else if (p == 'a' || p == 'A')
                {
                    if (argsCount == 1)
                    {
                        content = content.Replace(old, serie.name);
                    }
                }
                else if (p == 'b' || p == 'B')
                {
                    var bIndex = dataIndex;
                    if (argsCount >= 2)
                    {
                        var args1Str = args[1].ToString();
                        if (s_RegexN.IsMatch(args1Str))
                        {
                            bIndex = int.Parse(args1Str);
                        }
                    }
                    var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
                    if (needCategory)
                    {
                        content = content.Replace(old, category);
                    }
                    else
                    {
                        var serieData = serie.GetSerieData(bIndex, dataZoom);
                        content = content.Replace(old, serieData.name);
                    }
                }
                else if (p == 'c' || p == 'C' || p == 'd' || p == 'D')
                {
                    var isPercent      = p == 'd' || p == 'D';
                    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);
                        var percent = total == 0 ? 0 : value / serie.yTotal * 100;
                        content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter));
                    }
                    else
                    {
                        content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
                    }
                }
            }
            content = s_RegexNewLine.Replace(content, PH_NN);
            return(foundDot);
        }
コード例 #19
0
        private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                                  ThemeInfo themeInfo, bool isCartesian, DataZoom dataZoom = null)
        {
            string key = serie.name;
            float  xValue, yValue;

            serie.GetXYData(index, dataZoom, out xValue, out yValue);
            var isIngore         = serie.IsIgnorePoint(index);
            var serieData        = serie.GetSerieData(index, dataZoom);
            var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);

            if (isCartesian)
            {
                if (serieData != null && serieData.highlighted)
                {
                    sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
                    sb.Append("[").Append(ChartCached.FloatToStr(xValue, numericFormatter)).Append(",")
                    .Append(ChartCached.FloatToStr(yValue, numericFormatter)).Append("]");
                }
            }
            else
            {
                var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
                               ChartCached.FloatToStr(yValue, numericFormatter);
                sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>")
                .Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
                .Append(valueTxt);
            }
        }
コード例 #20
0
ファイル: Series.cs プロジェクト: 04maoj/Pens-Up
 /// <summary>
 /// 获得维度Y的最大最小值
 /// </summary>
 /// <param name="dataZoom"></param>
 /// <param name="axisIndex"></param>
 /// <param name="minVaule"></param>
 /// <param name="maxValue"></param>
 public void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
 {
     GetMinMaxValue(dataZoom, axisIndex, true, out minVaule, out maxValue);
 }
コード例 #21
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, DataZoom dataZoom = null, bool isCartesian = false)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb           = ChartHelper.sb;
         var title        = tooltip.titleFormatter;
         var formatTitle  = !string.IsNullOrEmpty(title);
         var needCategory = false;
         var first        = true;
         var isScatter    = false;
         sb.Length = 0;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter    = GetItemFormatter(tooltip, serie, null);
                     var numericFormatter = GetItemNumericFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         Replace(ref itemTitle, PH_A, i, serie.name, true);
                         sb.Append(itemTitle).Append(PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         var    foundDot  = false;
                         var    serieData = serie.GetSerieData(tempIndex);
                         string content   = itemFormatter;
                         Replace(ref content, PH_A, i, serie.name, true);
                         Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true);
                         if (itemFormatter.IndexOf(PH_I) >= 0)
                         {
                             foundDot = true;
                             Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)), true);
                         }
                         for (int n = 0; n < serieData.data.Count; n++)
                         {
                             var valueStr = ChartCached.FloatToStr(serieData.GetData(n), numericFormatter);
                             Replace(ref content, GetPHCC(n), i, valueStr, true);
                         }
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(PH_NN);
                     }
                 }
             }
             else
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var itemFormatter    = GetItemFormatter(tooltip, serie, serieData);
                 var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
                 var percent          = serieData.GetData(1) / serie.yTotal * 100;
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     var valueStr = ChartCached.FloatToStr(serieData.GetData(1), numericFormatter);
                     Replace(ref title, PH_A, i, serie.name, true);
                     Replace(ref title, PH_B, i, needCategory ? category : serieData.name, true);
                     Replace(ref title, PH_C, i, valueStr, true);
                     Replace(ref title, PH_D, i, ChartCached.FloatToStr(percent, string.Empty, 1), true);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     string content  = itemFormatter;
                     var    valueStr = ChartCached.FloatToStr(serieData.GetData(1), numericFormatter);
                     Replace(ref content, PH_A, i, serie.name, true);
                     Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true);
                     Replace(ref content, PH_C, i, valueStr, true);
                     Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, string.Empty, 1), true);
                     for (int n = 0; n < serieData.data.Count; n++)
                     {
                         valueStr = ChartCached.FloatToStr(serieData.GetData(n), numericFormatter);
                         Replace(ref content, GetPHCC(n), i, valueStr, true);
                     }
                     if (!first)
                     {
                         sb.Append(PH_NN);
                     }
                     sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory)
             {
                 return(category + PH_NN + TrimAndReplaceLine(sb));
             }
             else
             {
                 return(TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = title.Replace(PH_ON, PH_NN);
             title = title.Replace(PH_BR, PH_NN);
             return(title + PH_NN + TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.show)
             {
                 var needCategory     = serie.type == SerieType.Line || serie.type == SerieType.Bar;
                 var serieData        = serie.GetSerieData(dataIndex, dataZoom);
                 var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
                 var percent          = serieData.GetData(1) / serie.yTotal * 100;
                 Replace(ref content, PH_A, i, serie.name);
                 Replace(ref content, PH_B, i, needCategory ? category : serieData.name);
                 Replace(ref content, PH_C, i, ChartCached.FloatToStr(serieData.GetData(1), numericFormatter));
                 Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, string.Empty, 1));
                 Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
                 for (int n = 0; n < serieData.data.Count; n++)
                 {
                     var valueStr = ChartCached.FloatToStr(serieData.GetData(n), numericFormatter);
                     if (i == 0)
                     {
                         Replace(ref content, GetPHCC(n), i, valueStr, true);
                     }
                     Replace(ref content, GetPHCC(i, n), i, valueStr, true);
                 }
             }
         }
         content = content.Replace(PH_ON, PH_NN);
         content = content.Replace(PH_BR, PH_NN);
         return(content);
     }
 }
コード例 #22
0
ファイル: Series.cs プロジェクト: 04maoj/Pens-Up
        public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool yValue, out int minVaule, out int maxValue)
        {
            float min = int.MaxValue;
            float max = int.MinValue;

            if (IsStack())
            {
                GetStackSeries(ref _stackSeriesForMinMax);
                foreach (var ss in _stackSeriesForMinMax)
                {
                    _serieTotalValueForMinMax.Clear();
                    for (int i = 0; i < ss.Value.Count; i++)
                    {
                        var serie = ss.Value[i];
                        if (serie.axisIndex != axisIndex)
                        {
                            continue;
                        }
                        var showData = serie.GetDataList(dataZoom);
                        for (int j = 0; j < showData.Count; j++)
                        {
                            if (!_serieTotalValueForMinMax.ContainsKey(j))
                            {
                                _serieTotalValueForMinMax[j] = 0;
                            }
                            _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + (yValue ? showData[j].data[1] : showData[i].data[0]);
                        }
                    }
                    float tmax = int.MinValue;
                    float tmin = int.MaxValue;
                    foreach (var tt in _serieTotalValueForMinMax)
                    {
                        if (tt.Value > tmax)
                        {
                            tmax = tt.Value;
                        }
                        if (tt.Value < tmin)
                        {
                            tmin = tt.Value;
                        }
                    }
                    if (tmax > max)
                    {
                        max = tmax;
                    }
                    if (tmin < min)
                    {
                        min = tmin;
                    }
                }
            }
            else
            {
                for (int i = 0; i < m_Series.Count; i++)
                {
                    if (m_Series[i].axisIndex != axisIndex)
                    {
                        continue;
                    }
                    if (IsActive(i))
                    {
                        var showData = m_Series[i].GetDataList(dataZoom);
                        foreach (var data in showData)
                        {
                            if (yValue)
                            {
                                if (data.data[1] > max)
                                {
                                    max = data.data[1];
                                }
                                if (data.data[1] < min)
                                {
                                    min = data.data[1];
                                }
                            }
                            else
                            {
                                if (data.data[0] > max)
                                {
                                    max = data.data[0];
                                }
                                if (data.data[0] < min)
                                {
                                    min = data.data[0];
                                }
                            }
                        }
                    }
                }
            }
            if (max == int.MinValue && min == int.MaxValue)
            {
                minVaule = 0;
                maxValue = 90;
            }
            else
            {
                minVaule = Mathf.FloorToInt(min);
                maxValue = Mathf.CeilToInt(max);
            }
        }
コード例 #23
0
        /// <summary>
        /// 获得指定维数的最大最小值
        /// </summary>
        /// <param name="dimension"></param>
        /// <param name="dataZoom"></param>
        /// <returns></returns>
        public static void UpdateMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null)
        {
            float min = 0, max = 0;

            GetMinMaxData(serie, dimension, out min, out max, dataZoom);
            if (ceilRate < 0)
            {
                serie.runtimeDataMin = min;
                serie.runtimeDataMax = max;
            }
            else
            {
                serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
                serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
            }
        }
コード例 #24
0
 /// <summary>
 /// 获得维度Y的最大最小值
 /// </summary>
 /// <param name="dataZoom"></param>
 /// <param name="axisIndex"></param>
 /// <param name="minVaule"></param>
 /// <param name="maxValue"></param>
 internal void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis,
                               out float minVaule, out float maxValue)
 {
     GetMinMaxValue(dataZoom, axisIndex, isValueAxis, true, out minVaule, out maxValue);
 }
コード例 #25
0
 private float GetAxisPosition(Grid grid, Axis axis, DataZoom dataZoom, int dataCount, double value)
 {
     return(AxisHelper.GetAxisPosition(grid, axis, value, dataCount, dataZoom));
 }
コード例 #26
0
        internal void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool yValue,
                                     out float minVaule, out float maxValue)
        {
            float min            = int.MaxValue;
            float max            = int.MinValue;
            var   isPercentStack = IsPercentStack(SerieType.Bar);

            if (!IsStack() || (isValueAxis && !yValue))
            {
                for (int i = 0; i < m_Series.Count; i++)
                {
                    var serie = m_Series[i];
                    if (serie.axisIndex != axisIndex)
                    {
                        continue;
                    }

                    if (IsActive(i))
                    {
                        if (isPercentStack && IsPercentStack(serie.name, SerieType.Bar))
                        {
                            if (100 > max)
                            {
                                max = 100;
                            }
                            if (0 < min)
                            {
                                min = 0;
                            }
                        }
                        else
                        {
                            var showData = m_Series[i].GetDataList(dataZoom);
                            foreach (var data in showData)
                            {
                                if (yValue)
                                {
                                    var currData = data.GetData(1);
                                    if (currData > max)
                                    {
                                        max = currData;
                                    }
                                    if (currData < min)
                                    {
                                        min = currData;
                                    }
                                }
                                else
                                {
                                    if (data.data[0] > max)
                                    {
                                        max = data.data[0];
                                    }
                                    if (data.data[0] < min)
                                    {
                                        min = data.data[0];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                GetStackSeries(ref _stackSeriesForMinMax);
                foreach (var ss in _stackSeriesForMinMax)
                {
                    _serieTotalValueForMinMax.Clear();
                    for (int i = 0; i < ss.Value.Count; i++)
                    {
                        var serie = ss.Value[i];
                        if (serie.axisIndex != axisIndex || !IsActive(i))
                        {
                            continue;
                        }
                        var showData = serie.GetDataList(dataZoom);
                        if (IsPercentStack(serie.stack, SerieType.Bar))
                        {
                            for (int j = 0; j < showData.Count; j++)
                            {
                                _serieTotalValueForMinMax[j] = 100;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < showData.Count; j++)
                            {
                                if (!_serieTotalValueForMinMax.ContainsKey(j))
                                {
                                    _serieTotalValueForMinMax[j] = 0;
                                }
                                _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] +
                                                               (yValue ? showData[j].GetData(1) : showData[i].data[0]);
                            }
                        }
                    }
                    float tmax = int.MinValue;
                    float tmin = int.MaxValue;
                    foreach (var tt in _serieTotalValueForMinMax)
                    {
                        if (tt.Value > tmax)
                        {
                            tmax = tt.Value;
                        }
                        if (tt.Value < tmin)
                        {
                            tmin = tt.Value;
                        }
                    }
                    if (tmax > max)
                    {
                        max = tmax;
                    }
                    if (tmin < min)
                    {
                        min = tmin;
                    }
                }
            }
            if (max == int.MinValue && min == int.MaxValue)
            {
                minVaule = 0;
                maxValue = 0;
            }
            else
            {
                minVaule = min > 1 ? Mathf.FloorToInt(min) : min;
                maxValue = max > 1 ? Mathf.CeilToInt(max) : max;
            }
        }
コード例 #27
0
 internal string GetFormatterContent(int dataIndex, Series series, string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null)
 {
     if (string.IsNullOrEmpty(m_Formatter))
     {
         if (string.IsNullOrEmpty(m_ItemFormatter))
         {
             return("");
         }
         else
         {
             var sb           = ChartHelper.sb;
             var title        = m_TitleFormatter;
             var formatTitle  = !string.IsNullOrEmpty(title);
             var needCategory = false;
             var first        = true;
             sb.Length = 0;
             for (int i = 0; i < series.Count; i++)
             {
                 var serie     = series.GetSerie(i);
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 var percent   = serieData.GetData(1) / serie.yTotal * 100;
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (serie.show)
                 {
                     string content = m_ItemFormatter;
                     content = content.Replace("{a}", serie.name);
                     content = content.Replace("{b}", needCategory ? category : serieData.name);
                     content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                     content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                     if (!first)
                     {
                         sb.Append("\n");
                     }
                     sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
                     sb.Append(content);
                     first = false;
                 }
                 if (formatTitle)
                 {
                     if (i == 0)
                     {
                         title = title.Replace("{a}", serie.name);
                         title = title.Replace("{b}", needCategory ? category : serieData.name);
                         title = title.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                         title = title.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                     }
                     title = title.Replace("{a" + i + "}", serie.name);
                     title = title.Replace("{b" + i + "}", needCategory ? category : serieData.name);
                     title = title.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                     title = title.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
                 }
             }
             if (string.IsNullOrEmpty(title))
             {
                 if (needCategory)
                 {
                     return(category + "\n" + sb.ToString());
                 }
                 else
                 {
                     return(sb.ToString());
                 }
             }
             else
             {
                 title = title.Replace("\\n", "\n");
                 title = title.Replace("<br/>", "\n");
                 return(title + "\n" + sb.ToString());
             }
         }
     }
     else
     {
         string content = m_Formatter;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.show)
             {
                 var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
                 var serieData    = serie.GetSerieData(dataIndex, dataZoom);
                 var percent      = serieData.GetData(1) / serie.yTotal * 100;
                 if (i == 0)
                 {
                     content = content.Replace("{a}", serie.name);
                     content = content.Replace("{b}", needCategory ? category : serieData.name);
                     content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                     content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                 }
                 content = content.Replace("{a" + i + "}", serie.name);
                 content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name);
                 content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                 content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
             }
         }
         content = content.Replace("\\n", "\n");
         content = content.Replace("<br/>", "\n");
         return(content);
     }
 }
コード例 #28
0
 public virtual void OnDataZoomRangeChanged(DataZoom dataZoom)
 {
 }
コード例 #29
0
 /// <summary>
 /// 获得维度Y的最大最小值
 /// </summary>
 /// <param name="dataZoom"></param>
 /// <param name="axisIndex"></param>
 /// <param name="minVaule"></param>
 /// <param name="maxValue"></param>
 internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
                                      bool inverse, out float minVaule, out float maxValue)
 {
     GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue);
 }
コード例 #30
0
        /// <summary>
        /// 获得标签显示的名称
        /// </summary>
        /// <param name="index"></param>
        /// <param name="minValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="dataZoom"></param>
        /// <returns></returns>
        internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue,
                                            DataZoom dataZoom, bool forcePercent)
        {
            int split = GetSplitNumber(axis, coordinateWidth, dataZoom);

            if (axis.type == Axis.AxisType.Value)
            {
                if (minValue == 0 && maxValue == 0)
                {
                    return(string.Empty);
                }
                var value = 0f;
                if (forcePercent)
                {
                    maxValue = 100;
                }
                if (axis.interval > 0)
                {
                    if (index == split)
                    {
                        value = maxValue;
                    }
                    else
                    {
                        value = minValue + index * axis.interval;
                    }
                }
                else
                {
                    value = minValue + (maxValue - minValue) * index / split;
                    if (!axis.clockwise && value != minValue)
                    {
                        value = maxValue - value;
                    }
                }
                if (axis.inverse)
                {
                    value    = -value;
                    minValue = -minValue;
                    maxValue = -maxValue;
                }

                if (forcePercent)
                {
                    return(string.Format("{0}%", (int)value));
                }
                else
                {
                    return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue));
                }
            }
            else if (axis.type == Axis.AxisType.Log)
            {
                float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) :
                              Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index);
                if (axis.inverse)
                {
                    value    = -value;
                    minValue = -minValue;
                    maxValue = -maxValue;
                }
                return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true));
            }
            var showData  = axis.GetDataList(dataZoom);
            int dataCount = showData.Count;

            if (dataCount <= 0)
            {
                return("");
            }
            int rate     = Mathf.RoundToInt(dataCount * 1f / split);
            int newIndex = index * rate;

            if (newIndex <= dataCount - 1)
            {
                return(axis.axisLabel.GetFormatterContent(showData[newIndex]));
            }
            else
            {
                if (rate == 1)
                {
                    return(string.Empty);
                }
                else if (axis.boundaryGap && coordinateWidth / dataCount > 10)
                {
                    return(string.Empty);
                }
                else
                {
                    if ((index - 1) * rate > dataCount - 1)
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        return(axis.axisLabel.GetFormatterContent(showData[dataCount - 1]));
                    }
                }
            }
        }