提交 ad838340 编写于 作者: L lang

List map

上级 9bc61378
define(function (require) {
var Bar = require('../../echarts').extendChartView({
return require('../../echarts').extendChartView({
type: 'bar',
......@@ -62,6 +62,4 @@ define(function (require) {
this.data = data;
}
});
return Bar;
});
\ No newline at end of file
......@@ -13,7 +13,7 @@ define(function(require) {
var columnsMap = {};
zrUtil.each(barSeries, function (seriesModel, idx) {
var cartesian = seriesModel.coordinateSystem
var cartesian = seriesModel.coordinateSystem;
var categoryAxis = cartesian.getAxesByScale('ordinal')[0];
......@@ -130,7 +130,7 @@ define(function(require) {
var lastStackCoords = {};
ecModel.eachSeries(function (seriesModel) {
ecModel.eachSeriesByType('bar', function (seriesModel) {
var data = seriesModel.getData();
var cartesian = seriesModel.coordinateSystem;
......
......@@ -22,11 +22,7 @@ define(function(require) {
* `[[10, 10], [20, 20], [30, 30]]`
*/
dataToCoords: function (data) {
var array = [];
data.each(function (dataItem) {
array.push(this.dataToCoord(dataItem));
}, this);
return array;
return data.map(this.dataToCoord, this);
},
dataToCoord: function (dataItem) {
......
......@@ -177,6 +177,17 @@ define(function(require) {
}
},
/**
* Data mapping, returned array is flatten
*/
map: function (cb, context) {
var ret = [];
this.each(function (item, idx) {
ret.push(cb && cb.call(context || this, item));
}, context);
return ret;
},
/**
* In-place filter
*/
......@@ -195,17 +206,17 @@ define(function(require) {
/**
* In-place map
*/
mapInPlace: function (cb, context) {
context = context || this;
if (this.depth > 1) {
createArrayIterWithDepth(
this.depth, this.properties, cb, context, 'map'
)(this.elements, 0);
}
else {
this.elements = zrUtil.map(this.elements, cb, context);
}
},
// mapInPlace: function (cb, context) {
// context = context || this;
// if (this.depth > 1) {
// createArrayIterWithDepth(
// this.depth, this.properties, cb, context, 'map'
// )(this.elements, 0);
// }
// else {
// this.elements = zrUtil.map(this.elements, cb, context);
// }
// },
/**
* @return {module:echarts/data/List~Entry}
......@@ -249,14 +260,19 @@ define(function(require) {
};
zrUtil.each(['X', 'Y', 'Z', 'Value'], function (name) {
// TODO Map and filter
zrUtil.each(['each'], function (iterType) {
List.prototype[iterType + name] = function (cb, context) {
this[iterType](function (item, idx) {
return cb && cb.call(context || this, item['get' + name](idx));
}, context);
};
});
List.prototype['each' + name] = function (cb, context) {
this.each(function (item, idx) {
cb && cb.call(context || this, item['get' + name](idx));
}, context);
};
List.prototype['map' + name] = function (cb, context) {
var ret = [];
this.each(function (item) {
ret.push(cb && cb.call(context || this, item['get' + name]()));
}, context);
return ret;
};
});
List.fromArray = function (data, dimension, parentModel) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册