mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 09:20:08 +00:00
优化Axis的数值Label的默认显示格式
This commit is contained in:
@@ -827,18 +827,18 @@ namespace XCharts.Runtime
|
||||
return logBaseE ? (float) Math.Log(value) : (float) Math.Log(value, logBase);
|
||||
}
|
||||
|
||||
public int GetLogMinIndex()
|
||||
public double GetLogMinIndex()
|
||||
{
|
||||
return logBaseE ?
|
||||
(int) Math.Log(context.minValue) :
|
||||
(int) Math.Log(context.minValue, logBase);
|
||||
Math.Log(context.minValue) :
|
||||
Math.Log(context.minValue, logBase);
|
||||
}
|
||||
|
||||
public int GetLogMaxIndex()
|
||||
public double GetLogMaxIndex()
|
||||
{
|
||||
return logBaseE ?
|
||||
(int) Math.Log(context.maxValue) :
|
||||
(int) Math.Log(context.maxValue, logBase);
|
||||
Math.Log(context.maxValue) :
|
||||
Math.Log(context.maxValue, logBase);
|
||||
}
|
||||
|
||||
public double GetLabelValue(int index)
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace XCharts.Runtime
|
||||
var min = axis is YAxis ? 20 : 80;
|
||||
if (eachWid > min) return dataCount;
|
||||
var tick = Mathf.CeilToInt(min / eachWid);
|
||||
return (int) (dataCount / tick);
|
||||
return (int)(dataCount / tick);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -132,7 +132,7 @@ namespace XCharts.Runtime
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
if (forcePercent)
|
||||
return string.Format("{0}%", (int) value);
|
||||
return string.Format("{0}%", (int)value);
|
||||
else
|
||||
return axis.axisLabel.GetFormatterContent(index, value, minValue, maxValue);
|
||||
}
|
||||
@@ -255,9 +255,8 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var value = axis.GetLabelValue(index);
|
||||
var lastValue = axis.GetLabelValue(index - 1);
|
||||
return axis.context.minMaxRange == 0 ?
|
||||
0 :
|
||||
(float) (coordinateWidth * (value - lastValue) / axis.context.minMaxRange);
|
||||
return axis.context.minMaxRange == 0 ? 0 :
|
||||
(float)(coordinateWidth * (value - lastValue) / axis.context.minMaxRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -345,7 +344,10 @@ namespace XCharts.Runtime
|
||||
int maxSplit = 0;
|
||||
maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit);
|
||||
minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit);
|
||||
axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
|
||||
var splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
|
||||
if (splitNumber > 15)
|
||||
splitNumber = 15;
|
||||
axis.splitNumber = splitNumber;
|
||||
return;
|
||||
}
|
||||
if (axis.type == Axis.AxisType.Time) { }
|
||||
@@ -460,7 +462,7 @@ namespace XCharts.Runtime
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
if (dataCount == 0) dataCount = axis.data.Count;
|
||||
var categoryIndex = (int) value;
|
||||
var categoryIndex = (int)value;
|
||||
var scaleWid = AxisHelper.GetDataWidth(axis, gridHeight, dataCount, dataZoom);
|
||||
float startY = gridXY + (axis.boundaryGap ? scaleWid / 2 : 0);
|
||||
return startY + scaleWid * categoryIndex;
|
||||
@@ -468,9 +470,8 @@ namespace XCharts.Runtime
|
||||
else
|
||||
{
|
||||
var yDataHig = (axis.context.minMaxRange == 0) ? 0f :
|
||||
(float) ((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
|
||||
(float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
|
||||
return gridXY + yDataHig;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,7 +540,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
return (int) value;
|
||||
return (int)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -550,9 +551,9 @@ namespace XCharts.Runtime
|
||||
if (totalSplitNumber == -1)
|
||||
totalSplitNumber = GetTotalSplitGridNum(axis);
|
||||
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
return Mathf.CeilToInt(((float) ((value - axis.min) / axis.max) * totalSplitNumber) - 1);
|
||||
return Mathf.CeilToInt(((float)((value - axis.min) / axis.max) * totalSplitNumber) - 1);
|
||||
else
|
||||
return Mathf.CeilToInt(((float) ((value - axis.context.minValue) / axis.context.minMaxRange) * totalSplitNumber) - 1);
|
||||
return Mathf.CeilToInt(((float)((value - axis.context.minValue) / axis.context.minMaxRange) * totalSplitNumber) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -565,15 +566,15 @@ namespace XCharts.Runtime
|
||||
|
||||
if (axis.IsLog())
|
||||
{
|
||||
int minIndex = axis.GetLogMinIndex();
|
||||
float nowIndex = axis.GetLogValue(value);
|
||||
var minIndex = axis.GetLogMinIndex();
|
||||
var nowIndex = axis.GetLogValue(value);
|
||||
return includeGridXY ?
|
||||
gridXY + (nowIndex - minIndex) / axis.splitNumber * gridHeight :
|
||||
(nowIndex - minIndex) / axis.splitNumber * gridHeight;
|
||||
(float)(gridXY + (nowIndex - minIndex) / axis.splitNumber * gridHeight) :
|
||||
(float)((nowIndex - minIndex) / axis.splitNumber * gridHeight);
|
||||
}
|
||||
else if (axis.IsCategory())
|
||||
{
|
||||
var categoryIndex = (int) value;
|
||||
var categoryIndex = (int)value;
|
||||
return includeGridXY ?
|
||||
gridXY + (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex :
|
||||
(axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex;
|
||||
@@ -584,9 +585,9 @@ namespace XCharts.Runtime
|
||||
if (axis.context.minMaxRange != 0)
|
||||
{
|
||||
if (realLength)
|
||||
yDataHig = (float) (value * gridHeight / axis.context.minMaxRange);
|
||||
yDataHig = (float)(value * gridHeight / axis.context.minMaxRange);
|
||||
else
|
||||
yDataHig = (float) ((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
|
||||
yDataHig = (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
|
||||
}
|
||||
return includeGridXY ?
|
||||
gridXY + yDataHig :
|
||||
|
||||
@@ -336,33 +336,38 @@ namespace XCharts.Runtime
|
||||
|
||||
public virtual string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false)
|
||||
{
|
||||
var newNumericFormatter = numericFormatter;
|
||||
if (string.IsNullOrEmpty(newNumericFormatter) && !isLog)
|
||||
{
|
||||
newNumericFormatter = MathUtil.IsInteger(maxValue) ? "0" : "f" + MathUtil.GetPrecision(maxValue);
|
||||
}
|
||||
if (string.IsNullOrEmpty(m_Formatter))
|
||||
{
|
||||
if (isLog)
|
||||
{
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, newNumericFormatter));
|
||||
}
|
||||
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 minAcc = MathUtil.GetPrecision(minValue);
|
||||
int maxAcc = MathUtil.GetPrecision(maxValue);
|
||||
int curAcc = MathUtil.GetPrecision(value);
|
||||
int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc);
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.FloatToStr(value, numericFormatter, acc));
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.FloatToStr(value, newNumericFormatter, acc));
|
||||
}
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
|
||||
return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, newNumericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
var content = m_Formatter;
|
||||
FormatterHelper.ReplaceAxisLabelContent(ref content, numericFormatter, value);
|
||||
FormatterHelper.ReplaceAxisLabelContent(ref content, newNumericFormatter, value);
|
||||
return GetFormatterFunctionContent(labelIndex, value, content);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFormatterDateTime(int labelIndex, double value, double minValue, double maxValue)
|
||||
{
|
||||
var timestamp = (int) value;
|
||||
var timestamp = (int)value;
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp);
|
||||
var dateString = string.Empty;
|
||||
if (string.IsNullOrEmpty(numericFormatter) || numericFormatter.Equals("f2"))
|
||||
|
||||
Reference in New Issue
Block a user