@@ -47,10 +47,10 @@ import {
47
47
fixLabelForNumberVariables ,
48
48
fixLabelsForNumberVariables ,
49
49
grayOutLastSeries ,
50
- omitEmptyNoDataSeries ,
51
50
vocabularyWithMissingData ,
52
51
variablesAreUnique ,
53
52
nonUniqueWarning ,
53
+ hasIncompleteCases ,
54
54
} from '../../../utils/visualization' ;
55
55
import { VariablesByInputName } from '../../../utils/data-element-constraints' ;
56
56
// use lodash instead of Math.min/max
@@ -208,15 +208,24 @@ function BarplotViz(props: VisualizationProps) {
208
208
) ;
209
209
210
210
const findEntityAndVariable = useFindEntityAndVariable ( entities ) ;
211
- const { variable, entity, overlayVariable, facetVariable } = useMemo ( ( ) => {
211
+ const {
212
+ variable,
213
+ entity,
214
+ overlayVariable,
215
+ overlayEntity,
216
+ facetVariable,
217
+ facetEntity,
218
+ } = useMemo ( ( ) => {
212
219
const xAxisVariable = findEntityAndVariable ( vizConfig . xAxisVariable ) ;
213
220
const overlayVariable = findEntityAndVariable ( vizConfig . overlayVariable ) ;
214
221
const facetVariable = findEntityAndVariable ( vizConfig . facetVariable ) ;
215
222
return {
216
223
variable : xAxisVariable ?. variable ,
217
224
entity : xAxisVariable ?. entity ,
218
225
overlayVariable : overlayVariable ?. variable ,
226
+ overlayEntity : overlayVariable ?. entity ,
219
227
facetVariable : facetVariable ?. variable ,
228
+ facetEntity : facetVariable ?. entity ,
220
229
} ;
221
230
} , [
222
231
findEntityAndVariable ,
@@ -227,23 +236,45 @@ function BarplotViz(props: VisualizationProps) {
227
236
228
237
const data = usePromise (
229
238
useCallback ( async ( ) : Promise < BarplotDataWithStatistics | undefined > => {
230
- if ( variable == null ) return undefined ;
239
+ if (
240
+ variable == null ||
241
+ entity == null ||
242
+ filteredCounts . pending ||
243
+ filteredCounts . value == null
244
+ )
245
+ return undefined ;
231
246
232
247
if ( ! variablesAreUnique ( [ variable , overlayVariable , facetVariable ] ) )
233
248
throw new Error ( nonUniqueWarning ) ;
234
249
235
250
const params = getRequestParams ( studyId , filters ?? [ ] , vizConfig ) ;
236
251
237
- const response = dataClient . getBarplot (
252
+ const response = await dataClient . getBarplot (
238
253
computation . descriptor . type ,
239
254
params as BarplotRequestParams
240
255
) ;
241
256
242
- const showMissing =
243
- vizConfig . showMissingness &&
244
- ( overlayVariable != null || facetVariable != null ) ;
257
+ // figure out if we need to show the missing data for the stratification variables
258
+ // if it has no incomplete cases we don't have to
245
259
const showMissingOverlay =
246
- vizConfig . showMissingness && overlayVariable != null ;
260
+ vizConfig . showMissingness &&
261
+ hasIncompleteCases (
262
+ overlayEntity ,
263
+ overlayVariable ,
264
+ entity ,
265
+ filteredCounts . value ,
266
+ response . completeCasesTable
267
+ ) ;
268
+ const showMissingFacet =
269
+ vizConfig . showMissingness &&
270
+ hasIncompleteCases (
271
+ facetEntity ,
272
+ facetVariable ,
273
+ entity ,
274
+ filteredCounts . value ,
275
+ response . completeCasesTable
276
+ ) ;
277
+
247
278
const vocabulary = fixLabelsForNumberVariables (
248
279
variable ?. vocabulary ,
249
280
variable
@@ -257,34 +288,33 @@ function BarplotViz(props: VisualizationProps) {
257
288
facetVariable
258
289
) ;
259
290
260
- return omitEmptyNoDataSeries (
261
- grayOutLastSeries (
262
- reorderData (
263
- barplotResponseToData (
264
- await response ,
265
- variable ,
266
- overlayVariable ,
267
- facetVariable
268
- ) ,
269
- vocabulary ,
270
- vocabularyWithMissingData ( overlayVocabulary , showMissing ) ,
271
- vocabularyWithMissingData ( facetVocabulary , showMissing )
291
+ return grayOutLastSeries (
292
+ reorderData (
293
+ barplotResponseToData (
294
+ response ,
295
+ variable ,
296
+ overlayVariable ,
297
+ facetVariable
272
298
) ,
273
- showMissingOverlay
299
+ vocabulary ,
300
+ vocabularyWithMissingData ( overlayVocabulary , showMissingOverlay ) ,
301
+ vocabularyWithMissingData ( facetVocabulary , showMissingFacet )
274
302
) ,
275
- showMissing
303
+ showMissingOverlay
276
304
) ;
277
305
} , [
278
306
// using vizConfig only causes issue with onCheckedLegendItemsChange
279
307
studyId ,
280
308
filters ,
309
+ filteredCounts ,
281
310
dataClient ,
282
311
vizConfig . xAxisVariable ,
283
312
vizConfig . overlayVariable ,
284
313
vizConfig . facetVariable ,
285
314
vizConfig . valueSpec ,
286
315
vizConfig . showMissingness ,
287
316
variable ,
317
+ entity ,
288
318
overlayVariable ,
289
319
computation . descriptor . type ,
290
320
] )
@@ -401,7 +431,7 @@ function BarplotViz(props: VisualizationProps) {
401
431
vizConfig . valueSpec === 'count' ? 'Count' : 'Proportion' ,
402
432
legendTitle : overlayVariable ?. displayName ,
403
433
interactive : true ,
404
- showSpinner : data . pending ,
434
+ showSpinner : data . pending || filteredCounts . pending ,
405
435
dependentAxisLogScale : vizConfig . dependentAxisLogScale ,
406
436
// set dependent axis range for log scale
407
437
dependentAxisRange : dependentAxisRange ,
@@ -473,12 +503,12 @@ function BarplotViz(props: VisualizationProps) {
473
503
outputEntity = { entity }
474
504
stratificationIsActive = { overlayVariable != null }
475
505
enableSpinner = { vizConfig . xAxisVariable != null && ! data . error }
476
- totalCounts = { totalCounts }
477
- filteredCounts = { filteredCounts }
506
+ totalCounts = { totalCounts . value }
507
+ filteredCounts = { filteredCounts . value }
478
508
/>
479
509
< VariableCoverageTable
480
510
completeCases = { data . pending ? undefined : data . value ?. completeCases }
481
- filters = { filters }
511
+ filteredCounts = { filteredCounts }
482
512
outputEntityId = { vizConfig . xAxisVariable ?. entityId }
483
513
variableSpecs = { [
484
514
{
0 commit comments