Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/components/ChartHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const ChartHeader = ({
setShowLegend,
showOtherGroundTruthSeasons,
setShowOtherGroundTruthSeasons,
showHistogram,
setShowHistogram,
} = useView();

const about = useContext(ChartAboutContext);
Expand Down Expand Up @@ -148,6 +150,10 @@ const ChartHeader = ({
setShowOtherGroundTruthSeasons={setShowOtherGroundTruthSeasons}
disableOtherGroundTruthSeasons={isSurveillance}
showIntervals={!isSurveillance}
showHistogram={showHistogram}
setShowHistogram={
viewType === "flu_forecasts" ? setShowHistogram : null
}
/>
</Popover.Dropdown>
</Popover>
Expand Down
6 changes: 1 addition & 5 deletions app/src/components/ViewSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ const ViewSelector = ({ showActive = true, onNavigate }) => {
label: "Standard view",
value: DATASETS.flu.defaultView,
},
{
label: "Detailed view",
value: "fludetailed",
},
{
label: "Peak forecasts",
value: "flu_peak",
Expand Down Expand Up @@ -63,7 +59,7 @@ const ViewSelector = ({ showActive = true, onNavigate }) => {
];

const fluViewValues = new Set(fluViews.map((view) => view.value));
const isFluActive = fluViewValues.has(viewType);
const isFluActive = fluViewValues.has(viewType) || viewType === "fludetailed";

useEffect(() => {
if (isFluActive) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/components/controls/ForecastChartControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const ForecastChartControls = ({
disableOtherGroundTruthSeasons = false,
showIntervals = true,
intervalOptions = INTERVAL_OPTIONS,
showHistogram = false,
setShowHistogram = null,
}) => {
const selectedIntervals = intervalOptions
.filter((option) => intervalVisibility?.[option.value])
Expand Down Expand Up @@ -92,6 +94,21 @@ const ForecastChartControls = ({
offLabel="Off"
/>
</Group>
{typeof setShowHistogram === "function" && (
<Group align="center" gap="md">
<Text size="xs" c="dimmed" style={{ minWidth: 90 }}>
Histogram
</Text>
<Switch
aria-label="Histogram"
checked={showHistogram}
onChange={(event) => setShowHistogram(event.currentTarget.checked)}
size="sm"
onLabel="On"
offLabel="Off"
/>
</Group>
)}
{typeof setShowOtherGroundTruthSeasons === "function" && (
<Group align="center" gap="md">
<Text
Expand Down
18 changes: 11 additions & 7 deletions app/src/components/views/FluView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const FluView = ({
intervalVisibility,
showLegend,
showOtherGroundTruthSeasons,
showHistogram,
} = useView();
const histogramVisible =
viewType === "fludetailed" ||
(viewType === "flu_forecasts" && showHistogram);
const forecasts = data?.forecasts;
const stableModelOrderRef = useRef([]);
const stableModelOrder = useMemo(() => {
Expand Down Expand Up @@ -90,14 +94,14 @@ const FluView = ({
]);

const extraTraces = useMemo(() => {
if (viewType !== "fludetailed") return [];
if (!histogramVisible) return [];
return rateChangeData.map((trace) => ({
...trace,
orientation: "h",
xaxis: "x2",
yaxis: "y2",
}));
}, [rateChangeData, viewType]);
}, [rateChangeData, histogramVisible]);

const activeModels = useMemo(() => {
const activeModelSet = new Set();
Expand Down Expand Up @@ -127,7 +131,7 @@ const FluView = ({
}
}

if (viewType === "fludetailed") {
if (histogramVisible) {
const rateChangeSet = forecastsForDate["wk flu hosp rate change"];
if (rateChangeSet) {
Object.keys(rateChangeSet).forEach((model) =>
Expand All @@ -138,7 +142,7 @@ const FluView = ({
});

return activeModelSet;
}, [forecasts, selectedDates, selectedTarget, viewType]);
}, [forecasts, selectedDates, selectedTarget, viewType, histogramVisible]);

const forecastTarget =
viewType === "flu" || viewType === "flu_forecasts"
Expand All @@ -154,7 +158,7 @@ const FluView = ({
(baseLayout) => {
const baseXAxis = {
...baseLayout.xaxis,
domain: viewType === "fludetailed" ? [0, 0.8] : baseLayout.xaxis.domain,
domain: histogramVisible ? [0, 0.8] : baseLayout.xaxis.domain,
};

const nextLayout = {
Expand All @@ -163,7 +167,7 @@ const FluView = ({
xaxis: baseXAxis,
};

if (viewType !== "fludetailed") {
if (!histogramVisible) {
return nextLayout;
}

Expand Down Expand Up @@ -207,7 +211,7 @@ const FluView = ({
},
};
},
[viewType, lastSelectedDate, colorScheme],
[histogramVisible, lastSelectedDate, colorScheme],
);

if (viewType === "flu_peak") {
Expand Down
20 changes: 20 additions & 0 deletions app/src/contexts/ViewContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ export const ViewProvider = ({ children }) => {
);
const [showOtherGroundTruthSeasons, setShowOtherGroundTruthSeasons] =
useState(() => urlManager.getAdvancedParams().showOtherGroundTruthSeasons);
const [showHistogram, setShowHistogram] = useState(
() => urlManager.getAdvancedParams().showHistogram,
);

const {
data,
Expand Down Expand Up @@ -875,6 +878,7 @@ export const ViewProvider = ({ children }) => {
intervalVisibility: urlIntervals,
showLegend: urlLegend,
showOtherGroundTruthSeasons: urlShowOtherGroundTruthSeasons,
showHistogram: urlShowHistogram,
} = urlManager.getAdvancedParams();

if (isSurveillanceView && urlShowOtherGroundTruthSeasons) {
Expand All @@ -899,6 +903,9 @@ export const ViewProvider = ({ children }) => {
if (urlShowOtherGroundTruthSeasons !== showOtherGroundTruthSeasons) {
setShowOtherGroundTruthSeasons(urlShowOtherGroundTruthSeasons);
}
if (urlShowHistogram !== showHistogram) {
setShowHistogram(urlShowHistogram);
}
}, [
searchParams,
location.pathname,
Expand All @@ -909,6 +916,7 @@ export const ViewProvider = ({ children }) => {
intervalVisibility,
showLegend,
showOtherGroundTruthSeasons,
showHistogram,
]);

const setChartScaleWithUrl = useCallback(
Expand Down Expand Up @@ -956,6 +964,16 @@ export const ViewProvider = ({ children }) => {
[urlManager, isForecastPage],
);

const setShowHistogramWithUrl = useCallback(
(nextValue) => {
setShowHistogram(nextValue);
if (isForecastPage) {
urlManager.updateAdvancedParams({ showHistogram: nextValue });
}
},
[urlManager, isForecastPage],
);

const contextValue = {
selectedLocation,
locationMessage,
Expand Down Expand Up @@ -1018,6 +1036,8 @@ export const ViewProvider = ({ children }) => {
setShowLegend: setShowLegendWithUrl,
showOtherGroundTruthSeasons,
setShowOtherGroundTruthSeasons: setShowOtherGroundTruthSeasonsWithUrl,
showHistogram,
setShowHistogram: setShowHistogramWithUrl,
};

return (
Expand Down
11 changes: 11 additions & 0 deletions app/src/utils/urlManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class URLParameterManager {
const intervalsParam = this.searchParams.get("intervals");
const legendParam = this.searchParams.get("legend");
const otherGtParam = this.searchParams.get("other_gt");
const histogramParam = this.searchParams.get("histogram");

const chartScale = normalizeChartScale(scaleParam || DEFAULT_CHART_SCALE);
let intervalVisibility = { ...DEFAULT_INTERVAL_VISIBILITY };
Expand Down Expand Up @@ -110,6 +111,7 @@ export class URLParameterManager {
intervalVisibility,
showLegend,
showOtherGroundTruthSeasons,
showHistogram: histogramParam === "1" || histogramParam === "true",
};
}

Expand Down Expand Up @@ -142,6 +144,7 @@ export class URLParameterManager {
intervalVisibility,
showLegend,
showOtherGroundTruthSeasons,
showHistogram,
}) {
const updatedParams = new URLSearchParams(this.searchParams);

Expand Down Expand Up @@ -182,6 +185,14 @@ export class URLParameterManager {
}
}

if (typeof showHistogram === "boolean") {
if (showHistogram) {
updatedParams.set("histogram", "1");
} else {
updatedParams.delete("histogram");
}
}

if (updatedParams.toString() !== this.searchParams.toString()) {
this.setSearchParams(updatedParams, { replace: true });
}
Expand Down
Loading