@@ -24,6 +24,7 @@ export interface NonBlockCanvasDisplayModel {
2424 drawn : boolean
2525 loading : boolean
2626 lastDrawnOffsetPx ?: number
27+ lastDrawnBpPerPx ?: number
2728 statusMessage ?: string
2829 showLegend ?: boolean
2930 legendItems ?: ( ) => LegendItem [ ]
@@ -86,15 +87,24 @@ const DataDisplay = observer(function DataDisplay({
8687 model : NonBlockCanvasDisplayModel
8788 children ?: React . ReactNode
8889} ) {
89- const { drawn, loading, showLegend, legendItems } = model
90+ const { drawn, loading, showLegend, legendItems, lastDrawnBpPerPx } = model
9091 const view = getContainingView ( model ) as LinearGenomeViewModel
9192 const items = legendItems ?.( ) ?? [ ]
9293
94+ // Check if the view has zoomed (bpPerPx changed) since the last render.
95+ // When zoomed, we don't show the old shifted content because it's at
96+ // the wrong scale.
97+ const hasZoomed =
98+ lastDrawnBpPerPx !== undefined && lastDrawnBpPerPx !== view . bpPerPx
99+
93100 // Calculate how much to shift the rendered canvas to account for scrolling.
94101 // When the user scrolls, view.offsetPx changes but the canvas content
95102 // stays the same until a new render completes. This shift keeps the
96103 // content aligned during that time.
97- const calculatedLeft = ( model . lastDrawnOffsetPx ?? 0 ) - view . offsetPx
104+ // Only apply the shift if we haven't zoomed.
105+ const calculatedLeft = hasZoomed
106+ ? 0
107+ : ( model . lastDrawnOffsetPx ?? 0 ) - view . offsetPx
98108
99109 return (
100110 // this data-testid is located here because changing props on the canvas
@@ -104,12 +114,16 @@ const DataDisplay = observer(function DataDisplay({
104114 style = { {
105115 position : 'absolute' ,
106116 left : calculatedLeft ,
117+ // Hide content when zoomed until new render completes
118+ visibility : hasZoomed ? 'hidden' : undefined ,
107119 } }
108120 >
109121 { children }
110122 </ div >
111123 { showLegend && items . length > 0 ? < FloatingLegend items = { items } /> : null }
112- { calculatedLeft !== 0 || loading ? < LoadingBar model = { model } /> : null }
124+ { hasZoomed || calculatedLeft !== 0 || loading ? (
125+ < LoadingBar model = { model } />
126+ ) : null }
113127 </ div >
114128 )
115129} )
0 commit comments