Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-3731: Graph UI changes (#6197)

christof-wittreich9f355e65277f
diff --git a/web/js/components/charting/chart-component.js b/web/js/components/charting/chart-component.js
index 19abda78f..57ba833a6 100644
--- a/web/js/components/charting/chart-component.js
+++ b/web/js/components/charting/chart-component.js
@@ -93,17 +93,29 @@ function ChartComponent (props) {
function CustomTooltip({ active, payload, label }) {
if (active && payload && payload.length) {
+ if (!Number.isNaN(payload[0].value)) {
+ return (
+ <div className="custom-tooltip">
+ <p className="label" style={{ color: 'gray' }}>
+ {label}
+ </p>
+ <p className="label" style={{ color: '#000' }}>
+ <span className="custom-data-rect" style={{ backgroundColor: payload[0].color }} />
+ {`${payload[0].name}${formattedUnit}: `}
+ <b>
+ {formatToThreeDigits(payload[0].value)}
+ </b>
+ </p>
+ </div>
+ );
+ }
return (
<div className="custom-tooltip">
<p className="label" style={{ color: 'gray' }}>
{label}
</p>
<p className="label" style={{ color: '#000' }}>
- <span className="custom-data-rect" style={{ backgroundColor: payload[0].color }} />
- {`${payload[0].name}${formattedUnit}: `}
- <b>
- {formatToThreeDigits(payload[0].value)}
- </b>
+ No data
</p>
</div>
);
@@ -112,6 +124,71 @@ function ChartComponent (props) {
return null;
}
+ // Gets the indices of the tick positions so that they are evenly spaced
+ function getTickPositions(dataLength) {
+ // If dataLength is too small, just show first and last tick
+ if (dataLength < 8) return [0, dataLength - 1];
+
+ const numGaps = dataLength < 15 ? 4 : 5;
+ const gapsArr = Array(numGaps).fill(Math.floor(dataLength / numGaps));
+
+ // Last gap must be at least 3 to give extra room for end-aligned label
+ gapsArr[gapsArr.length - 1] = Math.max(Math.floor(dataLength / 4), 3);
+
+ const gapsTotal = gapsArr.reduce((a, b) => a + b, 0);
+ let leftoverGap = (dataLength - 1) - gapsTotal;
+
+ let i = 0;
+ // Reduce gaps that are too large due to last gap size
+ while (leftoverGap < 0 && i < numGaps - 1) {
+ gapsArr[i] -= 1;
+ leftoverGap += 1;
+ i = (i + 1) % (numGaps - 1);
+ }
+
+ i = 0;
+ // Distribute extra gaps across existing gaps
+ while (leftoverGap > 0 && i < numGaps - 1) {
+ gapsArr[i] += 1;
+ leftoverGap -= 1;
+ i = (i + 1) % (numGaps - 1);
+ }
+
+ // Build final array of tick positions based on calculated gaps
+ const tickPosArr = [0];
+ for (let i = 0; i < gapsArr.length; i += 1) {
+ tickPosArr.push(tickPosArr[tickPosArr.length - 1] + gapsArr[i]);
+ }
+ tickPosArr[tickPosArr.length - 1] = dataLength - 1;
+
+ return tickPosArr;
+ }
+
+ const tickPositions = getTickPositions(data.length);
+
+ function CustomXAxisTick(obj) {
+ const {
+ x, y, fill, textAnchor, visibleTicksCount, index, payload,
+ } = obj;
+ const anchorPos = index === visibleTicksCount - 1 ? 'end' : textAnchor;
+ const isLabeled = tickPositions.includes(index);
+ if (isLabeled) {
+ return (
+ <g transform={`translate(${x}, ${y})`}>
+ <line x1="0" y1="0" x2="0" y2="-8" stroke={fill} />
+ <text x={anchorPos === 'end' ? 10 : 0} y={0} dy={16} textAnchor={anchorPos} fill={fill}>
+ {payload.value}
+ </text>
+ </g>
+ );
+ }
+ return (
+ <g transform={`translate(${x}, ${y})`}>
+ <line x1="0" y1="-4" x2="0" y2="-8" stroke={fill} />
+ </g>
+ );
+ }
+
const yAxisValuesArr = getYAxisValues(data);
/**
@@ -147,7 +224,7 @@ function ChartComponent (props) {
* @param {Object} chartData
*/
function getQuickStatistics(chartData) {
- const count = chartData.length;
+ let count = 0;
let minTotal = 0;
let maxTotal = 0;
let meanTotal = 0;
@@ -155,11 +232,14 @@ function ChartComponent (props) {
let stddevTotal = 0;
for (let i = 0; i < chartData.length; i += 1) {
- meanTotal += chartData[i].mean;
- minTotal += chartData[i].min;
- maxTotal += chartData[i].max;
- medianTotal += chartData[i].median;
- stddevTotal += chartData[i].stddev;
+ if (!Number.isNaN(chartData[i].mean)) {
+ meanTotal += chartData[i].mean;
+ minTotal += chartData[i].min;
+ maxTotal += chartData[i].max;
+ medianTotal += chartData[i].median;
+ stddevTotal += chartData[i].stddev;
+ count += 1;
+ }
}
return (
@@ -297,7 +377,7 @@ function ChartComponent (props) {
<Tooltip content={CustomTooltip} />
{' '}
{getLineChart(data)}
- <XAxis dataKey="name" stroke="#a6a5a6" />
+ <XAxis dataKey="name" stroke="#a6a5a6" interval={0} tick={<CustomXAxisTick />} tickLine={false} />
<YAxis
type="number"
stroke="#a6a5a6"
@@ -310,7 +390,12 @@ function ChartComponent (props) {
dx: -40,
}}
/>
- <Legend formatter={() => `${title}`} />
+ <Legend
+ formatter={() => `${title}`}
+ wrapperStyle={{
+ paddingTop: '7px',
+ }}
+ />
</LineChart>
</div>
<div className="charting-stat-text">
@@ -392,7 +477,7 @@ function ChartComponent (props) {
/>
<i className="charting-disclaimer-block">
{`${errors.error_count} `}
- dates requested have no data, so are not shown in the chart.
+ {errors.error_count === 1 ? 'requested date has no data and is represented as a gap in the chart.' : 'requested dates have no data and are represented as gaps in the chart.'}
</i>
{!errorCollapsed
&& (
diff --git a/web/js/components/sidebar/charting-mode-options.js b/web/js/components/sidebar/charting-mode-options.js
index 96973cc5c..e2cf509eb 100644
--- a/web/js/components/sidebar/charting-mode-options.js
+++ b/web/js/components/sidebar/charting-mode-options.js
@@ -301,6 +301,8 @@ function ChartingModeOptions(props) {
try {
const response = await fetch(simpleStatsURI, requestOptions);
const data = await response.text();
+ // Mock data, to be removed before merging
+ // const data = JSON.stringify({"mean": {"2025-09-10T00:00:00Z": 0.32626962336612314, "2025-09-11T00:00:00Z": 0.5039413804624584, "2025-09-12T00:00:00Z": 0.6364696921707916, "2025-09-13T00:00:00Z": 0.6708885118357888, "2025-09-14T00:00:00Z": 0.8617797424304515, "2025-09-15T00:00:00Z": 0.8216062795654208, "2025-09-16T00:00:00Z": 0.636655055327338, "2025-09-17T00:00:00Z": 0.5692548394958568, "2025-09-18T00:00:00Z": 0.6042759015815452, "2025-09-19T00:00:00Z": 0.6671228369732474, "2025-09-20T00:00:00Z": 0.6438424278008147, "2025-09-21T00:00:00Z": 0.93460329417892, "2025-09-22T00:00:00Z": 0.8468979259479646, "2025-09-23T00:00:00Z": 0.5895524603400779, "2025-09-24T00:00:00Z": 0.4824067719484085, "2025-09-25T00:00:00Z": 0.5168849128927858, "2025-09-26T00:00:00Z": 0.6026034577982918, "2025-09-27T00:00:00Z": 0.5244425180168761, "2025-09-28T00:00:00Z": 0.5866451379247902, "2025-09-30T00:00:00Z": 0.4702760520116403, "2025-10-01T00:00:00Z": 0.48182150608662827, "2025-10-02T00:00:00Z": 0.3823509882219332, "2025-10-03T00:00:00Z": 0.7139505056593664, "2025-10-04T00:00:00Z": 0.9638534612792451, "2025-10-05T00:00:00Z": 0.6867387375222029, "2025-10-06T00:00:00Z": 0.6924459682425589, "2025-10-07T00:00:00Z": 0.7024427898956004, "2025-10-08T00:00:00Z": 0, "2025-10-09T00:00:00Z": 0}, "median": {"2025-09-10T00:00:00Z": "0.25", "2025-09-11T00:00:00Z": "0.4", "2025-09-12T00:00:00Z": "0.55", "2025-09-13T00:00:00Z": "0.55", "2025-09-14T00:00:00Z": "0.725", "2025-09-15T00:00:00Z": "0.775", "2025-09-16T00:00:00Z": "0.55", "2025-09-17T00:00:00Z": "0.425", "2025-09-18T00:00:00Z": "0.525", "2025-09-19T00:00:00Z": "0.525", "2025-09-20T00:00:00Z": "0.425", "2025-09-21T00:00:00Z": "0.825", "2025-09-22T00:00:00Z": "0.675", "2025-09-23T00:00:00Z": "0.525", "2025-09-24T00:00:00Z": "0.4", "2025-09-25T00:00:00Z": "0.45", "2025-09-26T00:00:00Z": "0.475", "2025-09-27T00:00:00Z": "0.425", "2025-09-28T00:00:00Z": "0.475", "2025-09-30T00:00:00Z": "0.375", "2025-10-01T00:00:00Z": "0.425", "2025-10-02T00:00:00Z": "0.3", "2025-10-03T00:00:00Z": "0.525", "2025-10-04T00:00:00Z": "0.725", "2025-10-05T00:00:00Z": "0.5", "2025-10-06T00:00:00Z": "0.625", "2025-10-07T00:00:00Z": "0.6", "2025-10-08T00:00:00Z": 0, "2025-10-09T00:00:00Z": 0}, "max": {"2025-09-10T00:00:00Z": 1.6, "2025-09-11T00:00:00Z": 2.075, "2025-09-12T00:00:00Z": 4.975, "2025-09-13T00:00:00Z": 2.775, "2025-09-14T00:00:00Z": 4.975, "2025-09-15T00:00:00Z": 3.9, "2025-09-16T00:00:00Z": 3.475, "2025-09-17T00:00:00Z": 3.45, "2025-09-18T00:00:00Z": 2.8, "2025-09-19T00:00:00Z": 2.6, "2025-09-20T00:00:00Z": 2.95, "2025-09-21T00:00:00Z": 3.025, "2025-09-22T00:00:00Z": 4.975, "2025-09-23T00:00:00Z": 2.175, "2025-09-24T00:00:00Z": 2.5, "2025-09-25T00:00:00Z": 1.975, "2025-09-26T00:00:00Z": 2.2, "2025-09-27T00:00:00Z": 2.85, "2025-09-28T00:00:00Z": 2.0, "2025-09-30T00:00:00Z": 2.4, "2025-10-01T00:00:00Z": 1.95, "2025-10-02T00:00:00Z": 2.45, "2025-10-03T00:00:00Z": 2.925, "2025-10-04T00:00:00Z": 4.4, "2025-10-05T00:00:00Z": 2.975, "2025-10-06T00:00:00Z": 2.475, "2025-10-07T00:00:00Z": 2.7, "2025-10-08T00:00:00Z": 0, "2025-10-09T00:00:00Z": 0}, "min": {"2025-09-10T00:00:00Z": 0.0, "2025-09-11T00:00:00Z": 0.0, "2025-09-12T00:00:00Z": 0.0, "2025-09-13T00:00:00Z": 0.0, "2025-09-14T00:00:00Z": 0.0, "2025-09-15T00:00:00Z": 0.0, "2025-09-16T00:00:00Z": 0.0, "2025-09-17T00:00:00Z": 0.0, "2025-09-18T00:00:00Z": 0.0, "2025-09-19T00:00:00Z": 0.0, "2025-09-20T00:00:00Z": 0.0, "2025-09-21T00:00:00Z": 0.0, "2025-09-22T00:00:00Z": 0.0, "2025-09-23T00:00:00Z": 0.0, "2025-09-24T00:00:00Z": 0.0, "2025-09-25T00:00:00Z": 0.0, "2025-09-26T00:00:00Z": 0.0, "2025-09-27T00:00:00Z": 0.0, "2025-09-28T00:00:00Z": 0.0, "2025-09-30T00:00:00Z": 0.0, "2025-10-01T00:00:00Z": 0.0, "2025-10-02T00:00:00Z": 0.0, "2025-10-03T00:00:00Z": 0.0, "2025-10-04T00:00:00Z": 0.0, "2025-10-05T00:00:00Z": 0.0, "2025-10-06T00:00:00Z": 0.0, "2025-10-07T00:00:00Z": 0.0, "2025-10-08T00:00:00Z": 0, "2025-10-09T00:00:00Z": 0}, "stdev": {"2025-09-10T00:00:00Z": 0.2996384743659499, "2025-09-11T00:00:00Z": 0.4217835608583786, "2025-09-12T00:00:00Z": 0.48480904392469776, "2025-09-13T00:00:00Z": 0.5519831699979253, "2025-09-14T00:00:00Z": 0.6836449366385909, "2025-09-15T00:00:00Z": 0.5772791344241578, "2025-09-16T00:00:00Z": 0.49879087509208164, "2025-09-17T00:00:00Z": 0.5710494882904773, "2025-09-18T00:00:00Z": 0.47281206713402174, "2025-09-19T00:00:00Z": 0.5397050772283568, "2025-09-20T00:00:00Z": 0.6245294514132563, "2025-09-21T00:00:00Z": 0.6804210128289083, "2025-09-22T00:00:00Z": 0.6944088906142988, "2025-09-23T00:00:00Z": 0.41970150563344993, "2025-09-24T00:00:00Z": 0.3834694302700857, "2025-09-25T00:00:00Z": 0.3789662830732043, "2025-09-26T00:00:00Z": 0.503109287861155, "2025-09-27T00:00:00Z": 0.4378406817031671, "2025-09-28T00:00:00Z": 0.459214688817658, "2025-09-30T00:00:00Z": 0.38934798554736716, "2025-10-01T00:00:00Z": 0.346205632386419, "2025-10-02T00:00:00Z": 0.34302545677825946, "2025-10-03T00:00:00Z": 0.6436004501055309, "2025-10-04T00:00:00Z": 0.8056352454342522, "2025-10-05T00:00:00Z": 0.6002012453021701, "2025-10-06T00:00:00Z": 0.47181570590882344, "2025-10-07T00:00:00Z": 0.5313159945604392, "2025-10-08T00:00:00Z": 0, "2025-10-09T00:00:00Z": 0}, "stderr": "0.00033191396261756203", "hist": [["0.0", "1379967"], ["0.49749999999999994", "821488"], ["0.9949999999999999", "404937"], ["1.4924999999999997", "168503"], ["1.9899999999999998", "54128"], ["2.4875", "18491"], ["2.9849999999999994", "5641"], ["3.4824999999999995", "1989"], ["3.9799999999999995", "17"], ["4.477499999999999", "500"]], "errors": {"error_count": 2, "error_days": "['2025-09-29T00:00:00Z', '2025-10-10T00:00:00Z']"}});
// This is the response when the imageStat server fails
if (!data || data === 'null') {
return {
@@ -348,6 +350,11 @@ function ChartingModeOptions(props) {
*/
function formatGIBSDataForRecharts(data) {
const xAxisNames = getKeysFromObj(data.min);
+ // Add error days to data
+ if (data.errors?.error_count > 0) {
+ xAxisNames.push(...data.errors.error_days.replace(/[[\]']/g, '').split(', '));
+ xAxisNames.sort();
+ }
const rechartsData = [];
for (let i = 0; i < xAxisNames.length; i += 1) {
const name = xAxisNames[i];