Skip to content

Commit

Permalink
fix bug where single-month-at-a-time broke, and sort years left-right…
Browse files Browse the repository at this point in the history
… increasing
  • Loading branch information
gchenfc committed Sep 24, 2023
1 parent cf32c69 commit efa1b06
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions _blog/2023-09-23/calendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ body{
right: 0;
}
.calendar-container-below {
padding-top: 434px; /* Adjust this value to be at least the height of .container */
padding-top: 449px; /* Adjust this value to be at least the height of .container */
}

@media (max-width: 1200px) {
Expand Down Expand Up @@ -87,7 +87,7 @@ header .current-date{
}
.calendar{
padding: 20px;
margin-bottom: 20px;
/* margin-bottom: 20px; */
}
.calendar ul{
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions _blog/2023-09-23/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const renderCalendar_ = (year, daysTag, currentDateTag) => {
};
const renderCalendar = () => {
for (let i = 0; i < daysTagAll.length; i++) {
renderCalendar_(currYear - i, daysTagAll[i], currentDateTagAll[i]);
renderCalendar_(currYear - daysTagAll.length + i + 1, daysTagAll[i], currentDateTagAll[i]);
}
update_calendar(); // See traffic.js
};
Expand Down Expand Up @@ -139,7 +139,7 @@ function centerScroll() {

// Set the scroll position to the center
// scrollContainer.scrollLeft = (scrollWidth - clientWidth) / 2;
scrollContainer.scrollLeft = 300;
scrollContainer.scrollLeft = scrollWidth - clientWidth - 300;
}
centerScroll();

Expand Down
2 changes: 1 addition & 1 deletion _blog/2023-09-23/mega_calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const renderMegaCalendar = () => {
// Now render the calendar for each year
const currYear = new Date().getFullYear();
for (let i = 0; i < daysTagAll1.length; i++) {
renderMegaCalendar_(currYear - i, daysTagAll1[i], currentDateTagAll1[i]);
renderMegaCalendar_(currYear - daysTagAll1.length + i + 1, daysTagAll1[i], currentDateTagAll1[i]);
}
update_calendar(); // See traffic.js
};
Expand Down
14 changes: 8 additions & 6 deletions _blog/2023-09-23/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ function parseTsv(content) {

const elem_id = `_${year}-${newDate.getMonth() + 1}-${newDate.getDate()}`;
const elem = root.getElementById(elem_id);
const elems = root.querySelectorAll(`#${elem_id}`);
for (const elem of elems) {
if (!elem) continue; // Not a day in the calendar
const number = parseInt(columns[coli].replace(/,/g, ""), 10);
const color = colorScale(number, min, max);
const numberStr = (number / 1000000).toFixed(2) + "M"; // Convert number to 1.23M

const number = parseInt(columns[coli].replace(/,/g, ""), 10);
const color = colorScale(number, min, max);
const numberStr = (number / 1000000).toFixed(2) + "M"; // Convert number to 1.23M

elem.style.backgroundColor = color;
elem.setAttribute("data-after", numberStr);
elem.style.backgroundColor = color;
elem.setAttribute("data-after", numberStr);
}
}
}
}
Expand Down

0 comments on commit efa1b06

Please sign in to comment.