Client Code API¶
Model¶
- client_code.Model.GraphInfo¶
alias of
client_code.Model.GraphData
- client_code.Model.language = 'en'¶
The language for the web app. The locale in
server_code.Model2050Server.translate(). Set to “th” for Thai language example.
- client_code.Model.process_layout_data(data)¶
Take a json payload (data) of the weboutputs_summary_table named range and return a nested data structure of OrderedDict’s such that:
return_value[tab][sub_tab][position] = GraphInfo instance
- where:
tab = string referencing an output tab
sub_tab = string referencing an output sub-tab
position = one of (1-5, “Top”, “Bottom”, “Page”) indicating the position of an output within a sub-tab
GraphInfo instance = The relevant metadata required to built an output
- Returns
Structured data of the layout of the figures in the web app.
- Return type
OrderedDict
- client_code.Model.translate(text)¶
Translate the text into the already selected language. Calls server function
server_code.Model2050Server.translate().- Parameters
text (str) – The text to be translated.
- Returns
The translated text.
- Return type
str
Plots¶
- client_code.Plots.PLOTS_REGISTRY = {'line': <function plot_line>, 'map': <function plot_map>, 'sankey/flow': <function plot_sankey>, 'stacked area with overlying line(s)': <function plot_stacked_area>}¶
Dictionary mapping plot type names to their functions.
- client_code.Plots.format_plot(plot, title)¶
Apply standard formatting to plot. For Anvil Plot objects this must be called before the data attribute of the plot is set.
- client_code.Plots.plot_line(plot, model_solution, output, title, axis_unit)¶
Plots the line plot type of plots. The traces are plotted as individual line plots with markers.
- Parameters
plot (plotly.graph_objects.Figure) – The figure in the anvil app
model_solution (dict) – The solution returned by the model
output (str) – The named range corresponding to the output for this plot
title (str) – The title of the figure
axis_unit (str) – Unit to add as y-axis title
- client_code.Plots.plot_map(plot, model_solution, outputs, title, _=None)¶
Plot the Map type to show land areas over a map of the region.
- Parameters
plot (plotly.graph_objects.Figure) – The figure in the anvil app
model_solution (dict) – The solution returned by the model
outputs (str) – The named ranges corresponding to the outputs for this plot
title (str) – The title of the figure
_ – dummy argument to match interface of other plotting routines
- client_code.Plots.plot_sankey(plot, model_solution, output, title, valuesuffix)¶
Creates and plots a Sankey flow diagram.
- Parameters
plot (plotly.graph_objects.Figure) – The figure in the anvil app
model_solution (dict) – The solution returned by the model
output (str) – The named range corresponding to the output for this plot
title (str) – The title of the figure
valuesuffice (str) – Value passed as valuesuffix to Go.Sankey
- client_code.Plots.plot_stacked_area(plot, model_solution, output, title, axis_unit)¶
Plots the stacked area type of plots. The traces stack on top of each other to make a total.
- Parameters
plot (plotly.graph_objects.Figure) – The figure in the anvil app
model_solution (dict) – The solution returned by the model
output (str) – The named range corresponding to the output for this plot
title (str) – The title of the figure
axis_unit (str) – Unit to add as y-axis title
Main¶
- class client_code.Main.Main(*args: Any, **kwargs: Any)¶
- property expert_mode¶
A boolean property of the current app mode. True if in Expert Mode.
- expert_toggle_click(**event_args)¶
This method is called when the expert_toggle button is clicked.
- get_url_vals()¶
Get lever values from url, if available. Otherwise use defaults.
- pathways_dropdown_change(**event_args)¶
This method is called when an item is selected from the dropdown
- refresh_headers(xs)¶
Update x positions of labels acting as column headers
- reset_button_click(**event_args)¶
This method is called when the button is clicked
- select_figures()¶
Initialise the FiguresPanel and add it to the plot area of the app.
- set_ambition_levers()¶
Set the values of the AmbitionLevers to match the urls.
Updates the values if the LeverGroup is already populated, otherwise populates the LeverGroup.
- set_defaults(years_only=False)¶
Set the url values (for levers and years) to their defaults.
- Parameters
years_only (bool) – True when only changing the start and end year values and leaving the lever values. False also sets levers to defaults.
- set_expert_mode(expert_mode)¶
Change app mode into Expert or back to Standard Mode.
Expert Mode gives the option to select the start and end years for each Ambition Lever and extends the graphs into 2100. Standard Mode resets start and end year values to defaults and removes the ability to edit them and returns the year max to 2050.
- Parameters
expert_mode (bool) – True when converting the app into Expert Mode.
- set_url(inputs=None, start_years=None, end_years=None)¶
Set lever values in the url.
- Parameters
inputs (list) – A list of lever values
- show(**event_args)¶
show event handler. Last function to be called.
- update_graphs()¶
Collect the level values and update the graphs and url hash.
FiguresPanel¶
- class client_code.Main.FiguresPanel.FiguresPanel(*args: Any, **kwargs: Any)¶
- calculate(inputs, start_year, end_year, expert_mode=False)¶
Run the model based on new inputs and build the graphs and warnings.
Args: inputs (list): A list of all the ambition lever values. start_year (list): A list of the start year for each ambition lever. end_year (list): A list of the end year for each ambition lever. expert_mode (bool, optional): Flag to run in expert mode. Defaults to False.
- tab_click(**event_args)¶
This method is called when the button is clicked
LeverGroup¶
- class client_code.Main.LeverGroup.LeverGroup(*args: Any, **kwargs: Any)¶
- arrow_button_click(**event_args)¶
This method is called when the button is clicked
- group_lever_clicked(**event_args)¶
x-refresh event handler for the group level ambition lever
- lever_clicked(**event_args)¶
x-refresh event handler used for ambition levers that are part of the group.
- lever_updated()¶
Update the group lever value when one of the sub-levers is changed.
- show(**event_args)¶
show event handler. Control for any out of range input values that will have been changed.
AmbitionLever¶
- class client_code.Main.AmbitionLever.AmbitionLever(*args: Any, **kwargs: Any)¶
- complete_init(name, value, event_handler, start_year=2020, end_year=2050, tooltips=['', '', '', '', ''], bold=False, click_event_handler=None)¶
Set lever properties
- show(**event_args)¶
show event handler. Expects self.item to be populated with required data for arguments of complete_init.
- show_info(**event_kwargs)¶
Display a popup showing collected tooltip information for the lever