From 78c544531a00928157ea3f2df2b6e1e45726b0b5 Mon Sep 17 00:00:00 2001 From: Juano Date: Thu, 4 Apr 2024 16:32:58 -0400 Subject: [PATCH] donut chart follows selected fiscal year --- src/components/BeApp.ts | 2 +- src/components/charts/BeMapDonutChart.ts | 14 +++++++------- src/state/State.ts | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/BeApp.ts b/src/components/BeApp.ts index 2ee0679..9d5eeb4 100644 --- a/src/components/BeApp.ts +++ b/src/components/BeApp.ts @@ -158,7 +158,7 @@ export class BeApp extends StateProvider { > ` : ''} - ${this.state.agencyDisbursementsForSelectedCountryAndLatestFY + ${this.state.agencyDisbursementsForSelectedCountryAndFY ? html`

${this.state.selectedCountryFormatted}: Overview

diff --git a/src/components/charts/BeMapDonutChart.ts b/src/components/charts/BeMapDonutChart.ts index 01b50bb..ecf952f 100644 --- a/src/components/charts/BeMapDonutChart.ts +++ b/src/components/charts/BeMapDonutChart.ts @@ -72,20 +72,20 @@ 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]) } ] @@ -93,10 +93,10 @@ export class BeMapDonutChart extends StateProvider { } 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; @@ -132,7 +132,7 @@ export class BeMapDonutChart extends StateProvider { - FY${this.state.latestFY} Total: + FY${this.state.selectedFiscalYear} Total: ${USD_FORMATTER.format(total)} diff --git a/src/state/State.ts b/src/state/State.ts index 7f7e5b9..671ed2e 100644 --- a/src/state/State.ts +++ b/src/state/State.ts @@ -174,17 +174,17 @@ export class State { return this.fiscalYears[this.fiscalYears.length - 1]; } - get agencyDisbursementsForSelectedCountryAndLatestFY(): + get agencyDisbursementsForSelectedCountryAndFY(): | Record | 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]; } );