DictColors.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const whiteColor = '#ffffff';
  2. const blackColor = '#666666';
  3. export const Colors = [
  4. // 背景颜色,文字颜色
  5. ['#2196F3', whiteColor],
  6. ['#08C9C9', whiteColor],
  7. ['#00C345', whiteColor],
  8. ['#FAD714', whiteColor],
  9. ['#FF9300', whiteColor],
  10. ['#F52222', whiteColor],
  11. ['#EB2F96', whiteColor],
  12. ['#7500EA', whiteColor],
  13. ['#2D46C4', whiteColor],
  14. ['#484848', whiteColor],
  15. // --------------------
  16. ['#C9E6FC', blackColor],
  17. ['#C3F2F2', blackColor],
  18. ['#C2F1D2', blackColor],
  19. ['#FEF6C6', blackColor],
  20. ['#FFE5C2', blackColor],
  21. ['#FDCACA', blackColor],
  22. ['#FACDE6', blackColor],
  23. ['#DEC2FA', blackColor],
  24. ['#CCD2F1', blackColor],
  25. ['#D3D3D3', blackColor],
  26. ];
  27. export const NONE_COLOR = ['#e9e9e9', blackColor];
  28. /**
  29. * 返回一个颜色迭代器,每次调用返回一个颜色,当颜色用完后,再从头开始
  30. * @param {number} initIndex 初始颜色索引
  31. * @returns {{getIndex: function, next: function}}
  32. */
  33. export function getColorIterator(initIndex = 0) {
  34. let index = initIndex;
  35. if (index < 0 || index >= Colors.length) {
  36. index = 0;
  37. }
  38. return {
  39. getIndex: () => index,
  40. next() {
  41. const color = Colors[index];
  42. index = (index + 1) % Colors.length;
  43. return color;
  44. },
  45. };
  46. }
  47. /**
  48. * 根据颜色获取当前坐标和颜色
  49. */
  50. export function getItemColor(color) {
  51. if (!color) {
  52. return NONE_COLOR[1];
  53. }
  54. let colorIndex = Colors.findIndex((value) => {
  55. return value[0] === color;
  56. });
  57. if (colorIndex === -1) {
  58. return NONE_COLOR[1];
  59. }
  60. return Colors[colorIndex][1];
  61. }