forked from Uaman/JS_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.html
More file actions
203 lines (191 loc) · 8.17 KB
/
report.html
File metadata and controls
203 lines (191 loc) · 8.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Data Report</title>
<!-- WebDataRocks CSS -->
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, rgb(245, 245, 250) 0%, rgb(235, 232, 232) 100%);
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
background-color: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
h1 {
text-align: center;
color: #3264cf;
margin-bottom: 20px;
}
#pivotContainer {
height: 600px;
margin-top: 20px;
}
.no-data {
text-align: center;
padding: 40px;
color: #666;
}
.back-button {
display: inline-block;
margin-top: 20px;
padding: 8px 16px;
background-color: #3264cf;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
text-decoration: none;
font-weight: 500;
transition: all 0.3s ease;
}
.back-button:hover {
background-color: #264ea3;
transform: translateY(-1px);
box-shadow: 0 3px 10px rgba(50, 100, 207, 0.3);
}
#dataDebug {
margin-top: 20px;
padding: 10px;
background-color: #f5f5f5;
border-radius: 8px;
font-family: monospace;
font-size: 14px;
max-height: 200px;
overflow: auto;
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Weather Data Report</h1>
<div id="pivotContainer"></div>
<div id="noDataMessage" class="no-data" style="display: none;">
No weather data available. Please search for a city on the main page first.
</div>
<div id="dataDebug"></div>
<a href="./index.html" class="back-button">Back to Weather</a>
</div>
<!-- WebDataRocks Scripts -->
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Get weather data from localStorage
const weatherData = localStorage.getItem('weatherReportData');
const debugElement = document.getElementById('dataDebug');
// For debugging
if (weatherData) {
try {
const parsedForDebug = JSON.parse(weatherData);
debugElement.textContent = 'Data found: ' + parsedForDebug.length + ' records';
// Uncomment for detailed debugging:
// debugElement.textContent += '\n' + JSON.stringify(parsedForDebug[0], null, 2);
// debugElement.style.display = 'block';
} catch (e) {
debugElement.textContent = 'Error parsing data: ' + e.message;
debugElement.style.display = 'block';
}
} else {
debugElement.textContent = 'No data found in localStorage';
debugElement.style.display = 'block';
}
if (!weatherData || weatherData === '[]') {
document.getElementById('pivotContainer').style.display = 'none';
document.getElementById('noDataMessage').style.display = 'block';
return;
}
try {
const parsedData = JSON.parse(weatherData);
if (!parsedData || parsedData.length === 0) {
throw new Error('No data records found');
}
// Add sort order and format dates
parsedData.forEach((item, index) => {
if (item.Date) {
// Add numeric sort order based on original position
item.SortOrder = index;
const date = new Date(item.Date);
item.Date = date.toLocaleDateString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric'
});
}
});
// Initialize WebDataRocks with more detailed configuration
const pivot = new WebDataRocks({
container: "#pivotContainer",
toolbar: true,
report: {
dataSource: {
data: parsedData
},
slice: {
rows: [
{ uniqueName: "Date", sort: "asc", sortOrder: "SortOrder" }
],
columns: [
{ uniqueName: "Measures" }
],
measures: [
{ uniqueName: "MaxTemp", caption: "Max Temp (°C)", aggregation: "none" },
{ uniqueName: "MinTemp", caption: "Min Temp (°C)", aggregation: "none" },
{ uniqueName: "Humidity", caption: "Humidity (%)", aggregation: "none" },
{ uniqueName: "WindSpeed", caption: "Wind (km/h)", aggregation: "none" },
{ uniqueName: "Pressure", caption: "Pressure (hPa)", aggregation: "none" },
{ uniqueName: "Conditions", caption: "Conditions", aggregation: "none" }
]
},
formats: [
{
name: "temperature",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 0,
suffix: "°C"
}
],
options: {
grid: {
type: "classic",
showGrandTotals: "off",
showHeaders: true
},
configuratorButton: true,
configuratorActive: false,
datePattern: "dd/MM/yyyy",
defaultHierarchySortName: "asc"
}
}
});
const city = parsedData.length > 0 ? parsedData[0].City : 'Unknown';
const country = parsedData.length > 0 ? parsedData[0].Country : '';
const locationInfo = country ? `${city}, ${country}` : city;
document.querySelector('h1').textContent = `Weather Report for ${locationInfo}`;
pivot.on('reportcomplete', function() {
console.log('Report loaded successfully');
});
} catch (error) {
console.error("Error initializing pivot table:", error);
document.getElementById('pivotContainer').style.display = 'none';
document.getElementById('noDataMessage').style.display = 'block';
document.getElementById('noDataMessage').textContent = 'Error loading weather data: ' + error.message;
debugElement.textContent = 'Error: ' + error.message;
debugElement.style.display = 'block';
}
});
</script>
</body>
</html>