diff --git a/src/components/Charts/Bar.tsx b/src/components/Charts/Bar.tsx index 45a4b36c61b54eda6fdbafcb9242a822bab3f0c1..62ca898f1ec8a8c770095689814a9ab8bb715593 100644 --- a/src/components/Charts/Bar.tsx +++ b/src/components/Charts/Bar.tsx @@ -48,7 +48,7 @@ const Bar = ({ }: BarProps) => { const dispatch = useAppDispatch() const { - chart: { selectedDate }, + chart: { selectedDate, currentTimeStep }, global: { fluidStatus }, } = useAppSelector(state => state.ecolyo) const [clicked, setClicked] = useState(false) @@ -81,18 +81,25 @@ const Bar = ({ const lastDataDates = fluidStatus.map( fluid => fluid.lastDataDate ?? DateTime.local(0) ) - const lastDataDate = isMulti + /** Pick current fluid date or max for multi */ + let lastDataDate = isMulti ? DateTime.max(...lastDataDates) : lastDataDates[fluidType] - const dataMissingUpcoming = Boolean( + /** Remove a day when viewing half-hour */ + lastDataDate = lastDataDate.plus({ + days: currentTimeStep === TimeStep.HALF_AN_HOUR ? 1 : 0, + }) + + /** True when between lastData and today's range */ + const isDataMissingOrUpcoming = Boolean( dataload.date > lastDataDate && dataload.date < DateTime.local() ) let value = dataload.value /** Adjust value for upcoming data (placeholder bars) */ - if (dataMissingUpcoming && average) { + if (isDataMissingOrUpcoming && average) { if (average > 1) { // Use 10% of average if average is above 1 value = average * 0.1 @@ -194,7 +201,7 @@ const Bar = ({ </g> )} {/* placeholder bar for upcoming values */} - {height > 0 && dataMissingUpcoming && ( + {height > 0 && isDataMissingOrUpcoming && ( <g transform={`translate(${xScaleValue}, ${yScaleValue})`} className="barFill"