-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added uplot for some stats in now.html
- Loading branch information
1 parent
a1b1784
commit 6323d87
Showing
5 changed files
with
121 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Prepare the data | ||
const currentYear = new Date().getFullYear(); | ||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | ||
const distancesCurrentYear = [ 71, 141, 279, 318, 85, 365, 472, 497, 302, 276, 224, 157]; | ||
const distancesPreviousYear = [ 97, 100, 82, 275, 293, 270, 197, 272, 83, 255, 89, 0]; | ||
|
||
// Data structure for uPlot | ||
const data = [ | ||
months.map((m, i) => i), // Convert month names to indices | ||
distancesPreviousYear, | ||
distancesCurrentYear, | ||
]; | ||
|
||
// Set the options | ||
const options = { | ||
height: 200, | ||
series: [ | ||
{ value: (self, rawValue) => months[rawValue] }, // Assuming months are 0-indexed | ||
{ | ||
label: "2022", | ||
stroke: 'gray', | ||
width: 2, | ||
value: (self, rawValue) => rawValue + ' km', // Append 'km' units to series values | ||
}, | ||
{ | ||
label: "2023", | ||
stroke: 'blue', | ||
width: 2, | ||
value: (self, rawValue) => rawValue + ' km', // Append 'km' units to series values | ||
}, | ||
], | ||
axes: [ | ||
{ | ||
values: (self, ticks) => ticks.map(idx => months[idx]), // Format x-axis labels | ||
grid: { show: false }, // Hide x-axis gridlines | ||
}, | ||
{ | ||
show: false, // Hide y-axis labels and gridlines | ||
grid: { show: false }, | ||
}, | ||
], | ||
}; | ||
|
||
// Target a DOM element | ||
const element = document.getElementById('chart'); | ||
|
||
// | ||
|
||
function createChart() { | ||
const element = document.getElementById('chart'); | ||
if (element) { | ||
element.innerHTML = ''; | ||
|
||
// Since the DOM is fully loaded, no need for requestAnimationFrame | ||
const uplot = new uPlot(options, data, element); | ||
|
||
// Set the initial size explicitly | ||
uplot.setSize({ | ||
width: element.clientWidth, | ||
height: options.height | ||
}); | ||
|
||
// Resize handling | ||
let resizeTimer; | ||
window.addEventListener('resize', () => { | ||
clearTimeout(resizeTimer); | ||
resizeTimer = setTimeout(() => { | ||
uplot.setSize({ | ||
width: element.clientWidth, | ||
height: options.height | ||
}); | ||
}, 100); | ||
}); | ||
} | ||
} | ||
|
||
// Execute immediately since this script is loaded at the end of the body | ||
createChart(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Clock on now.html | ||
|
||
function changeTimeZone(date, timeZone) { | ||
if (typeof date === 'string') { | ||
return new Date( | ||
new Date(date).toLocaleString('en-US', { | ||
timeZone, | ||
}), | ||
); | ||
} | ||
|
||
return new Date( | ||
date.toLocaleString('en-US', { | ||
timeZone, | ||
}), | ||
); | ||
} | ||
|
||
const krkDate = changeTimeZone(new Date(), 'Europe/Warsaw'); | ||
console.log(krkDate); // 👉️ "Sun Jan 16 2022 08:54:44" | ||
|
||
var seconds = krkDate.getSeconds(); | ||
var minutes = krkDate.getMinutes(); | ||
var hours = krkDate.getHours(); | ||
hours = (hours > 12) ? hours - 12 : hours; | ||
minutes = (minutes * 60) + seconds; | ||
hours = (hours * 3600) + minutes; | ||
|
||
document.querySelector('.clock-second-hand').setAttribute('transform', 'rotate('+360*(seconds/60)+',192,192)'); | ||
document.querySelector('.clock-minute-hand').setAttribute('transform', 'rotate('+360*(minutes/3600)+',192,192)'); | ||
document.querySelector('.clock-hour-hand').setAttribute('transform', 'rotate('+360*(hours/43200)+',192,192)'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters