From bd0d1a440455fd535d5d8d6bef8cccdfdc9caa8e Mon Sep 17 00:00:00 2001 From: Philipp Schaad Date: Tue, 3 Sep 2024 11:47:45 +0200 Subject: [PATCH] Cleanup and fixes --- scss/sdfv.scss | 2 +- src/renderer/renderer.ts | 18 ++++++++++- src/sdfg_diff_viewr.ts | 27 +++++++++-------- src/utils/sdfv_settings.ts | 62 +++++++++++++++++--------------------- 4 files changed, 60 insertions(+), 49 deletions(-) diff --git a/scss/sdfv.scss b/scss/sdfv.scss index 12e912bb..777aed18 100644 --- a/scss/sdfv.scss +++ b/scss/sdfv.scss @@ -75,7 +75,6 @@ body.sdfv { } #diff-container { - position: relative; resize: both; width: 90%; height: 90%; @@ -84,6 +83,7 @@ body.sdfv { display: flex; .diff-contents { + position: relative; width: 50%; height: 100%; } diff --git a/src/renderer/renderer.ts b/src/renderer/renderer.ts index 6588912a..3e2470dc 100644 --- a/src/renderer/renderer.ts +++ b/src/renderer/renderer.ts @@ -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 { @@ -558,7 +574,7 @@ export class SDFGRenderer extends EventEmitter { html: 'settings', title: 'Settings', click: () => { - SDFVSettings.getInstance().show(this); + SDFVSettings.getInstance().show(); }, }).appendTo(this.toolbar); } diff --git a/src/sdfg_diff_viewr.ts b/src/sdfg_diff_viewr.ts index a683178e..fad29a7d 100644 --- a/src/sdfg_diff_viewr.ts +++ b/src/sdfg_diff_viewr.ts @@ -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; removedKeys: Set; @@ -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); @@ -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( diff --git a/src/utils/sdfv_settings.ts b/src/utils/sdfv_settings.ts index f458f883..d1adba98 100644 --- a/src/utils/sdfv_settings.ts +++ b/src/utils/sdfv_settings.ts @@ -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'; @@ -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( + event: U, listener: SDFVSettingsEvent[U] + ): this; + + emit( + event: U, ...args: Parameters + ): boolean; + +} + +/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +export class SDFVSettings extends EventEmitter { private readonly _settingsDict: Map< SDFVSettingKey, SDFVSettingValT @@ -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)) { @@ -66,7 +84,6 @@ export class SDFVSettings { } private modal: Modal | null = null; - private renderer: SDFGRenderer | null = null; private addSlider( root: JQuery, category: string, key: SDFVSettingKey, @@ -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', () => { @@ -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); }); } @@ -200,7 +217,7 @@ export class SDFVSettings { } this._settingsDict.set(key, isChecked); - this.onSettingChanged(setting); + this.emit('setting_changed', setting); }, }).appendTo(checkContainer); $('