-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
227 lines (199 loc) · 7.46 KB
/
app.js
File metadata and controls
227 lines (199 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Dashboard data (placeholder)
const dashboards = [
{
title: "Oscar Awards Explorer",
description: "Explore 97 years of Academy Award winners and nominations through an interactive timeline and search tool powered by real data.",
image: "img/oscar-awards.jpg",
link: "https://bytecode001.github.io/OpenDataDashboards/dashboards/oscar-awards/"
},
{
title: "COVID-19 World Statistics",
description: "Real-time dashboard with global pandemic statistics, including cases, vaccinations, and regional trends.",
image: "img/placeholder.jpg",
link: "dashboards/covid-stats/index.html"
},
{
title: "Financial Markets Analysis",
description: "Dynamic visualization of financial markets with interactive charts and asset performance analysis.",
image: "img/placeholder.jpg",
link: "dashboards/financial-markets/index.html"
},
{
title: "World Population Demographics",
description: "Global demographic exploration with interactive maps and future population projections by country.",
image: "img/placeholder.jpg",
link: "dashboards/population/index.html"
},
{
title: "Energy Consumption Patterns",
description: "Analysis of global energy consumption focusing on renewable sources and sustainability trends.",
image: "img/placeholder.jpg",
link: "dashboards/energy/index.html"
},
{
title: "E-commerce Trends 2024",
description: "Comprehensive e-commerce trends dashboard with market analysis, product categories, and shopping behaviors.",
image: "img/placeholder.jpg",
link: "dashboards/ecommerce/index.html"
}
];
// Function to create a dashboard card
function createDashboardCard(dashboard, index) {
const card = document.createElement('article');
card.className = 'dashboard-card';
card.style.animationDelay = `${index * 0.1}s`;
card.innerHTML = `
<div class="card-image-container">
<img src="${dashboard.image}" alt="${dashboard.title}" class="card-image" loading="lazy">
</div>
<div class="card-content">
<h2 class="card-title">${dashboard.title}</h2>
<p class="card-description">${dashboard.description}</p>
<a href="${dashboard.link}" class="view-button" onclick="handleCardClick(event)">
<span class="view-button-text">View Dashboard</span>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="5" y1="12" x2="19" y2="12"></line>
<polyline points="12 5 19 12 12 19"></polyline>
</svg>
</a>
</div>
`;
// Click on entire card
card.addEventListener('click', (e) => {
if (!e.target.classList.contains('view-button') && !e.target.closest('.view-button')) {
window.location.href = dashboard.link;
}
});
return card;
}
// Handle click with ripple effect
function handleCardClick(event) {
event.stopPropagation();
const button = event.currentTarget;
// Create ripple effect
const ripple = document.createElement('span');
const rect = button.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = event.clientX - rect.left - size / 2;
const y = event.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
button.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
}
// Initialize dashboard grid
function initializeDashboards() {
const grid = document.getElementById('dashboards');
dashboards.forEach((dashboard, index) => {
const card = createDashboardCard(dashboard, index);
grid.appendChild(card);
});
}
// Smooth scroll for anchor links
function initializeSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// Intersection Observer for scroll animations
function initializeScrollAnimations() {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.animationPlayState = 'running';
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1
});
document.querySelectorAll('.dashboard-card').forEach(card => {
card.style.animationPlayState = 'paused';
observer.observe(card);
});
}
// Theme management (light/dark mode)
function initializeThemeToggle() {
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
// Listen for system preference changes
prefersDarkScheme.addEventListener('change', (e) => {
document.body.classList.toggle('dark-mode', e.matches);
});
}
// Lazy loading for images with fallback
function initializeLazyLoading() {
const images = document.querySelectorAll('img[loading="lazy"]');
images.forEach(img => {
img.addEventListener('error', function() {
this.src = 'img/placeholder.jpg';
});
});
}
// Hero background animation on mouse movement
function initializeHeroAnimation() {
const hero = document.querySelector('.hero');
const heroContent = document.querySelector('.hero-content');
hero.addEventListener('mousemove', (e) => {
const { clientX, clientY } = e;
const { width, height } = hero.getBoundingClientRect();
const xPos = (clientX / width - 0.5) * 20;
const yPos = (clientY / height - 0.5) * 20;
heroContent.style.transform = `translate(${xPos}px, ${yPos}px)`;
});
hero.addEventListener('mouseleave', () => {
heroContent.style.transform = 'translate(0, 0)';
});
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
initializeDashboards();
initializeSmoothScroll();
initializeThemeToggle();
initializeLazyLoading();
initializeHeroAnimation();
// Initialize scroll animations after a brief delay
setTimeout(() => {
initializeScrollAnimations();
}, 100);
});
// Performance optimization: Debounce for resize events
let resizeTimer;
window.addEventListener('resize', () => {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
// Re-initialize components that depend on window dimensions
initializeHeroAnimation();
}, 250);
});
// Add style for ripple effect
const style = document.createElement('style');
style.textContent = `
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);