Skip to content

Commit e04cb1f

Browse files
authored
fix(condo): DOMA-7291 use original data for pie charts (#3907)
1 parent 2c5db4d commit e04cb1f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

apps/condo/domains/analytics/components/charts/payment/dataMappers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const PaymentByPropertyDataMapper = (paidTitle: string): PaymentChart => new Pay
1717
chart: (viewMode, data) => {
1818
const createdByGroup = groupBy(data, 'createdBy')
1919

20+
const totalSum = data.reduce((prev, curr) => prev + Number(curr.sum), 0)
21+
2022
const series: Array<EchartsSeries> = [{
2123
name: paidTitle,
2224
data: Object.entries(createdByGroup).map(([groupLabel, dataObj]) => ({
@@ -25,7 +27,10 @@ const PaymentByPropertyDataMapper = (paidTitle: string): PaymentChart => new Pay
2527
})).sort((a, b) => b.value - a.value).slice(0, TOP_VALUES),
2628
radius: '75%',
2729
type: viewMode,
28-
label: { show: true, formatter: (e) => e.percent + '%' },
30+
label: {
31+
show: true,
32+
formatter: ({ value }) => totalSum > 0 ? (value / totalSum * 100).toFixed(1) + '%' : '-',
33+
},
2934
}]
3035
return {
3136
legend: [],

apps/condo/domains/analytics/components/charts/resident/dataMappers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ type ResidentChartCardType = (props: ResidentChartCardProps) => React.ReactEleme
1919
const ResidentByPropertyDataMapper = (residentsTitle: string): ResidentChart => new ResidentChart({
2020
pie: {
2121
chart: (viewMode, data) => {
22+
const totalCount = data.reduce((prev, curr) => prev + Number(curr.count), 0)
23+
2224
const series: Array<EchartsSeries> = [{
2325
type: viewMode,
2426
name: residentsTitle,
2527
radius: '75%',
26-
label: { show: true, formatter: (e) => e.percent + '%' },
28+
label: {
29+
show: true,
30+
formatter: ({ value }) => totalCount > 0 ? (Number(value) / totalCount * 100).toFixed(0) + '%' : '-',
31+
},
2732
data: data.slice(0, TOP_VALUES).map(resident => ({ value: resident.count, name: resident.address })),
2833
}]
2934

0 commit comments

Comments
 (0)