Skip to content

Commit 48b3d06

Browse files
committed
NASAEARTH-16 fix issue with colorbar plot colors
The last date added to yLabels was the duplicate of the end date. This happened due to timezone issues. That duplicate date caused ChartJS to draw the last data point overtop of other points.
1 parent 046b8cf commit 48b3d06

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/components/colorbar-plot/colorbar-plot.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
5959
});
6060

6161
// Add the next month to the yLabels
62-
const lastDateMonth = new Date(yLabels[yLabels.length - 1]).getMonth() + 1;
63-
const lastDateYear = new Date(yLabels[yLabels.length - 1]).getFullYear();
64-
// Note: Javascript correctly handles a month of 13 as the next year
65-
const lastDate = new Date(lastDateYear, lastDateMonth);
66-
yLabels.push(lastDate.toISOString().split("T")[0]);
62+
// We use UTC methods to avoid timezone issues
63+
const lastDate = new Date(yLabels[yLabels.length - 1]);
64+
// These are 0 based months
65+
const lastDateMonth = new Date(lastDate).getUTCMonth();
66+
const lastDateYear = new Date(lastDate).getUTCFullYear();
67+
// Javascript correctly handles a month of 12 as the next year
68+
const endDate = new Date(Date.UTC(lastDateYear, lastDateMonth + 1));
69+
yLabels.push(endDate.toISOString().split("T")[0]);
6770

6871
const selectedYMDDate = loadedImages[currentImageIndex].date;
6972

@@ -90,6 +93,21 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
9093
});
9194
const datasets: IDataset[] = Array.from(datasetMap.values());
9295

96+
// After creating the datasets, add a check for date ranges are only 1 month
97+
const invalidDateRanges = datasets.flatMap(dataset =>
98+
dataset.data.filter(dataPoint => {
99+
const [startDate, _endDate] = dataPoint.y;
100+
const start = new Date(startDate);
101+
const end = new Date(_endDate);
102+
const diffInMonths = (end.getFullYear() - start.getFullYear()) * 12 + (end.getMonth() - start.getMonth());
103+
return diffInMonths !== 1;
104+
})
105+
);
106+
107+
if (invalidDateRanges.length > 0) {
108+
console.warn("Found data points with date ranges greater than 1 month:", invalidDateRanges);
109+
}
110+
93111
// Note: any is used here as the Bar type doesn't support the `events:` list but the code does
94112
const options: any = {
95113
animation: {

src/models/plugin-state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export function pinLabel(pin: IMapPin) {
2828
return `${pin.lat.toFixed(2)}, ${pin.long.toFixed(2)}`;
2929
}
3030

31-
3231
class PluginState {
3332
neoDataset: NeoDataset | undefined;
3433
neoDatasetName = "";

0 commit comments

Comments
 (0)