Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alerts axis #1115

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/containers/datasets/alerts/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const MONTHS = [
{ label: 'January', value: 1, shortLabel: 'Jan' },
{ label: 'February', value: 2, shortLabel: 'Feb' },
{ label: 'March', value: 3, shortLabel: 'Mar' },
{ label: 'April', value: 4, shortLabel: 'Apr' },
{ label: 'May', value: 5, shortLabel: 'May' },
{ label: 'June', value: 6, shortLabel: 'Jun' },
{ label: 'July', value: 7, shortLabel: 'Jul' },
{ label: 'August', value: 8, shortLabel: 'Aug' },
{ label: 'September', value: 9, shortLabel: 'Sep' },
{ label: 'October', value: 10, shortLabel: 'Oct' },
{ label: 'November', value: 11, shortLabel: 'Nov' },
{ label: 'December', value: 12, shortLabel: 'Dec' },
];

export const MONTHS_CONVERSION = {
January: 'Jan',
February: 'Feb',
March: 'March',
April: 'April',
May: 'May',
June: 'June',
July: 'July',
August: 'Aug',
September: 'Sept',
October: 'Oct',
November: 'Nov',
December: 'Dec',
};
45 changes: 9 additions & 36 deletions src/containers/datasets/alerts/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,10 @@ import type { LocationTypes } from 'containers/datasets/locations/types';

import API_cloud_functions from 'services/cloud-functions';

import { MONTHS, MONTHS_CONVERSION } from './constants';
import Tooltip from './tooltip';
import type { UseParamsOptions, DataResponse, CustomAreaGeometry } from './types';

// widget data
const months = [
{ label: 'January', value: 1, shortLabel: 'Jan' },
{ label: 'February', value: 2, shortLabel: 'Feb' },
{ label: 'March', value: 3, shortLabel: 'Mar' },
{ label: 'April', value: 4, shortLabel: 'Apr' },
{ label: 'May', value: 5, shortLabel: 'May' },
{ label: 'June', value: 6, shortLabel: 'Jun' },
{ label: 'July', value: 7, shortLabel: 'Jul' },
{ label: 'August', value: 8, shortLabel: 'Aug' },
{ label: 'September', value: 9, shortLabel: 'Sep' },
{ label: 'October', value: 10, shortLabel: 'Oct' },
{ label: 'November', value: 11, shortLabel: 'Nov' },
{ label: 'December', value: 12, shortLabel: 'Dec' },
];

const monthsConversion = {
January: 'Jan',
February: 'Feb',
March: 'March',
April: 'April',
May: 'May',
June: 'June',
July: 'July',
August: 'Aug',
September: 'Sept',
October: 'Oct',
November: 'Nov',
December: 'Dec',
};

const getStops = () => {
const colorSchema = ['rgba(199, 43, 214, 1)', 'rgba(235, 68, 68, 0.7)', 'rgba(255, 194, 0, 0.5)'];

Expand All @@ -70,7 +40,7 @@ const getData = (data) =>
sortBy(
data?.map((d) => {
const year = Number(d.date.value.split('-', 1)[0]);
const month = months?.find((m) => m.value === new Date(d.date.value).getMonth() + 1);
const month = MONTHS?.find((m) => m.value === new Date(d.date.value).getMonth() + 1);
const day = new Date(year, month.value, 0).getDate();

const lastDay = new Date(year, month.value, 0).getDate();
Expand All @@ -83,7 +53,7 @@ const getData = (data) =>
end: `${year}-${month.value < 10 ? '0' : ''}${month.value}-${day}`,
start: d.date.value,
title: month.label,
name: `${monthsConversion[month.label]} '${new Date(year + 1, 0, 0).toLocaleDateString(
name: `${MONTHS_CONVERSION[month.label]} '${new Date(year + 1, 0, 0).toLocaleDateString(
'en',
{
year: '2-digit',
Expand Down Expand Up @@ -202,13 +172,15 @@ export function useAlerts<T>(
(d) => selectedStartDate?.value <= d.date.value && d.date.value <= selectedEndDate?.value
);

const fixedXAxis = fullData.map((d) => d.year);

const chartData = getData(dataFiltered);
const startIndex = fullData.findIndex((d) => d.startDate?.value === selectedStartDate?.value);
const endIndex = fullData.findIndex((d) => d.endDate?.value === selectedEndDate?.value);

return useMemo(() => {
const alertsTotal = getTotal(dataFiltered);
const dataLimitOverflow = dataFiltered.length > 12;
const dataLimitOverflow = dataFiltered.length > 16;

const config = {
data: chartData,
Expand All @@ -234,7 +206,7 @@ export function useAlerts<T>(
xAxis: {
tick: TickSmall,
...(dataLimitOverflow && { ticks: Array.from(new Set(chartData.map((d) => d.year))) }),
interval: dataLimitOverflow ? 0 : 'preserveStart',
interval: 0,
type: 'category',
},
yAxis: {
Expand Down Expand Up @@ -362,7 +334,8 @@ export function useAlerts<T>(
},
xAxis: {
tick: TickSmall,
interval: 'preserveStartEnd',
ticks: Array.from(new Set(fixedXAxis)),
interval: 0,
type: 'category',
},

Expand Down
Loading