#!/usr/bin/perl
use strict;
use warnings;
# HTML Template
my $html_template = <<'HTML';
<!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">
<!-- Removed Chart.js, added Google Charts -->
<script type="text/javascript" src="https://w...content-available-to-author-only...c.com/charts/loader.js"></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: 100%;
height: 400px; /* Updated height to make chart more flexible */
}
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 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 */
}
/* "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>
%TABLE_ROWS%
</tbody>
</table>
</div>
<!-- Pie Chart Section -->
<div class="chart-container">
<!-- This is where the Google Pie Chart will be rendered -->
<div id="pieChart"></div>
</div>
</div>
<!-- Tabs Section -->
<div class="tabs">
%TABS%
</div>
<!-- Tab Content -->
%TAB_CONTENTS%
<!-- 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 type="text/javascript">
// Load Google Charts library
google.charts.load('current', {
packages: ['corechart', 'piechart']
});
google.charts.setOnLoadCallback(drawChart);
// Pie Chart Data and Options
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Category', 'Value'],
['Red', 300],
['Blue', 50],
['Yellow', 100],
['Green', 40],
['Purple', 120]
]);
var options = {
title: 'Pie Chart Example',
is3D: false,
slices: {
0: {offset: 0.1},
1: {offset: 0.1},
2: {offset: 0.1},
3: {offset: 0.1},
4: {offset: 0.1}
},
legend: { position: 'top' }
};
var chart = new google.visualization.PieChart(document.getElementById('pieChart'));
chart.draw(data, options);
}
// Dark Mode Toggle Functionality (Same as before)
const toggleButton = document.getElementById('darkModeToggle');
toggleButton.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
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>
HTML
# Sample data for the table (can be dynamic)
my @table_data = (
{ id => 1, name => "John Doe", age => 28, city => "New York" },
{ id => 2, name => "Jane Smith", age => 34, city => "Los Angeles" },
{ id => 3, name => "Sam Johnson", age => 25, city => "Chicago" },
);
# Generate table rows
my $table_rows = '';
foreach my $row (@table_data) {
$table_rows .= "<tr data-tab=\"tab$row->{id}\">\n";
$table_rows .= "<td class=\"tab-id\">$row->{id}</td>\n";
$table_rows .= "<td>$row->{name}</td>\n";
$table_rows .= "<td>$row->{age}</td>\n";
$table_rows .= "<td>$row->{city}</td>\n";
$table_rows .= "</tr>\n";
}
# Generate tabs
my $tabs = '';
for (my $i = 1; $i <= 7; $i++) {
$tabs .= "<div class=\"tab\" data-tab=\"tab$i\">Tab $i</div>\n";
}
# Generate tab contents
my $tab_contents = '';
for (my $i = 1; $i <= 7; $i++) {
$tab_contents .= "<div class=\"tab-content\" id=\"tab$i\">\n";
$tab_contents .= "<p>This is content for Tab $i.</p>\n";
$tab_contents .= "</div>\n";
}
# Replace placeholders in the template
$html_template =~ s/%TABLE_ROWS%/$table_rows/g;
$html_template =~ s/%TABS%/$tabs/g;
$html_template =~ s/%TAB_CONTENTS%/$tab_contents/g;
# Output the final HTML
print header
(-type
=> 'text/html', -charset
=> 'UTF-8');