public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false) { if (showAsPositiveNumber && value < 0) { value = Mathf.Abs(value); } if (string.IsNullOrEmpty(m_Formatter)) { if (isLog) { return(ChartCached.NumberToStr(value, numericFormatter)); } if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1) { int minAcc = ChartHelper.GetFloatAccuracy(minValue); int maxAcc = ChartHelper.GetFloatAccuracy(maxValue); int curAcc = ChartHelper.GetFloatAccuracy(value); int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc); return(ChartCached.FloatToStr(value, numericFormatter, acc)); } return(ChartCached.NumberToStr(value, numericFormatter)); } else { var content = m_Formatter; FormatterHelper.ReplaceAxisLabelContent(ref content, numericFormatter, value); return(content); } }
public static string GetFormatterContent(Serie serie, SerieData serieData, float dataValue, float dataTotal, SerieLabel serieLabel = null) { if (serieLabel == null) { serieLabel = SerieHelper.GetSerieLabel(serie, serieData); } var numericFormatter = GetLabelNumericFormatter(serie, serieData); var serieName = serie.name; var dataName = serieData != null ? serieData.name : null; if (string.IsNullOrEmpty(serieLabel.formatter)) { return(ChartCached.NumberToStr(dataValue, numericFormatter)); } else { var content = serieLabel.formatter.Replace("{a}", serieName); content = content.Replace("{b}", dataName); content = content.Replace("{c}", ChartCached.NumberToStr(dataValue, numericFormatter)); content = content.Replace("{c:f0}", ChartCached.IntToStr((int)Mathf.Round(dataValue))); content = content.Replace("{c:f1}", ChartCached.FloatToStr(dataValue, string.Empty, 1)); content = content.Replace("{c:f2}", ChartCached.FloatToStr(dataValue, string.Empty, 2)); var percent = dataValue == 0 && dataTotal == 0 ? 0 : dataValue / dataTotal * 100; content = content.Replace("{d}", ChartCached.NumberToStr(percent, numericFormatter)); content = content.Replace("{d:f0}", ChartCached.IntToStr((int)Mathf.Round(percent))); content = content.Replace("{d:f1}", ChartCached.FloatToStr(percent, string.Empty, 1)); content = content.Replace("{d:f2}", ChartCached.FloatToStr(percent, string.Empty, 2)); content = content.Replace("\\n", "\n"); content = content.Replace("<br/>", "\n"); return(content); } }
public static string GetFormatterContent(Serie serie, SerieData serieData, double dataValue, double dataTotal, SerieLabel serieLabel, Color color) { if (serieLabel == null) { serieLabel = SerieHelper.GetSerieLabel(serie, serieData); } var numericFormatter = serieLabel == null ? serie.label.numericFormatter : serieLabel.numericFormatter; var serieName = serie.name; var dataName = serieData != null ? serieData.name : null; if (serieLabel.formatterFunction != null) { return(serieLabel.formatterFunction(serieData.index, dataValue)); } if (string.IsNullOrEmpty(serieLabel.formatter)) { return(ChartCached.NumberToStr(dataValue, numericFormatter)); } else { var content = serieLabel.formatter; FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue, dataTotal, serieName, dataName, color); return(content); } }
public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false) { if (showAsPositiveNumber && value < 0) { value = Mathf.Abs(value); } if (string.IsNullOrEmpty(m_Formatter)) { if (isLog) { return(ChartCached.NumberToStr(value, numericFormatter)); } if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1) { int minAcc = ChartHelper.GetFloatAccuracy(minValue); int maxAcc = ChartHelper.GetFloatAccuracy(maxValue); int curAcc = ChartHelper.GetFloatAccuracy(value); int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc); return(ChartCached.FloatToStr(value, numericFormatter, acc)); } return(ChartCached.NumberToStr(value, numericFormatter)); } else if (m_Formatter.Contains("{value")) { var content = m_Formatter; if (content.Contains("{value:f0}")) { content = m_Formatter.Replace("{value:f0}", ChartCached.IntToStr((int)value)); } if (content.Contains("{value:f2}")) { content = m_Formatter.Replace("{value:f2}", ChartCached.FloatToStr(value, string.Empty, 2)); } else if (content.Contains("{value:f1}")) { content = m_Formatter.Replace("{value:f1}", ChartCached.FloatToStr(value, string.Empty, 1)); } else if (content.Contains("{value}")) { content = m_Formatter.Replace("{value}", ChartCached.NumberToStr((int)value, numericFormatter)); } content = content.Replace("\\n", "\n"); content = content.Replace("<br/>", "\n"); return(content); } else { return(value.ToString(m_Formatter)); } }
public static string GetFormatterContent(Serie serie, MarkLineData data) { var serieLabel = data.label; var numericFormatter = serieLabel.numericFormatter; if (serieLabel.formatterFunction != null) { return(serieLabel.formatterFunction(data.index, data.runtimeValue)); } if (string.IsNullOrEmpty(serieLabel.formatter)) { return(ChartCached.NumberToStr(data.runtimeValue, numericFormatter)); } else { var content = serieLabel.formatter; FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, data.runtimeValue, 0, serie.name, data.name, Color.clear); return(content); } }
public static string GetFormatterContent(Serie serie, SerieData serieData, float dataValue, float dataTotal, SerieLabel serieLabel = null) { if (serieLabel == null) { serieLabel = SerieHelper.GetSerieLabel(serie, serieData); } var numericFormatter = GetLabelNumericFormatter(serie, serieData); var serieName = serie.name; var dataName = serieData != null ? serieData.name : null; if (string.IsNullOrEmpty(serieLabel.formatter)) { return(ChartCached.NumberToStr(dataValue, numericFormatter)); } else { var content = serieLabel.formatter; FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue, dataTotal, serieName, dataName); return(content); } }