Changed around line 1
+ const canvas = document.getElementById('pcaPlot');
+ const ctx = canvas.getContext('2d');
+ const leaders = [];
+ const colors = ['#ff4d4d', '#6c5ce7', '#ffaf40', '#2ecc71'];
+
+ // Generate random leader data
+ for (let i = 0; i < 200; i++) {
+ leaders.push({
+ x: Math.random() * 0.8 + 0.1,
+ y: Math.random() * 0.8 + 0.1,
+ name: `Leader ${i+1}`,
+ era: Math.random() > 0.5 ? 'Modern' : 'Historical',
+ traits: Array.from({length: 5}, () => Math.random())
+ });
+ }
+
+ function resizeCanvas() {
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ drawPlot();
+ }
+
+ function drawPlot() {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ leaders.forEach(leader => {
+ const x = leader.x * canvas.width;
+ const y = leader.y * canvas.height;
+
+ ctx.beginPath();
+ ctx.arc(x, y, 5, 0, Math.PI * 2);
+ ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)];
+ ctx.fill();
+
+ // Add glow effect
+ ctx.shadowColor = ctx.fillStyle;
+ ctx.shadowBlur = 15;
+ ctx.shadowOffsetX = 0;
+ ctx.shadowOffsetY = 0;
+ });
+ }
+
+ document.getElementById('leaderForm').addEventListener('submit', (e) => {
+ e.preventDefault();
+ const input = document.getElementById('leaderDesc').value;
+
+ // Simulate similarity analysis
+ const randomLeader = leaders[Math.floor(Math.random() * leaders.length)];
+ const resultDiv = document.getElementById('result');
+
+ resultDiv.innerHTML = `
+
Closest Match Found:
+
Era: ${randomLeader.era}
+
Authoritarian Tendency Score: ${Math.floor(Math.random()*100)}/100
+ `;
+
+ resultDiv.classList.remove('hidden');
+ });
+
+ // Initial setup
+ window.addEventListener('resize', resizeCanvas);
+ resizeCanvas();
+
+ // Add interactive hover effect
+ canvas.addEventListener('mousemove', (e) => {
+ const rect = canvas.getBoundingClientRect();
+ const mouseX = e.clientX - rect.left;
+ const mouseY = e.clientY - rect.top;
+
+ leaders.forEach(leader => {
+ const x = leader.x * canvas.width;
+ const y = leader.y * canvas.height;
+ const dist = Math.hypot(mouseX - x, mouseY - y);
+
+ if (dist < 15) {
+ ctx.beginPath();
+ ctx.arc(x, y, 15, 0, Math.PI * 2);
+ ctx.fillStyle = 'rgba(255, 255, 255, 0.1)';
+ ctx.fill();
+ }
+ });
+ });