Skip to content

Commit 68152a7

Browse files
Fix bugs
1 parent b276f89 commit 68152a7

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/GrapherComponent/ScatterPlot/Graph.tsx

+16-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { scaleOrdinal, scaleLinear, scaleThreshold, scaleSqrt } from 'd3-scale';
88
import minBy from 'lodash.minby';
99
import UNDPColorModule from 'undp-viz-colors';
1010
import flattenDeep from 'lodash.flattendeep';
11-
import min from 'lodash.min';
1211
import { Tooltip } from '../../Components/Tooltip';
1312
import {
1413
CountryGroupDataType,
@@ -106,24 +105,26 @@ export function Graph(props: Props) {
106105
.range([0.25, 30])
107106
.nice()
108107
: undefined;
109-
const xFullArray = flattenDeep(
108+
const fullArray = flattenDeep(
110109
data.map(d => {
111110
const xIndicatorIndex = d.indicators.findIndex(
112111
el => xIndicatorMetaData.DataKey === el.indicator,
113112
);
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+
);
120116
const yIndicatorIndex = d.indicators.findIndex(
121117
el => yIndicatorMetaData.DataKey === el.indicator,
122118
);
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+
};
125126
}),
126-
);
127+
).filter(d => d.x !== undefined && d.y !== undefined);
127128
const dataFormatted = orderBy(
128129
data
129130
.map(d => {
@@ -286,7 +287,7 @@ export function Graph(props: Props) {
286287
regionData.indicators[refXIndicatorIndex].yearlyData.length - 1
287288
]?.value;
288289
const xMaxValue = keepAxisSame
289-
? (max(xFullArray) as number)
290+
? (maxBy(fullArray, d => d.x)?.x as number)
290291
: maxBy(dataFormatted, d => d.xVal)
291292
? refXVal && showReference
292293
? (maxBy(dataFormatted, d => d.xVal)?.xVal as number) > refXVal
@@ -295,7 +296,7 @@ export function Graph(props: Props) {
295296
: (maxBy(dataFormatted, d => d.xVal)?.xVal as number)
296297
: 0;
297298
const xMinValue = keepAxisSame
298-
? (min(xFullArray) as number)
299+
? (minBy(fullArray, d => d.x)?.x as number)
299300
: minBy(dataFormatted, d => d.xVal)
300301
? refXVal && showReference
301302
? (minBy(dataFormatted, d => d.xVal)?.xVal as number) < refXVal
@@ -324,7 +325,7 @@ export function Graph(props: Props) {
324325
regionData.indicators[refYIndicatorIndex].yearlyData.length - 1
325326
]?.value;
326327
const yMaxValue = keepAxisSame
327-
? (max(yFullArray) as number)
328+
? (maxBy(fullArray, d => d.y)?.y as number)
328329
: maxBy(dataFormatted, d => d.yVal)
329330
? refYVal && showReference
330331
? (maxBy(dataFormatted, d => d.yVal)?.yVal as number) > refYVal
@@ -333,7 +334,7 @@ export function Graph(props: Props) {
333334
: (maxBy(dataFormatted, d => d.yVal)?.yVal as number)
334335
: 0;
335336
const yMinValue = keepAxisSame
336-
? (min(yFullArray) as number)
337+
? (minBy(fullArray, d => d.y)?.y as number)
337338
: minBy(dataFormatted, d => d.yVal)
338339
? refYVal && showReference
339340
? (minBy(dataFormatted, d => d.yVal)?.yVal as number) < refYVal

0 commit comments

Comments
 (0)