class ColorManager { private colors: Array = []; /** * 调色盘注册 * @param colors */ public registe(colors) { const isEmpty = (Array.isArray(this.colors) && this.colors.length === 0) || !this.colors; if (isEmpty) { this.colors = colors; } } /** * 从调色盘中挑选颜色 * @param pickInfo * @returns pickedColors * TODO:待支持指定的配色策略(如Pie图按照相邻色系配色等) */ public pick(pickInfo: any) { const { colors } = this; const { count, // 获取颜色对象的数量 } = pickInfo; // 从调色盘提取颜色队列 let pickedColors = []; if (!pickInfo || !count) { pickedColors = colors; } else if (count <= colors.length + 1) { pickedColors = colors.slice(0, count); } else { const restLength = count - (colors.length + 1); pickedColors = [...colors, ...colors.slice(0, restLength)]; } return pickedColors; } } export default ColorManager;