StrategyForge's picture
Claude Opus 4.6
Design system overhaul: neutral monochrome theme, Geist Variable font, new chart palette
d933a8b
Raw History Blame Contribute Delete
6.69 kB
// ===== Screen 8: Volume & Revenue Drivers =====
function fetchPageData() {
const filters = getFilterState();
fetch('/diagnostics/api/diagnostics/data', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(filters)
})
.then(r => r.json())
.then(data => {
renderKPICards('diagKpiGrid', data.kpis);
// Section 0: Marketing ROI Scorecard Table
renderRoiScorecard(data.tables.marketing_roi_scorecard);
// Section 1: Revenue Decomposition
renderChart('chart_decomposition', data.charts.chart_decomposition);
// Section 2: Volume Contribution by Period + Donut + Support Table
renderChart('chart_vol_contribution', data.charts.chart_vol_contribution);
renderChart('chart_base_incremental', data.charts.chart_base_incremental);
renderSupportContribTable(data.tables.support_contribution);
// Section 3: Investment Mix + Efficiency Trend
renderChart('chart_inv_mix', data.charts.chart_inv_mix);
renderChart('chart_efficiency_trend', data.charts.chart_efficiency_trend);
// Section 4: Contribution Waterfall + Period Change
renderChart('chart_contribution', data.charts.chart_contribution);
renderChart('chart_waterfall', data.charts.chart_waterfall);
// Section 5: Seasonality + Summary Table
renderChart('chart_seasonality', data.charts.chart_seasonality);
renderOverallSummary(data.tables.overall_summary);
updateTimestamp();
})
.catch(err => console.error('Error loading diagnostics data:', err));
}
// ---- helpers ----
function changeClass(val) {
if (val > 0) return 'positive';
if (val < 0) return 'negative';
return 'neutral';
}
function changeArrow(val) {
if (val > 0) return '▲';
if (val < 0) return '▼';
return '—';
}
// ---- Section 0: Marketing ROI Scorecard Table ----
function renderRoiScorecard(rows) {
const tbody = document.getElementById('roiScorecardBody');
if (!tbody || !rows) return;
if (rows.length === 0) {
tbody.innerHTML = '<tr><td colspan="10" style="text-align:center;color:#737373;">No data available</td></tr>';
return;
}
tbody.innerHTML = rows.map(r => {
const invCls = changeClass(r.inv_chg);
const roiCls = changeClass(r.roi_chg);
const effCls = changeClass(r.efficiency_cur - r.efficiency_prev);
const isTotal = r.driver === 'Total Marketing';
const rowStyle = isTotal ? 'style="font-weight:700;border-top:2px solid rgba(255,255,255,0.12);background:rgba(255,255,255,0.03);"' : '';
const nameStyle = `style="font-weight:${isTotal ? '700' : '600'};color:${r.color};"`;
return `<tr ${rowStyle}>
<td ${nameStyle}>
<i data-feather="${r.icon}" style="width:14px;height:14px;display:inline;vertical-align:middle;margin-right:6px;"></i>
${r.driver}
</td>
<td class="num">${r.inv_cur_fmt}</td>
<td class="num" style="color:#737373;">${r.inv_prev_fmt}</td>
<td class="num ${invCls}">
<span class="change-badge ${invCls}">${changeArrow(r.inv_chg)} ${Math.abs(r.inv_chg).toFixed(1)}%</span>
</td>
<td class="num">${r.vol_uplift_pct.toFixed(1)}%</td>
<td class="num ${effCls}" style="font-weight:600;">${r.efficiency_cur_fmt}</td>
<td class="num" style="color:#737373;">${r.efficiency_prev_fmt}</td>
<td class="num ${roiCls}" style="font-weight:600;">${r.roi_cur_fmt}</td>
<td class="num" style="color:#737373;">${r.roi_prev_fmt}</td>
<td class="num ${roiCls}">
<span class="change-badge ${roiCls}">${changeArrow(r.roi_chg)} ${Math.abs(r.roi_chg).toFixed(1)}%</span>
</td>
</tr>`;
}).join('');
if (typeof feather !== 'undefined') feather.replace();
}
// ---- Section 2: Support vs Contribution Table ----
function renderSupportContribTable(rows) {
const tbody = document.getElementById('supportContribBody');
if (!tbody || !rows) return;
if (rows.length === 0) {
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;color:#737373;">No data available</td></tr>';
return;
}
const catColors = {
'Media': '#3987e5',
'Promo': '#22c55e',
'Base': '#737373',
};
tbody.innerHTML = rows.map(r => {
const catColor = catColors[r.category] || '#9ca3af';
const isBase = r.category === 'Base';
const rowStyle = isBase ? 'style="color:#737373;"' : '';
return `<tr ${rowStyle}>
<td style="font-weight:600;">${r.driver}</td>
<td>
<span style="padding:2px 8px;border-radius:4px;font-size:11px;font-weight:600;
background:${catColor}22;color:${catColor};">
${r.category}
</span>
</td>
<td class="num">${r.support}</td>
<td class="num" style="font-weight:600;">${r.rev_contribution}</td>
<td class="num">${r.vol_contribution}</td>
<td class="num">${r.efficiency}</td>
<td class="num">${r.pct_of_total}</td>
</tr>`;
}).join('');
}
// ---- Section 5: Overall KPI Summary Table ----
function renderOverallSummary(rows) {
const tbody = document.getElementById('overallSummaryBody');
if (!tbody || !rows) return;
if (rows.length === 0) {
tbody.innerHTML = '<tr><td colspan="5" style="text-align:center;color:#737373;">No data available</td></tr>';
return;
}
tbody.innerHTML = rows.map(r => {
const cls = changeClass(r.change_pct);
const indent = r.indent ? 'style="padding-left: 28px; color: #737373;"' : '';
return `<tr>
<td ${indent}>
<i data-feather="${r.icon}" style="width:14px;height:14px;display:inline;vertical-align:middle;margin-right:6px;"></i>
${r.metric}
</td>
<td class="num" style="font-weight:600;">${r.current_fmt}</td>
<td class="num">${r.previous_fmt}</td>
<td class="num ${cls}">${r.change_abs_fmt}</td>
<td class="num ${cls}">
<span class="change-badge ${cls}">
${changeArrow(r.change_pct)} ${Math.abs(r.change_pct).toFixed(1)}%
</span>
</td>
</tr>`;
}).join('');
if (typeof feather !== 'undefined') feather.replace();
}
document.addEventListener('DOMContentLoaded', fetchPageData);