fork download
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use CGI qw(:standard);
  5.  
  6. # HTML Template
  7. my $html_template = <<'HTML';
  8. <!DOCTYPE html>
  9. <html lang="en">
  10. <head>
  11.   <meta charset="UTF-8">
  12.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  13.   <title>Table and Pie Chart with Tabs</title>
  14.   <link rel="stylesheet" href="https://c...content-available-to-author-only...e.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
  15.   <script src="https://c...content-available-to-author-only...r.net/npm/chart.js"></script>
  16.   <script src="https://c...content-available-to-author-only...r.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
  17.   <style>
  18.   /* Default Light Mode */
  19.   body {
  20.   font-family: Arial, sans-serif;
  21.   margin: 0;
  22.   padding: 0;
  23.   background-color: #f4f4f4;
  24.   color: #333;
  25.   transition: all 0.3s ease;
  26.   }
  27.  
  28.   header {
  29.   width: 100%;
  30.   text-align: center;
  31.   padding: 20px 0;
  32.   font-size: 24px;
  33.   font-weight: bold;
  34.   background-color: #fff;
  35.   color: #333;
  36.   }
  37.  
  38.   .container {
  39.   display: flex;
  40.   justify-content: space-between;
  41.   padding: 20px;
  42.   }
  43.  
  44.   .table-container {
  45.   flex: 1;
  46.   margin-right: 20px;
  47.   }
  48.  
  49.   .chart-container {
  50.   width: 400px;
  51.   height: 400px;
  52.   }
  53.  
  54.   table {
  55.   width: 100%;
  56.   border-collapse: collapse;
  57.   margin-bottom: 20px;
  58.   }
  59.  
  60.   table, th, td {
  61.   border: 1px solid #ddd;
  62.   }
  63.  
  64.   th, td {
  65.   padding: 8px 12px;
  66.   text-align: left;
  67.   }
  68.  
  69.   th {
  70.   background-color: #f4f4f4;
  71.   }
  72.  
  73.   canvas {
  74.   width: 200px;
  75.   height: 200px;
  76.   }
  77.  
  78.   .tabs {
  79.   display: flex;
  80.   margin-top: 20px;
  81.   justify-content: center;
  82.   }
  83.  
  84.   .tab {
  85.   padding: 10px 20px;
  86.   margin: 0 5px;
  87.   cursor: pointer;
  88.   border: 1px solid #ddd;
  89.   border-radius: 5px;
  90.   background-color: #f4f4f4;
  91.   text-align: center;
  92.   }
  93.  
  94.   .tab:hover {
  95.   background-color: #ddd;
  96.   }
  97.  
  98.   .tab-content {
  99.   display: none;
  100.   margin-top: 20px;
  101.   padding: 20px;
  102.   border: 1px solid #ddd;
  103.   border-top: none;
  104.   }
  105.  
  106.   .active-tab {
  107.   background-color: #ccc;
  108.   }
  109.  
  110.   .active-content {
  111.   display: block;
  112.   }
  113.  
  114.   .active-row {
  115.   background-color: #e0f7fa;
  116.   }
  117.  
  118.   /* Dark Mode Styles */
  119.   .dark-mode {
  120.   background-color: #333;
  121.   color: #fff;
  122.   }
  123.  
  124.   .dark-mode header {
  125.   background-color: #444;
  126.   color: #fff;
  127.   }
  128.  
  129.   .dark-mode .tab {
  130.   background-color: #444;
  131.   color: #fff;
  132.   border: 1px solid #555;
  133.   }
  134.  
  135.   .dark-mode .tab:hover {
  136.   background-color: #555;
  137.   }
  138.  
  139.   .dark-mode table, .dark-mode th, .dark-mode td {
  140.   border: 1px solid #555;
  141.   }
  142.  
  143.   .dark-mode th {
  144.   background-color: #666;
  145.   }
  146.  
  147.   .dark-mode .tab-content {
  148.   background-color: #444;
  149.   color: #fff;
  150.   }
  151.  
  152.   .dark-mode .active-row {
  153.   background-color: #555;
  154.   }
  155.  
  156.   /* Dark Mode Button (Icon version) */
  157.   .dark-mode-toggle {
  158.   position: absolute;
  159.   top: 20px;
  160.   right: 20px;
  161.   background-color: transparent;
  162.   border: none;
  163.   cursor: pointer;
  164.   font-size: 24px;
  165.   color: #fff;
  166.   transition: background-color 0.3s ease, color 0.3s ease;
  167.   display: flex;
  168.   justify-content: center;
  169.   align-items: center;
  170.   width: 40px;
  171.   height: 40px;
  172.   border-radius: 50%;
  173.   padding: 5px;
  174.   }
  175.  
  176.   /* Light Mode Icon */
  177.   .dark-mode-toggle.light-mode i {
  178.   color: #ffeb3b; /* Yellow sun icon for light mode */
  179.   }
  180.  
  181.   /* Hover Effect for Light Mode (Sun) */
  182.   .dark-mode-toggle.light-mode:hover {
  183.   background-color: #fff;
  184.   }
  185.  
  186.   .dark-mode-toggle.light-mode:hover i {
  187.   color: #ffea00; /* Lighter yellow when hovered */
  188.   }
  189.  
  190.   /* Dark Mode Icon (Moon) */
  191.   .dark-mode-toggle.dark-mode i {
  192.   color: #fff; /* White crescent icon in dark mode */
  193.   }
  194.  
  195.   /* Hover Effect for Dark Mode (Moon) */
  196.   .dark-mode-toggle.dark-mode:hover {
  197.   background-color: #444; /* Blends with the dark background */
  198.   }
  199.  
  200.   .dark-mode-toggle.dark-mode:hover i {
  201.   color: #fff;
  202.   }
  203.  
  204.   /* Chart.js Legend Text (Dark Mode Fix) */
  205.   .dark-mode .chartjs-legend li {
  206.   color: #fff !important; /* Ensure legend text is visible in dark mode */
  207.   }
  208.  
  209.   /* "Back to Top" Button */
  210.   .back-to-top {
  211.   position: fixed;
  212.   bottom: 20px;
  213.   right: 20px;
  214.   background-color: transparent;
  215.   border: none;
  216.   cursor: pointer;
  217.   font-size: 24px;
  218.   color: #fff;
  219.   transition: background-color 0.3s ease, color 0.3s ease;
  220.   display: flex;
  221.   justify-content: center;
  222.   align-items: center;
  223.   width: 40px;
  224.   height: 40px;
  225.   border-radius: 50%;
  226.   padding: 5px;
  227.   opacity: 0; /* Initially hidden */
  228.   visibility: hidden; /* Initially hidden */
  229.   transition: opacity 0.3s ease, visibility 0.3s ease;
  230.   }
  231.  
  232.   .back-to-top.show {
  233.   opacity: 1;
  234.   visibility: visible;
  235.   }
  236.  
  237.   .back-to-top i {
  238.   color: #00bcd4; /* Light cyan color for the arrow */
  239.   }
  240.  
  241.   /* Hover Effect for "Back to Top" Button */
  242.   .back-to-top:hover {
  243.   background-color: #00bcd4;
  244.   color: #fff;
  245.   }
  246.  
  247.   .back-to-top:hover i {
  248.   transform: scale(1.1);
  249.   }
  250.  
  251.   </style>
  252. </head>
  253. <body>
  254.  
  255.   <header>Table and Pie Chart with Tab</header>
  256.   <div class="container">
  257.   <!-- Table Section -->
  258.   <div class="table-container">
  259.   <table>
  260.   <thead>
  261.   <tr>
  262.   <th>ID</th>
  263.   <th>Name</th>
  264.   <th>Age</th>
  265.   <th>City</th>
  266.   </tr>
  267.   </thead>
  268.   <tbody>
  269.   %TABLE_ROWS%
  270.   </tbody>
  271.   </table>
  272.   </div>
  273.  
  274.   <!-- Pie Chart Section -->
  275.   <div class="chart-container">
  276.   <canvas id="pieChart"></canvas>
  277.   </div>
  278.   </div>
  279.  
  280.   <!-- Tabs Section -->
  281.   <div class="tabs">
  282.   %TABS%
  283.   </div>
  284.  
  285.   <!-- Tab Content -->
  286.   %TAB_CONTENTS%
  287.  
  288.   <!-- Dark Mode Toggle Button -->
  289.   <button id="darkModeToggle" class="dark-mode-toggle light-mode">
  290.   <i class="fas fa-sun"></i>
  291.   </button>
  292.  
  293.   <!-- Back to Top Button -->
  294.   <button class="back-to-top" id="backToTopBtn">
  295.   <i class="fas fa-arrow-up"></i>
  296.   </button>
  297.  
  298.   <script>
  299.   // Pie Chart Data
  300.   const data = {
  301.   labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple'],
  302.   datasets: [{
  303.   data: [300, 50, 100, 40, 120],
  304.   hoverOffset: 4
  305.   }]
  306.   };
  307.  
  308.   const config = {
  309.   type: 'pie',
  310.   data: data,
  311.   options: {
  312.   responsive: true,
  313.   maintainAspectRatio: false,
  314.   animation: {
  315.   duration: 1500,
  316.   easing: 'easeInOutCubic',
  317.   animateRotate: true,
  318.   animateScale: true,
  319.   },
  320.   plugins: {
  321.   legend: {
  322.   position: 'top',
  323.   labels: {
  324.   color: '#333',
  325.   }
  326.   },
  327.   datalabels: {
  328.   anchor: 'center',
  329.   align: 'center',
  330.   font: {
  331.   weight: 'bold',
  332.   size: 14,
  333.   },
  334.   color: '#fff',
  335.   formatter: (value, context) => {
  336.   let total = context.dataset._meta[Object.keys(context.dataset._meta)[0]].total;
  337.   let percentage = ((value / total) * 100).toFixed(1);
  338.   return `${value} (${percentage}%)`;
  339.   }
  340.   }
  341.   }
  342.   }
  343.   };
  344.   const pieChart = new Chart(document.getElementById('pieChart'), config);
  345. // Dark Mode Fix for Chart.js Legend Text
  346. const updateChartLegendForDarkMode = () => {
  347. if (document.body.classList.contains('dark-mode')) {
  348. // Change the legend label color to white in dark mode
  349. pieChart.options.plugins.legend.labels.color = '#fff';
  350. pieChart.update();
  351. } else {
  352. // Reset the legend label color to black for light mode
  353. pieChart.options.plugins.legend.labels.color = '#333';
  354. pieChart.update();
  355. }
  356. };
  357.  
  358.   // Scroll to top functionality
  359.   const backToTopBtn = document.getElementById('backToTopBtn');
  360.  
  361.   window.onscroll = () => {
  362.   if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
  363.   backToTopBtn.classList.add('show');
  364.   } else {
  365.   backToTopBtn.classList.remove('show');
  366.   }
  367.   };
  368.  
  369.   backToTopBtn.onclick = () => {
  370.   window.scrollTo({
  371.   top: 0,
  372.   behavior: 'smooth'
  373.   });
  374.   };
  375.  
  376.   // Tab Switching Functionality with Table Row Sync
  377.   const tabs = document.querySelectorAll('.tab');
  378.   const contents = document.querySelectorAll('.tab-content');
  379.   const tableRows = document.querySelectorAll('tbody tr');
  380.  
  381.   tabs.forEach(tab => {
  382.   tab.addEventListener('click', () => {
  383.   const targetTab = tab.getAttribute('data-tab');
  384.  
  385.   // Hide all tab contents
  386.   contents.forEach(content => content.classList.remove('active-content'));
  387.   tabs.forEach(tab => tab.classList.remove('active-tab'));
  388.   tableRows.forEach(row => row.classList.remove('active-row'));
  389.  
  390.   // Show the clicked tab content
  391.   document.getElementById(targetTab).classList.add('active-content');
  392.  
  393.   // Mark the clicked tab as active
  394.   tab.classList.add('active-tab');
  395.  
  396.   // Highlight the corresponding table row
  397.   const correspondingRow = document.querySelector(`tr[data-tab="${targetTab}"]`);
  398.   correspondingRow.classList.add('active-row');
  399.   });
  400.   });
  401.  
  402.   // Table Row Click to Open Corresponding Tab
  403.   tableRows.forEach(row => {
  404.   row.addEventListener('click', () => {
  405.   const targetTab = row.getAttribute('data-tab');
  406.   const tab = document.querySelector(`.tab[data-tab="${targetTab}"]`);
  407.  
  408.   // Trigger the tab click to highlight the tab and row
  409.   tab.click();
  410.   });
  411.   });
  412.  
  413.   // Dark Mode Toggle Functionality
  414.   const toggleButton = document.getElementById('darkModeToggle');
  415.   toggleButton.addEventListener('click', () => {
  416.   document.body.classList.toggle('dark-mode');
  417. updateChartLegendForDarkMode();
  418.   const icon = document.querySelector('.dark-mode-toggle i');
  419.   if (document.body.classList.contains('dark-mode')) {
  420.   icon.classList.remove('fa-sun');
  421.   icon.classList.add('fa-moon');
  422.   toggleButton.classList.remove('light-mode');
  423.   toggleButton.classList.add('dark-mode');
  424.   } else {
  425.   icon.classList.remove('fa-moon');
  426.   icon.classList.add('fa-sun');
  427.   toggleButton.classList.remove('dark-mode');
  428.   toggleButton.classList.add('light-mode');
  429.   }
  430.   });
  431.   </script>
  432. </body>
  433. </html>
  434. HTML
  435.  
  436. # Sample data for the table (can be dynamic)
  437. my @table_data = (
  438. { id => 1, name => "John Doe", age => 28, city => "New York" },
  439. { id => 2, name => "Jane Smith", age => 34, city => "Los Angeles" },
  440. { id => 3, name => "Sam Johnson", age => 25, city => "Chicago" },
  441. );
  442.  
  443. # Generate table rows
  444. my $table_rows = '';
  445. foreach my $row (@table_data) {
  446. $table_rows .= "<tr data-tab=\"tab$row->{id}\">\n";
  447. $table_rows .= "<td class=\"tab-id\">$row->{id}</td>\n";
  448. $table_rows .= "<td>$row->{name}</td>\n";
  449. $table_rows .= "<td>$row->{age}</td>\n";
  450. $table_rows .= "<td>$row->{city}</td>\n";
  451. $table_rows .= "</tr>\n";
  452. }
  453.  
  454. # Generate tabs
  455. my $tabs = '';
  456. for (my $i = 1; $i <= 7; $i++) {
  457. $tabs .= "<div class=\"tab\" data-tab=\"tab$i\">Tab $i</div>\n";
  458. }
  459.  
  460. # Generate tab contents
  461. my $tab_contents = '';
  462. for (my $i = 1; $i <= 7; $i++) {
  463. $tab_contents .= "<div class=\"tab-content\" id=\"tab$i\">\n";
  464. $tab_contents .= "<p>This is content for Tab $i.</p>\n";
  465. $tab_contents .= "</div>\n";
  466. }
  467.  
  468. # Replace placeholders in the template
  469. $html_template =~ s/%TABLE_ROWS%/$table_rows/g;
  470. $html_template =~ s/%TABS%/$tabs/g;
  471. $html_template =~ s/%TAB_CONTENTS%/$tab_contents/g;
  472.  
  473. # Output the final HTML
  474. print header(-type => 'text/html', -charset => 'UTF-8');
  475. print $html_template;
  476.  
Success #stdin #stdout 0.04s 9256KB
stdin
Standard input is empty
stdout
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Table and Pie Chart with Tabs</title>
    <link rel="stylesheet" href="https://c...content-available-to-author-only...e.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <script src="https://c...content-available-to-author-only...r.net/npm/chart.js"></script>
    <script src="https://c...content-available-to-author-only...r.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
    <style>
        /* Default Light Mode */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
            color: #333;
            transition: all 0.3s ease;
        }

        header {
            width: 100%;
            text-align: center;
            padding: 20px 0;
            font-size: 24px;
            font-weight: bold;
            background-color: #fff;
            color: #333;
        }

        .container {
            display: flex;
            justify-content: space-between;
            padding: 20px;
        }

        .table-container {
            flex: 1;
            margin-right: 20px;
        }

        .chart-container {
            width: 400px;
            height: 400px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        table, th, td {
            border: 1px solid #ddd;
        }

        th, td {
            padding: 8px 12px;
            text-align: left;
        }

        th {
            background-color: #f4f4f4;
        }

        canvas {
            width: 200px;
            height: 200px;
        }

        .tabs {
            display: flex;
            margin-top: 20px;
            justify-content: center;
        }

        .tab {
            padding: 10px 20px;
            margin: 0 5px;
            cursor: pointer;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f4f4f4;
            text-align: center;
        }

        .tab:hover {
            background-color: #ddd;
        }

        .tab-content {
            display: none;
            margin-top: 20px;
            padding: 20px;
            border: 1px solid #ddd;
            border-top: none;
        }

        .active-tab {
            background-color: #ccc;
        }

        .active-content {
            display: block;
        }

        .active-row {
            background-color: #e0f7fa;
        }

        /* Dark Mode Styles */
        .dark-mode {
            background-color: #333;
            color: #fff;
        }

        .dark-mode header {
            background-color: #444;
            color: #fff;
        }

        .dark-mode .tab {
            background-color: #444;
            color: #fff;
            border: 1px solid #555;
        }

        .dark-mode .tab:hover {
            background-color: #555;
        }

        .dark-mode table, .dark-mode th, .dark-mode td {
            border: 1px solid #555;
        }

        .dark-mode th {
            background-color: #666;
        }

        .dark-mode .tab-content {
            background-color: #444;
            color: #fff;
        }

        .dark-mode .active-row {
            background-color: #555;
        }

        /* Dark Mode Button (Icon version) */
        .dark-mode-toggle {
            position: absolute;
            top: 20px;
            right: 20px;
            background-color: transparent;
            border: none;
            cursor: pointer;
            font-size: 24px;
            color: #fff;
            transition: background-color 0.3s ease, color 0.3s ease;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            padding: 5px;
        }

        /* Light Mode Icon */
        .dark-mode-toggle.light-mode i {
            color: #ffeb3b;  /* Yellow sun icon for light mode */
        }

        /* Hover Effect for Light Mode (Sun) */
        .dark-mode-toggle.light-mode:hover {
            background-color: #fff;
        }

        .dark-mode-toggle.light-mode:hover i {
            color: #ffea00; /* Lighter yellow when hovered */
        }

        /* Dark Mode Icon (Moon) */
        .dark-mode-toggle.dark-mode i {
            color: #fff;  /* White crescent icon in dark mode */
        }

        /* Hover Effect for Dark Mode (Moon) */
        .dark-mode-toggle.dark-mode:hover {
            background-color: #444; /* Blends with the dark background */
        }

        .dark-mode-toggle.dark-mode:hover i {
            color: #fff;
        }

        /* Chart.js Legend Text (Dark Mode Fix) */
        .dark-mode .chartjs-legend li {
            color: #fff !important; /* Ensure legend text is visible in dark mode */
        }

        /* "Back to Top" Button */
        .back-to-top {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: transparent;
            border: none;
            cursor: pointer;
            font-size: 24px;
            color: #fff;
            transition: background-color 0.3s ease, color 0.3s ease;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            padding: 5px;
            opacity: 0; /* Initially hidden */
            visibility: hidden; /* Initially hidden */
            transition: opacity 0.3s ease, visibility 0.3s ease;
        }

        .back-to-top.show {
            opacity: 1;
            visibility: visible;
        }

        .back-to-top i {
            color: #00bcd4; /* Light cyan color for the arrow */
        }

        /* Hover Effect for "Back to Top" Button */
        .back-to-top:hover {
            background-color: #00bcd4;
            color: #fff;
        }

        .back-to-top:hover i {
            transform: scale(1.1);
        }

    </style>
</head>
<body>

    <header>Table and Pie Chart with Tab</header>
    <div class="container">
        <!-- Table Section -->
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Age</th>
                        <th>City</th>
                    </tr>
                </thead>
                <tbody>
                    <tr data-tab="tab1">
<td class="tab-id">1</td>
<td>John Doe</td>
<td>28</td>
<td>New York</td>
</tr>
<tr data-tab="tab2">
<td class="tab-id">2</td>
<td>Jane Smith</td>
<td>34</td>
<td>Los Angeles</td>
</tr>
<tr data-tab="tab3">
<td class="tab-id">3</td>
<td>Sam Johnson</td>
<td>25</td>
<td>Chicago</td>
</tr>

                </tbody>
            </table>
        </div>

        <!-- Pie Chart Section -->
        <div class="chart-container">
            <canvas id="pieChart"></canvas>
        </div>
    </div>

    <!-- Tabs Section -->
    <div class="tabs">
        <div class="tab" data-tab="tab1">Tab 1</div>
<div class="tab" data-tab="tab2">Tab 2</div>
<div class="tab" data-tab="tab3">Tab 3</div>
<div class="tab" data-tab="tab4">Tab 4</div>
<div class="tab" data-tab="tab5">Tab 5</div>
<div class="tab" data-tab="tab6">Tab 6</div>
<div class="tab" data-tab="tab7">Tab 7</div>

    </div>

    <!-- Tab Content -->
    <div class="tab-content" id="tab1">
<p>This is content for Tab 1.</p>
</div>
<div class="tab-content" id="tab2">
<p>This is content for Tab 2.</p>
</div>
<div class="tab-content" id="tab3">
<p>This is content for Tab 3.</p>
</div>
<div class="tab-content" id="tab4">
<p>This is content for Tab 4.</p>
</div>
<div class="tab-content" id="tab5">
<p>This is content for Tab 5.</p>
</div>
<div class="tab-content" id="tab6">
<p>This is content for Tab 6.</p>
</div>
<div class="tab-content" id="tab7">
<p>This is content for Tab 7.</p>
</div>


    <!-- Dark Mode Toggle Button -->
    <button id="darkModeToggle" class="dark-mode-toggle light-mode">
        <i class="fas fa-sun"></i>
    </button>

    <!-- Back to Top Button -->
    <button class="back-to-top" id="backToTopBtn">
        <i class="fas fa-arrow-up"></i>
    </button>

    <script>
      // Pie Chart Data
        const data = {
            labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple'],
            datasets: [{
                data: [300, 50, 100, 40, 120],
                hoverOffset: 4
            }]
        };

        const config = {
            type: 'pie',
            data: data,
            options: {
                responsive: true,
                maintainAspectRatio: false,
                animation: {
                    duration: 1500,
                    easing: 'easeInOutCubic',
                    animateRotate: true,
                    animateScale: true,
                },
                plugins: {
                    legend: {
                        position: 'top',
                        labels: {
                            color: '#333',
                        }
                    },
                    datalabels: {
                        anchor: 'center',
                        align: 'center',
                        font: {
                            weight: 'bold',
                            size: 14,
                        },
                        color: '#fff',
                        formatter: (value, context) => {
                            let total = context.dataset._meta[Object.keys(context.dataset._meta)[0]].total;
                            let percentage = ((value / total) * 100).toFixed(1);
                            return `${value} (${percentage}%)`;
                        }
                    }
                }
            }
        };
        const pieChart = new Chart(document.getElementById('pieChart'), config);
		// Dark Mode Fix for Chart.js Legend Text
		const updateChartLegendForDarkMode = () => {
			if (document.body.classList.contains('dark-mode')) {
				// Change the legend label color to white in dark mode
				pieChart.options.plugins.legend.labels.color = '#fff';
				pieChart.update();
			} else {
				// Reset the legend label color to black for light mode
				pieChart.options.plugins.legend.labels.color = '#333';
				pieChart.update();
			}
		};
		
        // Scroll to top functionality
        const backToTopBtn = document.getElementById('backToTopBtn');

        window.onscroll = () => {
            if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
                backToTopBtn.classList.add('show');
            } else {
                backToTopBtn.classList.remove('show');
            }
        };

        backToTopBtn.onclick = () => {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        };

        // Tab Switching Functionality with Table Row Sync
        const tabs = document.querySelectorAll('.tab');
        const contents = document.querySelectorAll('.tab-content');
        const tableRows = document.querySelectorAll('tbody tr');

        tabs.forEach(tab => {
            tab.addEventListener('click', () => {
                const targetTab = tab.getAttribute('data-tab');
                
                // Hide all tab contents
                contents.forEach(content => content.classList.remove('active-content'));
                tabs.forEach(tab => tab.classList.remove('active-tab'));
                tableRows.forEach(row => row.classList.remove('active-row'));
                
                // Show the clicked tab content
                document.getElementById(targetTab).classList.add('active-content');
                
                // Mark the clicked tab as active
                tab.classList.add('active-tab');
                
                // Highlight the corresponding table row
                const correspondingRow = document.querySelector(`tr[data-tab="${targetTab}"]`);
                correspondingRow.classList.add('active-row');
            });
        });

        // Table Row Click to Open Corresponding Tab
        tableRows.forEach(row => {
            row.addEventListener('click', () => {
                const targetTab = row.getAttribute('data-tab');
                const tab = document.querySelector(`.tab[data-tab="${targetTab}"]`);

                // Trigger the tab click to highlight the tab and row
                tab.click();
            });
        });

        // Dark Mode Toggle Functionality
        const toggleButton = document.getElementById('darkModeToggle');
        toggleButton.addEventListener('click', () => {
            document.body.classList.toggle('dark-mode');
			updateChartLegendForDarkMode();
            const icon = document.querySelector('.dark-mode-toggle i');
            if (document.body.classList.contains('dark-mode')) {
                icon.classList.remove('fa-sun');
                icon.classList.add('fa-moon');
                toggleButton.classList.remove('light-mode');
                toggleButton.classList.add('dark-mode');
            } else {
                icon.classList.remove('fa-moon');
                icon.classList.add('fa-sun');
                toggleButton.classList.remove('dark-mode');
                toggleButton.classList.add('light-mode');
            }
        });
    </script>
</body>
</html>