-
Notifications
You must be signed in to change notification settings - Fork 1
BarChartController Class
The BarChartController class is part of the controllers package
(package org.example.globalgoodsindex.controllers) .
It manages a BarChart that dynamically displays data based on selected products and salaries. It allows users to see how many products can be purchased with the average net salary in different countries. The class listens for changes in product and salary selection, updates the chart, and refreshes the UI when the language changes.
Initializes the BarChart by setting up listeners for products, salaries, and language changes.
- Binds axis labels to localized strings.
- Sets up listeners to track changes in product and salary selections.
- Sets up a listener for language changes to refresh the UI when necessary.
Binds the x and y-axis labels to localized strings.
- Uses
L10N.createStringBinding()to bind the axis labels to the appropriate strings for "country" and "amount".
Sets up listeners to track product selection changes.
- Adds a listener to each product’s selection property. If a product is selected, it triggers the
addProductToChart()method to add the product to the chart. If deselected, it calls theremoveProductFromChart()method to remove the product from the chart.
Sets up listeners to track country selection changes.
- Adds a listener to each salary’s selection property. If a salary (country) is selected, it triggers the
addSalariesToChart()method to add the salary data to the chart. If deselected, it calls theremoveSalariesFromChart()method to remove the salary data.
Sets up a listener to refresh the UI when the language changes.
- Listens for changes to the y-axis label and calls the
refreshUI()method to update the chart with the new language.
Refreshes the entire BarChart UI.
- Clears the chart and re-adds all selected products and salaries.
- This method is called when the language changes to update the UI.
Adds a data point to the chart for a product and salary, calculating how many units of the product can be purchased with the salary.
- Retrieves the product price for the given salary's country. If the price is invalid (less than 0), it shows a notification to the user(toast message) and exits.
- Calculates the number of products that can be purchased using the salary and price.
- Creates a data point
(XYChart.Data<String, Number>)with:-
XValue: The country name (salary). -
YValue: The number of products purchasable.
-
- Adds the data point to the chart and attaches a tooltip showing detailed information (salary, product price, and products count).
Creates a Tooltip displaying salary, product price, and purchasable quantity.
- Constructs a tooltip with formatted information about salary, product price, and how many products can be purchased with the salary.
new Tooltip(countryName, productName, salary, price, productsCount);