echarts
Version:
A powerful charting and visualization library for browser
34 lines (27 loc) • 989 B
JavaScript
var classUtil = require('../../util/clazz');
var set = classUtil.set;
var get = classUtil.get;
module.exports = {
clearColorPalette: function () {
set(this, 'colorIdx', 0);
set(this, 'colorNameMap', {});
},
getColorFromPalette: function (name, scope) {
scope = scope || this;
var colorIdx = get(scope, 'colorIdx') || 0;
var colorNameMap = get(scope, 'colorNameMap') || set(scope, 'colorNameMap', {});
if (colorNameMap[name]) {
return colorNameMap[name];
}
var colorPalette = this.get('color', true) || [];
if (!colorPalette.length) {
return;
}
var color = colorPalette[colorIdx];
if (name) {
colorNameMap[name] = color;
}
set(scope, 'colorIdx', (colorIdx + 1) % colorPalette.length);
return color;
}
};