-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
- Loading branch information
Showing
8 changed files
with
97 additions
and
90 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
{ | ||
"title": "Status", | ||
"peer": "Peer", | ||
"peers": "Peers", | ||
"addresses": "Addresses", | ||
"nodeInfo": "Node Info", | ||
"cid": "CID", | ||
"version": "Version", | ||
"advanced": "Advanced", | ||
"publicKey": "Public Key", | ||
"upSpeed": "Up speed", | ||
"downSpeed": "Down speed", | ||
"spaceUsed": "Space used", | ||
"bandwidthOverTime": "Bandwidth over time", | ||
"bandwidthByPeer": "Bandwidth by peer", | ||
"distributionOfPeers": "Distribution of peers" | ||
"distributionOfPeers": "Distribution of peers", | ||
"rateIn": "Rate In", | ||
"rateOut": "Rate Out", | ||
"totalIn": "Total In", | ||
"totalOut": "Total Out", | ||
"more": "...and {{count}} more" | ||
} |
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
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 |
---|---|---|
@@ -1,78 +1,70 @@ | ||
import React, { Component } from 'react' | ||
import React from 'react' | ||
import { translate } from 'react-i18next' | ||
import { Title } from './Commons' | ||
import { Pie } from 'react-chartjs-2' | ||
import { connect } from 'redux-bundler-react' | ||
import PropTypes from 'prop-types' | ||
import Box from '../components/box/Box' | ||
|
||
export class CountryChart extends Component { | ||
static propTypes = { | ||
peerLocations: PropTypes.object.isRequired | ||
} | ||
|
||
render () { | ||
const { peerLocations } = this.props | ||
|
||
const countryLabels = {} | ||
const countsByCountry = {} | ||
const CountryChart = ({ t, peerLocations, className }) => { | ||
const countryLabels = {} | ||
const countsByCountry = {} | ||
|
||
Object.keys(peerLocations).forEach(peerId => { | ||
const { country_code: code, country_name: label } = peerLocations[peerId] | ||
countsByCountry[code] = (countsByCountry[code] || 0) + 1 | ||
countryLabels[code] = label | ||
}) | ||
Object.keys(peerLocations).forEach(peerId => { | ||
const { country_code: code, country_name: label } = peerLocations[peerId] | ||
countsByCountry[code] = (countsByCountry[code] || 0) + 1 | ||
countryLabels[code] = label | ||
}) | ||
|
||
const countryRanking = Object.keys(countsByCountry).sort((a, b) => { | ||
return countsByCountry[b] - countsByCountry[a] | ||
}) | ||
const countryRanking = Object.keys(countsByCountry).sort((a, b) => { | ||
return countsByCountry[b] - countsByCountry[a] | ||
}) | ||
|
||
const totalCountries = Object.keys(peerLocations).length | ||
const totalCountries = Object.keys(peerLocations).length | ||
|
||
let data | ||
let data | ||
|
||
if (countryRanking.length < 5) { | ||
data = countryRanking | ||
.map(code => Math.round((countsByCountry[code] / totalCountries) * 100)) | ||
} else { | ||
data = countryRanking | ||
.slice(0, 3) | ||
.map(code => Math.round((countsByCountry[code] / totalCountries) * 100)) | ||
if (countryRanking.length < 5) { | ||
data = countryRanking | ||
.map(code => Math.round((countsByCountry[code] / totalCountries) * 100)) | ||
} else { | ||
data = countryRanking | ||
.slice(0, 3) | ||
.map(code => Math.round((countsByCountry[code] / totalCountries) * 100)) | ||
|
||
data = data.concat(100 - data.reduce((total, p) => total + p)) | ||
} | ||
data = data.concat(100 - data.reduce((total, p) => total + p)) | ||
} | ||
|
||
const datasets = [{ | ||
data, | ||
backgroundColor: ['#69c4cd', '#f39031', '#ea5037', '#3e9096'], | ||
label: 'Peer Countries' | ||
}] | ||
const datasets = [{ | ||
data, | ||
backgroundColor: ['#69c4cd', '#f39031', '#ea5037', '#3e9096'], | ||
label: 'Peer Countries' | ||
}] | ||
|
||
const options = { | ||
responsive: true, | ||
legend: { | ||
display: true, | ||
position: 'bottom' | ||
} | ||
const options = { | ||
responsive: true, | ||
legend: { | ||
display: true, | ||
position: 'bottom' | ||
} | ||
} | ||
|
||
let labels | ||
|
||
if (countryRanking.length < 5) { | ||
labels = countryRanking.map(code => countryLabels[code]) | ||
} else { | ||
labels = countryRanking | ||
.slice(0, 3) | ||
.map(code => countryLabels[code]) | ||
.concat('Other') | ||
} | ||
let labels | ||
|
||
return ( | ||
<Box className={this.props.className}> | ||
<Title>Distribution of peers</Title> | ||
<Pie data={{ datasets, labels }} options={options} /> | ||
</Box> | ||
) | ||
if (countryRanking.length < 5) { | ||
labels = countryRanking.map(code => countryLabels[code]) | ||
} else { | ||
labels = countryRanking | ||
.slice(0, 3) | ||
.map(code => countryLabels[code]) | ||
.concat('Other') | ||
} | ||
|
||
return ( | ||
<Box className={className}> | ||
<Title>{t('distributionOfPeers')}</Title> | ||
<Pie data={{ datasets, labels }} options={options} /> | ||
</Box> | ||
) | ||
} | ||
|
||
export default connect('selectPeerLocations', CountryChart) | ||
export default connect('selectPeerLocations', translate('status')(CountryChart)) |
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
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
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
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