Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions html/httpgd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ function postLogMessage(content) {
}
window.addEventListener('message', (ev) => {
const msg = ev.data;
console.info(msg);
if (msg.message === 'updatePlot') {
updatePlot({
id: String(msg.plotId),
svg: msg.svg
});
}
else if (msg.message === 'focusPlot') {
console.log('focussing plot');
focusPlot(String(msg.plotId));
}
else if (msg.message === 'toggleStyle') {
Expand Down
2 changes: 0 additions & 2 deletions html/httpgd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ function postLogMessage(content: any){

window.addEventListener('message', (ev: MessageEvent<InMessage>) => {
const msg = ev.data;
console.info(msg);
if(msg.message === 'updatePlot'){
updatePlot({
id: String(msg.plotId),
svg: msg.svg
});
} else if(msg.message === 'focusPlot'){
console.log('focussing plot');
focusPlot(String(msg.plotId));
} else if(msg.message === 'toggleStyle'){
toggleStyle(msg.useOverwrites);
Expand Down
2 changes: 1 addition & 1 deletion html/httpgd/styleOverwrites.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

svg text {
font-family: var(--vscode-editor-font-family) !important;
stroke: var(--vscode-foreground) !important;
fill: var(--vscode-foreground) !important;
}

.httpgd line, .httpgd polyline, .httpgd polygon, .httpgd path, .httpgd circle, .httpgd rect:not(:first-of-type) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,8 @@
"vscode",
"original"
],
"enumDescriptions": [
"Match background and primary stroke color to the current color theme",
"markdownEnumDescriptions": [
"Match background and primary stroke color to the current color theme (Or apply custom CSS overwrites, if specified in `#r.plot.customStyleOverwrites#`)",
"Use original colors"
],
"markdownDescription": "Which color theme to use when launching the plot viewer."
Expand Down Expand Up @@ -1246,7 +1246,7 @@
"r.plot.customStyleOverwrites": {
"type": "string",
"default": "",
"markdownDescription": "Path to a custom CSS file to be used for `r.plot.toggleStyle`. WARNING: replaces default CSS overwrites!"
"markdownDescription": "Path to a custom CSS file to be used when `#r.plot.defaults.colorTheme#` is `vscode`. Replaces the default CSS overwrites!"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/plotViewer/httpgdTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class IHttpgdViewer {
webviewPanel?: vscode.WebviewPanel;

// Api that provides plot contents etc.
api: IHttpgdViewerApi;
api?: IHttpgdViewerApi;

// active plots
plots: HttpgdPlot[];
Expand Down
39 changes: 28 additions & 11 deletions src/plotViewer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class HttpgdViewer implements IHttpgdViewer {
webviewPanel?: vscode.WebviewPanel;

// Api that provides plot contents etc.
readonly api: Httpgd;
api?: Httpgd;

// active plots
plots: HttpgdPlot[] = [];
Expand Down Expand Up @@ -329,8 +329,13 @@ export class HttpgdViewer implements IHttpgdViewer {
this.api.onPlotsChange(() => {
this.checkStateDelayed();
});
this.api.onConnectionChange(() => {
this.checkStateDelayed();
this.api.onConnectionChange((disconnected: boolean) => {
if(disconnected){
this.api?.dispose();
this.api = undefined;
} else{
this.checkStateDelayed();
}
});
this.customOverwriteCssPath = config().get('plot.customStyleOverwrites', '');
const localResourceRoots = (
Expand Down Expand Up @@ -451,7 +456,7 @@ export class HttpgdViewer implements IHttpgdViewer {
id ??= this.activePlot;
if(id){
this.hidePlot(id);
await this.api.closePlot(id);
await this.api?.closePlot(id);
}
}

Expand Down Expand Up @@ -531,6 +536,9 @@ export class HttpgdViewer implements IHttpgdViewer {
}
}
protected async checkState(): Promise<void> {
if(!this.api){
return;
}
const oldUpid = this.state?.upid;
this.state = await this.api.getState();
if(this.state.upid !== oldUpid){
Expand Down Expand Up @@ -560,8 +568,9 @@ export class HttpgdViewer implements IHttpgdViewer {
void this.resizePlot();
} else if(!this.resizeTimeout){
this.resizeTimeout = setTimeout(() => {
void this.resizePlot();
this.resizeTimeout = undefined;
void this.resizePlot().then(() =>
this.resizeTimeout = undefined
);
}, this.resizeTimeoutLength);
}
}
Expand All @@ -572,12 +581,17 @@ export class HttpgdViewer implements IHttpgdViewer {
const height = this.scaledViewHeight;
const width = this.scaledViewWidth;
const plt = await this.getPlotContent(id, height, width);
this.plotWidth = plt.width;
this.plotHeight = plt.height;
this.updatePlot(plt);
if(plt){
this.plotWidth = plt.width;
this.plotHeight = plt.height;
this.updatePlot(plt);
}
}

protected async refreshPlots(redraw: boolean = false, force: boolean = false): Promise<void> {
if(!this.api){
return;
}
const nPlots = this.plots.length;
const oldPlotIds = this.plots.map(plt => plt.id);
let plotIds = await this.api.getPlotIds();
Expand Down Expand Up @@ -629,7 +643,10 @@ export class HttpgdViewer implements IHttpgdViewer {
void this.setContextValues();
}

protected async getPlotContent(id: PlotId, height?: number, width?: number): Promise<HttpgdPlot> {
protected async getPlotContent(id: PlotId, height?: number, width?: number): Promise<HttpgdPlot | undefined> {
if(!this.api){
return undefined;
}
height ||= this.scaledViewHeight;
width ||= this.scaledViewWidth;
const plt = await this.api.getPlotContent(id, height, width);
Expand Down Expand Up @@ -777,7 +794,7 @@ export class HttpgdViewer implements IHttpgdViewer {
// Dispose-function to clean up when vscode closes
// E.g. to close connections etc., notify R, ...
public dispose(): void {
this.api.dispose();
this.api?.dispose();
}
}

Expand Down