21
21
<b-message v-if =" error" type =" is-danger" has-icon icon-size =" is-small" size =" is-small" >
22
22
<p > {{ $t('unexpected-error-info-message') }} </p >
23
23
</b-message >
24
- <div class =" histogram-actions" v-else-if =" !loading && !hasHistograms " >
24
+ <div class =" histogram-actions" v-else-if =" !loadingHistograms && !hasSomeHistograms " >
25
25
<a class =" button is-small is-fullwidth" @click =" computeHistograms()" >{{$t('button-compute-histogram')}}</a >
26
26
</div >
27
- <b-tabs type =" is-boxed" class =" histogram" v-else-if =" loading || hasHistograms" >
28
- <b-loading :is-full-page =" false" class =" small" :active =" loading" />
27
+ <div class =" histogram-actions" v-else-if =" (loadingHistograms || hasSomeHistograms) && !hasAllHistograms" >
28
+ <progress class =" progress is-info" :value =" histogramProgress" max =" 100" >
29
+ {{histogramProgress}}%
30
+ </progress >
31
+ </div >
32
+ <b-tabs type =" is-boxed" class =" histogram" v-else-if =" hasAllHistograms" >
29
33
<b-tab-item v-for =" sampleHisto in sampleHistograms" :key =" `${sampleHisto.id}`" >
30
34
<template #header >
31
35
<i class =" fa fa-circle color-preview" :style =" {color: sampleColor(sampleHisto.sample)}" />
74
78
</div >
75
79
<div class =" actions" >
76
80
<div class =" level" >
77
- <template v-if =" maxRank > 1 && hasHistograms " >
81
+ <template v-if =" maxRank > 1 && hasAllHistograms " >
78
82
<button class =" level-item button is-small" @click =" adjustToImage()" >{{$t('button-adjust-image')}}</button >
79
83
<button class =" level-item button is-small" @click =" adjustToSlice()" >{{$t('button-adjust-slice')}}</button >
80
84
</template >
81
- <button v-else-if =" hasHistograms " class =" level-item button is-small" @click =" adjustToImage()" >{{$t('button-adjust')}}</button >
85
+ <button v-else-if =" hasAllHistograms " class =" level-item button is-small" @click =" adjustToImage()" >{{$t('button-adjust')}}</button >
82
86
83
87
<button class =" level-item button is-small" @click =" reset()" >{{$t('button-reset')}}</button >
84
88
</div >
85
- <a class =" is-fullwidth button is-small" @click =" switchHistogramScale()" v-if =" hasHistograms " >{{switchHistogramScaleLabel}}</a >
89
+ <a class =" is-fullwidth button is-small" @click =" switchHistogramScale()" v-if =" hasAllHistograms " >{{switchHistogramScaleLabel}}</a >
86
90
</div >
87
91
</div >
88
92
</template >
@@ -92,6 +96,7 @@ import {get} from '@/utils/store-helpers';
92
96
import CytomineSlider from ' @/components/form/CytomineSlider' ;
93
97
import {ImageFilterProjectCollection , SampleHistogramCollection } from ' cytomine-client' ;
94
98
import SampleHistogram from ' @/components/viewer/panels/SampleHistogram' ;
99
+ import constants from ' @/utils/constants' ;
95
100
96
101
export default {
97
102
name: ' color-manipulation' ,
@@ -103,7 +108,10 @@ export default {
103
108
return {
104
109
filters: null ,
105
110
sampleHistograms: null ,
106
- loading: false ,
111
+ loadingHistograms: false ,
112
+ nbHistograms: 0 ,
113
+ refreshInterval: constants .HISTOGRAM_REFRESH_INTERVAL ,
114
+ timeout: null ,
107
115
error: false ,
108
116
revisionBrightnessContrast: 0 ,
109
117
};
@@ -137,12 +145,21 @@ export default {
137
145
maxValue () {
138
146
return Math .pow (2 , this .image .bitPerSample );
139
147
},
140
- hasHistograms () {
141
- return this .sampleHistograms && this .sampleHistograms .length > 0 ;
148
+ expectedNbHistograms () {
149
+ return this .image .depth * this .image .duration * this .image .channels * this .image .samplePerPixel ;
150
+ },
151
+ hasAllHistograms () {
152
+ return this .nbHistograms === this .expectedNbHistograms ;
153
+ },
154
+ hasSomeHistograms () {
155
+ return this .nbHistograms > 0 ;
142
156
},
143
157
canComputeHistogram () {
144
158
return this .image .bitPerSample && this .image .samplePerPixel ;
145
159
},
160
+ histogramProgress () {
161
+ return this .nbHistograms / this .expectedNbHistograms * 100 ;
162
+ },
146
163
147
164
selectedFilter: {
148
165
get () {
@@ -193,7 +210,7 @@ export default {
193
210
},
194
211
watch: {
195
212
slice () {
196
- this .fetchSampleHistograms ();
213
+ this .refresh ();
197
214
}
198
215
},
199
216
methods: {
@@ -234,6 +251,29 @@ export default {
234
251
235
252
return ' grey' ;
236
253
},
254
+ async refresh () {
255
+ await this .fetchImageHistogramsCount ();
256
+ clearTimeout (this .timeout );
257
+ if (this .nbHistograms < this .expectedNbHistograms && (this .nbHistograms > 0 || this .loadingHistograms )) {
258
+ this .timeout = setTimeout (this .refresh , this .refreshInterval );
259
+ }
260
+ else if (this .nbHistograms === this .expectedNbHistograms ) {
261
+ if (! this .sampleHistograms ) {
262
+ await this .$store .dispatch (this .imageModule + ' refreshDefaultMinMax' , {image: this .image });
263
+ }
264
+ await this .fetchSampleHistograms ();
265
+ this .loadingHistograms = false ;
266
+ }
267
+ },
268
+ async fetchImageHistogramsCount () {
269
+ try {
270
+ this .nbHistograms = await this .image .fetchNbSampleHistograms ();
271
+ }
272
+ catch (error) {
273
+ console .log (error);
274
+ this .error = true ;
275
+ }
276
+ },
237
277
async fetchSampleHistograms () {
238
278
try {
239
279
this .sampleHistograms = (await SampleHistogramCollection .fetchAll ({filterKey: ' sliceinstance' , filterValue: this .slice .id })).array ;
@@ -243,18 +283,16 @@ export default {
243
283
this .error = true ;
244
284
}
245
285
},
246
- async computeHistograms () {
247
- this .loading = true ;
286
+ computeHistograms () {
287
+ this .loadingHistograms = true ;
248
288
try {
249
- await this .image .extractHistogram ();
250
- await this .$store .dispatch (this .imageModule + ' refreshDefaultMinMax' , {image: this .image });
251
- await this .fetchSampleHistograms ();
289
+ this .image .extractHistogram ();
290
+ this .refresh ();
252
291
}
253
292
catch (error) {
254
293
console .log (error);
255
294
this .error = true ;
256
295
}
257
- this .loading = false ;
258
296
}
259
297
},
260
298
async created () {
@@ -269,11 +307,14 @@ export default {
269
307
}
270
308
this .filters = filters;
271
309
272
- this .fetchSampleHistograms ();
310
+ this .refresh ();
273
311
}
274
312
catch (error) {
275
313
console .log (error);
276
314
}
315
+ },
316
+ beforeDestroy () {
317
+ clearTimeout (this .timeout );
277
318
}
278
319
};
279
320
</script >
0 commit comments