MCPcopy Create free account
hub / github.com/BrainicHQ/DoHSpeedTest / getBarColor

Function getBarColor

script.js:1116–1135  ·  view source on GitHub ↗
(responseTime, allData, border = false)

Source from the content-addressed store, hash-verified

1114}
1115
1116function getBarColor(responseTime, allData, border = false) {
1117 if (!allData || allData.length === 0) return border ? '#22c55e' : '#22c55e80';
1118
1119 const times = allData.map(d => d.avg).filter(t => t !== null);
1120 const min = Math.min(...times);
1121 const max = Math.max(...times);
1122 if (min === max) return border ? '#22c55e' : '#22c55e80';
1123
1124 const norm = (responseTime - min) / (max - min);
1125 let r, g;
1126 if (norm <= 0.5) {
1127 r = Math.round(255 * (norm * 2));
1128 g = 255;
1129 } else {
1130 r = 255;
1131 g = Math.round(255 * (2 - norm * 2));
1132 }
1133 const hex = `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}00`;
1134 return border ? hex : hex + '80';
1135}
1136
1137// ─── Server Capability Check ─────────────────────────────────────────────────
1138

Callers 1

updateChartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected