mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
优化Log对数轴
This commit is contained in:
@@ -828,6 +828,8 @@ namespace XCharts.Runtime
|
||||
|
||||
public double GetLogMinIndex()
|
||||
{
|
||||
if (context.minValue <= 0 || context.minValue == 1)
|
||||
return 0;
|
||||
return logBaseE ?
|
||||
Math.Log(context.minValue) :
|
||||
Math.Log(context.minValue, logBase);
|
||||
@@ -835,6 +837,8 @@ namespace XCharts.Runtime
|
||||
|
||||
public double GetLogMaxIndex()
|
||||
{
|
||||
if (context.maxValue <= 0 || context.maxValue == 1)
|
||||
return 0;
|
||||
return logBaseE ?
|
||||
Math.Log(context.maxValue) :
|
||||
Math.Log(context.maxValue, logBase);
|
||||
|
||||
@@ -344,7 +344,8 @@ 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);
|
||||
var splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
|
||||
|
||||
var splitNumber = maxSplit + minSplit;
|
||||
if (splitNumber > 15)
|
||||
splitNumber = 15;
|
||||
axis.splitNumber = splitNumber;
|
||||
|
||||
@@ -682,7 +682,7 @@ namespace XCharts.Runtime
|
||||
public static double GetMaxDivisibleValue(double max, double ceilRate)
|
||||
{
|
||||
if (max == 0) return 0;
|
||||
double pow = 1;
|
||||
double pow = 1;
|
||||
if (max > -1 && max < 1)
|
||||
{
|
||||
pow = Mathf.Pow(10, MathUtil.GetPrecision(max));
|
||||
@@ -739,7 +739,7 @@ namespace XCharts.Runtime
|
||||
public static double GetMinDivisibleValue(double min, double ceilRate)
|
||||
{
|
||||
if (min == 0) return 0;
|
||||
double pow = 1;
|
||||
double pow = 1;
|
||||
if (min > -1 && min < 1)
|
||||
{
|
||||
pow = Mathf.Pow(10, MathUtil.GetPrecision(min));
|
||||
@@ -770,20 +770,13 @@ namespace XCharts.Runtime
|
||||
|
||||
public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
splitNumber = 1;
|
||||
if (value <= 0) return 0;
|
||||
double max = 0;
|
||||
double max = isLogBaseE ? Math.Exp(splitNumber) : Math.Pow(logBase, splitNumber);
|
||||
while (max < value)
|
||||
{
|
||||
if (isLogBaseE)
|
||||
{
|
||||
max = Math.Exp(splitNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
max = Math.Pow(logBase, splitNumber);
|
||||
}
|
||||
splitNumber++;
|
||||
max = isLogBaseE ? Math.Exp(splitNumber) : Math.Pow(logBase, splitNumber);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
@@ -791,19 +784,13 @@ namespace XCharts.Runtime
|
||||
public static double GetMinLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value <= 0) return 0;
|
||||
if (value > 1) return 1;
|
||||
double min = 1;
|
||||
double min = isLogBaseE ? Math.Exp(-splitNumber) : Math.Pow(logBase, -splitNumber);
|
||||
while (min > value)
|
||||
{
|
||||
if (isLogBaseE)
|
||||
{
|
||||
min = Math.Exp(-splitNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
min = Math.Pow(logBase, -splitNumber);
|
||||
}
|
||||
splitNumber++;
|
||||
min = isLogBaseE ? Math.Exp(-splitNumber) : Math.Pow(logBase, -splitNumber);
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user