-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix assets chart counts not ordered correctly
- Loading branch information
1 parent
2f16524
commit 303d071
Showing
6 changed files
with
94 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 26 additions & 60 deletions
86
apps/visualizator-fe/src/components/AssetsTransferedPlot/AssetsTransferedPlot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/visualizator-fe/src/components/AssetsTransferedPlot/color-pallete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const colorPallete = [ | ||
'#FF6384', | ||
'#36A2EB', | ||
'#FFCE56', | ||
'#4BC0C0', | ||
'#9966FF', | ||
'#FF9F40', | ||
'#E7E9ED', | ||
'#70D6FF', | ||
'#FF70A6', | ||
'#FF9770', | ||
'#FFD670', | ||
'#E9FF70', | ||
'#8AEFFF', | ||
'#B5E85E', | ||
'#FF7575', | ||
'#B28DFF', | ||
'#FFC0CB', | ||
'#C0C0FF', | ||
'#C4FAF8', | ||
'#F2D7D5' | ||
]; |
19 changes: 19 additions & 0 deletions
19
apps/visualizator-fe/src/components/AssetsTransferedPlot/utils/aggregateDataByParachain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TFunction } from 'i18next'; | ||
import { TAssetCounts, TAggregatedData } from '../../../types/types'; | ||
import { getParachainById } from '../../../utils/utils'; | ||
|
||
export const aggregateDataByParachain = (counts: TAssetCounts, t: TFunction): TAggregatedData[] => { | ||
const accumulator: Record<string, TAggregatedData> = {}; | ||
counts.forEach(asset => { | ||
const parachainKey = asset.paraId | ||
? getParachainById(asset.paraId) || `ID ${asset.paraId}` | ||
: t('total'); | ||
if (!accumulator[parachainKey]) { | ||
accumulator[parachainKey] = { parachain: parachainKey, counts: {} }; | ||
} | ||
const currentCount = accumulator[parachainKey].counts[asset.symbol] || 0; | ||
accumulator[parachainKey].counts[asset.symbol] = currentCount + asset.count; | ||
}); | ||
|
||
return Object.values(accumulator); | ||
}; |
17 changes: 17 additions & 0 deletions
17
apps/visualizator-fe/src/components/AssetsTransferedPlot/utils/generateSeries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BarChartSeries } from '@mantine/charts'; | ||
import { TAssetCounts } from '../../../types/types'; | ||
import { colorPallete } from '../color-pallete'; | ||
|
||
export const generateSeries = (counts: TAssetCounts): BarChartSeries[] => { | ||
const seenSymbols = new Set<string>(); | ||
return counts.reduce<BarChartSeries[]>((acc, asset, index) => { | ||
if (!seenSymbols.has(asset.symbol)) { | ||
seenSymbols.add(asset.symbol); | ||
acc.push({ | ||
name: asset.symbol, | ||
color: colorPallete[index % colorPallete.length] | ||
}); | ||
} | ||
return acc; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters