Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasaifee42 committed Mar 25, 2024
1 parent b276f89 commit 68152a7
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/GrapherComponent/ScatterPlot/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { scaleOrdinal, scaleLinear, scaleThreshold, scaleSqrt } from 'd3-scale';
import minBy from 'lodash.minby';
import UNDPColorModule from 'undp-viz-colors';
import flattenDeep from 'lodash.flattendeep';
import min from 'lodash.min';
import { Tooltip } from '../../Components/Tooltip';
import {
CountryGroupDataType,
Expand Down Expand Up @@ -106,24 +105,26 @@ export function Graph(props: Props) {
.range([0.25, 30])
.nice()
: undefined;
const xFullArray = flattenDeep(
const fullArray = flattenDeep(
data.map(d => {
const xIndicatorIndex = d.indicators.findIndex(
el => xIndicatorMetaData.DataKey === el.indicator,
);
const arr = d.indicators[xIndicatorIndex].yearlyData.map(el => el.value);
return arr;
}),
);
const yFullArray = flattenDeep(
data.map(d => {
const xArr = d.indicators[xIndicatorIndex]?.yearlyData.map(
el => el.value,
);
const yIndicatorIndex = d.indicators.findIndex(
el => yIndicatorMetaData.DataKey === el.indicator,
);
const arr = d.indicators[yIndicatorIndex].yearlyData.map(el => el.value);
return arr;
const yArr = d.indicators[yIndicatorIndex]?.yearlyData.map(
el => el.value,
);
return {
x: max(xArr),
y: max(yArr),
};
}),
);
).filter(d => d.x !== undefined && d.y !== undefined);
const dataFormatted = orderBy(
data
.map(d => {
Expand Down Expand Up @@ -286,7 +287,7 @@ export function Graph(props: Props) {
regionData.indicators[refXIndicatorIndex].yearlyData.length - 1
]?.value;
const xMaxValue = keepAxisSame
? (max(xFullArray) as number)
? (maxBy(fullArray, d => d.x)?.x as number)
: maxBy(dataFormatted, d => d.xVal)
? refXVal && showReference
? (maxBy(dataFormatted, d => d.xVal)?.xVal as number) > refXVal
Expand All @@ -295,7 +296,7 @@ export function Graph(props: Props) {
: (maxBy(dataFormatted, d => d.xVal)?.xVal as number)
: 0;
const xMinValue = keepAxisSame
? (min(xFullArray) as number)
? (minBy(fullArray, d => d.x)?.x as number)
: minBy(dataFormatted, d => d.xVal)
? refXVal && showReference
? (minBy(dataFormatted, d => d.xVal)?.xVal as number) < refXVal
Expand Down Expand Up @@ -324,7 +325,7 @@ export function Graph(props: Props) {
regionData.indicators[refYIndicatorIndex].yearlyData.length - 1
]?.value;
const yMaxValue = keepAxisSame
? (max(yFullArray) as number)
? (maxBy(fullArray, d => d.y)?.y as number)
: maxBy(dataFormatted, d => d.yVal)
? refYVal && showReference
? (maxBy(dataFormatted, d => d.yVal)?.yVal as number) > refYVal
Expand All @@ -333,7 +334,7 @@ export function Graph(props: Props) {
: (maxBy(dataFormatted, d => d.yVal)?.yVal as number)
: 0;
const yMinValue = keepAxisSame
? (min(yFullArray) as number)
? (minBy(fullArray, d => d.y)?.y as number)
: minBy(dataFormatted, d => d.yVal)
? refYVal && showReference
? (minBy(dataFormatted, d => d.yVal)?.yVal as number) < refYVal
Expand Down

0 comments on commit 68152a7

Please sign in to comment.