Skip to content

Commit

Permalink
Relayer chart performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretSaturn committed Nov 11, 2024
1 parent 60ac67f commit 53eef2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
16 changes: 3 additions & 13 deletions src/pages/analytics/components/RelayerChartWithDateSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,13 @@ export default function RelayerChartWithDateSlider() {
chainMap.set(chainBech32Prefix, (chainMap.get(chainBech32Prefix) || 0) + entry.Transactions)
}

// Prepare an array of { prefix, label } pairs
const prefixLabelPairs = Array.from(chainsSet).map((prefix) => ({
prefix,
label: prefix
}))

// Sort prefixLabelPairs by label alphabetically
prefixLabelPairs.sort((a, b) => a.label.localeCompare(b.label))

// Extract the sorted bech32Prefixes and labels
const sortedBech32Prefixes = prefixLabelPairs.map((pair) => pair.prefix)
const labels = prefixLabelPairs.map((pair) => pair.label)
// Sort the prefixes alphabetically and use them as labels
const labels = Array.from(chainsSet).sort()

// Create datasets for each relayer
const datasets = Array.from(relayersSet).map((relayer) => {
const chainMap = dataMatrix.get(relayer)!
const data = sortedBech32Prefixes.map((prefix) => chainMap.get(prefix) || 0)
const data = labels.map((prefix) => chainMap.get(prefix) || 0)
return {
label: relayer,
data,
Expand Down
22 changes: 5 additions & 17 deletions src/pages/analytics/components/RelayerChartWithProviderSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,18 @@ export default function RelayerChartWithProviderSlider() {
dateMap.set(date, (dateMap.get(date) || 0) + entry.Transactions)
}

// Sort dates
// Sort dates and chains
const sortedDates = Array.from(datesSet).sort((a, b) => new Date(a).getTime() - new Date(b).getTime())

// Prepare an array of { prefix, label } pairs for chains
const prefixLabelPairs = Array.from(chainsSet).map((prefix) => ({
prefix,
label: prefix
}))

// Sort prefixLabelPairs by label alphabetically
prefixLabelPairs.sort((a, b) => a.label.localeCompare(b.label))

// Extract the sorted bech32Prefixes and labels
const sortedBech32Prefixes = prefixLabelPairs.map((pair) => pair.prefix)
const chainLabels = prefixLabelPairs.map((pair) => pair.label)
const sortedChains = Array.from(chainsSet).sort((a, b) => a.localeCompare(b))

// Create datasets for each chain
const datasets = sortedBech32Prefixes.map((chainPrefix, index) => {
const datasets = sortedChains.map((chainPrefix) => {
const dateMap = dataMatrix.get(chainPrefix)!
const data = sortedDates.map((date) => dateMap.get(date) || 0)
return {
label: chainLabels[index],
label: chainPrefix,
data,
backgroundColor: getColorFromChain(chainLabels[index])
backgroundColor: getColorFromChain(chainPrefix)
}
})

Expand Down

0 comments on commit 53eef2d

Please sign in to comment.