Skip to content

Commit

Permalink
Cleanup and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Sep 3, 2024
1 parent b2b389a commit bd0d1a4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion scss/sdfv.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ body.sdfv {
}

#diff-container {
position: relative;
resize: both;
width: 90%;
height: 90%;
Expand All @@ -84,6 +83,7 @@ body.sdfv {
display: flex;

.diff-contents {
position: relative;
width: 50%;
height: 100%;
}
Expand Down
18 changes: 17 additions & 1 deletion src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ export class SDFGRenderer extends EventEmitter {
this.on('graph_edited', () => {
this.draw_async();
});

SDFVSettings.getInstance().on('setting_changed', (setting) => {
if (setting.relayout) {
this.add_loading_animation();
setTimeout(() => {
this.relayout();
this.draw_async();
}, 10);
}

if (setting.redrawUI)
this.initUI();

if (setting.redraw !== false && !setting.relayout)
this.draw_async();
});
}

public destroy(): void {
Expand Down Expand Up @@ -558,7 +574,7 @@ export class SDFGRenderer extends EventEmitter {
html: '<i class="material-symbols-outlined">settings</i>',
title: 'Settings',
click: () => {
SDFVSettings.getInstance().show(this);
SDFVSettings.getInstance().show();
},
}).appendTo(this.toolbar);
}
Expand Down
27 changes: 14 additions & 13 deletions src/sdfg_diff_viewr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ const DIFF_IGNORE_ATTRIBUTES = [
'layout',
];

const ENABLED_RENDERER_FEATURES: RendererUIFeature[] = [
'settings',
'zoom_to_fit_all',
'zoom_to_fit_width',
'collapse',
'expand',
'pan_mode',
];

export interface DiffMap {
addedKeys: Set<string>;
removedKeys: Set<string>;
Expand Down Expand Up @@ -345,12 +336,21 @@ export class WebSDFGDiffViewer extends SDFGDiffViewer {
throw Error('Failed to find diff renderer containers');

const leftRenderer = new SDFGRenderer(
graphA, leftContainer, undefined, null, null, false, null, null,
ENABLED_RENDERER_FEATURES
graphA, leftContainer, undefined, null, null, false, null, null, [
'settings',
'zoom_to_fit_all',
'zoom_to_fit_width',
'collapse',
'expand',
]
);
const rightRenderer = new SDFGRenderer(
graphB, rightContainer, undefined, null, null, false, null, null,
ENABLED_RENDERER_FEATURES
graphB, rightContainer, undefined, null, null, false, null, null, [
'zoom_to_fit_all',
'zoom_to_fit_width',
'collapse',
'expand',
]
);

const viewer = new WebSDFGDiffViewer(leftRenderer, rightRenderer);
Expand Down Expand Up @@ -512,6 +512,7 @@ export class WebSDFGDiffViewer extends SDFGDiffViewer {
}

public outline(): void {
SDFVWebUI.getInstance().infoContentContainer.html('');
if (!this.diffMap) {
SDFVWebUI.getInstance().infoSetTitle('SDFG Diff Outline');
SDFVWebUI.getInstance().infoContentContainer.text(
Expand Down
62 changes: 28 additions & 34 deletions src/utils/sdfv_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import $ from 'jquery';

import {
Modal,
} from 'bootstrap';
import { SDFGRenderer } from '../renderer/renderer';
import EventEmitter from 'events';
import { Modal } from 'bootstrap';
import * as settingsManifest from '../settings_manifest.json';
import { AllFields } from './utils';

Expand Down Expand Up @@ -42,7 +40,25 @@ interface SDFVSettingRange extends SDFVSetting {
step?: number;
}

export class SDFVSettings {
interface SDFVSettingsEvent {
'setting_changed': (setting: SDFVSetting) => void,
}

/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
export interface SDFVSettings {

on<U extends keyof SDFVSettingsEvent>(
event: U, listener: SDFVSettingsEvent[U]
): this;

emit<U extends keyof SDFVSettingsEvent>(
event: U, ...args: Parameters<SDFVSettingsEvent[U]>
): boolean;

}

/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
export class SDFVSettings extends EventEmitter {

private readonly _settingsDict: Map<
SDFVSettingKey, SDFVSettingValT
Expand All @@ -51,6 +67,8 @@ export class SDFVSettings {
private static readonly INSTANCE: SDFVSettings = new SDFVSettings();

private constructor() {
super();

const categories = settingsManifest.viewerSettings.categories;
for (const category of Object.values(categories)) {
for (const [sName, setting] of Object.entries(category.settings)) {
Expand All @@ -66,7 +84,6 @@ export class SDFVSettings {
}

private modal: Modal | null = null;
private renderer: SDFGRenderer | null = null;

private addSlider(
root: JQuery<HTMLElement>, category: string, key: SDFVSettingKey,
Expand Down Expand Up @@ -134,7 +151,7 @@ export class SDFVSettings {
nVal = +nVal;
numberInput.val(nVal);
this._settingsDict.set(key, nVal);
this.onSettingChanged(setting);
this.emit('setting_changed', setting);
}
});
numberInput.on('change', () => {
Expand All @@ -152,14 +169,14 @@ export class SDFVSettings {

sliderInput.val(nVal);
this._settingsDict.set(key, nVal);
this.onSettingChanged(setting);
this.emit('setting_changed', setting);
}
});
resetBtn.on('click', () => {
numberInput.val(setting.default);
sliderInput.val(setting.default);
this._settingsDict.set(key, setting.default);
this.onSettingChanged(setting);
this.emit('setting_changed', setting);
});
}

Expand Down Expand Up @@ -200,7 +217,7 @@ export class SDFVSettings {
}

this._settingsDict.set(key, isChecked);
this.onSettingChanged(setting);
this.emit('setting_changed', setting);
},
}).appendTo(checkContainer);
$('<label>', {
Expand Down Expand Up @@ -323,32 +340,9 @@ export class SDFVSettings {
return modalElement;
}

private onSettingChanged(setting: SDFVSetting): void {
if (setting.relayout) {
this.renderer?.add_loading_animation();
setTimeout(() => {
this.renderer?.relayout();
this.renderer?.draw_async();
}, 10);
}

if (setting.redrawUI)
this.renderer?.initUI();

if (setting.redraw !== false && !setting.relayout)
this.renderer?.draw_async();

if (this.renderer?.get_in_vscode())
this.renderer.emit('settings_changed', SDFVSettings.settingsDict);
}

public show(renderer?: SDFGRenderer): void {
public show(): void {
if (!this.modal)
this.modal = new Modal(this.constructModal()[0], {});

if (renderer)
this.renderer = renderer;

this.modal.show();
}

Expand Down

0 comments on commit bd0d1a4

Please sign in to comment.