@@ -143,6 +143,8 @@ fmltc.MonitorTraining = function(util, modelUuid, modelEntitiesByUuid, datasetEn
143143 this . imagesDiv . style . height = this . modelDiv . clientHeight + 'px' ;
144144
145145 this . util . addTabClickListener ( this . tab_onclick . bind ( this ) ) ;
146+ window . addEventListener ( 'resize' , this . resizeImages . bind ( this ) ) ;
147+
146148
147149 if ( ! this . util . isTrainingDone ( this . modelEntity ) ) {
148150 this . util . showTab ( 'modelTab' ) ;
@@ -164,10 +166,10 @@ fmltc.MonitorTraining = function(util, modelUuid, modelEntitiesByUuid, datasetEn
164166 this . lastPageButton . onclick = this . lastPageButton_onclick . bind ( this ) ;
165167} ;
166168
167- fmltc . MonitorTraining . prototype . setHeightOfEvalImagesDiv = function ( ) {
169+ fmltc . MonitorTraining . prototype . onImagesTabSelected = function ( ) {
168170 let height = this . imagesDiv . clientHeight ;
169171 if ( height == 0 ) {
170- setTimeout ( this . setHeightOfEvalImagesDiv . bind ( this ) , 100 ) ;
172+ setTimeout ( this . onImagesTabSelected . bind ( this ) , 100 ) ;
171173 return ;
172174 }
173175 let element = this . evalImagesDiv ;
@@ -183,6 +185,23 @@ fmltc.MonitorTraining.prototype.setHeightOfEvalImagesDiv = function() {
183185 element = parent ;
184186 }
185187 this . evalImagesDiv . style . height = height + 'px' ;
188+
189+ this . resizeImages ( ) ;
190+ } ;
191+
192+ fmltc . MonitorTraining . prototype . onResize = function ( ) {
193+ this . resizeImages ( ) ;
194+ } ;
195+
196+ fmltc . MonitorTraining . prototype . resizeImages = function ( ) {
197+ for ( const tag in this . evalImages . mapTagToImgs ) {
198+ const divForTag = this . evalImages . mapTagToDiv [ tag ] ;
199+ const mapStepToImg = this . evalImages . mapTagToImgs [ tag ] ;
200+ for ( const step in mapStepToImg ) {
201+ const img = mapStepToImg [ step ] ;
202+ this . setImgSize ( img , img . naturalWidth , img . naturalHeight , divForTag ) ;
203+ }
204+ }
186205} ;
187206
188207fmltc . MonitorTraining . prototype . updateButtons = function ( ) {
@@ -974,7 +993,6 @@ fmltc.MonitorTraining.prototype.addImages = function(o, newMapTagToSteps) {
974993
975994 // Create a table with captions in the top row and the image in the bottom row.
976995 const table = document . createElement ( 'table' ) ;
977- table . style . width = this . evalImagesDiv . scrollWidth + 'px' ;
978996 // Top row.
979997 let tr = table . insertRow ( - 1 ) ;
980998 let td = tr . insertCell ( - 1 ) ;
@@ -1110,13 +1128,8 @@ fmltc.MonitorTraining.prototype.xhr_retrieveImage_onreadystatechange = function(
11101128 const mapStepToImg = o . mapTagToImgs [ tag ] ;
11111129 const img = mapStepToImg [ step ] ;
11121130 img . src = window . URL . createObjectURL ( xhr . response ) ;
1113- const parentClientWidth = img . parentElement . clientWidth ;
1114- let divisor = 3 ;
1115- if ( value . width > value . height ) {
1116- divisor = value . width / ( parentClientWidth - 2 ) ;
1117- }
1118- img . setAttribute ( 'width' , value . width / divisor ) ;
1119- img . setAttribute ( 'height' , value . height / divisor ) ;
1131+ const divForTag = o . mapTagToDiv [ tag ] ;
1132+ this . setImgSize ( img , value . width , value . height , divForTag ) ;
11201133
11211134 const sortedSteps = o . mapTagToSteps [ tag ] ;
11221135 if ( step == sortedSteps [ sortedSteps . length - 1 ] ) {
@@ -1140,6 +1153,17 @@ fmltc.MonitorTraining.prototype.xhr_retrieveImage_onreadystatechange = function(
11401153 }
11411154} ;
11421155
1156+ fmltc . MonitorTraining . prototype . setImgSize = function ( img , naturalWidth , naturalHeight , divForTag ) {
1157+ if ( img . src == '//:0' || naturalWidth == 0 || divForTag . clientWidth == 0 ) {
1158+ return ;
1159+ }
1160+ let divisor = naturalWidth / ( divForTag . clientWidth - 2 ) ;
1161+ if ( divisor != 0 ) {
1162+ img . setAttribute ( 'width' , naturalWidth / divisor ) ;
1163+ img . setAttribute ( 'height' , naturalHeight / divisor ) ;
1164+ }
1165+ } ;
1166+
11431167fmltc . MonitorTraining . prototype . firstPageButton_onclick = function ( ) {
11441168 if ( this . evalImages . currentPageIndex > 0 ) {
11451169 this . evalImages . currentPageIndex = 0 ;
@@ -1217,6 +1241,6 @@ fmltc.MonitorTraining.prototype.tab_onclick = function(tabContentId) {
12171241 this . drawCharts ( ) ;
12181242
12191243 } else if ( tabContentId == 'imagesTabContent' ) {
1220- this . setHeightOfEvalImagesDiv ( ) ;
1244+ this . onImagesTabSelected ( ) ;
12211245 }
12221246} ;
0 commit comments