Skip to content

Commit 686c8ba

Browse files
committed
Switch back to checking bitmap-level diff
For the moment, checking for bitmap-level differences seems to be a better indicator than recordPlot() for if a plot has changed.
1 parent a1748ed commit 686c8ba

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/webr_kernel.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { KernelMessage } from '@jupyterlab/services';
33
import { IKernel } from '@jupyterlite/kernel';
44

55
import { Console, WebR, Shelter} from 'webr';
6-
import { RObject, RList, RCharacter, RLogical } from 'webr';
6+
import { RList, RCharacter, RLogical } from 'webr';
77

88
const webRVersion = "0.3.0-rc.0";
99
const baseRVersion = "4.3.3";
@@ -15,7 +15,7 @@ export class WebRKernel extends BaseKernel {
1515
init: Promise<void>;
1616
#webRConsole: Console;
1717
#bitmapCanvas: HTMLCanvasElement;
18-
#lastRecord: RObject | null = null;
18+
#lastPlot: string | null = null;
1919

2020
constructor(options: IKernel.IOptions) {
2121
super(options);
@@ -190,7 +190,6 @@ export class WebRKernel extends BaseKernel {
190190
dev.set(${dev})
191191
dev.copy(which = capture_dev)
192192
dev.off(capture_dev)
193-
recordPlot()
194193
}, silent = TRUE)
195194
`);
196195
const image = capturePlot.images[0];
@@ -199,16 +198,8 @@ export class WebRKernel extends BaseKernel {
199198
this.#bitmapCanvas.getContext('bitmaprenderer')?.transferFromImageBitmap(image);
200199
const plotData = this.#bitmapCanvas.toDataURL('image/png');
201200

202-
// Send plot data to client if a new.plot() has been triggered or if
203-
// the plot has changed since last time
204-
const plotChanged = await this.webR.evalRBoolean('!identical(a, b)', {
205-
env: {
206-
a: this.#lastRecord,
207-
b: capturePlot.result,
208-
}
209-
})
210-
if (newPlot || plotChanged) {
211-
this.#lastRecord = capturePlot.result;
201+
if (newPlot || plotData !== this.#lastPlot) {
202+
this.#lastPlot = plotData;
212203
this.displayData({
213204
data: {
214205
'image/png': plotData.split(",")[1],

0 commit comments

Comments
 (0)