2021-01-25 08:56:02 +00:00
|
|
|
import React, {useEffect, useState} from 'react';
|
|
|
|
|
2021-01-25 09:40:37 +00:00
|
|
|
import {ResponsivePie} from '@nivo/pie';
|
|
|
|
import {queryAssets} from '../api/bbgo';
|
2021-01-25 10:29:31 +00:00
|
|
|
import {currencyColor} from '../src/utils';
|
2021-01-25 08:56:02 +00:00
|
|
|
|
|
|
|
function reduceAssetsBy(assets, field, minimum) {
|
|
|
|
let as = []
|
|
|
|
|
|
|
|
let others = {id: "others", labels: "others", value: 0.0}
|
|
|
|
for (let key in assets) {
|
|
|
|
if (assets[key]) {
|
|
|
|
let a = assets[key]
|
|
|
|
let value = a[field]
|
|
|
|
|
|
|
|
if (value < minimum) {
|
|
|
|
others.value += value
|
|
|
|
} else {
|
|
|
|
as.push({
|
|
|
|
id: a.currency,
|
|
|
|
label: a.currency,
|
|
|
|
color: currencyColor(a.currency),
|
|
|
|
value: Math.round(value, 1),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return as
|
|
|
|
}
|
|
|
|
|
2021-01-25 10:29:31 +00:00
|
|
|
export default function TotalAssetsPie() {
|
2021-01-25 08:56:02 +00:00
|
|
|
const [assets, setAssets] = useState({})
|
|
|
|
|
2021-01-25 09:40:37 +00:00
|
|
|
useEffect(() => {
|
|
|
|
queryAssets((assets) => {
|
|
|
|
setAssets(assets)
|
|
|
|
})
|
2021-01-25 08:56:02 +00:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
return <ResponsivePie
|
|
|
|
data={reduceAssetsBy(assets, "inUSD", 2)}
|
2021-02-05 04:41:37 +00:00
|
|
|
margin={{top: 40, right: 80, bottom: 80, left: 0}}
|
2021-01-25 08:56:02 +00:00
|
|
|
padding={0.2}
|
|
|
|
innerRadius={0.8}
|
|
|
|
padAngle={1.0}
|
2021-01-26 08:35:21 +00:00
|
|
|
valueFormat=" >-$f"
|
2021-01-25 08:56:02 +00:00
|
|
|
colors={{datum: 'data.color'}}
|
|
|
|
// colors={{scheme: 'nivo'}}
|
2021-01-26 08:35:21 +00:00
|
|
|
cornerRadius={0.1}
|
2021-01-25 08:56:02 +00:00
|
|
|
borderWidth={1}
|
|
|
|
borderColor={{from: 'color', modifiers: [['darker', 0.2]]}}
|
|
|
|
radialLabelsSkipAngle={10}
|
|
|
|
radialLabelsTextColor="#333333"
|
|
|
|
radialLabelsLinkColor={{from: 'color'}}
|
2021-01-29 03:42:46 +00:00
|
|
|
sliceLabelsSkipAngle={30}
|
2021-01-25 08:56:02 +00:00
|
|
|
sliceLabelsTextColor="#fff"
|
|
|
|
legends={[
|
|
|
|
{
|
2021-01-25 10:29:31 +00:00
|
|
|
anchor: 'right',
|
|
|
|
direction: 'column',
|
2021-01-25 08:56:02 +00:00
|
|
|
justify: false,
|
2021-01-26 08:35:21 +00:00
|
|
|
translateX: 30,
|
2021-01-25 10:29:31 +00:00
|
|
|
translateY: 0,
|
|
|
|
itemsSpacing: 5,
|
|
|
|
itemWidth: 120,
|
|
|
|
itemHeight: 24,
|
2021-01-25 08:56:02 +00:00
|
|
|
itemTextColor: '#999',
|
|
|
|
itemOpacity: 1,
|
|
|
|
symbolSize: 18,
|
|
|
|
symbolShape: 'circle',
|
|
|
|
effects: [
|
|
|
|
{
|
|
|
|
on: 'hover',
|
|
|
|
style: {
|
|
|
|
itemTextColor: '#000'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
}
|