widgets
main.widgets
¤
Widgets to be used to interact with the plots.
Functions¤
add_bar_callback_to_button(button, dates, plot, chart_months)
¤
Add the JS callback to a button to update a plot x_range and picker dates.
'window.skip_bar_picker_callback = true' is used to prevent the callback in add_bar_callback_to_date_pickers from being run concurrently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
button
|
Button
|
The button to add the callback to |
required |
dates
|
tuple[datetime, datetime]
|
Tuple of datetimes used to update the plot x_range |
required |
plot
|
figure
|
The plot the button will be used to update |
required |
chart_months
|
list[str]
|
list of months for x-axis in bar chart |
required |
Source code in main/widgets.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
add_bar_callback_to_date_pickers(start_picker, end_picker, plot, chart_months)
¤
Add the JS callback to start and end date pickers to update a bar plot x_range.
As the x-range is categorical, we supply the list of formatted chart_months, index the list using the dates selected in the date pickers, and use the indexed list to update x_range.factors. '(window.skip_bar_picker_callback)' is used to prevent interference when the plot is updated using the buttons (otherwise when the buttons update the date pickers, this callback is also run).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_picker
|
DatePicker
|
The start date picker to add the callback to |
required |
end_picker
|
DatePicker
|
The end date picker to add the callback to |
required |
plot
|
figure
|
The plot modified by the date pickers |
required |
chart_months
|
list[str]
|
list of months for x-axis in bar chart |
required |
Source code in main/widgets.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
add_callback_to_button(button, dates, plot, start_picker, end_picker, include_future_dates=True)
¤
Add the JS callback to a button to update a plot x_range and picker dates.
If future dates are not included (e.g. for cost recovery plots), the end date of the x_range is the last day of the previous month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
button
|
Button
|
The button to add the callback to |
required |
dates
|
tuple[datetime, datetime]
|
Tuple of datetimes used to update the plot x_range |
required |
plot
|
figure
|
The plot the button will be used to update |
required |
start_picker
|
DatePicker
|
The start date picker to update |
required |
end_picker
|
DatePicker
|
The end date picker to update |
required |
include_future_dates
|
bool
|
Whether to include future dates in the timeseries plot |
True
|
Source code in main/widgets.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
add_timeseries_callback_to_date_pickers(start_picker, end_picker, plot)
¤
Add the JS callback to start and end date pickers to update a plot x_range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_picker
|
DatePicker
|
The start date picker to add the callback to |
required |
end_picker
|
DatePicker
|
The end date picker to add the callback to |
required |
plot
|
figure
|
The plot modified by the date pickers |
required |
Source code in main/widgets.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
date_picker(title, default_date, min_date, max_date)
¤
Provides a Date Picker widget to select dates in the plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title to display above the Date Picker. |
required |
default_date
|
date
|
The initial date to display |
required |
min_date
|
date
|
The earliest possible date the user can select |
required |
max_date
|
date
|
The latest possible date the user can select |
required |
Returns:
| Type | Description |
|---|---|
DatePicker
|
The initialised Date Picker widget. |
Source code in main/widgets.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
get_plot_date_pickers(min_date, max_date, default_start, default_end)
¤
Get start and end date pickers for a timeseries plot.
Creates separate date pickers to choose the start and end date to use as the x_range for a plot. Both pickers are provided with a default date to display and minimum and maximum possible dates that the user can select.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_date
|
date
|
The earliest possible date the user can select |
required |
max_date
|
date
|
The latest possible date the user can select |
required |
default_start
|
date
|
The default date to display in the start picker |
required |
default_end
|
date
|
The default date to display in the end picker |
required |
Returns: A tuple of date pickers for selecting the start and end dates of
Source code in main/widgets.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |