From 3022aa57930733a1d3280998ec5c4ddc93627db5 Mon Sep 17 00:00:00 2001 From: Jasmeet Singh Date: Fri, 26 Apr 2024 13:52:06 +0530 Subject: [PATCH] fix: turnout percentage graph --- .../AnalyticsDelegationSplitGraph.tsx | 4 ++-- .../AnalyticsTurnoutPercentageGraph.tsx | 21 ++++++++++++------- .../AnalyticsVoteSplitGraph.tsx | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsDelegationSplitGraph.tsx b/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsDelegationSplitGraph.tsx index e3f586a340..a2dfcc9113 100644 --- a/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsDelegationSplitGraph.tsx +++ b/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsDelegationSplitGraph.tsx @@ -88,8 +88,8 @@ const AnalyticsDelegationSplitGraph = ({ delegationSplitData, isUsedInAccounts } const tickInterval = Math.ceil(filteredChartData.length / 10); const tickValues = filteredChartData.filter((_, index) => index % tickInterval === 0).map((item) => `${item.index}`); - const minIndex = delegationSplitData[0].index; - const maxIndex = delegationSplitData[delegationSplitData.length - 1].index; + const minIndex = delegationSplitData[0]?.index; + const maxIndex = delegationSplitData[delegationSplitData?.length - 1]?.index; const marks = { [0]: minIndex.toString(), [delegationSplitData.length - 1]: maxIndex.toString() diff --git a/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsTurnoutPercentageGraph.tsx b/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsTurnoutPercentageGraph.tsx index d10dce6526..9fbd40988b 100644 --- a/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsTurnoutPercentageGraph.tsx +++ b/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsTurnoutPercentageGraph.tsx @@ -57,7 +57,11 @@ const AnalyticsTurnoutPercentageGraph = ({ supportData }: IAnalyticsTurnoutPerce useEffect(() => { setIsLoading(true); - setSelectedRange(calculateDefaultRange(supportData.length)); + if (supportData.length > 0) { + setSelectedRange(calculateDefaultRange(supportData.length)); + } else { + setSelectedRange([0, 0]); + } setIsLoading(false); }, [supportData.length]); @@ -67,14 +71,17 @@ const AnalyticsTurnoutPercentageGraph = ({ supportData }: IAnalyticsTurnoutPerce const data = [ { id: 'Turnout', - data: supportData.slice(selectedRange[0], selectedRange[1] + 1).map((item) => ({ - x: item.index, - y: parseFloat(item.percentage).toFixed(2) - })) + data: supportData + .slice(selectedRange[0], selectedRange[1] + 1) + .map((item) => ({ + x: item.index, + y: parseFloat(item.percentage) ? parseFloat(item.percentage).toFixed(2) : null + })) + .filter((item) => item.y !== null) } ]; - const minIndex = supportData[0].index; - const maxIndex = supportData[supportData.length - 1].index; + const minIndex = supportData[0]?.index; + const maxIndex = supportData[supportData?.length - 1]?.index; const marks = { [0]: minIndex.toString(), [supportData.length - 1]: maxIndex.toString() diff --git a/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsVoteSplitGraph.tsx b/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsVoteSplitGraph.tsx index 2c63f16c0c..fc9963983c 100644 --- a/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsVoteSplitGraph.tsx +++ b/src/components/TrackLevelAnalytics/AnalyticsVotingTrends/TrackAnalyticsgraphs/AnalyticsVoteSplitGraph.tsx @@ -94,7 +94,7 @@ const AnalyticsVoteSplitGraph = ({ votesSplitData, isUsedInAccounts, isSmallScre const tickValues = chartData.filter((_, index) => index % tickInterval === 0).map((item) => `${item.index}`); const minIndex = votesSplitData[0]?.index; - const maxIndex = votesSplitData[votesSplitData.length - 1]?.index; + const maxIndex = votesSplitData[votesSplitData?.length - 1]?.index; const marks = { [0]: minIndex.toString(), [votesSplitData.length - 1]: maxIndex.toString()