Skip to content

Commit

Permalink
fix calculation using quarters where none are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
awildturtok committed Apr 29, 2024
1 parent f9e21e4 commit 9f274ff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions frontend/src/js/preview/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ export function useDateTickHandler(stats: PreviewStatistics) {
let shouldTickRender: (date: Date) => boolean = () => false;

if (previewStatsIsDateStats(stats)) {
const quarterCount = Object.keys(stats.quarterCounts).length;
const monthCount = Object.keys(stats.monthCounts).length;

// default -> months
shouldTickRender = () => true;
// > 12 months -> quarters
if (quarterCount > 4) {
if (monthCount > 12) {
shouldTickRender = (date: Date) => date.getMonth() % 3 === 0;
}
// > 12 quarters -> halfyears
if (quarterCount > 12) {
if (monthCount > 4*12) {
shouldTickRender = (date: Date) => date.getMonth() % 6 === 0;
}
// > 12 halfyears -> years
if (quarterCount > 24) {
if (monthCount > 6*12) {
shouldTickRender = (date: Date) => date.getMonth() === 0;
}
// > 12 years -> decades
if (quarterCount > 48) {
if (monthCount > 12*12) {
shouldTickRender = (date: Date) =>
date.getFullYear() % 10 === 0 && date.getMonth() === 0;
}
Expand Down

0 comments on commit 9f274ff

Please sign in to comment.