`; } const renderChart = (id, type, data, options) => { const ctx = document.getElementById(id)?.getContext('2d'); if(!ctx) return; if(charts[id]) charts[id].destroy(); charts[id] = new Chart(ctx, { type, data, options }); }; function renderCharts(data) { // Domain Authority Chart const daBins = { "0-10": 0, "11-20": 0, "21-30": 0, "31-40": 0, "41-50": 0, "51-60": 0, "61-70": 0, "71-80": 0, "81-90": 0, "91-100": 0 }; data.forEach(r => { const bin = Math.min(Math.floor(r.domain_authority / 10) * 10 + 1, 91); const binKey = `${bin}-${bin+9 > 100 ? 100 : bin+9}`; if(r.domain_authority === 0) daBins["0-10"]++; else if(daBins[binKey] !== undefined) daBins[binKey]++; }); renderChart('link-da-chart', 'bar', { labels: Object.keys(daBins), datasets: [{ label: 'Number of Linking Domains', data: Object.values(daBins), backgroundColor: 'rgba(13, 148, 136, 0.7)' }] }, { responsive: true, maintainAspectRatio: false, plugins:{legend:{display:false}}, scales:{y:{beginAtZero: true, ticks: {stepSize: 1}}} } ); // Top Anchor Texts Chart const anchorCounts = data.reduce((acc, r) => { acc[r.anchor_text] = (acc[r.anchor_text] || 0) + 1; return acc; }, {}); const topAnchors = Object.entries(anchorCounts).sort((a,b) => b[1] - a[1]).slice(0, 10); renderChart('link-anchor-chart', 'bar', { labels: topAnchors.map(a => a[0]), datasets: [{ label: 'Frequency', data: topAnchors.map(a => a[1]), backgroundColor: 'rgba(8, 145, 178, 0.7)' }] }, { responsive: true, maintainAspectRatio: false, indexAxis: 'y', plugins:{legend:{display:false}} } ); } function renderTopLinksTable(data) { const sortedLinks = [...data].sort((a,b) => b.domain_authority - a.domain_authority); elements.topLinksTbody.innerHTML = sortedLinks.slice(0, 15).map(link => ` ${link.source_url} ${link.domain_authority} ${link.link_type} ${link.anchor_text} `).join(''); } window.linkDownloadPDF = () => { html2canvas(document.getElementById('link-pdf-content'), { scale: 2 }).then(canvas => { const pdf = new jspdf.jsPDF({ orientation: 'landscape', unit: 'pt', format: 'a4' }); pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 40, 40, pdf.internal.pageSize.getWidth() - 80, 0); pdf.save('External_Link_Analysis.pdf'); }); }; loadSampleData(); });
Scroll to Top