MCPcopy
hub / github.com/zxlie/FeHelper / isColorDark

Function isColorDark

apps/chart-maker/chart-generator.js:554–592  ·  view source on GitHub ↗
(color)

Source from the content-addressed store, hash-verified

552
553// 判断颜色是否为深色
554function isColorDark(color) {
555 // 处理rgba格式
556 if (color && color.startsWith('rgba')) {
557 const parts = color.match(/rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)/);
558 if (parts) {
559 const r = parseInt(parts[1]);
560 const g = parseInt(parts[2]);
561 const b = parseInt(parts[3]);
562 // 计算亮度 (根据人眼对RGB的敏感度加权)
563 const brightness = (r * 0.299 + g * 0.587 + b * 0.114) / 255;
564 return brightness < 0.7; // 亮度小于0.7认为是深色
565 }
566 }
567
568 // 处理rgb格式
569 if (color && color.startsWith('rgb(')) {
570 const parts = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
571 if (parts) {
572 const r = parseInt(parts[1]);
573 const g = parseInt(parts[2]);
574 const b = parseInt(parts[3]);
575 const brightness = (r * 0.299 + g * 0.587 + b * 0.114) / 255;
576 return brightness < 0.7;
577 }
578 }
579
580 // 处理十六进制格式
581 if (color && color.startsWith('#')) {
582 color = color.replace('#', '');
583 const r = parseInt(color.length === 3 ? color.substring(0, 1).repeat(2) : color.substring(0, 2), 16);
584 const g = parseInt(color.length === 3 ? color.substring(1, 2).repeat(2) : color.substring(2, 4), 16);
585 const b = parseInt(color.length === 3 ? color.substring(2, 3).repeat(2) : color.substring(4, 6), 16);
586 const brightness = (r * 0.299 + g * 0.587 + b * 0.114) / 255;
587 return brightness < 0.7;
588 }
589
590 // 默认返回true,使用白色文本
591 return true;
592}
593
594// 应用颜色方案
595function applyColorScheme(data, colorScheme, chartType) {

Callers 2

getChartOptionsFunction · 0.85
applyColorSchemeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected