代码来自fusion
1. 分别计算两个边界值相对10的对数(取下限值)。
2. 计算间隔值y_interval
a. 取两个对数的最大值为powTen
b. 间隔值y_interval 为10的powTen次幂
c. 如果边界值分别除于y_interval小于2的话, y_interval = y_interval/10 (除于10平衡一下,以端值距离某边的边界值过远)
3. 端值计算
y_topBound = (Math.floor(maxValue / y_interval) + 1) * y_interval;
if (minValue < 0)
{
y_lowerBound = Math.floor(minValue / y_interval) * y_interval;
}
else
{
y_lowerBound = 0;
} // end else if
Chart.prototype.calcYAxisLimits = function ()
{
maxValue = this.getYAxisMaxValue();
minValue = this.getYAxisMinValue();
var maxPowerOfTen = Math.floor(Math.log(Math.abs(maxValue)) / 2.302585E+000);
var minPowerOfTen = Math.floor(Math.log(Math.abs(minValue)) / 2.302585E+000);
var powerOfTen = Math.max(minPowerOfTen, maxPowerOfTen);
var y_interval = Math.pow(10, powerOfTen);
if (Math.abs(maxValue) / y_interval < 2 && Math.abs(minValue) / y_interval < 2)
{
--powerofTen;
y_interval = Math.pow(10, powerOfTen);
} // end if
var y_topBound = (Math.floor(maxValue / y_interval) + 1) * y_interval;
var y_lowerBound;
if (minValue < 0)
{
y_lowerBound = Math.floor(minValue / y_interval) * y_interval;
}
else
{
y_lowerBound = 0;
} // end else if
if (this.Params.yAxisMaxValue == null || this.Params.yAxisMaxValue == undefined || this.Params.yAxisMaxValue == "" || this.Params.yAxisMaxValue < maxValue)
{
this.Params.yAxisMaxValue = y_topBound;
} // end if
if (this.Params.yAxisMinValue == null || this.Params.yAxisMinValue == undefined || this.Params.yAxisMinValue == "" || this.Params.yAxisMinValue > minValue)
{
this.Params.yAxisMinValue = y_lowerBound;
} // end if
this.Params.yAxisMaxValue = Number(this.Params.yAxisMaxValue);
this.Params.yAxisMinValue = Number(this.Params.yAxisMinValue);
};