liquid-funding/app/components/dashboard/PledgeAllocationsChart.jsx

79 lines
1.8 KiB
React
Raw Normal View History

2018-12-16 17:59:33 +00:00
import React from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import Typography from '@material-ui/core/Typography'
import { Doughnut } from 'react-chartjs-2'
import { toEther } from '../../utils/conversions'
import { getTokenLabel } from '../../utils/currencies'
2018-12-20 16:23:05 +00:00
import { getColor } from '../../utils/colorSchemes'
2018-12-16 17:59:33 +00:00
const styles = {
card: {
minWidth: 275,
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
fontSize: 14,
},
pos: {
marginBottom: 12,
},
}
const pledgesChartData = pledges => {
const data = []
const labels = []
const backgroundColor = []
2018-12-20 16:23:05 +00:00
pledges.forEach((pledge, idx) => {
2019-01-25 19:31:51 +00:00
const { pledgeId, amount, token } = pledge
2018-12-16 17:59:33 +00:00
const converted = toEther(amount)
data.push(converted)
labels.push(
2019-01-25 19:31:51 +00:00
`pledge ${pledgeId} - ${getTokenLabel(token)}`
2018-12-16 17:59:33 +00:00
)
2018-12-20 16:23:05 +00:00
backgroundColor.push(getColor('Dark2-8', idx))
2018-12-16 17:59:33 +00:00
})
return {
datasets: [
{
data,
backgroundColor,
hoverBackgroundColor: backgroundColor
}
],
labels
}
}
function SimpleCard(props) {
2019-01-25 19:31:51 +00:00
const { classes, title, pledges } = props
2018-12-16 17:59:33 +00:00
return (
2019-01-25 19:31:51 +00:00
<Card className={classes.card}>
<CardContent>
<Typography variant="h5" component="h2">
{title}
</Typography>
<Typography className={classes.pos} color="textSecondary">
How your funds are distributed among pledges
</Typography>
<Doughnut data={pledgesChartData(pledges)} />
</CardContent>
</Card>
2018-12-16 17:59:33 +00:00
)
}
SimpleCard.propTypes = {
classes: PropTypes.object.isRequired,
2019-01-25 19:31:51 +00:00
title: PropTypes.string,
pledges: PropTypes.array.isRequired
2018-12-16 17:59:33 +00:00
}
export default withStyles(styles)(SimpleCard)