@@ -17,7 +17,7 @@ const PhenotypeHistogram = ({
17
17
selectedCovariates,
18
18
outcome,
19
19
selectedContinuousItem,
20
- useAnimation ,
20
+ readOnly ,
21
21
handleChangeTransformation,
22
22
handleChangeMinOutlierCutoff,
23
23
handleChangeMaxOutlierCutoff,
@@ -49,6 +49,14 @@ const PhenotypeHistogram = ({
49
49
queryConfig ,
50
50
) ;
51
51
52
+ const getMinCutoff = ( continuousItem ) => continuousItem ?. filters ?. find (
53
+ ( filter ) => filter . type === FILTERS . greaterThanOrEqualTo ,
54
+ ) ?. value ?? null ;
55
+
56
+ const getMaxCutoff = ( continuousItem ) => continuousItem ?. filters ?. find (
57
+ ( filter ) => filter . type === FILTERS . lessThanOrEqualTo ,
58
+ ) ?. value ?? null ;
59
+
52
60
useEffect ( ( ) => {
53
61
// Validate and give error message if there is no data:
54
62
if (
@@ -70,6 +78,9 @@ const PhenotypeHistogram = ({
70
78
payload : MESSAGES . NO_BINS_ERROR ,
71
79
} ) ;
72
80
}
81
+ setMinOutlierCutoff ( getMinCutoff ( selectedContinuousItem ) ) ;
82
+ setMaxOutlierCutoff ( getMaxCutoff ( selectedContinuousItem ) ) ;
83
+ setSelectedTransformation ( selectedContinuousItem . transformation ) ;
73
84
}
74
85
} , [ data ] ) ;
75
86
@@ -90,33 +101,31 @@ const PhenotypeHistogram = ({
90
101
barColor : 'darkblue' ,
91
102
xAxisLegend : selectedContinuousItem . concept_name ,
92
103
yAxisLegend : 'Persons' ,
93
- useAnimation,
94
- minCutoff :
95
- selectedContinuousItem . filters ?. find (
96
- ( filter ) => filter . type === FILTERS . greaterThanOrEqualTo ,
97
- ) ?. value ?? undefined ,
98
- maxCutoff :
99
- selectedContinuousItem . filters ?. find (
100
- ( filter ) => filter . type === FILTERS . lessThanOrEqualTo ,
101
- ) ?. value ?? undefined ,
104
+ useAnimation : ! readOnly ,
105
+ minCutoff : getMinCutoff ( selectedContinuousItem ) ,
106
+ maxCutoff : getMaxCutoff ( selectedContinuousItem ) ,
102
107
} ;
103
108
return (
104
109
< React . Fragment >
105
110
{ inlineErrorMessage }
106
111
{ data . bins !== null && (
107
112
< div >
113
+ < div > { ( outcome ?. variable_type === 'custom_dichotomous' && readOnly
114
+ ? '\u2139\uFE0F histogram displaying data from both case and control groups'
115
+ : '' ) }
116
+ </ div >
108
117
< div className = 'GWASUI-row' >
109
118
< div className = 'GWASUI-column transformation-dropdown-label' >
110
119
< label
111
120
id = 'transformation-dropdown-label'
112
121
htmlFor = 'transformation-select'
113
- >
114
- Select Transformation
122
+ > { ( readOnly ? 'Selected Transformation' : 'Select Transformation' ) }
115
123
</ label >
116
124
</ div >
117
125
< div className = 'GWASUI-column transformation-select' >
118
126
< Select
119
127
id = 'transformation-select'
128
+ disabled = { readOnly }
120
129
showSearch = { false }
121
130
labelInValue
122
131
value = { selectedTransformation }
@@ -145,17 +154,18 @@ const PhenotypeHistogram = ({
145
154
< div className = 'GWASUI-column' >
146
155
< InputNumber
147
156
id = 'input-minOutlierCutoff'
157
+ disabled = { readOnly }
148
158
value = { minOutlierCutoff }
149
159
onChange = { ( value ) => {
150
160
setMinOutlierCutoff ( value ) ;
151
161
handleChangeMinOutlierCutoff ( value ) ;
152
162
} }
153
- min = { data . bins [ 0 ] ?. start || 0 }
154
- max = {
155
- maxOutlierCutoff
156
- || data . bins [ data . bins . length - 1 ] ?. end
157
- || 100
158
- }
163
+ min = { ( data . bins [ 0 ] ?. start ?? 0 ) - 1 }
164
+ max = { ( ( ) => {
165
+ const lastBinEnd = data . bins [ data . bins . length - 1 ] ?. end ;
166
+ const cutOffValue = maxOutlierCutoff ?? lastBinEnd ?? 100 ;
167
+ return cutOffValue + 1 ;
168
+ } ) ( ) }
159
169
onKeyDown = { ( e ) => {
160
170
const { key } = e ;
161
171
// Allow only numeric keys, backspace, and delete, and one decimal point
@@ -165,6 +175,7 @@ const PhenotypeHistogram = ({
165
175
&& key !== 'Delete'
166
176
&& key !== 'ArrowLeft'
167
177
&& key !== 'ArrowRight'
178
+ && ( key !== '-' || e . target . value . includes ( '-' ) )
168
179
&& ( key !== '.' || e . target . value . includes ( '.' ) )
169
180
) {
170
181
e . preventDefault ( ) ;
@@ -180,13 +191,18 @@ const PhenotypeHistogram = ({
180
191
< div className = 'GWASUI-column' >
181
192
< InputNumber
182
193
id = 'input-maxOutlierCutoff'
194
+ disabled = { readOnly }
183
195
value = { maxOutlierCutoff }
184
196
onChange = { ( value ) => {
185
197
setMaxOutlierCutoff ( value ) ;
186
198
handleChangeMaxOutlierCutoff ( value ) ;
187
199
} }
188
- min = { minOutlierCutoff || data . bins [ 0 ] ?. start || 0 }
189
- max = { data . bins [ data . bins . length - 1 ] ?. end || 100 }
200
+ min = { ( ( ) => {
201
+ const firstBinStart = data . bins [ 0 ] ?. start ;
202
+ const cutOffValue = minOutlierCutoff ?? firstBinStart ?? 0 ;
203
+ return cutOffValue - 1 ;
204
+ } ) ( ) }
205
+ max = { ( data . bins [ data . bins . length - 1 ] ?. end ?? 100 ) + 1 }
190
206
onKeyDown = { ( e ) => {
191
207
const { key } = e ;
192
208
// Allow only numeric keys, backspace, and delete, and one decimal point
@@ -196,6 +212,7 @@ const PhenotypeHistogram = ({
196
212
&& key !== 'Delete'
197
213
&& key !== 'ArrowLeft'
198
214
&& key !== 'ArrowRight'
215
+ && ( key !== '-' || e . target . value . includes ( '-' ) )
199
216
&& ( key !== '.' || e . target . value . includes ( '.' ) )
200
217
) {
201
218
e . preventDefault ( ) ;
@@ -216,7 +233,7 @@ PhenotypeHistogram.propTypes = {
216
233
selectedCovariates : PropTypes . array ,
217
234
outcome : PropTypes . object ,
218
235
selectedContinuousItem : PropTypes . object . isRequired ,
219
- useAnimation : PropTypes . bool ,
236
+ readOnly : PropTypes . bool ,
220
237
handleChangeTransformation : PropTypes . func ,
221
238
handleChangeMinOutlierCutoff : PropTypes . func ,
222
239
handleChangeMaxOutlierCutoff : PropTypes . func ,
@@ -226,7 +243,7 @@ PhenotypeHistogram.defaultProps = {
226
243
dispatch : null ,
227
244
selectedCovariates : [ ] ,
228
245
outcome : null ,
229
- useAnimation : true ,
246
+ readOnly : false ,
230
247
handleChangeTransformation : null ,
231
248
handleChangeMinOutlierCutoff : null ,
232
249
handleChangeMaxOutlierCutoff : null ,
0 commit comments