From 94401146428d4a26d39fdeed340637c3a92f861e Mon Sep 17 00:00:00 2001 From: ivmartel Date: Thu, 9 Jan 2025 15:24:24 +0100 Subject: [PATCH] Init ui at renderend, merge load handlers --- tests/pacs/viewer.js | 62 +++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/tests/pacs/viewer.js b/tests/pacs/viewer.js index 1520d43350..0773112b14 100644 --- a/tests/pacs/viewer.js +++ b/tests/pacs/viewer.js @@ -168,11 +168,6 @@ function viewerSetup() { dataLoadProgress.reduce(sumReducer) / numberOfDataToLoad; } }); - _app.addEventListener('load', function (event) { - if (!viewOnFirstLoadItem) { - _app.render(event.dataid); - } - }); _app.addEventListener('loaditem', function (event) { if (typeof event.warn !== 'undefined') { console.warn('load-warn', event.warn); @@ -185,18 +180,40 @@ function viewerSetup() { // remove abort shortcut window.removeEventListener('keydown', abortShortcut); }); - - const firstRender = []; _app.addEventListener('load', function (event) { + // render if not done yet + if (!viewOnFirstLoadItem) { + _app.render(event.dataid); + } + // update sliders with new data info + initSliders(); + // log meta data const meta = _app.getMetaData(event.dataid); console.log('metadata', getMetaDataWithNames(meta)); + // get modality + let modality; + if (event.loadtype === 'image' && + typeof meta['00080060'] !== 'undefined') { + modality = meta['00080060'].value[0]; + } + // log DICOM SEG + if (modality === 'SEG') { + logFramePosPats(_app.getMetaData(event.dataid)); + } + // log DICOM SR + if (modality === 'SR') { + console.log('DICOM SR'); + const srContent = dwv.getSRContent(meta); + console.log(srContent.toString()); + } + }); - // update UI at first render - if (!firstRender.includes(event.dataid)) { - // store data id - firstRender.push(event.dataid); - // init gui on first load + let didRender = false; + _app.addEventListener('renderend', function (/*event*/) { + // update UI at first render of first data + if (!didRender) { + didRender = true; if (_app.getDataIds().length === 1) { // set app tool setAppTool(); @@ -210,27 +227,6 @@ function viewerSetup() { const smoothingChk = document.getElementById('changesmoothing'); smoothingChk.disabled = false; } - // update sliders with new data info - initSliders(); - } - - let modality; - if (event.loadtype === 'image' && - typeof meta['00080060'] !== 'undefined') { - modality = meta['00080060'].value[0]; - } - - // Special DICOM SEG - if (modality === 'SEG') { - // log SEG details - logFramePosPats(_app.getMetaData(event.dataid)); - } - - // DICOM SR specific - if (modality === 'SR') { - console.log('DICOM SR'); - const srContent = dwv.getSRContent(meta); - console.log(srContent.toString()); } });