`).join(''); grid.addEventListener('click', (e) => { const card = e.target.closest('.interactive-card'); if (card) { const itemId = card.dataset.id; const itemData = data.find(d => d.id === itemId); if (itemData) { detailsPane.innerHTML = `
${itemData.icon}
${itemData.title}
${itemData.description}
${itemData.useCases ? `
Best For: ${itemData.useCases}
` : ''} ${itemData.tips ? `
Pro Tip: ${itemData.tips}
` : ''} ${itemData.example ? `
Example: ${itemData.example}
` : ''}
`; detailsPane.classList.remove('hidden'); } } }); } populateGrid('ad-formats-grid', 'ad-format-details', appData.adFormats); populateGrid('targeting-grid', 'targeting-details', appData.targeting); // --- CHART.JS LOGIC --- const chartOptions = { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom', }, tooltip: { bodyFont: { size: 14 }, titleFont: { size: 16, weight: 'bold' } } }, }; // Age Chart const ageCtx = document.getElementById('ageChart'); if (ageCtx) { new Chart(ageCtx, { type: 'doughnut', data: { labels: ['18-24', '25-34', '35-49', '50-64', '65+'], datasets: [{ label: 'User Age Distribution', data: [18, 35, 30, 12, 5], backgroundColor: ['#38bdf8', '#0ea5e9', '#0284c7', '#0369a1', '#075985'], borderColor: '#f8fafc', borderWidth: 4 }] }, options: chartOptions }); } // Interest Chart const interestCtx = document.getElementById('interestChart'); if (interestCtx) { new Chart(interestCtx, { type: 'bar', data: { labels: ['Technology', 'News', 'Music', 'Sports', 'Finance', 'Gaming'], datasets: [{ label: '% of Users Interested', data: [75, 72, 68, 65, 58, 55], backgroundColor: '#0ea5e9', borderRadius: 4 }] }, options: { ...chartOptions, indexAxis: 'y' } }); } // Objectives Chart const objectivesCtx = document.getElementById('objectivesChart'); if (objectivesCtx) { new Chart(objectivesCtx, { type: 'bar', data: { labels: ['Reach', 'Website Clicks', 'Engagements', 'Conversions'], datasets: [ { label: 'Cost Per Result ($) - Lower is better', data: [0.01, 0.85, 0.15, 12.50], backgroundColor: '#0ea5e9', yAxisID: 'y', borderRadius: 4 }, { label: 'Volume of Results - Higher is better', data: [100000, 5000, 15000, 200], backgroundColor: '#0369a1', yAxisID: 'y1', borderRadius: 4 } ] }, options: { ...chartOptions, scales: { y: { beginAtZero: true, position: 'left', title: { display: true, text: 'Cost ($)' } }, y1: { beginAtZero: true, position: 'right', grid: { drawOnChartArea: false }, title: { display: true, text: 'Volume' } } } } }); } // Optimization Chart const optimizationCtx = document.getElementById('optimizationChart'); if (optimizationCtx) { const initialData = { labels: ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6', 'Day 7'], datasets: [{ label: 'Cost Per Acquisition ($)', data: [15.2, 16.1, 15.8, 16.5, 17.2, 16.8, 17.5], borderColor: '#f43f5e', // rose-500 backgroundColor: '#fecdd3', // rose-200 fill: true, tension: 0.4 }] }; const optimizationChart = new Chart(optimizationCtx, { type: 'line', data: initialData, options: { ...chartOptions, scales: { y: { beginAtZero: false, title: { display: true, text: 'Cost Per Acquisition ($)' } } } } }); document.getElementById('optimize-btn').addEventListener('click', () => { const newData = [15.2, 16.1, 15.8, 14.5, 12.3, 11.8, 11.2]; optimizationChart.data.datasets[0].data = newData; optimizationChart.data.datasets[0].borderColor = '#16a34a'; // emerald-600 optimizationChart.data.datasets[0].backgroundColor = '#a7f3d0'; // emerald-200 optimizationChart.update(); }); } });