@@ -21,7 +21,7 @@ import { WebviewPlotThumbnail } from './webviewPlotThumbnail.js';
21
21
import { usePositronPlotsContext } from '../positronPlotsContext.js' ;
22
22
import { WebviewPlotClient } from '../webviewPlotClient.js' ;
23
23
import { PlotClientInstance } from '../../../../services/languageRuntime/common/languageRuntimePlotClient.js' ;
24
- import { DarkFilter , IPositronPlotClient , IPositronPlotsService , PlotRenderFormat } from '../../../../services/positronPlots/common/positronPlots.js' ;
24
+ import { DarkFilter , IPositronPlotClient , IPositronPlotsService , isZoomablePlotClient , PlotRenderFormat , ZoomLevel } from '../../../../services/positronPlots/common/positronPlots.js' ;
25
25
import { StaticPlotClient } from '../../../../services/positronPlots/common/staticPlotClient.js' ;
26
26
import { PlotSizingPolicyIntrinsic } from '../../../../services/positronPlots/common/sizingPolicyIntrinsic.js' ;
27
27
import { PlotSizingPolicyAuto } from '../../../../services/positronPlots/common/sizingPolicyAuto.js' ;
@@ -58,6 +58,7 @@ export const PlotsContainer = (props: PlotContainerProps) => {
58
58
const positronPlotsContext = usePositronPlotsContext ( ) ;
59
59
const plotHistoryRef = React . createRef < HTMLDivElement > ( ) ;
60
60
const containerRef = useRef < HTMLDivElement > ( undefined ! ) ;
61
+ const [ zoom , setZoom ] = React . useState < ZoomLevel > ( ZoomLevel . Fit ) ;
61
62
62
63
// We generally prefer showing the plot history on the bottom (making the
63
64
// plot wider), but if the plot container is too wide, we show it on the
@@ -164,6 +165,29 @@ export const PlotsContainer = (props: PlotContainerProps) => {
164
165
} ;
165
166
} , [ plotWidth , plotHeight , props . positronPlotsService ] ) ;
166
167
168
+ useEffect ( ( ) => {
169
+ // Create the disposable store for cleanup.
170
+ const disposableStore = new DisposableStore ( ) ;
171
+
172
+ // Get the current plot instance using the selected instance ID from the
173
+ // PositronPlotsContext.
174
+ const currentPlotInstance = positronPlotsContext . positronPlotInstances . find (
175
+ ( plotInstance ) => plotInstance . id === positronPlotsContext . selectedInstanceId
176
+ ) ;
177
+ if ( currentPlotInstance && isZoomablePlotClient ( currentPlotInstance ) ) {
178
+ // Listen to the plot instance for zoom level changes.
179
+ disposableStore . add ( currentPlotInstance . onDidChangeZoomLevel ( ( zoomLevel ) => {
180
+ setZoom ( zoomLevel ) ;
181
+ } ) ) ;
182
+ // Set the initial zoom level.
183
+ setZoom ( currentPlotInstance . zoomLevel ) ;
184
+ }
185
+ return ( ) => {
186
+ // Dispose of the disposable store when the component unmounts.
187
+ disposableStore . dispose ( ) ;
188
+ }
189
+ } , [ positronPlotsContext . positronPlotInstances , positronPlotsContext . selectedInstanceId ] ) ;
190
+
167
191
/**
168
192
* Renders either a DynamicPlotInstance (resizable plot), a
169
193
* StaticPlotInstance (static plot image), or a WebviewPlotInstance
@@ -179,12 +203,12 @@ export const PlotsContainer = (props: PlotContainerProps) => {
179
203
height = { plotHeight }
180
204
plotClient = { plotInstance }
181
205
width = { plotWidth }
182
- zoom = { plotInstance . zoomLevel } /> ;
206
+ zoom = { zoom } /> ;
183
207
} else if ( plotInstance instanceof StaticPlotClient ) {
184
208
return < StaticPlotInstance
185
209
key = { plotInstance . id }
186
210
plotClient = { plotInstance }
187
- zoom = { plotInstance . zoomLevel } /> ;
211
+ zoom = { zoom } /> ;
188
212
} else if ( plotInstance instanceof WebviewPlotClient ) {
189
213
return < WebviewPlotInstance
190
214
key = { plotInstance . id }
0 commit comments