Skip to content

Add loader and refactor JavaScript for improved UX and performance#38

Merged
brichards64 merged 7 commits intoToolDAQ:masterfrom
ekumachidi:ce-monitoring-plots
Dec 9, 2024
Merged

Add loader and refactor JavaScript for improved UX and performance#38
brichards64 merged 7 commits intoToolDAQ:masterfrom
ekumachidi:ce-monitoring-plots

Conversation

@ekumachidi
Copy link
Contributor

This PR improves the user experience and performance of chart rendering by adding a loader indicator and refactoring the JavaScript for better asynchronous handling.

Key changes:

  • Loader indicator:

    • Introduced a spinner during data fetching and plot rendering to improve UX for large charts.
  • Refactor JS for better async handling:

    • Replaced callback-based async code with async/await and Promise for cleaner, more efficient data fetching and plot updates.
    • Improved error handling with try/catch blocks.
    • Streamlined makeplot and updateplot for more reliable chart rendering.
    • Optimized code by removing redundancies and simplifying logic (e.g., plot trace handling and dropdown population).
  • Makes the chart responsive to adjusting display sizes.

* Add divs to better structure monitoring plots
This refactor improves the maintainability of the js code by using modern JavaScript features like async/await and Promise. It also enhances the efficiency of the data processing and plot rendering logic, making the chart updates smoother and more reliable.

Changes introduced:
* Refactored asynchronous data fetching:
Converted gettable function to use Promise and async/await for cleaner and more manageable asynchronous code.
* Improved error handling by using try/catch blocks to handle potential errors during data fetching.
* Improved the plotting logic:
** Streamlined the makeplot and updateplot functions to ensure more efficient data handling.
** Modified the logic that updates plot data (data) by correctly pushing new values into the x and y arrays.
** Refined the handling of Plotly chart updates to properly append new data and refresh the graph.
* General code optimizations:
** Removed redundant code to enhance readability and maintainability.
** Ensured that Plotly traces are only removed when necessary to avoid unnecessary deletions.
** Simplified the logic for clearing previous plot traces before rendering new data.
* Enhanced dropdown handling:
** Refined logic in the updatedropdown function to improve the dropdown population process.
** Improved the handling of the select dropdown events and the plotting of data based on user selection.
For larger charts and visualisations, users get a blank page for a few seconds with no clue anything is happening on the page.
This commit adds a loader indicator during data fetching and plot rendering.
Summary of changes:
* Introduced a loading spinner:
** Added a loader div to the HTML structure, which displays a spinning animation during data fetching or plot rendering.
** Applied CSS for a simple, animated spinner using @Keyframes for smooth rotation.
* Displayed loader during data operations:
** Updated the makeplot and updateplot functions to display the loader when data is being fetched or when the plot is being updated.
** Ensured that the loader is shown while waiting for responses from the server (e.g., during data fetch operations) and hidden once the data is processed and the plot is rendered.

const output = document.getElementById("output");
const tableselect = document.getElementById("tableselect");
const select = document.querySelector('select');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to exist

@brichards64
Copy link
Contributor

please resolve that we seem to have both select and tableselect. select seems not to exist in the html but there are still event listeners and other things in the js. Please resolve

@brichards64 brichards64 merged commit 6199f5e into ToolDAQ:master Dec 9, 2024
@ekumachidi ekumachidi deleted the ce-monitoring-plots branch December 11, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants