Skip to content

Commit

Permalink
fix: turnout percentage graph
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmeets-6575 committed Apr 26, 2024
1 parent 83c1973 commit 3022aa5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3022aa5

Please sign in to comment.