提交 1676ea1a 编写于 作者: L lang

linearMap remove isArray evaluate

上级 ab7868a0
......@@ -432,8 +432,12 @@ define(function (require) {
*/
_resetInterval: function () {
var range = this._range = this.dataZoomModel.getPercentRange();
var viewExtent = this._getViewExtent();
this._handleEnds = linearMap(range, [0, 100], this._getViewExtent(), true);
this._handleEnds = [
linearMap(range[0], [0, 100], viewExtent, true),
linearMap(range[1], [0, 100], viewExtent, true)
];
},
/**
......@@ -455,7 +459,10 @@ define(function (require) {
handleIndex
);
this._range = asc(linearMap(handleEnds, viewExtend, [0, 100], true));
this._range = asc([
linearMap(handleEnds[0], viewExtend, [0, 100], true),
linearMap(handleEnds[1], viewExtend, [0, 100], true)
]);
},
/**
......
......@@ -257,13 +257,13 @@ define(function(require) {
var visualMapModel = this.visualMapModel;
var dataInterval = this._dataInterval = visualMapModel.getSelected();
var dataExtent = visualMapModel.getExtent();
var sizeExtent = [0, visualMapModel.itemSize[1]];
this._handleEnds = linearMap(
dataInterval,
visualMapModel.getExtent(),
[0, visualMapModel.itemSize[1]],
true
);
this._handleEnds = [
linearMap(dataInterval[0], dataExtent, sizeExtent,true),
linearMap(dataInterval[1], dataExtent, sizeExtent,true)
];
},
/**
......@@ -284,14 +284,13 @@ define(function(require) {
handleIndex === 'all' ? 'rigid' : 'push',
handleIndex
);
var dataExtent = visualMapModel.getExtent();
var sizeExtent = [0, visualMapModel.itemSize[1]];
// Update data interval.
this._dataInterval = linearMap(
handleEnds,
[0, visualMapModel.itemSize[1]],
visualMapModel.getExtent(),
true
);
this._dataInterval = [
linearMap(handleEnds[0], sizeExtent, dataExtent, true),
linearMap(handleEnds[1], sizeExtent, dataExtent, true)
];
},
/**
......
......@@ -11,6 +11,8 @@ define(function (require) {
extent[0] += margin;
extent[1] -= margin;
}
var normalizedExtent = [0, 1];
/**
* @name module:echarts/coord/CartesianAxis
* @constructor
......@@ -111,14 +113,16 @@ define(function (require) {
* @return {number}
*/
dataToCoord: function (data, clamp) {
data = this.scale.normalize(data);
var extent = this.getExtent();
var extent = this._extent;
var scale = this.scale;
data = scale.normalize(data);
if (this.onBand && scale.type === 'ordinal') {
extent = extent.slice();
fixExtentWithBands(extent, scale.count());
}
return linearMap(data, [0, 1], extent, clamp);
return linearMap(data, normalizedExtent, extent, clamp);
},
/**
......@@ -128,13 +132,15 @@ define(function (require) {
* @return {number}
*/
coordToData: function (coord, clamp) {
var extent = this.getExtent();
var extent = this._extent;
var scale = this.scale;
if (this.onBand) {
fixExtentWithBands(extent, this.scale.count());
if (this.onBand && scale.type === 'ordinal') {
extent = extent.slice();
fixExtentWithBands(extent, scale.count());
}
var t = linearMap(coord, extent, [0, 1], clamp);
var t = linearMap(coord, extent, normalizedExtent, clamp);
return this.scale.scale(t);
},
......
......@@ -25,12 +25,6 @@ define(function (require) {
*/
number.linearMap = function (val, domain, range, clamp) {
if (zrUtil.isArray(val)) {
return zrUtil.map(val, function (v) {
return number.linearMap(v, domain, range, clamp);
});
}
var sub = domain[1] - domain[0];
if (sub === 0) {
......
......@@ -11,6 +11,14 @@ define(function (require) {
var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
function linearMapArray(val, domain, range, clamp) {
if (zrUtil.isArray(val)) {
return zrUtil.map(val, function (v) {
return linearMap(v, domain, range, clamp);
});
}
return linearMap(val, domain, range, clamp);
}
/**
* @param {Object} option
* @param {string} [option.type] See visualHandlers.
......@@ -223,7 +231,7 @@ define(function (require) {
if (result == null) {
result = isCategory(this)
? getVisualForCategory(this, visual, normalized)
: linearMap(normalized, [0, 1], visual, true);
: linearMapArray(normalized, [0, 1], visual, true);
}
return result;
}
......@@ -322,7 +330,7 @@ define(function (require) {
if (result == null) {
result = isCategory(this)
? getVisualForCategory(this, visual, normalized)
: linearMap(normalized, [0, 1], visual, true);
: linearMapArray(normalized, [0, 1], visual, true);
}
return result;
}
......@@ -331,7 +339,7 @@ define(function (require) {
function arrayGetByNormalizedValue(arr, normalized) {
return arr[
Math.round(linearMap(normalized, [0, 1], [0, arr.length - 1], true))
Math.round(linearMapArray(normalized, [0, 1], [0, arr.length - 1], true))
];
}
......@@ -355,14 +363,14 @@ define(function (require) {
var normalizers = {
linear: function (value) {
return linearMap(value, this.option.dataExtent, [0, 1], true);
return linearMapArray(value, this.option.dataExtent, [0, 1], true);
},
piecewise: function (value) {
var pieceList = this.option.pieceList;
var pieceIndex = VisualMapping.findPieceIndex(value, pieceList);
if (pieceIndex != null) {
return linearMap(pieceIndex, [0, pieceList.length - 1], [0, 1], true);
return linearMapArray(pieceIndex, [0, pieceList.length - 1], [0, 1], true);
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册