@@ -7,6 +7,8 @@ import { Delaunay } from 'd3-delaunay';
7
7
import { scaleOrdinal , scaleLinear , scaleThreshold , scaleSqrt } from 'd3-scale' ;
8
8
import minBy from 'lodash.minby' ;
9
9
import UNDPColorModule from 'undp-viz-colors' ;
10
+ import flattenDeep from 'lodash.flattendeep' ;
11
+ import min from 'lodash.min' ;
10
12
import { Tooltip } from '../../Components/Tooltip' ;
11
13
import {
12
14
CountryGroupDataType ,
@@ -47,6 +49,7 @@ export function Graph(props: Props) {
47
49
selectedRegions,
48
50
selectedIncomeGroups,
49
51
selectedCountryGroup,
52
+ keepAxisSame,
50
53
} = useContext ( Context ) as CtxDataType ;
51
54
const [ selectedColor , setSelectedColor ] = useState < string | undefined > (
52
55
undefined ,
@@ -103,7 +106,24 @@ export function Graph(props: Props) {
103
106
. range ( [ 0.25 , 30 ] )
104
107
. nice ( )
105
108
: undefined ;
106
-
109
+ const xFullArray = flattenDeep (
110
+ data . map ( d => {
111
+ const xIndicatorIndex = d . indicators . findIndex (
112
+ el => xIndicatorMetaData . DataKey === el . indicator ,
113
+ ) ;
114
+ const arr = d . indicators [ xIndicatorIndex ] . yearlyData . map ( el => el . value ) ;
115
+ return arr ;
116
+ } ) ,
117
+ ) ;
118
+ const yFullArray = flattenDeep (
119
+ data . map ( d => {
120
+ const yIndicatorIndex = d . indicators . findIndex (
121
+ el => yIndicatorMetaData . DataKey === el . indicator ,
122
+ ) ;
123
+ const arr = d . indicators [ yIndicatorIndex ] . yearlyData . map ( el => el . value ) ;
124
+ return arr ;
125
+ } ) ,
126
+ ) ;
107
127
const dataFormatted = orderBy (
108
128
data
109
129
. map ( d => {
@@ -245,7 +265,6 @@ export function Graph(props: Props) {
245
265
'radiusValue' ,
246
266
'desc' ,
247
267
) ;
248
-
249
268
const refXIndicatorIndex = regionData
250
269
? regionData . indicators . findIndex (
251
270
el => xIndicatorMetaData . DataKey === el . indicator ,
@@ -266,14 +285,18 @@ export function Graph(props: Props) {
266
285
: regionData . indicators [ refXIndicatorIndex ] . yearlyData [
267
286
regionData . indicators [ refXIndicatorIndex ] . yearlyData . length - 1
268
287
] ?. value ;
269
- const xMaxValue = maxBy ( dataFormatted , d => d . xVal )
288
+ const xMaxValue = keepAxisSame
289
+ ? ( max ( xFullArray ) as number )
290
+ : maxBy ( dataFormatted , d => d . xVal )
270
291
? refXVal && showReference
271
292
? ( maxBy ( dataFormatted , d => d . xVal ) ?. xVal as number ) > refXVal
272
293
? ( maxBy ( dataFormatted , d => d . xVal ) ?. xVal as number )
273
294
: refXVal
274
295
: ( maxBy ( dataFormatted , d => d . xVal ) ?. xVal as number )
275
296
: 0 ;
276
- const xMinValue = minBy ( dataFormatted , d => d . xVal )
297
+ const xMinValue = keepAxisSame
298
+ ? ( min ( xFullArray ) as number )
299
+ : minBy ( dataFormatted , d => d . xVal )
277
300
? refXVal && showReference
278
301
? ( minBy ( dataFormatted , d => d . xVal ) ?. xVal as number ) < refXVal
279
302
? ( minBy ( dataFormatted , d => d . xVal ) ?. xVal as number )
@@ -300,14 +323,18 @@ export function Graph(props: Props) {
300
323
: regionData . indicators [ refYIndicatorIndex ] . yearlyData [
301
324
regionData . indicators [ refYIndicatorIndex ] . yearlyData . length - 1
302
325
] ?. value ;
303
- const yMaxValue = maxBy ( dataFormatted , d => d . yVal )
326
+ const yMaxValue = keepAxisSame
327
+ ? ( max ( yFullArray ) as number )
328
+ : maxBy ( dataFormatted , d => d . yVal )
304
329
? refYVal && showReference
305
330
? ( maxBy ( dataFormatted , d => d . yVal ) ?. yVal as number ) > refYVal
306
331
? ( maxBy ( dataFormatted , d => d . yVal ) ?. yVal as number )
307
332
: refYVal
308
333
: ( maxBy ( dataFormatted , d => d . yVal ) ?. yVal as number )
309
334
: 0 ;
310
- const yMinValue = minBy ( dataFormatted , d => d . yVal )
335
+ const yMinValue = keepAxisSame
336
+ ? ( min ( yFullArray ) as number )
337
+ : minBy ( dataFormatted , d => d . yVal )
311
338
? refYVal && showReference
312
339
? ( minBy ( dataFormatted , d => d . yVal ) ?. yVal as number ) < refYVal
313
340
? ( minBy ( dataFormatted , d => d . yVal ) ?. yVal as number )
0 commit comments