@@ -8,7 +8,6 @@ import { scaleOrdinal, scaleLinear, scaleThreshold, scaleSqrt } from 'd3-scale';
8
8
import minBy from 'lodash.minby' ;
9
9
import UNDPColorModule from 'undp-viz-colors' ;
10
10
import flattenDeep from 'lodash.flattendeep' ;
11
- import min from 'lodash.min' ;
12
11
import { Tooltip } from '../../Components/Tooltip' ;
13
12
import {
14
13
CountryGroupDataType ,
@@ -106,24 +105,26 @@ export function Graph(props: Props) {
106
105
. range ( [ 0.25 , 30 ] )
107
106
. nice ( )
108
107
: undefined ;
109
- const xFullArray = flattenDeep (
108
+ const fullArray = flattenDeep (
110
109
data . map ( d => {
111
110
const xIndicatorIndex = d . indicators . findIndex (
112
111
el => xIndicatorMetaData . DataKey === el . indicator ,
113
112
) ;
114
- const arr = d . indicators [ xIndicatorIndex ] . yearlyData . map ( el => el . value ) ;
115
- return arr ;
116
- } ) ,
117
- ) ;
118
- const yFullArray = flattenDeep (
119
- data . map ( d => {
113
+ const xArr = d . indicators [ xIndicatorIndex ] ?. yearlyData . map (
114
+ el => el . value ,
115
+ ) ;
120
116
const yIndicatorIndex = d . indicators . findIndex (
121
117
el => yIndicatorMetaData . DataKey === el . indicator ,
122
118
) ;
123
- const arr = d . indicators [ yIndicatorIndex ] . yearlyData . map ( el => el . value ) ;
124
- return arr ;
119
+ const yArr = d . indicators [ yIndicatorIndex ] ?. yearlyData . map (
120
+ el => el . value ,
121
+ ) ;
122
+ return {
123
+ x : max ( xArr ) ,
124
+ y : max ( yArr ) ,
125
+ } ;
125
126
} ) ,
126
- ) ;
127
+ ) . filter ( d => d . x !== undefined && d . y !== undefined ) ;
127
128
const dataFormatted = orderBy (
128
129
data
129
130
. map ( d => {
@@ -286,7 +287,7 @@ export function Graph(props: Props) {
286
287
regionData . indicators [ refXIndicatorIndex ] . yearlyData . length - 1
287
288
] ?. value ;
288
289
const xMaxValue = keepAxisSame
289
- ? ( max ( xFullArray ) as number )
290
+ ? ( maxBy ( fullArray , d => d . x ) ?. x as number )
290
291
: maxBy ( dataFormatted , d => d . xVal )
291
292
? refXVal && showReference
292
293
? ( maxBy ( dataFormatted , d => d . xVal ) ?. xVal as number ) > refXVal
@@ -295,7 +296,7 @@ export function Graph(props: Props) {
295
296
: ( maxBy ( dataFormatted , d => d . xVal ) ?. xVal as number )
296
297
: 0 ;
297
298
const xMinValue = keepAxisSame
298
- ? ( min ( xFullArray ) as number )
299
+ ? ( minBy ( fullArray , d => d . x ) ?. x as number )
299
300
: minBy ( dataFormatted , d => d . xVal )
300
301
? refXVal && showReference
301
302
? ( minBy ( dataFormatted , d => d . xVal ) ?. xVal as number ) < refXVal
@@ -324,7 +325,7 @@ export function Graph(props: Props) {
324
325
regionData . indicators [ refYIndicatorIndex ] . yearlyData . length - 1
325
326
] ?. value ;
326
327
const yMaxValue = keepAxisSame
327
- ? ( max ( yFullArray ) as number )
328
+ ? ( maxBy ( fullArray , d => d . y ) ?. y as number )
328
329
: maxBy ( dataFormatted , d => d . yVal )
329
330
? refYVal && showReference
330
331
? ( maxBy ( dataFormatted , d => d . yVal ) ?. yVal as number ) > refYVal
@@ -333,7 +334,7 @@ export function Graph(props: Props) {
333
334
: ( maxBy ( dataFormatted , d => d . yVal ) ?. yVal as number )
334
335
: 0 ;
335
336
const yMinValue = keepAxisSame
336
- ? ( min ( yFullArray ) as number )
337
+ ? ( minBy ( fullArray , d => d . y ) ?. y as number )
337
338
: minBy ( dataFormatted , d => d . yVal )
338
339
? refYVal && showReference
339
340
? ( minBy ( dataFormatted , d => d . yVal ) ?. yVal as number ) < refYVal
0 commit comments