@@ -13,14 +13,13 @@ import React, { PropsWithChildren, useCallback, useEffect, useState } from 'reac
13
13
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js' ;
14
14
import { PositronPlotsServices } from './positronPlotsState.js' ;
15
15
import { PositronPlotsContextProvider } from './positronPlotsContext.js' ;
16
- import { HistoryPolicy , IPositronPlotsService , ZoomLevel } from '../../../services/positronPlots/common/positronPlots.js' ;
16
+ import { HistoryPolicy , IPositronPlotsService , isZoomablePlotClient , ZoomLevel } from '../../../services/positronPlots/common/positronPlots.js' ;
17
17
import { DisposableStore } from '../../../../base/common/lifecycle.js' ;
18
18
import { PlotsContainer } from './components/plotsContainer.js' ;
19
19
import { ActionBars } from './components/actionBars.js' ;
20
20
import { INotificationService } from '../../../../platform/notification/common/notification.js' ;
21
21
import { PositronPlotsViewPane } from './positronPlotsView.js' ;
22
22
import { IPreferencesService } from '../../../services/preferences/common/preferences.js' ;
23
- import { PlotClientInstance } from '../../../services/languageRuntime/common/languageRuntimePlotClient.js' ;
24
23
25
24
/**
26
25
* PositronPlotsProps interface.
@@ -66,18 +65,16 @@ export const PositronPlots = (props: PropsWithChildren<PositronPlotsProps>) => {
66
65
} , [ props . positronPlotsService . positronPlotInstances . length , props . reactComponentContainer . height , props . reactComponentContainer . width ] ) ;
67
66
68
67
const zoomHandler = ( zoom : number ) => {
69
- setZoom ( zoom ) ;
70
68
const currentPlotId = props . positronPlotsService . selectedPlotId ;
71
69
if ( ! currentPlotId ) {
72
70
return ;
73
71
}
74
72
75
73
const plot = props . positronPlotsService . positronPlotInstances . find ( plot => plot . id === currentPlotId ) ;
76
- if ( ! plot || ! ( plot instanceof PlotClientInstance ) ) {
77
- return ;
74
+ if ( isZoomablePlotClient ( plot ) ) {
75
+ // Update the zoom level in the plot metadata.
76
+ plot . zoomLevel = zoom ;
78
77
}
79
- // Update the zoom level in the plot metadata.
80
- plot . zoomLevel = zoom ;
81
78
} ;
82
79
83
80
// Hooks.
@@ -142,30 +139,29 @@ export const PositronPlots = (props: PropsWithChildren<PositronPlotsProps>) => {
142
139
143
140
useEffect ( ( ) => {
144
141
// Set the initial zoom level for the current plot.
145
- const currentPlot = props . positronPlotsService . selectedPlotId ;
146
-
147
- if ( currentPlot ) {
148
- const plot = props . positronPlotsService . positronPlotInstances . find ( plot => plot . id === currentPlot ) ;
149
- if ( plot ) {
150
- setZoom ( plot . metadata . zoom_level || ZoomLevel . Fit ) ;
151
- }
152
- }
153
- } , [ props . positronPlotsService . positronPlotInstances , props . positronPlotsService . selectedPlotId ] ) ;
142
+ const disposableStore = new DisposableStore ( ) ;
154
143
155
- useEffect ( ( ) => {
156
- const disposable = props . positronPlotsService . onDidSelectPlot ( ( selectedPlotId ) => {
157
- const plot = props . positronPlotsService . positronPlotInstances . find ( plot => plot . id === selectedPlotId ) ;
158
- if ( plot ) {
159
- setZoom ( plot . metadata . zoom_level || ZoomLevel . Fit ) ;
160
- } else {
161
- setZoom ( ZoomLevel . Fit ) ;
144
+ disposableStore . add ( props . positronPlotsService . onDidSelectPlot ( plotId => {
145
+ const currentPlot = props . positronPlotsService . selectedPlotId ;
146
+
147
+ if ( currentPlot ) {
148
+ const plot = props . positronPlotsService . positronPlotInstances . find ( plot => plot . id === currentPlot ) ;
149
+ if ( isZoomablePlotClient ( plot ) ) {
150
+ disposableStore . add ( plot . onDidChangeZoomLevel ( ( zoomLevel ) => {
151
+ setZoom ( zoomLevel ) ;
152
+ } ) ) ;
153
+ setZoom ( plot . zoomLevel ) ;
154
+ } else {
155
+ setZoom ( ZoomLevel . Fit ) ;
156
+ }
162
157
}
163
- } ) ;
158
+ } ) ) ;
164
159
165
160
return ( ) => {
166
- disposable . dispose ( ) ;
167
- } ;
168
- } , [ props . positronPlotsService ] )
161
+ // Dispose of the disposable store to clean up event handlers.
162
+ disposableStore . dispose ( ) ;
163
+ }
164
+ } , [ props . positronPlotsService ] ) ;
169
165
170
166
// Render.
171
167
return (
0 commit comments