Skip to content

Commit 97a83e6

Browse files
committed
Add onDidChangesizingPolicy event on plot service
1 parent b870c38 commit 97a83e6

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

src/vs/workbench/contrib/positronPlots/browser/positronPlotsService.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
118118
/** The emitter for the onDidChangePlotsRenderSettings event */
119119
private readonly _onDidChangePlotsRenderSettings = new Emitter<PlotRenderSettings>();
120120

121+
/** The emitter for the _sizingPolicyEmitter event */
122+
private readonly _onDidChangeSizingPolicyEmitter = new Emitter<IPositronPlotSizingPolicy>;
123+
121124
/** The ID Of the currently selected plot, if any */
122125
private _selectedPlotId: string | undefined;
123126

@@ -205,7 +208,7 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
205208
this._selectedPlotId = id;
206209
const selectedPlot = this._plots.find((plot) => plot.id === id);
207210
if (selectedPlot instanceof PlotClientInstance) {
208-
this._selectedSizingPolicy = selectedPlot.sizingPolicy;
211+
this.setSelectedSizingPolicy(selectedPlot.sizingPolicy);
209212
}
210213
}));
211214

@@ -440,7 +443,8 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
440443
if (!policy) {
441444
throw new Error(`Invalid sizing policy ID: ${id}`);
442445
}
443-
this._selectedSizingPolicy = policy;
446+
447+
this.setSelectedSizingPolicy(policy);
444448
const selectedPlot = this._plots.find((plot) => this.selectedPlotId === plot.id);
445449
if (selectedPlot instanceof PlotClientInstance) {
446450
selectedPlot.sizingPolicy = policy;
@@ -863,6 +867,7 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
863867
onDidChangeHistoryPolicy: Event<HistoryPolicy> = this._onDidChangeHistoryPolicy.event;
864868
onDidChangeDarkFilterMode: Event<DarkFilter> = this._onDidChangeDarkFilterMode.event;
865869
onDidChangePlotsRenderSettings: Event<PlotRenderSettings> = this._onDidChangePlotsRenderSettings.event;
870+
onDidChangeSizingPolicy: Event<IPositronPlotSizingPolicy> = this._onDidChangeSizingPolicyEmitter.event;
866871

867872
// Gets the individual plot instances.
868873
get positronPlotInstances(): IPositronPlotClient[] {
@@ -1353,6 +1358,11 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
13531358
*/
13541359
initialize() {
13551360
}
1361+
1362+
private setSelectedSizingPolicy(policy: IPositronPlotSizingPolicy) {
1363+
this._selectedSizingPolicy = policy;
1364+
this._onDidChangeSizingPolicyEmitter.fire(policy);
1365+
}
13561366
}
13571367

13581368
function isActiveWebviewPlot(plot: IPositronPlotClient): plot is WebviewPlotClient {

src/vs/workbench/services/positronPlots/common/positronPlots.ts

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ export interface IPositronPlotsService {
145145
*/
146146
readonly onDidChangePlotsRenderSettings: Event<PlotRenderSettings>;
147147

148+
/**
149+
* Notifies subscribers when the settings for rendering a plot have changed.
150+
* This typically happens when the plot viewpane has been resized.
151+
*/
152+
readonly onDidChangeSizingPolicy: Event<IPositronPlotSizingPolicy>;
153+
148154
/**
149155
* Selects the plot with the specified ID.
150156
*

src/vs/workbench/services/positronPlots/test/common/testPositronPlotsService.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export class TestPositronPlotsService extends Disposable implements IPositronPlo
9595
private readonly _onDidChangePlotsRenderSettingsEmitter =
9696
this._register(new Emitter<PlotRenderSettings>());
9797

98+
/** The emitter for the _sizingPolicyEmitter event */
99+
private readonly _onDidChangeSizingPolicyEmitter =
100+
this._register(new Emitter<IPositronPlotSizingPolicy>());
101+
98102
//#endregion Private Properties
99103

100104
//#region Constructor
@@ -106,12 +110,12 @@ export class TestPositronPlotsService extends Disposable implements IPositronPlo
106110
super();
107111
}
108112

109-
getPlotsRenderSettings(): PlotRenderSettings {
110-
throw new Error('Method not implemented.');
111-
}
112-
setPlotsRenderSettings(settings: PlotRenderSettings): void {
113-
throw new Error('Method not implemented.');
114-
}
113+
getPlotsRenderSettings(): PlotRenderSettings {
114+
throw new Error('Method not implemented.');
115+
}
116+
setPlotsRenderSettings(settings: PlotRenderSettings): void {
117+
throw new Error('Method not implemented.');
118+
}
115119

116120
//#endregion Constructor
117121

@@ -199,6 +203,12 @@ export class TestPositronPlotsService extends Disposable implements IPositronPlo
199203
*/
200204
readonly onDidChangePlotsRenderSettings = this._onDidChangePlotsRenderSettingsEmitter.event;
201205

206+
/**
207+
* The onDidChangeSizingPolicy event.
208+
*/
209+
readonly onDidChangeSizingPolicy = this._onDidChangeSizingPolicyEmitter.event;
210+
211+
202212
/**
203213
* Selects the plot with the specified ID.
204214
*

0 commit comments

Comments
 (0)