The user wants a CFO Policy Influence Dashboard - this is a sophisticated financial/policy visualization tool. Let me think about what this should include:
Color scheme: Deep navy/dark blue background with gold/amber accents for financial feel, plus status colors (green for positive, red for risk, blue for neutral).
A comprehensive dashboard tracking lobbying activities, regulatory timelines, and financial sensitivities. Here's my approach:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CFO Policy Influence Dashboard</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #0a0e17;
--bg-secondary: #111827;
--bg-card: #1a2332;
--border: #2a3a52;
--text-primary: #f0f4f8;
--text-secondary: #8899aa;
--accent-gold: #d4a84b;
--accent-gold-dim: #a68532;
--positive: #22c55e;
--negative: #ef4444;
--neutral: #3b82f6;
--warning: #f59e0b;
}
body {
font-family: 'Segoe UI', system-ui, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
.dashboard {
display: grid;
grid-template-columns: 1fr;
gap: 20px;
padding: 20px;
max-width: 1800px;
margin: 0 auto;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 30px;
background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
border-bottom: 1px solid var(--border);
position: sticky;
top: 0;
z-index: 100;
}
.logo {
display: flex;
align-items: center;
gap: 15px;
}
.logo-icon {
width: 45px;
height: 45px;
background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-gold-dim) 100%);
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 18px;
color: var(--bg-primary);
}
.logo h1 {
font-size: 22px;
font-weight: 600;
color: var(--text-primary);
}
.logo span {
font-size: 12px;
color: var(--text-secondary);
display: block;
}
.header-stats {
display: flex;
gap: 30px;
}
.stat-item {
text-align: right;
}
.stat-value {
font-size: 24px;
font-weight: 700;
color: var(--accent-gold);
}
.stat-label {
font-size: 11px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 1px;
}
.grid-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 20px;
}
.card {
background: var(--bg-card);
border-radius: 12px;
border: 1px solid var(--border);
overflow: hidden;
transition: all 0.3s ease;
}
.card:hover {
border-color: var(--accent-gold-dim);
box-shadow: 0 8px 32px rgba(212, 168, 75, 0.1);
}
.card-header {
padding: 18px 22px;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
}
.card-title {
font-size: 14px;
font-weight: 600;
color: var(--text-primary);
display: flex;
align-items: center;
gap: 10px;
}
.card-title::before {
content: '';
width: 4px;
height: 18px;
background: var(--accent-gold);
border-radius: 2px;
}
.card-badge {
font-size: 10px;
padding: 4px 10px;
background: rgba(212, 168, 75, 0.15);
color: var(--accent-gold);
border-radius: 20px;
text-transform: uppercase;
letter-spacing: 1px;
}
.card-body {
padding: 20px;
}
.chart-container {
position: relative;
width: 100%;
height: 250px;
}
.chart-container canvas {
width: 100%;
height: 100%;
}
/* Lobbying Spend Chart */
.spend-chart {
height: 280px;
}
/* Timeline Styles */
.timeline-container {
position: relative;
padding: 20px 0;
overflow-x: auto;
}
.timeline-track {
position: relative;
height: 120px;
min-width: 800px;
}
.timeline-line {
position: absolute;
top: 50%;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, var(--border) 0%, var(--accent-gold) 50%, var(--border) 100%);
transform: translateY(-50%);
}
.timeline-event {
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
cursor: pointer;
transition: all 0.3s ease;
}
.event-marker {
width: 16px;
height: 16px;
border-radius: 50%;
border: 3px solid var(--bg-card);
transition: all 0.3s ease;
}
.event-marker.passed { background: var(--positive); }
.event-marker.pending { background: var(--warning); }
.event-marker.review { background: var(--neutral); }
.event-marker.risk { background: var(--negative); }
.timeline-event:hover .event-marker {
transform: scale(1.5);
box-shadow: 0 0 20px currentColor;
}
.event-label {
position: absolute;
top: 30px;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
font-size: 11px;
color: var(--text-secondary);
opacity: 0;
transition: all 0.3s ease;
}
.timeline-event:hover .event-label {
opacity: 1;
color: var(--text-primary);
}
.event-date {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
font-size: 10px;
color: var(--text-secondary);
}
/* Sensitivity Matrix */
.sensitivity-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
}
.sensitivity-item {
background: var(--bg-secondary);
border-radius: 8px;
padding: 15px;
text-align: center;
border: 1px solid transparent;
transition: all 0.3s ease;
cursor: pointer;
}
.sensitivity-item:hover {
border-color: var(--accent-gold-dim);
transform: translateY(-3px);
}
.sensitivity-item.high-impact {
border-color: var(--negative);
}
.sensitivity-item.medium-impact {
border-color: var(--warning);
}
.sensitivity-item.low-impact {
border-color: var(--positive);
}
.sens-label {
font-size: 11px;
color: var(--text-secondary);
margin-bottom: 8px;
}
.sens-value {
font-size: 18px;
font-weight: 700;
}
.sens-value.positive { color: var(--positive); }
.sens-value.negative { color: var(--negative); }
.sens-value.neutral { color: var(--neutral); }
.sens-change {
font-size: 10px;
margin-top: 5px;
}
/* Risk Gauge */
.gauge-container {
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.gauge-canvas {
width: 200px;
height: 120px;
}
.gauge-value {
text-align: center;
margin-top: 10px;
}
.gauge-number {
font-size: 36px;
font-weight: 700;
color: var(--warning);
}
.gauge-label {
font-size: 12px;
color: var(--text-secondary);
}
/* Policy List */
.policy-list {
max-height: 300px;
overflow-y: auto;
}
.policy-item {
display: flex;
align-items: center;
padding: 14px;
border-bottom: 1px solid var(--border);
transition: all 0.2s ease;
cursor: pointer;
}
.policy-item:hover {
background: var(--bg-secondary);
}
.policy-item:last-child {
border-bottom: none;
}
.policy-status {
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 15px;
flex-shrink: 0;
}
.policy-info {
flex: 1;
}
.policy-name {
font-size: 13px;
font-weight: 500;
margin-bottom: 4px;
}
.policy-meta {
font-size: 11px;
color: var(--text-secondary);
}
.policy-impact {
text-align: right;
}
.policy-amount {
font-size: 14px;
font-weight: 600;
}
.policy-probability {
font-size: 10px;
color: var(--text-secondary);
}
/* Tooltip */
.tooltip {
position: fixed;
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 8px;
padding: 12px 16px;
font-size: 12px;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease;
z-index: 1000;
max-width: 250px;
box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.tooltip.visible {
opacity: 1;
}
.tooltip-title {
font-weight: 600;
margin-bottom: 6px;
color: var(--accent-gold);
}
/* Animation keyframes */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
from { opacity: 0; transform: translateX(-20px); }
to { opacity: 1; transform: translateX(0); }
}
.card {
animation: fadeIn 0.5s ease forwards;
}
.card:nth-child(1) { animation-delay: 0.1s; }
.card:nth-child(2) { animation-delay: 0.2s; }
.card:nth-child(3) { animation-delay: 0.3s; }
/* Full width card */
.full-width {
grid-column: 1 / -1;
}
/* Correlation Matrix */
.correlation-matrix {
display: grid;
grid-template-columns: auto repeat(4, 1fr);
gap: 4px;
font-size: 11px;
}
.matrix-cell {
padding: 10px;
text-align: center;
border-radius: 4px;
background: var(--bg-secondary);
}
.matrix-header {
font-weight: 600;
color: var(--text-secondary);
}
.matrix-label {
text-align: left;
color: var(--text-secondary);
}
.matrix-value {
font-weight: 600;
}
/* Responsive */
@media (max-width: 768px) {
.header-stats {
display: none;
}
.grid-row {
grid-template-columns: 1fr;
}
.sensitivity-grid {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<header>
<div class="logo">
<div class="logo-icon">CF</div>
<div>
<h1>Policy Influence Dashboard</h1>
<span>Strategic Government Affairs Analytics</span>
</div>
</div>
<div class="header-stats">
<div class="stat-item">
<div class="stat-value" id="totalSpend">$4.2M</div>
<div class="stat-label">YTD Lobbying</div>
</div>
<div class="stat-item">
<div class="stat-value" id="activePolicies">12</div>
<div class="stat-label">Active Policies</div>
</div>
<div class="stat-item">
<div class="stat-value" id="riskScore">67</div>
<div class="stat-label">Risk Index</div>
</div>
</div>
</header>
<div class="dashboard">
<!-- Lobbying Spend Over Time -->
<div class="card full-width">
<div class="card-header">
<div class="card-title">Lobbying Expenditure Trend</div>
<div class="card-badge">Quarterly</div>
</div>
<div class="card-body">
<div class="chart-container spend-chart">
<canvas id="spendingChart"></canvas>
</div>
</div>
</div>
<!-- Regulatory Timeline -->
<div class="card full-width">
<div class="card-header">
<div class="card-title">Regulatory Timeline</div>
<div class="card-badge">FY 2024-2025</div>
</div>
<div class="card-body">
<div class="timeline-container">
<div class="timeline-track" id="timeline">
<div class="timeline-line"></div>
</div>
</div>
</div>
</div>
<div class="grid-row">
<!-- Policy Impact Tracker -->
<div class="card">
<div class="card-header">
<div class="card-title">Policy Impact Tracker</div>
<div class="card-badge">Live</div>
</div>
<div class="card-body">
<div class="policy-list" id="policyList"></div>
</div>
</div>
<!-- Financial Sensitivity -->
<div class="card">
<div class="card-header">
<div class="card-title">Financial Sensitivity Analysis</div>
<div class="card-badge">Model</div>
</div>
<div class="card-body">
<div class="sensitivity-grid" id="sensitivityGrid"></div>
</div>
</div>
<!-- Risk Gauge -->
<div class="card">
<div class="card-header">
<div class="card-title">Aggregate Risk Index</div>
<div class="card-badge">Dynamic</div>
</div>
<div class="card-body">
<div class="gauge-container">
<canvas id="gaugeChart" class="gauge-canvas"></canvas>
</div>
<div class="gauge-value">
<div class="gauge-number" id="gaugeValue">67</div>
<div class="gauge-label">Composite Policy Risk Score</div>
</div>
</div>
</div>
</div>
<!-- Correlation Matrix -->
<div class="card full-width">
<div class="card-header">
<div class="card-title">Policy-Financial Correlation Matrix</div>
<div class="card-badge">Statistical</div>
</div>
<div class="card-body">
<div class="chart-container" style="height: 200px;">
<canvas id="correlationChart"></canvas>
</div>
</div>
</div>
</div>
<div class="tooltip" id="tooltip">
<div class="tooltip-title"></div>
<div class="tooltip-content"></div>
</div>
<script>
// Data definitions
const lobbyingData = {
quarters: ['Q1 22', 'Q2 22', 'Q3 22', 'Q4 22', 'Q1 23', 'Q2 23', 'Q3 23', 'Q4 23', 'Q1 24', 'Q2 24', 'Q3 24', 'Q4 24'],
direct: [280, 310, 290, 350, 320, 380, 410, 390, 420, 450, 480, 520],
grassroots: [120, 140, 130, 160, 150, 180, 200, 190, 210, 230, 250, 280],
external: [80, 90, 85, 100, 95, 110, 120, 115, 130, 140, 150, 170]
};
const regulatoryEvents = [
{ id: 1, name: 'Basel III Implementation', date: '2024-03-15', status: 'passed', impact: '+$2.1M' },
{ id: 2, name: 'Climate Disclosure Rule', date: '2024-05-20', status: 'pending', impact: '-$4.5M' },
{ id: 3, name: 'Tax Reform Committee', date: '2024-07-10', status: 'review', impact: '+$8.2M' },
{ id: 4, name: 'Digital Asset Framework', date: '2024-09-01', status: 'pending', impact: '+$3.8M' },
{ id: 5, name: 'Antitrust Review', date: '2024-11-15', status: 'risk', impact: '-$12.4M' },
{ id: 6, name: 'ESG Reporting Mandate', date: '2025-01-20', status: 'pending', impact: '-$2.8M' },
{ id: 7, name: 'Trade Policy Update', date: '2025-03-10', status: 'review', impact: '+$5.6M' },
{ id: 8, name: 'Data Privacy Act', date: '2025-05-01', status: 'pending', impact: '-$1.9M' }
];
const policyItems = [
{ name: 'Infrastructure Bill Amendment', agency: 'House Ways & Means', status: 'pending', impact: '+$4.2M', probability: '72%' },
{ name: 'SEC Climate Rule', agency: 'Securities Exchange Comm.', status: 'review', impact: '-$6.8M', probability: '85%' },
{ name: 'Treasury Tax Guidance', agency: 'Department of Treasury', status: 'passed', impact: '+$2.1M', probability: '100%' },
{ name: 'Fed Rate Policy Comment', agency: 'Federal Reserve', status: 'pending', impact: '+$1.5M', probability: '45%' },
{ name: 'Export Control Reform', agency: 'Commerce Department', status: 'risk', impact: '-$8.3M', probability: '38%' },
{ name: 'Healthcare Pricing Rule', agency: 'HHS/CMS', status: 'review', impact: '-$3.2M', probability: '62%' }
];
const sensitivityData = [
{ label: 'Interest Rate', base: '5.25%', scenario: '+100bps', impact: '-$18M', type: 'negative', level: 'high' },
{ label: 'Tax Rate', base: '21%', scenario: '+5%', impact: '-$42M', type: 'negative', level: 'high' },
{ label: 'CapEx Credit', base: '10%', scenario: '+5%', impact: '+$12M', type: 'positive', level: 'medium' },
{ label: 'Carbon Tax', base: '$0', scenario: '$50/ton', impact: '-$28M', type: 'negative', level: 'high' },
{ label: 'R&D Incentive', base: '15%', scenario: '+10%', impact: '+$8M', type: 'positive', level: 'low' },
{ label: 'Tariff Rate', base: '3%', scenario: '+10%', impact: '-$15M', type: 'negative', level: 'medium' }
];
const correlationData = {
labels: ['Tax Policy', 'Climate Reg', 'Trade Policy', 'Digital Assets', 'Labor Rules'],
metrics: ['Revenue', 'OpEx', 'CapEx', 'Net Margin'],
values: [
[0.85, -0.42, 0.72, 0.15, -0.38],
[-0.65, 0.78, -0.55, 0.22, 0.68],
[0.45, -0.35, 0.82, 0.48, -0.25],
[0.72, -0.58, 0.65, 0.12, -0.45]
]
};
// Tooltip element
const tooltip = document.getElementById('tooltip');
function showTooltip(e, title, content) {
tooltip.querySelector('.tooltip-title').textContent = title;
tooltip.querySelector('.tooltip-content').textContent = content;
tooltip.style.left = (e.clientX + 15) + 'px';
tooltip.style.top = (e.clientY + 15) + 'px';
tooltip.classList.add('visible');
}
function hideTooltip() {
tooltip.classList.remove('visible');
}
// Spending Chart
function drawSpendingChart() {
const canvas = document.getElementById('spendingChart');
const ctx = canvas.getContext('2d');
const rect = canvas.parentElement.getBoundingClientRect();
canvas.width = rect.width * 2;
canvas.height = rect.height * 2;
ctx.scale(2, 2);
const width = rect.width;
const height = rect.height;
const padding = { top: 30, right: 30, bottom: 50, left: 60 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
// Find max value
const maxVal = Math.max(...lobbyingData.direct.map((v, i) =>
v + lobbyingData.grassroots[i] + lobbyingData.external[i]
));
const yScale = chartHeight / (maxVal * 1.1);
const xStep = chartWidth / (lobbyingData.quarters.length - 1);
// Draw grid
ctx.strokeStyle = '#2a3a52';
ctx.lineWidth = 1;
for (let i = 0; i <= 5; i++) {
const y = padding.top + (chartHeight / 5) * i;
ctx.beginPath();
ctx.moveTo(padding.left, y);
ctx.lineTo(width - padding.right, y);
ctx.stroke();
// Y labels
const val = Math.round(maxVal * 1.1 * (5 - i) / 5);
ctx.fillStyle = '#8899aa';
ctx.font = '10px Segoe UI';
ctx.textAlign = 'right';
ctx.fillText('$' + val + 'K', padding.left - 10, y + 4);
}
// X labels
lobbyingData.quarters.forEach((q, i) => {
const x = padding.left + i * xStep;
ctx.fillStyle = '#8899aa';
ctx.textAlign = 'center';
ctx.fillText(q, x, height - padding.bottom + 20);
});
// Animation progress
let progress = 0;
const animate = () => {
progress += 0.03;
if (progress > 1) progress = 1;
// Clear chart area
ctx.fillStyle = '#1a2332';
ctx.fillRect(padding.left, padding.top, chartWidth, chartHeight);
// Redraw grid
ctx.strokeStyle = '#2a3a52';
for (let i = 0; i <= 5; i++) {
const y = padding.top + (chartHeight / 5) * i;
ctx.beginPath();
ctx.moveTo(padding.left, y);
ctx.lineTo(width - padding.right, y);
ctx.stroke();
}
// Draw stacked areas
const datasets = [
{ data: lobbyingData.external, color: 'rgba(59, 130, 246, 0.6)', border: '#3b82f6' },
{ data: lobbyingData.grassroots, color: 'rgba(34, 197, 94, 0.6)', border: '#22c55e' },
{ data: lobbyingData.direct, color: 'rgba(212, 168, 75, 0.6)', border: '#d4a84b' }
];
datasets.forEach((dataset, di) => {
ctx.beginPath();
ctx.moveTo(padding.left, padding.top + chartHeight);
for (let i = 0; i <= Math.floor((lobbyingData.quarters.length - 1) * progress); i++) {
let sum = 0;
for (let j = di; j < datasets.length; j++) {
sum += datasets[j].data[i];
}
const x = padding.left + i * xStep;
const y = padding.top + chartHeight - sum * yScale;
if (i === 0) ctx.lineTo(x, y);
else ctx.lineTo(x, y);
}
const lastIdx = Math.floor((lobbyingData.quarters.length - 1) * progress);
ctx.lineTo(padding.left + lastIdx * xStep, padding.top + chartHeight);
ctx.closePath();
ctx.fillStyle = dataset.color;
ctx.fill();
// Draw line
ctx.beginPath();
for (let i = 0; i <= lastIdx; i++) {
let sum = 0;
for (let j = di; j < datasets.length; j++) {
sum += datasets[j].data[i];
}
const x = padding.left + i * xStep;
const y = padding.top + chartHeight - sum * yScale;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.strokeStyle = dataset.border;
ctx.lineWidth = 2;
ctx.stroke();
});
// Draw points
if (progress === 1) {
const allData = lobbyingData.direct.map((v, i) =>
v + lobbyingData.grassroots[i] + lobbyingData.external[i]
);
allData.forEach((val, i) => {
const x = padding.left + i * xStep;
const y = padding.top + chartHeight - val * yScale;
ctx.beginPath();
ctx.arc(x, y, 5, 0, Math.PI * 2);
ctx.fillStyle = '#d4a84b';
ctx.fill();
ctx.strokeStyle = '#1a2332';
ctx.lineWidth = 2;
ctx.stroke();
});
}
if (progress < 1) requestAnimationFrame(animate);
};
animate();
// Legend
const legend = [
{ label: 'Direct Lobbying', color: '#d4a84b' },
{ label: 'Grassroots', color: '#22c55e' },
{ label: 'External Affairs', color: '#3b82f6' }
];
legend.forEach((item, i) => {
const x = width - 200 + i * 100;
ctx.fillStyle = item.color;
ctx.fillRect(x - 60, 8, 12, 12);
ctx.fillStyle = '#f0f4f8';
ctx.font = '10px Segoe UI';
ctx.textAlign = 'left';
ctx.fillText(item.label, x - 44, 18);
});
}
// Timeline
function drawTimeline() {
const container = document.getElementById('timeline');
const startDate = new Date('2024-01-01');
const endDate = new Date('2025-06-30');
const totalDays = (endDate - startDate) / (1000 * 60 * 60 * 24);
regulatoryEvents.forEach(event => {
const eventDate = new Date(event.date);
const daysDiff = (eventDate - startDate) / (1000 * 60 * 60 * 24);
const position = (daysDiff / totalDays) * 100;
const el = document.createElement('div');
el.className = 'timeline-event';
el.style.left = position + '%';
el.innerHTML = `
<div class="event-marker ${event.status}"></div>
<div class="event-label">${event.name}</div>
<div class="event-date">${event.date}</div>
`;
el.addEventListener('mouseenter', (e) => {
showTooltip(e, event.name, `Status: ${event.status.toUpperCase()} | Impact: ${event.impact}`);
});
el.addEventListener('mouseleave', hideTooltip);
el.addEventListener('mousemove', (e) => {
tooltip.style.left = (e.clientX + 15) + 'px';
tooltip.style.top = (e.clientY + 15) + 'px';
});
container.appendChild(el);
});
}
// Policy List
function renderPolicyList() {
const container = document.getElementById('policyList');
policyItems.forEach((item, index) => {
const statusColors = {
passed: '#22c55e',
pending: '#f59e0b',
review: '#3b82f6',
risk: '#ef4444'
};
const el = document.createElement('div');
el.className = 'policy-item';
el.style.animationDelay = (index * 0.1) + 's';
el.innerHTML = `
<div class="policy-status" style="background: ${statusColors[item.status]}"></div>
<div class="policy-info">
<div class="policy-name">${item.name}</div>
<div class="policy-meta">${item.agency}</div>
</div>
<div class="policy-impact">
<div class="policy-amount" style="color: ${item.impact.startsWith('+') ? '#22c55e' : '#ef4444'}">${item.impact}</div>
<div class="policy-probability">${item.probability} probability</div>
</div>
`;
el.addEventListener('mouseenter', (e) => {
showTooltip(e, item.name, `Status: ${item.status} | Estimated financial impact: ${item.impact}`);
});
el.addEventListener('mouseleave', hideTooltip);
container.appendChild(el);
});
}
// Sensitivity Grid
function renderSensitivityGrid() {
const container = document.getElementById('sensitivityGrid');
sensitivityData.forEach(item => {
const el = document.createElement('div');
el.className = `sensitivity-item ${item.level}-impact`;
el.innerHTML = `
<div class="sens-label">${item.label}</div>
<div class="sens-value ${item.type}">${item.impact}</div>
<div class="sens-change">${item.base} → ${item.scenario}</div>
`;
el.addEventListener('mouseenter', (e) => {
showTooltip(e, `${item.label} Sensitivity`, `Base: ${item.base} | Scenario: ${item.scenario} | Impact: ${item.impact}`);
});
el.addEventListener('mouseleave', hideTooltip);
container.appendChild(el);
});
}
// Risk Gauge
function drawGauge() {
const canvas = document.getElementById('gaugeChart');
const ctx = canvas.getContext('2d');
canvas.width = 400;
canvas.height = 240;
const centerX = 200;
const centerY = 200;
const radius = 150;
let currentValue = 0;
const targetValue = 67;
const animate = () => {
currentValue += (targetValue - currentValue) * 0.05;
if (Math.abs(targetValue - currentValue) < 0.5) currentValue = targetValue;
ctx.clearRect(0, 0, 400, 240);
// Background arc
const gradient = ctx.createLinearGradient(50, 0, 350, 0);
gradient.addColorStop(0, '#22c55e');
gradient.addColorStop(0.5, '#f59e0b');
gradient.addColorStop(1, '#ef4444');
ctx.beginPath();
ctx.arc(centerX, centerY, radius, Math.PI, 2 * Math.PI, false);
ctx.lineWidth = 25;
ctx.strokeStyle = '#2a3a52';
ctx.stroke();
// Value arc
ctx.beginPath();
const endAngle = Math.PI + (currentValue / 100) * Math.PI;
ctx.arc(centerX, centerY, radius, Math.PI, endAngle, false);
ctx.lineWidth = 25;
ctx.strokeStyle = gradient;
ctx.lineCap = 'round';
ctx.stroke();
// Needle
const needleAngle = Math.PI + (currentValue / 100) * Math.PI;
const needleLength = radius - 40;
const needleX = centerX + Math.cos(needleAngle) * needleLength;
const needleY = centerY + Math.sin(needleAngle) * needleLength;
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.lineTo(needleX, needleY);
ctx.strokeStyle = '#f0f4f8';
ctx.lineWidth = 3;
ctx.lineCap = 'round';
ctx.stroke();
// Center dot
ctx.beginPath();
ctx.arc(centerX, centerY, 8, 0, Math.PI * 2);
ctx.fillStyle = '#d4a84b';
ctx.fill();
// Scale labels
ctx.fillStyle = '#8899aa';
ctx.font = '12px Segoe UI';
ctx.textAlign = 'center';
ctx.fillText('Low', 60, 220);
ctx.fillText('High', 340, 220);
document.getElementById('gaugeValue').textContent = Math.round(currentValue);
if (currentValue !== targetValue) requestAnimationFrame(animate);
};
animate();
}
// Correlation Chart
function drawCorrelationChart() {
const canvas = document.getElementById('correlationChart');
const ctx = canvas.getContext('2d');
const rect = canvas.parentElement.getBoundingClientRect();
canvas.width = rect.width * 2;
canvas.height = rect.height * 2;
ctx.scale(2, 2);
const width = rect.width;
const height = rect.height;
const padding = { top: 30, right: 20, bottom: 60, left: 100 };
const cellWidth = (width - padding.left - padding.right) / correlationData.labels.length;
const cellHeight = (height - padding.top - padding.bottom) / correlationData.metrics.length;
// Draw cells
correlationData.values.forEach((row, ri) => {
row.forEach((val, ci) => {
const x = padding.left + ci * cellWidth;
const y = padding.top + ri * cellHeight;
// Color based on correlation
let color;
if (val > 0) {
const intensity = Math.min(Math.abs(val), 1);
color = `rgba(34, 197, 94, ${intensity * 0.8})`;
} else {
const intensity = Math.min(Math.abs(val), 1);
color = `rgba(239, 68, 68, ${intensity * 0.8})`;
}
ctx.fillStyle = color;
ctx.fillRect(x + 2, y + 2, cellWidth - 4, cellHeight - 4);
// Value text
ctx.fillStyle = '#f0f4f8';
ctx.font = '12px Segoe UI';
ctx.textAlign = 'center';
ctx.fillText(val.toFixed(2), x + cellWidth / 2, y + cellHeight / 2 + 4);
});
});
// X labels (policies)
ctx.fillStyle = '#8899aa';
ctx.font = '11px Segoe UI';
correlationData.labels.forEach((label, i) => {
const x = padding.left + i * cellWidth + cellWidth / 2;
ctx.save();
ctx.translate(x, height - padding.bottom + 15);
ctx.rotate(-Math.PI / 6);
ctx.textAlign = 'right';
ctx.fillText(label, 0, 0);
ctx.restore();
});
// Y labels (metrics)
ctx.textAlign = 'right';
correlationData.metrics.forEach((label, i) => {
const y = padding.top + i * cellHeight + cellHeight / 2;
ctx.fillText(label, padding.left - 10, y + 4);
});
}
// Particle background
function initParticles() {
const canvas = document.createElement('canvas');
canvas.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:-1;opacity:0.3';
document.body.appendChild(canvas);
const ctx = canvas.getContext('2d');
let particles = [];
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resize();
window.addEventListener('resize', resize);
for (let i = 0; i < 50; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
size: Math.random() * 2 + 1
});
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fillStyle = '#d4a84b';
ctx.fill();
});
// Draw connections
ctx.strokeStyle = 'rgba(212, 168, 75, 0.1)';
ctx.lineWidth = 1;
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 150) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
requestAnimationFrame(animate);
}
animate();
}
// Dynamic data updates
function simulateUpdates() {
setInterval(() => {
// Update risk score
const currentRisk = parseInt(document.getElementById('riskScore').textContent);
const newRisk = Math.max(30, Math.min(90, currentRisk + (Math.random() - 0.5) * 10));
document.getElementById('riskScore').textContent = Math.round(newRisk);
document.getElementById('gaugeValue').textContent = Math.round(newRisk);
}, 5000);
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
drawSpendingChart();
drawTimeline();
renderPolicyList();
renderSensitivityGrid();
drawGauge();
drawCorrelationChart();
initParticles();
simulateUpdates();
// Resize handler
window.addEventListener('resize', () => {
drawSpendingChart();
drawCorrelationChart();
});
});
</script>
</body>
</html>