Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-3888: Charting Mode Error Days Handling (#6410)

christof-wittreichc50e710580ba
diff --git a/web/js/components/charting/chart-component.js b/web/js/components/charting/chart-component.js
index f9c3b0df7..50a30f77b 100644
--- a/web/js/components/charting/chart-component.js
+++ b/web/js/components/charting/chart-component.js
@@ -163,36 +163,8 @@ function ChartComponent(props) {
layerId,
} = liveData;
- // Normalize error days input robustly (supports array, CSV, and "['...','...']" forms)
- const errorDaysArr = useMemo(() => {
- const raw = errors?.error_days;
- if (Array.isArray(raw)) return raw.map((s) => String(s));
- if (raw == null) return [];
- if (typeof raw !== 'string') return [String(raw)];
-
- const trimmed = raw.trim();
-
- // Try JSON parse if looks like an array; tolerate single quotes
- if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
- try {
- const jsonish = trimmed.replace(/'/g, '"');
- const arr = JSON.parse(jsonish);
- if (Array.isArray(arr)) return arr.map((s) => String(s));
- } catch {
- // fall through to manual split
- }
- }
-
- // Fallback: strip brackets, split on comma, strip surrounding quotes
- return trimmed
- .replace(/^\[|\]$/g, '')
- .split(',')
- .map((s) => String(s).trim().replace(/^['"]|['"]$/g, ''))
- .filter(Boolean);
- }, [errors]);
-
// Build display string "YYYY-MM-DD, YYYY-MM-DD, ..." with non-breaking spaces
- const errorDatesDisplay = useMemo(() => errorDaysArr
+ const errorDatesDisplay = useMemo(() => errors?.error_days
.map((item) => {
const dateStr = typeof item === 'string'
? item
@@ -200,15 +172,13 @@ function ChartComponent(props) {
return (dateStr || '').split('T')[0];
})
.filter(Boolean)
- .join(', \u00A0\u00A0'), [errorDaysArr]);
+ .join(', \u00A0\u00A0'), [errors?.error_days]);
const format = util.getCoordinateFormat();
// Arbitrary array of colors to use
const lineColors = ['#A3905D', '#82CA9D', 'orange', 'pink', 'green', 'red', 'yellow', 'aqua', 'maroon'];
const formattedUnit = unit ? ` (${unit})` : '';
-
-
/**
* Return an array of provided min & max values buffered by 10%
* @param {number} min | the lowest mean value of the collected data
diff --git a/web/js/components/sidebar/charting-mode-options.js b/web/js/components/sidebar/charting-mode-options.js
index 182c6e950..2c663989c 100644
--- a/web/js/components/sidebar/charting-mode-options.js
+++ b/web/js/components/sidebar/charting-mode-options.js
@@ -348,6 +348,34 @@ function ChartingModeOptions(props) {
return parseFloat(parseFloat(str).toFixed(3));
}
+ // Normalize error days input robustly (supports array, CSV, and "['...','...']" forms)
+ function normalizeErrorDays(errors) {
+ const raw = errors?.error_days;
+ if (Array.isArray(raw)) return raw.map((s) => String(s));
+ if (raw == null) return [];
+ if (typeof raw !== 'string') return [String(raw)];
+
+ const trimmed = raw.trim();
+
+ // Try JSON parse if looks like an array; tolerate single quotes
+ if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
+ try {
+ const jsonish = trimmed.replace(/'/g, '"');
+ const arr = JSON.parse(jsonish);
+ if (Array.isArray(arr)) return arr.map((s) => String(s));
+ } catch {
+ // fall through to manual split
+ }
+ }
+
+ // Fallback: strip brackets, split on comma, strip surrounding quotes
+ return trimmed
+ .replace(/^\[|\]$/g, '')
+ .split(',')
+ .map((s) => String(s).trim().replace(/^['"]|['"]$/g, ''))
+ .filter(Boolean);
+ }
+
/**
* Process the ImageStat (GIBS) data for use in the Recharts library
* @param {Object} data | This contains the name (dates)
@@ -378,7 +406,12 @@ function ChartingModeOptions(props) {
function combineData(inputArr) {
if (!inputArr || inputArr.length === 0) return inputArr;
- if (inputArr.length === 1) return inputArr[0];
+ if (inputArr.length === 1) {
+ if (inputArr[0].body && Object.prototype.hasOwnProperty.call(inputArr[0].body, 'errors')) {
+ inputArr[0].body.errors.error_days = normalizeErrorDays(inputArr[0].body.errors);
+ }
+ return inputArr[0];
+ }
const output = {
ok: true,
body: {
@@ -404,8 +437,9 @@ function ChartingModeOptions(props) {
if (dataset.ok && !!dataset.body) {
Object.keys(dataset.body).forEach((key) => {
if (key === 'errors') {
+ const errorDays = normalizeErrorDays(dataset.body.errors.error_days);
output.body.errors.error_count += dataset.body.errors.error_count;
- output.body.errors.error_days.push(...dataset.body.errors.error_days.replaceAll(/('|\[|\])/gi, '').split(', '));
+ output.body.errors.error_days.push(...errorDays);
} else if (key === 'hist') {
output.body.hist.push(...dataset.body.hist);
} else if (key === 'stderr') {