Skip to content

Commit a3ccba8

Browse files
Harastar1001ihomp
andauthored
fix: combined sales and volumes charts (#230)
* fix: combined sales and volumes charts * fix: minor issues(size of chart and label) * Fix for translations, add currency to axis, condition for currency in label and axis --------- Co-authored-by: Viacheslav Bakshaev <bakshaev@protonmail.ch>
1 parent 96f0ede commit a3ccba8

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

Diff for: components/SimpleChart.js

+45-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const locales = {
2222
}
2323
}
2424

25-
export default function PriceChart({ data }) {
25+
export default function PriceChart({ data, combined, currency }) {
2626
const { i18n } = useTranslation()
2727
const { theme } = useTheme()
2828

@@ -55,14 +55,36 @@ export default function PriceChart({ data }) {
5555
type: 'datetime',
5656
labels: formatForXaxisLabels
5757
},
58-
yaxis: {
59-
labels: {
60-
formatter: (val) => {
61-
return niceNumber(val, 0, 0)
62-
}
63-
},
64-
tickAmount: 5
65-
},
58+
yaxis: combined
59+
? [
60+
{
61+
title: { text: data[0].name },
62+
labels: {
63+
formatter: (val) => {
64+
return niceNumber(val, 0, 0)
65+
}
66+
},
67+
tickAmount: 5
68+
},
69+
{
70+
title: { text: data[1].name },
71+
opposite: true,
72+
labels: {
73+
formatter: (val) => {
74+
return niceNumber(val, 0, 0) + (currency ? ' ' + currency.toUpperCase() : '')
75+
}
76+
},
77+
tickAmount: 5
78+
}
79+
]
80+
: {
81+
labels: {
82+
formatter: (val) => {
83+
return niceNumber(val, 0, 0)
84+
}
85+
},
86+
tickAmount: 5
87+
},
6688
chart: {
6789
id: 'simple-chart',
6890
type: 'area',
@@ -160,7 +182,12 @@ export default function PriceChart({ data }) {
160182
}
161183
},
162184
y: {
163-
formatter: (val) => niceNumber(val, 0, 0)
185+
formatter: (val, { seriesIndex }) => {
186+
if (combined && seriesIndex === 1) {
187+
return niceNumber(val, 0, 0) + (currency ? ' ' + currency.toUpperCase() : '')
188+
}
189+
return niceNumber(val, 0, 0)
190+
}
164191
},
165192
theme
166193
},
@@ -174,12 +201,14 @@ export default function PriceChart({ data }) {
174201
//colors: ['#006B7D'],
175202
}
176203

177-
const series = [
178-
{
179-
name: '',
180-
data
181-
}
182-
]
204+
const series = combined
205+
? data
206+
: [
207+
{
208+
name: '',
209+
data
210+
}
211+
]
183212

184213
return (
185214
<>

Diff for: pages/nft-volumes/index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ export default function NftVolumes({
877877

878878
const chartDivStyle =
879879
windowWidth > 600
880-
? { flexGrow: 0, flexBasis: 'calc(50% - 20px)' }
880+
? { flexGrow: 0, flexBasis: 'calc(60% - 20px)' }
881881
: { width: '100%', marginLeft: 0, marginRight: '10px' }
882882

883883
const collectionNameText = (data) => {
@@ -1072,16 +1072,20 @@ export default function NftVolumes({
10721072
) : (
10731073
<>
10741074
{chartIssuers.length > 0 && chartVolumes.length > 0 && (
1075-
<div className="flex" style={{ marginLeft: '10px' }}>
1076-
<div style={chartDivStyle}>
1077-
<h3>{t('sales-chart', { ns: 'nft-volumes' })}</h3>
1078-
<SimpleChart data={chartIssuers} />
1079-
</div>
1075+
<div className="flex" style={{ marginLeft: '10px', justifyContent: 'center' }}>
10801076
<div style={chartDivStyle}>
10811077
<h3>
1082-
{t('volumes-chart', { ns: 'nft-volumes' })} ({convertCurrency?.toUpperCase()})
1078+
{t('sales-chart', { ns: 'nft-volumes' })} / {t('volumes-chart', { ns: 'nft-volumes' })} (
1079+
{convertCurrency?.toUpperCase()})
10831080
</h3>
1084-
<SimpleChart data={chartVolumes} />
1081+
<SimpleChart
1082+
currency={selectedCurrency}
1083+
data={[
1084+
{ name: t('table.sales'), data: chartIssuers },
1085+
{ name: t('table.volume'), data: chartVolumes }
1086+
]}
1087+
combined={true}
1088+
/>
10851089
</div>
10861090
</div>
10871091
)}

0 commit comments

Comments
 (0)