提交 bee99de4 编写于 作者: P pah100

update log axis

上级 89969cb7
......@@ -2317,6 +2317,12 @@ require(['echarts'], function (ec){
<td> value </td>
<td> This option works when axis.type === 'log'. If set to false, negative value is supported. It is self-adapting by default, which means that if all of the data is negative, logPositive will be set to false, otherwise true. </td>
</tr>
<tr>
<td> <b>{number}</b> logLabelBase </td>
<td> null </td>
<td> value </td>
<td> This option works when axis.type === 'log'. If specified, axisLabel is drawn as exponent style. For example, when logLabelBase = 4, axisLabel is drawn like 4², 4³. If not specified, axisLabel is drawn like 1,000,000 as usual. </td>
</tr>
<tr>
<td> <b>{Object}</b> axisLine </td>
<td> varying </td>
......@@ -3722,7 +3728,7 @@ indicator : [
<td> <b>{Object}</b> itemStyle </td>
<td> {} </td>
<td>
see
see
<a href="#ItemStyle" title="">
itemStyle
</a>
......@@ -3771,7 +3777,7 @@ indicator : [
<td> <b>{Object}</b> itemStyle </td>
<td> {} </td>
<td>
see
see
<a href="#ItemStyle" title="">
itemStyle
</a>
......
......@@ -2331,6 +2331,12 @@ require(['echarts'], function (ec){
<td> 数值型,时间型 </td>
<td> 分割段数,不指定时根据min、max算法调整</td>
</tr>
<tr>
<td> <b>{number}</b> logLabelBase </td>
<td> null </td>
<td> value </td>
<td> axis.type === 'log'时生效。指定时,axisLabel显示为指数形式,如指定为4时,axisLabel可显示为4²、4³。不指定时,显示为普通形式,如 1,000,000 </td>
</tr>
<tr>
<td> <b>{Object}</b> logPositive </td>
<td> null </td>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="ECharts">
<meta name="author" content="kener.linfeng@gmail.com">
<title>ECharts · Example</title>
<link rel="shortcut icon" href="../asset/ico/favicon.png">
<link href="../asset/css/font-awesome.min.css" rel="stylesheet">
<link href="../asset/css/bootstrap.css" rel="stylesheet">
<link href="../asset/css/carousel.css" rel="stylesheet">
<link href="../asset/css/echartsHome.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="./www/js/echarts.js"></script>
<script src="../asset/js/codemirror.js"></script>
<script src="../asset/js/javascript.js"></script>
<link href="../asset/css/codemirror.css" rel="stylesheet">
<link href="../asset/css/monokai.css" rel="stylesheet">
</head>
<body>
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
<div class="container-fluid">
<div class="row-fluid example">
<div id="sidebar-code" class="col-md-4">
<div class="well sidebar-nav">
<div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
<textarea id="code" name="code">
option = {
title: {
text: "对数轴示例",
x: "center"
},
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c}"
},
legend: {
x: 'left',
data: ["2的指数", "3的指数"]
},
xAxis: [
{
type: "category",
name: "x",
splitLine: {show: false},
data: ["一", "二", "三", "四", "五", "六", "七", "八", "九"]
}
],
yAxis: [
{
type: "log",
logLabelBase: 3,
splitNumber: 3,
name: "y",
axisLabel: {
margin: '25',
textStyle: {
align: 'left'
}
}
}
],
toolbox: {
show: true,
feature: {
mark: {
show: true
},
dataView: {
show: true,
readOnly: true
},
restore: {
show: true
},
saveAsImage: {
show: true
}
}
},
calculable: true,
series: [
{
name: "3的指数",
type: "line",
data: [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
},
{
name: "2的指数",
type: "line",
data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
}
]
};
</textarea>
</div><!--/.well -->
</div><!--/span-->
<div id="graphic" class="col-md-8">
<div id="main" class="main"></div>
<div>
<button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
<span class="text-primary">切换主题</span>
<select id="theme-select"></select>
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="./line9.html">axisLabel普通形式显示</a>
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="./line11.html">负值log数轴</a>
<span id='wrong-message' style="color:red"></span>
</div>
</div><!--/span-->
</div><!--/row-->
</div><!--/.fluid-container-->
<footer id="footer"></footer>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../asset/js/jquery.min.js"></script>
<script type="text/javascript" src="../asset/js/echartsHome.js"></script>
<script src="../asset/js/bootstrap.min.js"></script>
<script src="../asset/js/echartsExample.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="ECharts">
<meta name="author" content="kener.linfeng@gmail.com">
<title>ECharts · Example</title>
<link rel="shortcut icon" href="../asset/ico/favicon.png">
<link href="../asset/css/font-awesome.min.css" rel="stylesheet">
<link href="../asset/css/bootstrap.css" rel="stylesheet">
<link href="../asset/css/carousel.css" rel="stylesheet">
<link href="../asset/css/echartsHome.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="./www/js/echarts.js"></script>
<script src="../asset/js/codemirror.js"></script>
<script src="../asset/js/javascript.js"></script>
<link href="../asset/css/codemirror.css" rel="stylesheet">
<link href="../asset/css/monokai.css" rel="stylesheet">
</head>
<body>
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
<div class="container-fluid">
<div class="row-fluid example">
<div id="sidebar-code" class="col-md-4">
<div class="well sidebar-nav">
<div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
<textarea id="code" name="code">
option = {
title: {
text: "对数轴示例",
x: "center"
},
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c}"
},
legend: {
x: 'left',
data: ["2的指数"]
},
xAxis: [
{
type: "category",
name: "x",
splitLine: {show: false},
data: ["一", "二", "三", "四", "五", "六", "七", "八", "九"]
}
],
yAxis: [
{
type: "log",
logLabelBase: 2,
name: "y",
axisLabel: {
margin: '25',
textStyle: {
align: 'left'
}
}
}
],
toolbox: {
show: true,
feature: {
mark: {
show: true
},
dataView: {
show: true,
readOnly: true
},
restore: {
show: true
},
saveAsImage: {
show: true
}
}
},
calculable: true,
series: [
{
name: "2的指数",
type: "line",
data: [-2, -4, -8, -16, -32, -64, -128]
}
]
};
</textarea>
</div><!--/.well -->
</div><!--/span-->
<div id="graphic" class="col-md-8">
<div id="main" class="main"></div>
<div>
<button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
<span class="text-primary">切换主题</span>
<select id="theme-select"></select>
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="./line9.html">axisLabel普通形式显示</a>
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="./line10.html">axisLabel指数形式显示</a>
<span id='wrong-message' style="color:red"></span>
</div>
</div><!--/span-->
</div><!--/row-->
</div><!--/.fluid-container-->
<footer id="footer"></footer>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../asset/js/jquery.min.js"></script>
<script type="text/javascript" src="../asset/js/echartsHome.js"></script>
<script src="../asset/js/bootstrap.min.js"></script>
<script src="../asset/js/echartsExample.js"></script>
</body>
</html>
......@@ -109,6 +109,10 @@ option = {
<button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
<span class="text-primary">切换主题</span>
<select id="theme-select"></select>
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="./line10.html">axisLabel指数形式显示</a>
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="./line11.html">负值log数轴</a>
<span id='wrong-message' style="color:red"></span>
</div>
......
......@@ -514,13 +514,15 @@ define(function (require) {
}
// console.log(this._min,this._max,'vvvvv111111',this.option.type)
// log情况暂时禁用boundaryGap。
var boundaryGap = this.option.type !== 'log' ? this.option.boundaryGap : [0, 0];
var gap = Math.abs(this._max - this._min);
this._min = isNaN(this.option.min - 0)
? (this._min - Math.abs(gap * this.option.boundaryGap[0]))
? (this._min - Math.abs(gap * boundaryGap[0]))
: (this.option.min - 0); // 指定min忽略boundaryGay[0]
this._max = isNaN(this.option.max - 0)
? (this._max + Math.abs(gap * this.option.boundaryGap[1]))
? (this._max + Math.abs(gap * boundaryGap[1]))
: (this.option.max - 0); // 指定max忽略boundaryGay[1]
if (this._min === this._max) {
if (this._max === 0) {
......@@ -750,7 +752,11 @@ define(function (require) {
}
this._valueList.push(ecDate.getNewDate(this._max));
this._reformLabelData(formatter);
this._reformLabelData((function (formatterStr) {
return function (value) {
return ecDate.format(formatterStr, value);
};
})(formatter));
},
_customerValue: function () {
......@@ -767,53 +773,52 @@ define(function (require) {
_reformLogValue: function() {
// log数轴本质就是缩放,相当于默认this.option.scale === true,所以不修正_min和_max到0。
var stepOpt = require('../util/smartLogSteps')({
var thisOption = this.option;
var result = require('../util/smartLogSteps')({
dataMin: this._min,
dataMax: this._max,
logPositive: this.option.logPositive,
splitNumber: this.option.splitNumber
logPositive: thisOption.logPositive,
logLabelBase: thisOption.logLabelBase,
splitNumber: thisOption.splitNumber
});
this._min = stepOpt.dataMin;
this._max = stepOpt.dataMax;
this._valueList = stepOpt.tickList;
this._min = result.dataMin;
this._max = result.dataMax;
this._valueList = result.tickList;
// {value2Coord: {Function}, coord2Value: {Function}}
this._dataMappingMethods = stepOpt.dataMappingMethods;
this._dataMappingMethods = result.dataMappingMethods;
this._reformLabelData();
this._reformLabelData(result.labelFormatter);
},
_reformLabelData: function (timeFormatter) {
_reformLabelData: function (innerFormatter) {
this._valueLabel = [];
var formatter = this.option.axisLabel.formatter;
if (formatter) {
for (var i = 0, l = this._valueList.length; i < l; i++) {
if (typeof formatter === 'function') {
this._valueLabel.push(
timeFormatter
? formatter.call(this.myChart, this._valueList[i], timeFormatter)
innerFormatter
? formatter.call(this.myChart, this._valueList[i], innerFormatter)
: formatter.call(this.myChart, this._valueList[i])
);
}
else if (typeof formatter === 'string') {
this._valueLabel.push(
timeFormatter
innerFormatter
? ecDate.format(formatter, this._valueList[i])
: formatter.replace('{value}',this._valueList[i])
);
}
}
}
else if (timeFormatter) {
for (var i = 0, l = this._valueList.length; i < l; i++) {
this._valueLabel.push(ecDate.format(timeFormatter, this._valueList[i]));
}
}
else {
// 每三位默认加,格式化
for (var i = 0, l = this._valueList.length; i < l; i++) {
this._valueLabel.push(this.numAddCommas(this._valueList[i]));
this._valueLabel.push(
innerFormatter
? innerFormatter(this._valueList[i])
: this.numAddCommas(this._valueList[i]) // 每三位默认加,格式化
);
}
}
},
......
......@@ -8,7 +8,7 @@
define(function(require) {
// Reference
var zrUtil = require('zrender/tool/util');
var number = require('./number');
var Mt = Math;
var mathLog = Mt.log;
var mathPow = Mt.pow;
......@@ -26,20 +26,40 @@ define(function(require) {
var EPSILON = 1e-9;
var DEFAULT_SPLIT_NUMBER = 5;
var MIN_BASE_10_SPLIT_NUMBER = 2;
var SUPERSCRIPTS = {
'0': '',
'1': '¹',
'2': '²',
'3': '³',
'4': '',
'5': '',
'6': '',
'7': '',
'8': '',
'9': '',
'-': ''
};
// Static variable
var logPositive;
var logLabelBase;
var logLabelMode; // enumeration:
// 'plain' (i.e. axis labels are shown like 10000)
// 'exponent' (i.e. axis labels are shown like 10²)
var lnBase;
var custOpts;
var splitNumber;
var logMappingOffset;
var absMin;
var absMax;
var dataMappingMethods;
var tickList;
/**
* Test cases:
* [2, 4, 8, 16, 32, 64, 128]
* [0.01, 0.1, 10, 100, 1000] logLabelBase: 3
* [0.01, 0.1, 10, 100, 1000] logLabelBase: -12
* [-2, -4, -8, -16, -32, -64, -128] logLabelBase: 3
* [2, 4, 8, 16, '-', 64, 128]
* [2, 4, 8, 16, 32, 64]
* [2, 4, 8, 16, 32]
......@@ -67,6 +87,8 @@ define(function(require) {
* [-0.00001, -0.00001, -0.00001]
* ['-', '-']
* ['-', 10]
* logarithmic axis in scatter (try dataZoom)
* logarithmic axis width dataZoom component (try xAxis and yAxis)
*/
/**
......@@ -77,6 +99,8 @@ define(function(require) {
* @param {number} opts.dataMin data Minimum
* @param {number} opts.dataMax data Maximum
* @param {number=} opts.logPositive Logarithmic sign. If not specified, it will be auto-detected.
* @param {number=} opts.logLabelBase Logaithmic base in axis label.
* If not specified, it will be set to 10 (and use 2 for detail)
* @param {number=} opts.splitNumber Number of sections perfered.
* @return {Object} {
* dataMin: New min,
......@@ -93,8 +117,6 @@ define(function(require) {
reformSetting();
makeTicksList();
dataMappingMethods = zrUtil.merge({}, makeDataMappingMethods(logPositive, logMappingOffset));
return [
makeResult(),
clearStaticVariables()
......@@ -105,8 +127,8 @@ define(function(require) {
* All of static variables must be clear here.
*/
function clearStaticVariables() {
dataMappingMethods = logPositive = custOpts = logMappingOffset =
absMin = absMax = splitNumber = tickList = null;
logPositive = custOpts = logMappingOffset = lnBase =
absMin = absMax = splitNumber = tickList = logLabelBase = logLabelMode = null;
}
/**
......@@ -114,9 +136,27 @@ define(function(require) {
* Reform min and max of data.
*/
function reformSetting() {
// Settings of log label base
logLabelBase = custOpts.logLabelBase;
if (logLabelBase == null) {
logLabelMode = 'plain';
logLabelBase = 10;
lnBase = LN10;
}
else {
logLabelBase = +logLabelBase;
if (logLabelBase < 1) { // log base less than 1 is not supported.
logLabelBase = 10;
}
logLabelMode = 'exponent';
lnBase = mathLog(logLabelBase);
}
// Settings of split number
splitNumber = custOpts.splitNumber;
splitNumber == null && (splitNumber = DEFAULT_SPLIT_NUMBER);
// Setting of data min and max
var dataMin = parseFloat(custOpts.dataMin);
var dataMax = parseFloat(custOpts.dataMax);
......@@ -133,6 +173,7 @@ define(function(require) {
dataMax = [dataMin, dataMin = dataMax][0]; // Exchange min, max.
}
// Settings of log positive
logPositive = custOpts.logPositive;
// If not specified, determine sign by data.
if (logPositive == null) {
......@@ -142,7 +183,7 @@ define(function(require) {
logPositive = dataMax > 0 || dataMin === 0;
}
// Set absMin and absMax, which must be greater than 0.
// Settings of absMin and absMax, which must be greater than 0.
absMin = logPositive ? dataMin : -dataMax;
absMax = logPositive ? dataMax : -dataMin;
// FIXME
......@@ -160,72 +201,81 @@ define(function(require) {
tickList = [];
// Estimate max exponent and min exponent
var maxDataLog10 = fixAccurate(mathLog(absMax) / LN10);
var minDataLog10 = fixAccurate(mathLog(absMin) / LN10);
var maxExpon10 = mathCeil(maxDataLog10);
var minExpon10 = mathFloor(minDataLog10);
var spanExpon10 = maxExpon10 - minExpon10;
var spanDataLog10 = maxDataLog10 - minDataLog10;
!(
spanExpon10 <= MIN_BASE_10_SPLIT_NUMBER
&& splitNumber > MIN_BASE_10_SPLIT_NUMBER
)
? base10Analysis() : detailAnalysis();
var maxDataLog = fixAccurate(mathLog(absMax) / lnBase);
var minDataLog = fixAccurate(mathLog(absMin) / lnBase);
var maxExpon = mathCeil(maxDataLog);
var minExpon = mathFloor(minDataLog);
var spanExpon = maxExpon - minExpon;
var spanDataLog = maxDataLog - minDataLog;
if (logLabelMode === 'exponent') {
baseAnalysis();
}
else { // logLabelMode === 'plain', we will self-adapter
!(
spanExpon <= MIN_BASE_10_SPLIT_NUMBER
&& splitNumber > MIN_BASE_10_SPLIT_NUMBER
)
? baseAnalysis() : detailAnalysis();
}
// In this situation, only plot base-10 ticks.
// In this situation, only draw base-10 ticks.
// Base-10 ticks: 10^h (i.e. 0.01, 0.1, 1, 10, 100, ...)
function base10Analysis() {
if (spanExpon10 < splitNumber) {
splitNumber = spanExpon10;
function baseAnalysis() {
if (spanExpon < splitNumber) {
splitNumber = spanExpon;
}
// Suppose:
// spanExpon10 > splitNumber
// stepExpon10 := floor(spanExpon10 / splitNumber)
// splitNumberFloat := spanExpon10 / stepExpon10
// spanExpon > splitNumber
// stepExpon := floor(spanExpon / splitNumber)
// splitNumberFloat := spanExpon / stepExpon
// There are tow expressions which are identically-true:
// splitNumberFloat - splitNumber <= 1
// stepExpon10 * ceil(splitNumberFloat) - spanExpon10 <= stepExpon10
// stepExpon * ceil(splitNumberFloat) - spanExpon <= stepExpon
// So we can calculate as follows:
var stepExpon10 = mathFloor(fixAccurate(spanExpon10 / splitNumber));
var stepExpon = mathFloor(fixAccurate(spanExpon / splitNumber));
// Put the plot in the middle of the min, max.
var splitNumberAdjust = mathCeil(fixAccurate(spanExpon10 / stepExpon10));
var spanExpon10Adjust = stepExpon10 * splitNumberAdjust;
var halfDiff10 = (spanExpon10Adjust - spanDataLog10) / 2;
var minExpon10Adjust = mathFloor(fixAccurate(minDataLog10 - halfDiff10));
var splitNumberAdjust = mathCeil(fixAccurate(spanExpon / stepExpon));
var spanExponAdjust = stepExpon * splitNumberAdjust;
var halfDiff = (spanExponAdjust - spanDataLog) / 2;
var minExponAdjust = mathFloor(fixAccurate(minDataLog - halfDiff));
if (aroundZero(minExponAdjust - minDataLog)) {
minExponAdjust -= 1;
}
// Build logMapping offset
logMappingOffset = -minExpon10Adjust * LN10;
logMappingOffset = -minExponAdjust * lnBase;
// Build tickList
for (var n = minExpon10Adjust; n - stepExpon10 < maxDataLog10; n += stepExpon10) {
tickList.push(mathPow(10, n));
for (var n = minExponAdjust; n - stepExpon <= maxDataLog; n += stepExpon) {
tickList.push(mathPow(logLabelBase, n));
}
}
// In this situation, base-2|10 ticks are used to make detailed split.
// Base-2|10 ticks: 10^h * 2^k (i.e. 0.1, 0.2, 0.4, 0.8, 1, 2, 4, 8, 10, 20, 40, 80),
// Base-2|10 ticks: 10^h * 2^k (i.e. 0.1, 0.2, 0.4, 1, 2, 4, 10, 20, 40),
// where k in [0, 1, 2].
// Because LN2 * 3 < LN10 and LN2 * 4 > LN10, k should be less than 3.
// And when k === 3, the tick is too close to that of k === 0, which looks weird. So we dont use 3.
// And when k === 3, the tick is too close to that of k === 0, which looks weird.
// So we do not use 3.
function detailAnalysis() {
// Find max exponent and min exponent.
// Calculate base on 3-hexadecimal (0, 1, 2, 10, 11, 12, 20).
var minDecimal = toDecimalFrom4Hex(minExpon10, 0);
var minDecimal = toDecimalFrom4Hex(minExpon, 0);
var endDecimal = minDecimal + 2;
while (
minDecimal < endDecimal
&& toH(minDecimal + 1) + toK(minDecimal + 1) * LN2D10 < minDataLog10
&& toH(minDecimal + 1) + toK(minDecimal + 1) * LN2D10 < minDataLog
) {
minDecimal++;
}
var maxDecimal = toDecimalFrom4Hex(maxExpon10, 0);
var maxDecimal = toDecimalFrom4Hex(maxExpon, 0);
var endDecimal = maxDecimal - 2; // maxDecimal is greater than 4
while (
maxDecimal > endDecimal
&& toH(maxDecimal - 1) + toK(maxDecimal - 1) * LN2D10 > maxDataLog10
&& toH(maxDecimal - 1) + toK(maxDecimal - 1) * LN2D10 > maxDataLog
) {
maxDecimal--;
}
......@@ -238,8 +288,6 @@ define(function(require) {
var h = toH(i);
var k = toK(i);
tickList.push(mathPow(10, h) * mathPow(2, k));
// FIXME
// 小数的显示
}
}
......@@ -266,11 +314,13 @@ define(function(require) {
function makeResult() {
var resultTickList = [];
for (var i = 0, len = tickList.length; i < len; i++) {
resultTickList[i] = formatNumber((logPositive ? 1 : -1) * tickList[i]);
resultTickList[i] = (logPositive ? 1 : -1) * tickList[i];
}
!logPositive && resultTickList.reverse();
var dataMappingMethods = makeDataMappingMethods();
var value2Coord = dataMappingMethods.value2Coord;
var newDataMin = value2Coord(resultTickList[0]);
var newDataMax = value2Coord(resultTickList[resultTickList.length - 1]);
......@@ -280,21 +330,54 @@ define(function(require) {
}
return {
// FIXME
// tickList.length 为0的情况
dataMin: newDataMin,
dataMax: newDataMax,
tickList: resultTickList,
logPositive: logPositive,
dataMappingMethods: zrUtil.merge({}, dataMappingMethods)
labelFormatter: makeLabelFormatter(),
dataMappingMethods: dataMappingMethods
};
}
/**
* Make axis label formatter.
*/
function makeLabelFormatter() {
if (logLabelMode === 'exponent') { // For label style like 3⁴.
// Static variables should be fixed in the scope of the methods.
var myLogLabelBase = logLabelBase;
var myLnBase = lnBase;
return function (value) {
if (!isFinite(parseFloat(value))) {
return '';
}
var sign = '';
if (value < 0) {
value = -value;
sign = '-';
}
return sign + myLogLabelBase + makeSuperscriptExponent(mathLog(value) / myLnBase);
};
}
else {
return function (value) { // Normal style like 0.001, 10,000,0
if (!isFinite(parseFloat(value))) {
return '';
}
return number.addCommas(formatNumber(value));
};
}
}
/**
* Make calculate methods.
* logPositive and logMappingOffset should be fixed in the scope of the methods.
*/
function makeDataMappingMethods(logPositive, logMappingOffset) {
function makeDataMappingMethods() {
// Static variables should be fixed in the scope of the methods.
var myLogPositive = logPositive;
var myLogMappingOffset = logMappingOffset;
return {
value2Coord: function (x) {
if (x == null || isNaN(x) || !isFinite(x)) {
......@@ -304,16 +387,16 @@ define(function(require) {
if (!isFinite(x)) {
x = EPSILON;
}
else if (logPositive && x < EPSILON) {
else if (myLogPositive && x < EPSILON) {
// FIXME
// It is suppose to be ignore, but not be set to EPSILON. See comments above.
x = EPSILON;
}
else if (!logPositive && x > -EPSILON) {
else if (!myLogPositive && x > -EPSILON) {
x = -EPSILON;
}
x = mathAbs(x);
return (logPositive ? 1 : -1) * (mathLog(x) + logMappingOffset);
return (myLogPositive ? 1 : -1) * (mathLog(x) + myLogMappingOffset);
},
coord2Value: function (x) {
if (x == null || isNaN(x) || !isFinite(x)) {
......@@ -323,9 +406,9 @@ define(function(require) {
if (!isFinite(x)) {
x = EPSILON;
}
return logPositive
? mathPow(LOG_BASE, x - logMappingOffset)
: -mathPow(LOG_BASE, -x + logMappingOffset);
return myLogPositive
? mathPow(LOG_BASE, x - myLogMappingOffset)
: -mathPow(LOG_BASE, -x + myLogMappingOffset);
}
};
}
......@@ -344,11 +427,29 @@ define(function(require) {
* @return {string}
*/
function formatNumber(num) {
// FIXME
// I think we should not do this here, but in valueAxis.js
// So refector is desired.
return Number(num).toFixed(15).replace(/\.?0*$/, '');
}
/**
* Make superscript exponent
*/
function makeSuperscriptExponent(exponent) {
exponent = formatNumber(Math.round(exponent)); // Do not support float superscript.
// (because I can not find superscript style of '.')
var result = [];
for (var i = 0, len = exponent.length; i < len; i++) {
var cha = exponent.charAt(i);
result.push(SUPERSCRIPTS[cha] || '');
}
return result.join('');
}
/**
* Decide whether near zero
*/
function aroundZero(val) {
return val > -EPSILON && val < EPSILON;
}
return smartLogSteps;
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册