Skip to content

Commit ea391a2

Browse files
committed
Notify backends of sizing policy changes
1 parent 66d3019 commit ea391a2

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/vs/workbench/contrib/positronPlots/browser/components/plotsContainer.tsx

+24-13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { DarkFilter, IPositronPlotClient, IPositronPlotsService, PlotRenderForma
2525
import { StaticPlotClient } from '../../../../services/positronPlots/common/staticPlotClient.js';
2626
import { PlotSizingPolicyIntrinsic } from '../../../../services/positronPlots/common/sizingPolicyIntrinsic.js';
2727
import { PlotSizingPolicyAuto } from '../../../../services/positronPlots/common/sizingPolicyAuto.js';
28+
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
2829

2930
/**
3031
* PlotContainerProps interface.
@@ -94,27 +95,37 @@ export const PlotsContainer = (props: PlotContainerProps) => {
9495
return;
9596
}
9697

97-
let policy = props.positronPlotsService.selectedSizingPolicy;
98+
const notify = () => {
99+
let policy = props.positronPlotsService.selectedSizingPolicy;
98100

99-
if (policy instanceof PlotSizingPolicyIntrinsic) {
100-
policy = new PlotSizingPolicyAuto;
101-
}
101+
if (policy instanceof PlotSizingPolicyIntrinsic) {
102+
policy = new PlotSizingPolicyAuto;
103+
}
102104

103-
const viewPortSize = {
104-
height: plotHeight,
105-
width: plotWidth,
106-
}
107-
let size = policy.getPlotSize(viewPortSize);
108-
size = size ? size : viewPortSize;
105+
const viewPortSize = {
106+
height: plotHeight,
107+
width: plotWidth,
108+
}
109+
let size = policy.getPlotSize(viewPortSize);
110+
size = size ? size : viewPortSize;
109111

110-
// Propagate current render settings. Use a debouncer to avoid excessive
111-
// messaging to language kernels.
112-
const debounceTimer = setTimeout(() => {
113112
props.positronPlotsService.setPlotsRenderSettings({
114113
size,
115114
pixel_ratio: DOM.getActiveWindow().devicePixelRatio,
116115
format: PlotRenderFormat.Png, // Currently hard-coded
117116
});
117+
};
118+
119+
// Renotify if the sizing policy changes
120+
const disposables = new DisposableStore();
121+
disposables.add(props.positronPlotsService.onDidChangeSizingPolicy((_policy) => {
122+
notify();
123+
}));
124+
125+
// Propagate current render settings. Use a debouncer to avoid excessive
126+
// messaging to language kernels.
127+
const debounceTimer = setTimeout(() => {
128+
notify()
118129
}, 500);
119130

120131
return () => clearTimeout(debounceTimer);

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

+4
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,10 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
13501350
* @param settings The new settings.
13511351
*/
13521352
setPlotsRenderSettings(settings: PlotRenderSettings): void {
1353+
// Sanitize values in case sizing policies create floating points
1354+
settings.size.height = Math.floor(settings.size.height);
1355+
settings.size.width = Math.floor(settings.size.width);
1356+
13531357
this._plotsRenderSettings.set(settings, undefined);
13541358
}
13551359

0 commit comments

Comments
 (0)