Class StatistiqueController

java.lang.Object
com.esprit.controllers.series.StatistiqueController
All Implemented Interfaces:
javafx.fxml.Initializable

public class StatistiqueController extends Object implements javafx.fxml.Initializable
Manages user interaction with the FXML file "/ui//ui/StatistiqueView.fxml". It initializes and populates a BarChart, PieChart, or BorderPane depending on the selected category from the ComboBox. The controller also handles events such as closing the application and updating the PieChart data. Additionally, it provides methods for showing the BarChart and PieChart graphs.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private javafx.scene.layout.BorderPane
     
    private static final Logger
     
    private Map<Category,Long>
     
    private javafx.scene.control.ComboBox<String>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private javafx.scene.chart.BarChart<String,Number>
    createBarChart(Map<Category,Long> statistics, int limit)
    Creates a bar chart based on category-related data, limiting the number of categorys displayed to a specified value.
    private void
    createToolTips(javafx.scene.chart.PieChart pc)
    Generates and installs tooltips for each data point in a pie chart, updating the text within the tooltip whenever the pie value changes.
    void
    handleClose(javafx.event.ActionEvent actionEvent)
    Terminates the application by calling `System.exit(0)`.
    private void
    Displays a bar chart for statistics passed as an argument and with a specified limit of 20.
    private void
    handleShowPieChart(javafx.event.ActionEvent event)
    1) retrieves category statistics from an implementation class, 2) prints the statistics to the console, and 3) creates and displays a pie chart representing the data using the `showPieChart()` method.
    private void
    Handles the display of category statistics when the user selects "Statistiques de catégorie" from the combo box.
    void
    handleUpdatePieData(javafx.event.ActionEvent actionEvent)
    Updates the value of a pie chart by multiplying its current value by 1.10 and setting it back to the chart.
    void
    Initializes an unspecified object or system.
    void
    initialize(URL url, ResourceBundle resourceBundle)
    Initializes a ComboBox with category options, sets the selected option to "Statistiques of category", and retrieves and maps category statistics from an service implementation to display in a bar chart with a limit of 20 categorys.
    private void
    Takes a map of category-specific count data and displays it as a bar chart.
    private void
    showBarChart(Map<Category,Long> statistics, int limit)
    Creates a bar chart from a map of category-related data, limiting the number of categorys displayed based on an input parameter.
    private void
    Generates a pie chart based on map data, adds tooltips and menu items to the chart, and displays it in the center of a BorderPane.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • statisticsComboBox

      private javafx.scene.control.ComboBox<String> statisticsComboBox
    • statistics

      private Map<Category,Long> statistics
    • borderPane

      private javafx.scene.layout.BorderPane borderPane
  • Constructor Details

    • StatistiqueController

      public StatistiqueController()
  • Method Details

    • createBarChart

      private javafx.scene.chart.BarChart<String,Number> createBarChart(Map<Category,Long> statistics, int limit)
      Creates a bar chart based on category-related data, limiting the number of categorys displayed to a specified value. It generates XY chart data series and installs tooltips for each data point.
      Parameters:
      statistics - map of categorys and their corresponding number of occurrences, which is used to generate the data series for the bar chart.

      - `statistics`: a map containing category-wise statistical data, where each key is a category and the value is the number of occurrences of that category.

      limit - maximum number of categorys to be plotted on the graph, and it is used to control the amount of data added to the chart through the `XYChart.Data` array.
    • showBarChart

      private void showBarChart(Map<Category,Long> statistics, int limit)
      Creates a bar chart from a map of category-related data, limiting the number of categorys displayed based on an input parameter. It adds data points to the chart and displays tooltips for each point.
      Parameters:
      statistics - Map containing statistics of categorys, where each key is a category and value is the number of occurrences of that category.

      - `Map<Category, Long> statistics`: A map containing categorys as keys and their corresponding number of occurrences as values.

      limit - maximum number of categorys to be displayed on the bar chart, and it is used to control the number of data points added to the graph during the loop.
    • initialize

      public void initialize(URL url, ResourceBundle resourceBundle)
      Initializes a ComboBox with category options, sets the selected option to "Statistiques of category", and retrieves and maps category statistics from an service implementation to display in a bar chart with a limit of 20 categorys.
      Specified by:
      initialize in interface javafx.fxml.Initializable
      Parameters:
      url - URL of a resource that provides the statistics data to be displayed in the graphical user interface.

      - Type: URL representing a web page with category statistics data.

      resourceBundle - application's resource bundle, which contains key-value pairs of localized messages and resources that can be used to display text and other data to the user.

      - `resourceBundle`: A ResourceBundle object containing key-value pairs representing category names and their corresponding statistics.

      Note: The `resourceBundle` is not explicitly mentioned in the code snippet provided, but it is implied based on the context of the function.

    • handleShowStatistics

      private void handleShowStatistics()
      Handles the display of category statistics when the user selects "Statistiques de catégorie" from the combo box. It retrieves the category statistics from an implementation of an interface `IServiceCategoryImpl`, maps them to a bar chart, and displays the chart in the center of the border pane.
    • handleShowBarChart

      private void handleShowBarChart()
      Displays a bar chart for statistics passed as an argument and with a specified limit of 20.
    • handleShowPieChart

      private void handleShowPieChart(javafx.event.ActionEvent event)
      1) retrieves category statistics from an implementation class, 2) prints the statistics to the console, and 3) creates and displays a pie chart representing the data using the `showPieChart()` method.
      Parameters:
      event - occurrence of a button press event that triggers the execution of the function.

      - Event type: `ActionEvent` - Target object: Undefined (as `event` is not referenced directly in the function body)

    • showPieChart

      private void showPieChart(Map<Category,Long> statistics)
      Generates a pie chart based on map data, adds tooltips and menu items to the chart, and displays it in the center of a BorderPane.
      Parameters:
      statistics - map of categorys and their corresponding counts, which is used to populate the data list for the pie chart.

      - `Map<Category, Long> statistics`: A map that associates a category with its count. The categorys are identified by `Category`, and the count is represented by a long value.

    • showBarChart

      private void showBarChart(Map<Category,Long> statistics)
      Takes a map of category-specific count data and displays it as a bar chart.
      Parameters:
      statistics - map of category-specific long values that will be displayed as bars on the bar chart.
    • createToolTips

      private void createToolTips(javafx.scene.chart.PieChart pc)
      Generates and installs tooltips for each data point in a pie chart, updating the text within the tooltip whenever the pie value changes.
      Parameters:
      pc - PieChart object that the function operates on, providing the data and nodes to create tooltips for.

      - `PieChart`: Represents a pie chart component - `getData()`: Returns a list of data points for the pie chart - `pieValueProperty()`: A property that holds the value of each data point as a double value.

    • handleClose

      public void handleClose(javafx.event.ActionEvent actionEvent)
      Terminates the application by calling `System.exit(0)`.
      Parameters:
      actionEvent - event that triggered the `handleClose()` function to execute, and it is passed as an argument to the function for further processing or handling.
    • handleUpdatePieData

      public void handleUpdatePieData(javafx.event.ActionEvent actionEvent)
      Updates the value of a pie chart by multiplying its current value by 1.10 and setting it back to the chart. Additionally, it creates tooltips for the chart.
      Parameters:
      actionEvent - event that triggered the `handleUpdatePieData()` method to be executed.

      - `actionEvent` represents an event related to a user interaction with the application. - It is an instance of the `ActionEvent` class in Java.

    • initialize

      public void initialize()
      Initializes an unspecified object or system.