提交 4dd7446b 编写于 作者: L lang

Color callback

上级 1ebfcebe
......@@ -13,7 +13,7 @@ var startCode = fs.readFileSync('wrap/start.js', 'utf-8');
var nutCode = fs.readFileSync('wrap/nut.js', 'utf-8');
var endCode = fs.readFileSync('wrap/end.js', 'utf-8');
mainCode = require('./optimizeString')(mainCode);
// mainCode = require('./optimizeString')(mainCode);
endCode = etpl.compile(endCode)({
parts: config.include
......
......@@ -84,6 +84,12 @@ define(function (require) {
color = LEGEND_DISABLE_COLOR;
}
// If color is a callback function
if (typeof color === 'function') {
// Use the first data
color = color(seriesModel.getFormatParams(0));
}
// Using rect symbol defaultly
var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
var symbolType = data.getVisual('symbol');
......
......@@ -2,20 +2,31 @@ define(function (require) {
return function (ecModel) {
ecModel.eachSeriesAll(function (seriesModel) {
var colorAccessPath = ['itemStyle', 'normal', 'color'];
var colorList = ecModel.get('color');
var data = seriesModel.getData();
var color = seriesModel.get('itemStyle.normal.color') // Set in itemStyle
var color = seriesModel.get(colorAccessPath) // Set in itemStyle
|| colorList[seriesModel.seriesIndex]; // Default color
data.setVisual('color', color);
data.each(function (idx) {
var itemModel = data.getItemModel(idx);
var color = itemModel.get('itemStyle.normal.color');
if (color != null) {
data.setItemVisual(idx, 'color', color);
// Only visible series has each data be visual encoded
if (!ecModel.isSeriesFiltered(seriesModel)) {
if (typeof color === 'function') {
data.each(function (idx) {
data.setItemVisual(
idx, 'color', color(seriesModel.getFormatParams(idx))
);
});
}
});
data.each(function (idx) {
var itemModel = data.getItemModel(idx);
var color = itemModel.get(colorAccessPath, true);
if (color != null) {
data.setItemVisual(idx, 'color', color);
}
});
}
});
}
};
});
\ No newline at end of file
......@@ -13,8 +13,6 @@ define(function (require) {
var symbolType = seriesModel.get('symbol') || defaultSymbolType;
var symbolSize = seriesModel.get('symbolSize');
// var coordSys = seriesModel.coordinateSystem;
data.setVisual({
legendSymbol: legendSymbol || symbolType,
symbol: symbolType,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册