Skip to content

Commit

Permalink
axis date function
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed Apr 8, 2024
1 parent 90e2dad commit 4b2c03f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/containers/datasets/alerts/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,35 @@ import API_cloud_functions from 'services/cloud-functions';
import Tooltip from './tooltip';
import type { UseParamsOptions, DataResponse, CustomAreaGeometry } from './types';

interface DataEntry {
date: {
value: string; // the date in YYYY-MM-DD format
};
count: number;
}

function extractMonthsOrYears(data: DataEntry[]): string[] {
const monthSet = new Set<string>();
const yearSet = new Set<string>();

data.forEach((entry) => {
const dateValue = entry.date.value;
const dateObject = new Date(dateValue);
// Format the date to "Month Year" (e.g., "May 2024")
const formattedMonthYear = dateObject.toLocaleString('en-US', {
month: 'long', // Full month name
year: 'numeric', // Four digit year
});
const yearOnly = dateObject.getFullYear().toString(); // Get the full year as a string

monthSet.add(formattedMonthYear);
yearSet.add(yearOnly);
});

// Determine which set to return based on the size of the monthSet
return monthSet.size > 19 ? Array.from(yearSet) : Array.from(monthSet);
}

// widget data
const months = [
{ label: 'January', value: 1, shortLabel: 'Jan' },
Expand Down

0 comments on commit 4b2c03f

Please sign in to comment.