File size: 2,864 Bytes
b97f52c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Shared JavaScript across all pages
console.log('Network Analytics Dashboard loaded');

// Initialize tooltips and interactive elements
document.addEventListener('DOMContentLoaded', function() {
    // Add loading states to buttons
    const buttons = document.querySelectorAll('button');
    buttons.forEach(button => {
        button.addEventListener('click', function() {
            if (this.textContent.includes('Real-time')) {
                // Simulate real-time data loading
                this.classList.add('loading');
                setTimeout(() => {
                    this.classList.remove('loading');
                    // Update active state
                    buttons.forEach(btn => btn.classList.remove('bg-primary', 'text-white'));
                    buttons.forEach(btn => btn.classList.add('bg-gray-200', 'text-gray-700'));
                    this.classList.remove('bg-gray-200', 'text-gray-700');
                    this.classList.add('bg-primary', 'text-white');
                }, 500);
            }
        });
    });

    // Add smooth transitions for chart containers
    const chartContainers = document.querySelectorAll('.bg-gray-50');
    chartContainers.forEach(container => {
        container.classList.add('transition-all', 'duration-300');
    });

    // Initialize live data updates
    function updateLiveData() {
        const liveIndicators = document.querySelectorAll('.pulse-live');
        liveIndicators.forEach(indicator => {
            // Simulate data update
            indicator.style.opacity = Math.random() * 0.3 + 0.7;
        });
    }

    // Update data every 5 seconds
    setInterval(updateLiveData, 5000);

    // Add scroll animations
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('animate-fade-in');
            }
        }, observerOptions);

    // Observe all feature cards and stats
    document.querySelectorAll('.bg-white').forEach(card => {
        observer.observe(card);
    });
});

// Utility functions
const Utils = {
    formatNumber: (num) => {
        return new Intl.NumberFormat().format(num);
    },
    
    formatPercentage: (num) => {
        return new Intl.NumberFormat('en-US', {
            style: 'percent',
            minimumFractionDigits: 1,
            maximumFractionDigits: 1
        }).format(num / 100);
    },
    
    formatBytes: (bytes) => {
        if (bytes === 0) return '0 Bytes';
        const k = 1024;
        const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
        const i = Math.floor(Math.log(bytes) / Math.log(k));
        return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
    }
};