Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Nexus Command Center</title> | |
| <!-- Importing FontAwesome for Icons --> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <!-- Google Fonts --> | |
| <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap" rel="stylesheet"> | |
| <style> | |
| /* | |
| * MODERN CSS VARIABLES & RESET | |
| */ | |
| :root { | |
| --bg-dark: #0f172a; | |
| --bg-panel: rgba(30, 41, 59, 0.7); | |
| --primary: #6366f1; /* Indigo */ | |
| --primary-hover: #4f46e5; | |
| --accent: #06b6d4; /* Cyan */ | |
| --success: #10b981; | |
| --danger: #ef4444; | |
| --text-main: #f8fafc; | |
| --text-muted: #94a3b8; | |
| --glass-border: 1px solid rgba(255, 255, 255, 0.1); | |
| --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5); | |
| --radius: 16px; | |
| --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| body { | |
| font-family: 'Outfit', sans-serif; | |
| background-color: var(--bg-dark); | |
| background-image: | |
| radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%), | |
| radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.15) 0px, transparent 50%); | |
| background-attachment: fixed; | |
| color: var(--text-main); | |
| min-height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| overflow-x: hidden; | |
| } | |
| /* | |
| * UTILITIES | |
| */ | |
| .glass { | |
| background: var(--bg-panel); | |
| backdrop-filter: blur(12px); | |
| -webkit-backdrop-filter: blur(12px); | |
| border: var(--glass-border); | |
| box-shadow: var(--shadow); | |
| } | |
| .btn { | |
| border: none; | |
| outline: none; | |
| cursor: pointer; | |
| padding: 0.6rem 1.2rem; | |
| border-radius: 8px; | |
| font-weight: 600; | |
| font-family: inherit; | |
| transition: var(--transition); | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| .btn-primary { | |
| background: linear-gradient(135deg, var(--primary), var(--accent)); | |
| color: white; | |
| } | |
| .btn-primary:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 0 15px rgba(99, 102, 241, 0.4); | |
| } | |
| .btn-icon { | |
| background: rgba(255,255,255,0.05); | |
| color: var(--text-main); | |
| padding: 0.5rem; | |
| border-radius: 50%; | |
| } | |
| .btn-icon:hover { | |
| background: rgba(255,255,255,0.15); | |
| color: var(--accent); | |
| } | |
| /* | |
| * HEADER | |
| */ | |
| header { | |
| padding: 1rem 2rem; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| position: sticky; | |
| top: 0; | |
| z-index: 100; | |
| border-bottom: var(--glass-border); | |
| } | |
| .logo { | |
| font-size: 1.5rem; | |
| font-weight: 700; | |
| background: linear-gradient(to right, var(--primary), var(--accent)); | |
| -webkit-background-clip: text; | |
| -webkit-text-fill-color: transparent; | |
| letter-spacing: -0.5px; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| .header-controls { | |
| display: flex; | |
| align-items: center; | |
| gap: 1.5rem; | |
| } | |
| .credit-link { | |
| font-size: 0.85rem; | |
| color: var(--text-muted); | |
| text-decoration: none; | |
| transition: var(--transition); | |
| } | |
| .credit-link:hover { | |
| color: var(--accent); | |
| } | |
| .user-avatar { | |
| width: 40px; | |
| height: 40px; | |
| border-radius: 50%; | |
| border: 2px solid var(--primary); | |
| object-fit: cover; | |
| } | |
| /* | |
| * MAIN LAYOUT | |
| */ | |
| main { | |
| flex: 1; | |
| padding: 2rem; | |
| max-width: 1400px; | |
| margin: 0 auto; | |
| width: 100%; | |
| display: grid; | |
| grid-template-columns: repeat(12, 1fr); | |
| grid-template-rows: auto auto; | |
| gap: 1.5rem; | |
| } | |
| /* | |
| * CARDS & WIDGETS | |
| */ | |
| .card { | |
| padding: 1.5rem; | |
| border-radius: var(--radius); | |
| display: flex; | |
| flex-direction: column; | |
| position: relative; | |
| overflow: hidden; | |
| animation: fadeIn 0.6s ease-out; | |
| } | |
| .card-header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 1rem; | |
| } | |
| .card-title { | |
| font-size: 1.1rem; | |
| font-weight: 600; | |
| color: var(--text-main); | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| /* | |
| * WIDGET: CLOCK & DATE | |
| */ | |
| .widget-welcome { | |
| grid-column: span 12; | |
| } | |
| .welcome-text h1 { | |
| font-size: 2rem; | |
| margin-bottom: 0.25rem; | |
| } | |
| .date-display { | |
| color: var(--text-muted); | |
| font-size: 1rem; | |
| } | |
| /* | |
| * WIDGET: FOCUS TIMER | |
| */ | |
| .widget-timer { | |
| grid-column: span 12; | |
| md: span 4; | |
| lg: span 4; | |
| align-items: center; | |
| justify-content: center; | |
| min-height: 300px; | |
| } | |
| .timer-circle { | |
| position: relative; | |
| width: 200px; | |
| height: 200px; | |
| } | |
| .timer-circle svg { | |
| transform: rotate(-90deg); | |
| width: 100%; | |
| height: 100%; | |
| } | |
| .timer-circle circle { | |
| fill: none; | |
| stroke-width: 8; | |
| stroke-linecap: round; | |
| } | |
| .circle-bg { | |
| stroke: rgba(255,255,255,0.05); | |
| } | |
| .circle-progress { | |
| stroke: var(--accent); | |
| stroke-dasharray: 565; /* 2 * PI * 90 */ | |
| stroke-dashoffset: 0; | |
| transition: stroke-dashoffset 1s linear; | |
| } | |
| .timer-text { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%); | |
| text-align: center; | |
| } | |
| .time-display { | |
| font-size: 2.5rem; | |
| font-weight: 700; | |
| font-variant-numeric: tabular-nums; | |
| } | |
| .timer-controls { | |
| margin-top: 1.5rem; | |
| display: flex; | |
| gap: 1rem; | |
| } | |
| /* | |
| * WIDGET: TASKS | |
| */ | |
| .widget-tasks { | |
| grid-column: span 12; | |
| md: span 8; | |
| lg: span 5; | |
| height: 400px; | |
| } | |
| .task-input-group { | |
| display: flex; | |
| gap: 0.5rem; | |
| margin-bottom: 1rem; | |
| } | |
| .task-input { | |
| flex: 1; | |
| background: rgba(0,0,0,0.2); | |
| border: 1px solid rgba(255,255,255,0.1); | |
| padding: 0.8rem; | |
| border-radius: 8px; | |
| color: white; | |
| font-family: inherit; | |
| } | |
| .task-input:focus { | |
| outline: none; | |
| border-color: var(--primary); | |
| } | |
| .task-list { | |
| list-style: none; | |
| overflow-y: auto; | |
| flex: 1; | |
| padding-right: 0.5rem; | |
| } | |
| /* Scrollbar styling */ | |
| .task-list::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| .task-list::-webkit-scrollbar-thumb { | |
| background: rgba(255,255,255,0.1); | |
| border-radius: 3px; | |
| } | |
| .task-item { | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| padding: 0.8rem; | |
| background: rgba(255,255,255,0.03); | |
| margin-bottom: 0.5rem; | |
| border-radius: 8px; | |
| transition: var(--transition); | |
| border-left: 3px solid transparent; | |
| } | |
| .task-item:hover { | |
| background: rgba(255,255,255,0.06); | |
| transform: translateX(4px); | |
| } | |
| .task-item.completed { | |
| opacity: 0.5; | |
| text-decoration: line-through; | |
| border-left-color: var(--success); | |
| } | |
| .task-item.pending { | |
| border-left-color: var(--accent); | |
| } | |
| .task-actions button { | |
| background: none; | |
| border: none; | |
| color: var(--text-muted); | |
| cursor: pointer; | |
| padding: 0.4rem; | |
| transition: color 0.2s; | |
| } | |
| .task-actions button:hover { | |
| color: var(--danger); | |
| } | |
| /* | |
| * WIDGET: ANALYTICS (CANVAS) | |
| */ | |
| .widget-analytics { | |
| grid-column: span 12; | |
| lg: span 3; | |
| height: 300px; | |
| } | |
| canvas { | |
| width: 100%; | |
| height: 100%; | |
| } | |
| /* | |
| * WIDGET: QUICK NOTES | |
| */ | |
| .widget-notes { | |
| grid-column: span 12; | |
| lg: span 6; | |
| height: 250px; | |
| } | |
| .notes-area { | |
| width: 100%; | |
| height: 100%; | |
| background: rgba(0,0,0,0.2); | |
| border: 1px solid rgba(255,255,255,0.1); | |
| border-radius: 8px; | |
| padding: 1rem; | |
| color: var(--text-muted); | |
| font-family: inherit; | |
| resize: none; | |
| font-size: 0.95rem; | |
| line-height: 1.5; | |
| } | |
| .notes-area:focus { | |
| outline: none; | |
| border-color: var(--primary); | |
| color: var(--text-main); | |
| } | |
| /* | |
| * TOAST NOTIFICATION | |
| */ | |
| .toast-container { | |
| position: fixed; | |
| bottom: 2rem; | |
| right: 2rem; | |
| z-index: 1000; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.5rem; | |
| } | |
| .toast { | |
| background: var(--bg-panel); | |
| backdrop-filter: blur(16px); | |
| border-left: 4px solid var(--accent); | |
| color: white; | |
| padding: 1rem 1.5rem; | |
| border-radius: 8px; | |
| box-shadow: 0 10px 30px rgba(0,0,0,0.5); | |
| display: flex; | |
| align-items: center; | |
| gap: 0.8rem; | |
| animation: slideIn 0.3s ease-out forwards; | |
| min-width: 250px; | |
| } | |
| .toast.success { border-left-color: var(--success); } | |
| .toast.error { border-left-color: var(--danger); } | |
| @keyframes slideIn { | |
| from { transform: translateX(100%); opacity: 0; } | |
| to { transform: translateX(0); opacity: 1; } | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; transform: translateY(20px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| /* | |
| * RESPONSIVE MEDIA QUERIES | |
| */ | |
| @media (min-width: 768px) { | |
| .widget-timer { grid-column: span 6; } | |
| .widget-tasks { grid-column: span 6; } | |
| .widget-analytics { grid-column: span 12; } | |
| .widget-notes { grid-column: span 12; } | |
| } | |
| @media (min-width: 1024px) { | |
| .widget-welcome { grid-column: span 8; } | |
| .widget-timer { grid-column: span 4; } | |
| .widget-tasks { grid-column: span 5; } | |
| .widget-analytics { grid-column: span 3; } | |
| .widget-notes { grid-column: span 4; } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <!-- Header --> | |
| <header class="glass"> | |
| <div class="logo"> | |
| <i class="fa-solid fa-cube"></i> NEXUS | |
| </div> | |
| <div class="header-controls"> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="credit-link"> | |
| Built with anycoder <i class="fa-solid fa-arrow-up-right-from-square" style="font-size: 0.7em;"></i> | |
| </a> | |
| <button class="btn-icon" id="theme-toggle" title="Toggle Theme (Demo)"> | |
| <i class="fa-solid fa-moon"></i> | |
| </button> | |
| <img src="https://picsum.photos/seed/nexusUser/100/100" alt="User" class="user-avatar"> | |
| </div> | |
| </header> | |
| <!-- Main Content --> | |
| <main> | |
| <!-- Welcome Widget --> | |
| <section class="card glass widget-welcome"> | |
| <div class="welcome-text"> | |
| <h1 id="greeting">Welcome back, Operator.</h1> | |
| <p class="date-display" id="current-date">Loading date...</p> | |
| </div> | |
| </section> | |
| <!-- Timer Widget --> | |
| <section class="card glass widget-timer"> | |
| <div class="card-header" style="width: 100%;"> | |
| <div class="card-title"><i class="fa-solid fa-hourglass-half"></i> Focus Flow</div> | |
| </div> | |
| <div class="timer-circle"> | |
| <svg> | |
| <circle class="circle-bg" cx="50%" cy="50%" r="90"></circle> | |
| <circle class="circle-progress" cx="50%" cy="50%" r="90" id="progress-ring"></circle> | |
| </svg> | |
| <div class="timer-text"> | |
| <div class="time-display" id="timer-display">25:00</div> | |
| <div style="font-size: 0.8rem; color: var(--text-muted);">FOCUS MODE</div> | |
| </div> | |
| </div> | |
| <div class="timer-controls"> | |
| <button class="btn btn-primary" id="start-btn"><i class="fa-solid fa-play"></i> Start</button> | |
| <button class="btn btn-icon" id="reset-btn"><i class="fa-solid fa-rotate-right"></i></button> | |
| </div> | |
| </section> | |
| <!-- Task List Widget --> | |
| <section class="card glass widget-tasks"> | |
| <div class="card-header"> | |
| <div class="card-title"><i class="fa-solid fa-list-check"></i> Mission Tasks</div> | |
| <span style="font-size: 0.8rem; color: var(--text-muted);" id="task-count">0 Active</span> | |
| </div> | |
| <form id="task-form" class="task-input-group"> | |
| <input type="text" class="task-input" id="task-input" placeholder="Enter new directive..." autocomplete="off"> | |
| <button type="submit" class="btn btn-primary"><i class="fa-solid fa-plus"></i></button> | |
| </form> | |
| <ul class="task-list" id="task-list"> | |
| <!-- Tasks injected via JS --> | |
| </ul> | |
| </section> | |
| <!-- Analytics Widget --> | |
| <section class="card glass widget-analytics"> | |
| <div class="card-header"> | |
| <div class="card-title"><i class="fa-solid fa-chart-line"></i> Efficiency</div> | |
| </div> | |
| <div style="flex: 1; position: relative;"> | |
| <canvas id="productivityChart"></canvas> | |
| </div> | |
| </section> | |
| <!-- Notes Widget --> | |
| <section class="card glass widget-notes"> | |
| <div class="card-header"> | |
| <div class="card-title"><i class="fa-regular fa-note-sticky"></i> Quick Log</div> | |
| <button class="btn-icon" id="clear-notes" title="Clear Notes"><i class="fa-solid fa-trash"></i></button> | |
| </div> | |
| <textarea class="notes-area" id="quick-notes" placeholder="Type your observations here..."></textarea> | |
| </section> | |
| </main> | |
| <!-- Toast Container --> | |
| <div class="toast-container" id="toast-container"></div> | |
| <script> | |
| /** | |
| * NEXUS COMMAND CENTER LOGIC | |
| * Pure Vanilla JavaScript - No Frameworks | |
| */ | |
| document.addEventListener('DOMContentLoaded', () => { | |
| initClock(); | |
| initTimer(); | |
| initTasks(); | |
| initNotes(); | |
| initChart(); | |
| }); | |
| /* --- 1. UTILITY FUNCTIONS --- */ | |
| const $ = (selector) => document.querySelector(selector); | |
| function showToast(message, type = 'info') { | |
| const container = $('#toast-container'); | |
| const toast = document.createElement('div'); | |
| toast.className = `toast ${type}`; | |
| let icon = 'fa-info-circle'; | |
| if (type === 'success') icon = 'fa-check-circle'; | |
| if (type === 'error') icon = 'fa-triangle-exclamation'; | |
| toast.innerHTML = `<i class="fa-solid ${icon}"></i> <span>${message}</span>`; | |
| container.appendChild(toast); | |
| // Remove after 3 seconds | |
| setTimeout(() => { | |
| toast.style.animation = 'slideIn 0.3s ease-out reverse forwards'; | |
| setTimeout(() => toast.remove(), 300); | |
| }, 3000); | |
| } | |
| /* --- 2. CLOCK & DATE --- */ | |
| function initClock() { | |
| const dateEl = $('#current-date'); | |
| const greetingEl = $('#greeting'); | |
| const hours = new Date().getHours(); | |
| // Dynamic Greeting | |
| let greet = 'Welcome back, Operator.'; | |
| if (hours < 12) greet = 'Good morning, Operator.'; | |
| else if (hours < 18) greet = 'Good afternoon, Operator.'; | |
| else greet = 'Good evening, Operator.'; | |
| greetingEl.textContent = greet; | |
| const updateTime = () => { | |
| const now = new Date(); | |
| dateEl.textContent = now.toLocaleDateString('en-US', { | |
| weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' | |
| }) + ' • ' + now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); | |
| }; | |
| updateTime(); | |
| setInterval(updateTime, 1000); | |
| } | |
| /* --- 3. FOCUS TIMER --- */ | |
| function initTimer() { | |
| let timeLeft = 25 * 60; // 25 minutes | |
| let timerId = null; | |
| let isRunning = false; | |
| const display = $('#timer-display'); | |
| const ring = $('#progress-ring'); | |
| const startBtn = $('#start-btn'); | |
| const resetBtn = $('#reset-btn'); | |
| // Circle circumference for dashoffset calculation | |
| const radius = ring.r.baseVal.value; | |
| const circumference = 2 * Math.PI * radius; | |
| ring.style.strokeDasharray = `${circumference} ${circumference}`; | |
| function setProgress(percent) { | |
| const offset = circumference - (percent / 100) * circumference; | |
| ring.style.strokeDashoffset = offset; | |
| } | |
| function updateDisplay() { | |
| const m = Math.floor(timeLeft / 60); | |
| const s = timeLeft % 60; | |
| display.textContent = `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`; | |
| const totalTime = 25 * 60; | |
| const percent = ((totalTime - timeLeft) / totalTime) * 100; | |
| setProgress(100 - percent); // Inverse progress (draining) | |
| } | |
| function toggleTimer() { | |
| if (isRunning) { | |
| clearInterval(timerId); | |
| startBtn.innerHTML = '<i class="fa-solid fa-play"></i> Resume'; | |
| startBtn.classList.remove('btn-danger'); // Hypothetical class | |
| } else { | |
| timerId = setInterval(() => { | |
| if (timeLeft > 0) { | |
| timeLeft--; | |
| updateDisplay(); | |
| } else { | |
| clearInterval(timerId); | |
| isRunning = false; | |
| startBtn.innerHTML = '<i class="fa-solid fa-play"></i> Start'; | |
| showToast('Focus session complete!', 'success'); | |
| } | |
| }, 1000); | |
| startBtn.innerHTML = '<i class="fa-solid fa-pause"></i> Pause'; | |
| } | |
| isRunning = !isRunning; | |
| } | |
| function resetTimer() { | |
| clearInterval(timerId); | |
| isRunning = false; | |
| timeLeft = 25 * 60; | |
| startBtn.innerHTML = '<i class="fa-solid fa-play"></i> Start'; | |
| updateDisplay(); | |
| setProgress(100); | |
| } | |
| startBtn.addEventListener('click', toggleTimer); | |
| resetBtn.addEventListener('click', resetTimer); | |
| // Initial set | |
| updateDisplay(); | |
| } | |
| /* --- 4. TASK MANAGER (Local Storage) --- */ | |
| function initTasks() { | |
| const form = $('#task-form'); | |
| const input = $('#task-input'); | |
| const list = $('#task-list'); | |
| const countEl = $('#task-count'); | |
| let tasks = JSON.parse(localStorage.getItem('nexus_tasks')) || [ | |
| { id: 1, text: 'Review system logs', completed: false }, | |
| { id: 2, text: 'Update security protocols', completed: true } | |
| ]; | |
| function save() { | |
| localStorage.setItem('nexus_tasks', JSON.stringify(tasks)); | |
| render(); | |
| } | |
| function render() { | |
| list.innerHTML = ''; | |
| let activeCount = 0; | |
| tasks.forEach(task => { | |
| if (!task.completed) activeCount++; | |
| const li = document.createElement('li'); | |
| li.className = `task-item ${task.completed ? 'completed' : 'pending'}`; | |
| li.innerHTML = ` | |
| <span>${task.text}</span> | |
| <div class="task-actions"> | |
| <button onclick="toggleTask(${task.id})"><i class="fa-solid fa-check"></i></button> | |
| <button onclick="deleteTask(${task.id})"><i class="fa-solid fa-xmark"></i></button> | |
| </div> | |
| `; | |
| list.appendChild(li); | |
| }); | |
| countEl.textContent = `${activeCount} Active`; | |
| } | |
| window.toggleTask = (id) => { | |
| tasks = tasks.map(t => t.id === id ? {...t, completed: !t.completed} : t); | |
| save(); | |
| }; | |
| window.deleteTask = (id) => { | |
| tasks = tasks.filter(t => t.id !== id); | |
| save(); | |
| showToast('Task removed', 'info'); | |
| }; | |
| form.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| const text = input.value.trim(); | |
| if (!text) return; | |
| tasks.unshift({ | |
| id: Date.now(), | |
| text, | |
| completed: false | |
| }); | |
| input.value = ''; | |
| save(); | |
| showToast('New directive added', 'success'); | |
| }); | |
| render(); | |
| } | |
| /* --- 5. QUICK NOTES --- */ | |
| function initNotes() { | |
| const area = $('#quick-notes'); | |
| const clearBtn = $('#clear-notes'); | |
| // Load saved notes | |
| area.value = localStorage.getItem('nexus_notes') || ''; | |
| // Auto-save on input | |
| area.addEventListener('input', () => { | |
| localStorage.setItem('nexus_notes', area.value); | |
| }); | |
| clearBtn.addEventListener('click', () => { | |
| if(confirm('Clear all notes?')) { | |
| area.value = ''; | |
| localStorage.removeItem('nexus_notes'); | |
| showToast('Notes cleared', 'info'); | |
| } | |
| }); | |
| } | |
| /* --- 6. CANVAS CHART (Custom Drawing) --- */ | |
| function initChart() { | |
| const canvas = $('#productivityChart'); | |
| const ctx = canvas.getContext('2d'); | |
| // Handle high DPI displays | |
| const dpr = window.devicePixelRatio || 1; | |
| const rect = canvas.getBoundingClientRect(); | |
| canvas.width = rect.width * dpr; | |
| canvas.height = rect.height * dpr; | |
| ctx.scale(dpr, dpr); | |
| // Mock Data | |
| const dataPoints = [20, 45, 30, 60, 55, 80, 70]; | |
| const labels = ['M', 'T', 'W', 'T', 'F', 'S', 'S']; | |
| const maxVal = 100; | |
| function draw() { | |
| const width = rect.width; | |
| const height = rect.height; | |
| const padding = 20; | |
| const chartHeight = height - padding * 2; | |
| const chartWidth = width - padding * 2; | |
| const stepX = chartWidth / (dataPoints.length - 1); | |
| ctx.clearRect(0, 0, width, height); | |
| // Gradient Fill | |
| const gradient = ctx.createLinearGradient(0, 0, 0, height); | |
| gradient.addColorStop(0, 'rgba(6, 182, 212, 0.5)'); // Cyan | |
| gradient.addColorStop(1, 'rgba(6, 182, 212, 0.0)'); | |
| // Draw Area | |
| ctx.beginPath(); | |
| ctx.moveTo(padding, height - padding); | |
| dataPoints.forEach((val, index) => { | |
| const x = padding + index * stepX; | |
| const y = height - padding - (val / maxVal) * chartHeight; | |
| if (index === 0) ctx.lineTo(x, y); | |
| else { | |
| // Bezier curve for smoothness | |
| const prevX = padding + (index - 1) * stepX; | |
| const prevY = height - padding - (dataPoints[index - 1] / maxVal) * chartHeight; | |
| const cp1x = prevX + (x - prevX) / 2; | |
| const cp1y = prevY; | |
| const cp2x = prevX + (x - prevX) / 2; | |
| const cp2y = y; | |
| ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); | |
| } | |
| }); | |
| ctx.lineTo(width - padding, height - padding); | |
| ctx.closePath(); | |
| ctx.fillStyle = gradient; | |
| ctx.fill(); | |
| // Draw Line | |
| ctx.beginPath(); | |
| dataPoints.forEach((val, index) => { | |
| const x = padding + index * stepX; | |
| const y = height - padding - (val / maxVal) * chartHeight; | |
| if (index === 0) ctx.moveTo(x, y); | |
| else { | |
| const prevX = padding + (index - 1) * stepX; | |
| const prevY = height - padding - (dataPoints[index - 1] / maxVal) * chartHeight; | |
| const cp1x = prevX + (x - prevX) / 2; | |
| const cp1y = prevY; | |
| const cp2x = prevX + (x - prevX) / 2; | |
| const cp2y = y; | |
| ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); | |
| } | |
| }); | |
| ctx.strokeStyle = '#06b6d4'; | |
| ctx.lineWidth = 3; | |
| ctx.stroke(); | |
| // Draw Points | |
| dataPoints.forEach((val, index) => { | |
| const x = padding + index * stepX; | |
| const y = height - padding - (val / maxVal) * chartHeight; | |
| ctx.beginPath(); | |
| ctx.arc(x, y, 4, 0, Math.PI * 2); | |
| ctx.fillStyle = '#fff'; | |
| ctx.fill(); | |
| // Labels | |
| ctx.fillStyle = '#94a3b8'; | |
| ctx.font = '10px Outfit'; | |
| ctx.textAlign = 'center'; | |
| ctx.fillText(labels[index], x, height - 5); | |
| }); | |
| } | |
| draw(); | |
| // Redraw on resize | |
| window.addEventListener('resize', () => { | |
| const newRect = canvas.getBoundingClientRect(); | |
| canvas.width = newRect.width * dpr; | |
| canvas.height = newRect.height * dpr; | |
| ctx.scale(dpr, dpr); | |
| draw(); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |