Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect policy parameter changes in policy right sidebar and parameter-over-time chart #839

Merged
merged 6 commits into from
Nov 27, 2023

Conversation

abhcs
Copy link
Collaborator

@abhcs abhcs commented Nov 11, 2023

Description

Fixes #53 and fixes #17. The issues are about accurately reflecting changes made through the policy editor inputs (dates, value) in the right sidebar and parameter-over-time chart.

Strategy for fix

The policy right sidebar (#53) and the parameter-over-time chart (#17) display the information in policy.reform.data, directly or via the getReformedParameter() function. I have modified getReformedParameter() so that the end date is also inserted into the reformed parameter, and I have used getReformedParameter() to construct new policy objects (see newReforms() in ParameterEditor.jsx). These changes ensure that the correct information is available to the right sidebar and the chart.

I have modified the input field component so that it does not store unnecessary state and calls the onChange function with the placeholder when the value is deleted from the field. This change was needed for #53.

I have added new logic for generating axis ranges for dates, and used it to update the parameter-over-time chart. This change helps with #17.

Tests

I have checked the behavior of the sidebar and the chart for policy inputs of different types (bool, %, numeric).

🤖 Generated by Copilot at ef787fe

Summary

🚀📈🧹

This pull request improves the functionality and performance of the parameter editing and plotting features in the policy engine app. It adds support for date units in plotly charts, simplifies the input field component, refactors the parameter editor component, enhances the parameter over time component, and optimizes the reform application algorithm.

ParameterEditor
Refines reform data and ID
Autumn of code smell

Walkthrough

  • Improve efficiency of applying reforms to parameter values over time by finding and updating only the first and last indices where the reform value differs from the original value (link)
  • Add "date" as a possible unit for formatting plotly chart axes based on the unit and values of the variable or parameter being plotted, and implement logic for setting the x-axis range to be five years before and after the minimum and maximum years from the values array (link, link)
  • Simplify InputField component by removing unnecessary state variable savedPlaceholder and using placeholder prop as default value when input field is empty, avoiding sending empty strings to onChange prop (link, link, link, link)
  • Extract logic for updating reform data and policy ID based on new parameter value into separate function onChange in ParameterEditor component, and use it for different types of controls (switch, slider, input field), removing unused state variable _ and converting input field value to number (link, link, link, link)
  • Enhance ParameterOverTime component by using getPlotlyAxisFormat function to format x-axis when unit is "date", merging and filtering original and reformed values arrays for both axes, and using dashed line for reformed values trace (link, link, link)

@abhcs abhcs requested a review from nikhilwoodruff November 11, 2023 21:41
@abhcs abhcs changed the title Reflect policy parameter changes in right hand pane and middle chart Reflect policy parameter changes in policy right sidebar and parameter-over-time chart Nov 11, 2023
@nikhilwoodruff
Copy link
Contributor

Thanks for this @abhcs! Just tested it out locally and it's a big improvement.
image

@nikhilwoodruff nikhilwoodruff merged commit 76df5e8 into PolicyEngine:master Nov 27, 2023
1 of 2 checks passed
@abhcs abhcs deleted the fix-issue-53 branch November 27, 2023 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants