提交 266004cb 编写于 作者: L lang

Markpoint precision

上级 b2d09149
define(function (require) {
var zrUtil = require('zrender/core/util');
var numberUtil = require('../../util/number');
var getPrecision = function (data, valueAxisDim, dataIndex) {
var precision = -1;
do {
precision = Math.max(
numberUtil.getPrecision(data.get(
valueAxisDim, dataIndex
)),
precision
);
data = data.stackedOn;
} while (data);
return precision;
};
var markerTypeCalculatorWithExtent = function (percent, data, baseAxisDim, valueAxisDim) {
var extent = data.getDataExtent(valueAxisDim);
......@@ -12,6 +28,12 @@ define(function (require) {
var dataIndex = data.indexOfNearest(valueAxisDim, val);
valueArr[1 - valueIndex] = data.get(baseAxisDim, dataIndex);
valueArr[valueIndex] = data.get(valueAxisDim, dataIndex, true);
var precision = getPrecision(data, valueAxisDim, dataIndex);
if (precision >= 0) {
valueArr[valueIndex] = +valueArr[valueIndex].toFixed(precision);
}
return valueArr;
};
......
......@@ -367,7 +367,7 @@ define(function (require) {
for (var i = 0; i < componentsList.length;) {
var component = componentsList[i];
if (! component.__keepAlive) {
if (!component.__keepAlive) {
this._zr.remove(component.group);
component.dispose(this._extensionAPI);
componentsList.splice(i, 1);
......
......@@ -6,6 +6,7 @@
define(function (require) {
var zrUtil = require('zrender/core/util');
var number = {};
function _trim(str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '');
......@@ -20,7 +21,7 @@ define(function (require) {
* @param {boolean} clamp
* @return {(number|Array.<number>}
*/
function linearMap(val, domain, range, clamp) {
number.linearMap = function (val, domain, range, clamp) {
if (zrUtil.isArray(val)) {
return zrUtil.map(val, function (v) {
......@@ -50,7 +51,7 @@ define(function (require) {
* @param {number} all
* @return {number}
*/
function parsePercent(percent, all) {
number.parsePercent = function(percent, all) {
switch (percent) {
case 'center':
case 'middle':
......@@ -74,34 +75,45 @@ define(function (require) {
}
return +percent;
}
};
/**
* Fix rounding error of float numbers
* @param {number} x
* @return {number}
*/
function round(x) {
number.round = function (x) {
// PENDING
return +(+x).toFixed(12);
}
function asc(arr) {
number.asc = function (arr) {
arr.sort(function (a, b) {
return a - b;
});
return arr;
}
return {
linearMap: linearMap,
parsePercent: parsePercent,
};
round: round,
/**
* Get precision
* @param {number} val
*/
number.getPrecision = function (val) {
// It is much faster than methods converting number to string as follows
// var tmp = val.toString();
// return tmp.length - 1 - tmp.indexOf('.');
// especially when precision is low
var e = 1;
var count = 0;
while (Math.round(val * e) / e !== val) {
e *= 10;
count++;
}
return count;
};
asc: asc,
// Number.MAX_SAFE_INTEGER, ie do not support.
number.MAX_SAFE_INTEGER = 9007199254740991;
// Number.MAX_SAFE_INTEGER, ie do not support.
MAX_SAFE_INTEGER: 9007199254740991
};
return number;
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册