提交 72391ab3 编写于 作者: P pissang

Validate dimensions in List. Fix dataZoom shadow error when using custom dimensions names.

上级 61da5ff2
...@@ -397,10 +397,13 @@ var SliderZoomView = DataZoomView.extend({ ...@@ -397,10 +397,13 @@ var SliderZoomView = DataZoomView.extend({
var otherDim = getOtherDim(dimNames.name); var otherDim = getOtherDim(dimNames.name);
var otherAxisInverse; var otherAxisInverse;
var coordSys = seriesModel.coordinateSystem; var coordSys = seriesModel.coordinateSystem;
if (otherDim != null && coordSys.getOtherAxis) { if (otherDim != null && coordSys.getOtherAxis) {
otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse; otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
} }
otherDim = seriesModel.coordDimToDataDim(otherDim)[0];
result = { result = {
thisAxis: thisAxis, thisAxis: thisAxis,
series: seriesModel, series: seriesModel,
......
...@@ -595,10 +595,14 @@ listProto.get = function (dim, idx, stack) { ...@@ -595,10 +595,14 @@ listProto.get = function (dim, idx, stack) {
if (idx < 0 || idx >= this._count) { if (idx < 0 || idx >= this._count) {
return NaN; return NaN;
} }
var storage = this._storage;
if (!storage[dim]) {
// TODO Warn ?
return NaN;
}
idx = this.getRawIndex(idx); idx = this.getRawIndex(idx);
var storage = this._storage;
var chunkIndex = Math.floor(idx / this._chunkSize); var chunkIndex = Math.floor(idx / this._chunkSize);
var chunkOffset = idx % this._chunkSize; var chunkOffset = idx % this._chunkSize;
...@@ -957,6 +961,14 @@ function normalizeDimensions(dimensions) { ...@@ -957,6 +961,14 @@ function normalizeDimensions(dimensions) {
return dimensions; return dimensions;
} }
function validateDimensions(list, dims) {
for (var i = 0; i < dims.length; i++) {
if (!list._storage[dims[i]]) {
console.error('Unkown dimension ' + dims[i]);
}
}
}
/** /**
* Data iteration * Data iteration
* @param {string|Array.<string>} * @param {string|Array.<string>}
...@@ -970,6 +982,8 @@ function normalizeDimensions(dimensions) { ...@@ -970,6 +982,8 @@ function normalizeDimensions(dimensions) {
* list.each(function (idx) {}) * list.each(function (idx) {})
*/ */
listProto.each = function (dims, cb, stack, context) { listProto.each = function (dims, cb, stack, context) {
'use strict';
if (typeof dims === 'function') { if (typeof dims === 'function') {
context = stack; context = stack;
stack = cb; stack = cb;
...@@ -979,6 +993,10 @@ listProto.each = function (dims, cb, stack, context) { ...@@ -979,6 +993,10 @@ listProto.each = function (dims, cb, stack, context) {
dims = zrUtil.map(normalizeDimensions(dims), this.getDimension, this); dims = zrUtil.map(normalizeDimensions(dims), this.getDimension, this);
if (__DEV__) {
validateDimensions(this, dims);
}
var dimSize = dims.length; var dimSize = dims.length;
context = context || this; context = context || this;
...@@ -1032,6 +1050,11 @@ listProto.filterSelf = function (dimensions, cb, stack, context) { ...@@ -1032,6 +1050,11 @@ listProto.filterSelf = function (dimensions, cb, stack, context) {
normalizeDimensions(dimensions), this.getDimension, this normalizeDimensions(dimensions), this.getDimension, this
); );
if (__DEV__) {
validateDimensions(this, dimensions);
}
var count = this.count(); var count = this.count();
var Ctor = getIndicesCtor(count); var Ctor = getIndicesCtor(count);
var newIndices = new Ctor(count); var newIndices = new Ctor(count);
...@@ -1091,6 +1114,11 @@ listProto.selectRange = function (range, stack) { ...@@ -1091,6 +1114,11 @@ listProto.selectRange = function (range, stack) {
dimensions.push(dim); dimensions.push(dim);
} }
} }
if (__DEV__) {
validateDimensions(this, dimensions);
}
var dimSize = dimensions.length; var dimSize = dimensions.length;
if (!dimSize) { if (!dimSize) {
return; return;
...@@ -1154,6 +1182,8 @@ listProto.selectRange = function (range, stack) { ...@@ -1154,6 +1182,8 @@ listProto.selectRange = function (range, stack) {
* @return {Array} * @return {Array}
*/ */
listProto.mapArray = function (dimensions, cb, stack, context) { listProto.mapArray = function (dimensions, cb, stack, context) {
'use strict';
if (typeof dimensions === 'function') { if (typeof dimensions === 'function') {
context = stack; context = stack;
stack = cb; stack = cb;
...@@ -1161,6 +1191,10 @@ listProto.mapArray = function (dimensions, cb, stack, context) { ...@@ -1161,6 +1191,10 @@ listProto.mapArray = function (dimensions, cb, stack, context) {
dimensions = []; dimensions = [];
} }
if (__DEV__) {
validateDimensions(this, dimensions);
}
var result = []; var result = [];
this.each(dimensions, function () { this.each(dimensions, function () {
result.push(cb && cb.apply(this, arguments)); result.push(cb && cb.apply(this, arguments));
...@@ -1208,10 +1242,16 @@ function cloneDimStore(originalDimStore) { ...@@ -1208,10 +1242,16 @@ function cloneDimStore(originalDimStore) {
* @return {Array} * @return {Array}
*/ */
listProto.map = function (dimensions, cb, stack, context) { listProto.map = function (dimensions, cb, stack, context) {
'use strict';
dimensions = zrUtil.map( dimensions = zrUtil.map(
normalizeDimensions(dimensions), this.getDimension, this normalizeDimensions(dimensions), this.getDimension, this
); );
if (__DEV__) {
validateDimensions(this, dimensions);
}
var list = cloneListForMapAndSample(this, dimensions); var list = cloneListForMapAndSample(this, dimensions);
// Following properties are all immutable. // Following properties are all immutable.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册