Skip to content

Commit

Permalink
donut chart follows selected fiscal year
Browse files Browse the repository at this point in the history
  • Loading branch information
graphographer committed Apr 4, 2024
1 parent 166857d commit 78c5445
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/BeApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class BeApp extends StateProvider {
></highlightable-map>
`
: ''}
${this.state.agencyDisbursementsForSelectedCountryAndLatestFY
${this.state.agencyDisbursementsForSelectedCountryAndFY
? html` <h4 class="sr-only">
${this.state.selectedCountryFormatted}: Overview
</h4>
Expand Down
14 changes: 7 additions & 7 deletions src/components/charts/BeMapDonutChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@ export class BeMapDonutChart extends StateProvider {
}

get data() {
if (!this.state.agencyDisbursementsForSelectedCountryAndLatestFY) {
if (!this.state.agencyDisbursementsForSelectedCountryAndFY) {
return;
}
return {
labels: Object.keys(
this.state.agencyDisbursementsForSelectedCountryAndLatestFY
this.state.agencyDisbursementsForSelectedCountryAndFY
),
datasets: [
{
data: Object.values(
this.state.agencyDisbursementsForSelectedCountryAndLatestFY
this.state.agencyDisbursementsForSelectedCountryAndFY
),
backgroundColor: Object.keys(
this.state.agencyDisbursementsForSelectedCountryAndLatestFY
this.state.agencyDisbursementsForSelectedCountryAndFY
).map(agency => HIGHLIGHT_COLORS[agency])
}
]
};
}

render() {
if (!this.state.agencyDisbursementsForSelectedCountryAndLatestFY) return '';
if (!this.state.agencyDisbursementsForSelectedCountryAndFY) return '';

const entries = Object.entries(
this.state.agencyDisbursementsForSelectedCountryAndLatestFY
this.state.agencyDisbursementsForSelectedCountryAndFY
).filter(([, amt]) => amt > 0);
const total = entries.reduce((acc, [, amt]) => {
acc += amt;
Expand Down Expand Up @@ -132,7 +132,7 @@ export class BeMapDonutChart extends StateProvider {
</tbody>
<tfoot>
<tr>
<td><b>FY${this.state.latestFY} Total:</b></td>
<td><b>FY${this.state.selectedFiscalYear} Total:</b></td>
<td>${USD_FORMATTER.format(total)}</td>
</tr>
</tfoot>
Expand Down
6 changes: 3 additions & 3 deletions src/state/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ export class State {
return this.fiscalYears[this.fiscalYears.length - 1];
}

get agencyDisbursementsForSelectedCountryAndLatestFY():
get agencyDisbursementsForSelectedCountryAndFY():
| Record<TAgency, number>
| undefined {
const { selectedCountry, latestFY } = this;
const { selectedCountry, selectedFiscalYear } = this;

if (!selectedCountry) return undefined;

const latestDisbursements = mapValues(
this.yearlyDisbursementsByCountryAndAgency[selectedCountry],
agencyDisbursements => {
return agencyDisbursements[latestFY];
return agencyDisbursements[selectedFiscalYear];
}
);

Expand Down

0 comments on commit 78c5445

Please sign in to comment.