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

Function updateChart

script.js:1031–1114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1029}
1030
1031function updateChart() {
1032 const canvas = $('dnsChart');
1033 const ctx = canvas.getContext('2d');
1034 const isDark = document.documentElement.classList.contains('dark');
1035
1036 const validData = chartData.filter(d => d.avg !== null).sort((a, b) => a.avg - b.avg);
1037 if (validData.length === 0) return;
1038
1039 // Dynamic height
1040 const height = Math.max(300, Math.min(800, validData.length * 32 + 80));
1041 canvas.parentElement.style.height = `${height}px`;
1042
1043 chartSection.classList.remove('hidden');
1044
1045 if (dnsChart) dnsChart.destroy();
1046
1047 const minVal = Math.min(...validData.map(d => d.avg));
1048 const scaleMin = Math.max(0, minVal * 0.7);
1049
1050 const textColor = isDark ? '#94a3b8' : '#64748b';
1051 const gridColor = isDark ? 'rgba(148,163,184,0.08)' : 'rgba(100,116,139,0.1)';
1052
1053 dnsChart = new Chart(ctx, {
1054 type: 'bar',
1055 data: {
1056 labels: validData.map(d => {
1057 const flag = countryFlag(d.countryCode);
1058 return flag ? `${flag} ${d.name}` : d.name;
1059 }),
1060 datasets: [{
1061 label: 'Avg Response Time (ms)',
1062 data: validData.map(d => d.avg),
1063 backgroundColor: validData.map(d => getBarColor(d.avg, validData)),
1064 borderColor: validData.map(d => getBarColor(d.avg, validData, true)),
1065 borderWidth: 1,
1066 borderRadius: 3
1067 }]
1068 },
1069 options: {
1070 indexAxis: 'y',
1071 responsive: true,
1072 maintainAspectRatio: false,
1073 interaction: { intersect: false, mode: 'y' },
1074 plugins: {
1075 legend: { display: false },
1076 tooltip: {
1077 backgroundColor: isDark ? '#1e293b' : '#fff',
1078 titleColor: isDark ? '#e2e8f0' : '#1e293b',
1079 bodyColor: isDark ? '#94a3b8' : '#64748b',
1080 borderColor: isDark ? '#334155' : '#e2e8f0',
1081 borderWidth: 1,
1082 padding: 10,
1083 cornerRadius: 6,
1084 callbacks: {
1085 label: function (context) {
1086 const s = validData[context.dataIndex];
1087 return [
1088 `Avg: ${s.avg.toFixed(2)} ms`,

Callers 2

script.jsFile · 0.85
updateChartWithDataFunction · 0.85

Calls 3

$Function · 0.85
countryFlagFunction · 0.85
getBarColorFunction · 0.85

Tested by

no test coverage detected