提交 ad838340 编写于 作者: L lang

List map

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