Skip to content

Commit

Permalink
measurements: reset container scroll on redraw
Browse files Browse the repository at this point in the history
Restores the behavior prior to adding the sticky x-axis where the
container resets to the top when the SVG is redrawn.

This explicit reset fixes the issue where the sticky x-axis can
potentially leave the panel in a scrolled state that displays a
huge white space.¹

¹ #1631 (comment)
  • Loading branch information
joverlee521 committed Feb 3, 2023
1 parent ece5f2a commit e2794b5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/measurements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const MeasurementsPlot = ({height, width, showLegend, setPanelTitle}) => {
const { title, x_axis_label, thresholds, fields, measurements, groupings } = collection;

// Ref to access the D3 SVG
const svgContainerRef = useRef(null);
const d3Ref = useRef(null);
const d3XAxisRef = useRef(null);

Expand Down Expand Up @@ -216,6 +217,9 @@ const MeasurementsPlot = ({height, width, showLegend, setPanelTitle}) => {

// Draw SVG from scratch
useEffect(() => {
// Reset the container to the top to prevent sticky x-axis from keeping
// the scroll position on whitespace.
svgContainerRef.current.scrollTop = 0;
clearMeasurementsSVG(d3Ref.current, d3XAxisRef.current);
drawMeasurementsSVG(d3Ref.current, d3XAxisRef.current, svgData);
}, [svgData]);
Expand Down Expand Up @@ -284,7 +288,7 @@ const MeasurementsPlot = ({height, width, showLegend, setPanelTitle}) => {
<Legend right width={width}/>
</ErrorBoundary>
}
<div id={svgContainerDOMId} style={getSVGContainerStyle()}>
<div id={svgContainerDOMId} ref={svgContainerRef} style={getSVGContainerStyle()}>
{hoverData &&
<HoverPanel
hoverData={hoverData}
Expand Down

0 comments on commit e2794b5

Please sign in to comment.