Skip to content

Commit

Permalink
Fix last domain date not being included (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva authored Sep 11, 2023
2 parents 4d341ed + 2bdfc83 commit 957ad79
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
18 changes: 17 additions & 1 deletion app/scripts/components/exploration/atoms/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import { add, max } from 'date-fns';

import { DAY_SIZE_MAX } from '../constants';
import {
TimeDensity,
TimelineDataset,
TimelineDatasetStatus,
TimelineDatasetSuccess
} from '../types.d.ts';
import { timelineDatasetsAtom, timelineSizesAtom } from './atoms';

function addDurationToDate(date, timeDensity: TimeDensity) {
const duration = {
[TimeDensity.YEAR]: { years: 1 },
[TimeDensity.MONTH]: { months: 1 },
[TimeDensity.DAY]: { days: 1 }
}[timeDensity];

return add(date, duration);
}

/**
* Calculates the date domain of the datasets, if any are selected.
* @returns Dataset date domain or undefined.
Expand All @@ -33,7 +44,12 @@ export function useTimelineDatasetsDomain() {
// is ordered and only look at first and last dates.
const [start, end] = extent(
successDatasets.flatMap((d) =>
d.data.domain.length ? [d.data.domain[0], d.data.domain.last] : []
d.data.domain.length
? [
d.data.domain[0],
addDurationToDate(d.data.domain.last, d.data.timeDensity)
]
: []
)
) as [Date, Date];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useAtom } from 'jotai';
import { timelineDatasetsAtom } from '../atoms/atoms';
import {
StacDatasetData,
TimeDensity,
TimelineDataset,
TimelineDatasetStatus
} from '../types.d.ts';
Expand Down Expand Up @@ -79,8 +80,8 @@ async function fetchStacDatasetById(
);

const commonTimeseriesParams = {
isPeriodic: data['dashboard:is_periodic'],
timeDensity: data['dashboard:time_density']
isPeriodic: !!data['dashboard:is_periodic'],
timeDensity: data['dashboard:time_density'] || TimeDensity.DAY
};

if (type === 'vector') {
Expand Down
26 changes: 26 additions & 0 deletions mock/datasets/sandbox.data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ layers:
label: "Out of season"
- color: "#804115"
label: "No data"
- id: facebook_population_density
stacCol: facebook_population_density
name: 'Facebook Population Density'
type: raster
description: 'Facebook high-resolution population density with a 30m² resolution'
zoomExtent:
- 0
- 20
sourceParams:
resampling: bilinear
bidx: 1
colormap_name: ylorrd
rescale:
- 0
- 69
legend:
type: gradient
min: "0"
max: "69"
stops:
- "#ffffcc"
- "#fee187"
- "#feab49"
- "#fc5b2e"
- "#d41020"
- "#800026"
related:
- type: dataset
id: no2
Expand Down

0 comments on commit 957ad79

Please sign in to comment.