This function will return a script that will download an image of a Plotly plot. Keyword Arguments: caller ('plot', 'iplot') -- specifies which function made the call for the download script. If `iplot`, then an extra condition is added into the download script to e
(caller)
| 192 | |
| 193 | |
| 194 | def get_image_download_script(caller): |
| 195 | """ |
| 196 | This function will return a script that will download an image of a Plotly |
| 197 | plot. |
| 198 | |
| 199 | Keyword Arguments: |
| 200 | caller ('plot', 'iplot') -- specifies which function made the call for the |
| 201 | download script. If `iplot`, then an extra condition is added into the |
| 202 | download script to ensure that download prompts aren't initiated on |
| 203 | page reloads. |
| 204 | """ |
| 205 | |
| 206 | if caller == "iplot": |
| 207 | check_start = "if(document.readyState == 'complete') {{" |
| 208 | check_end = "}}" |
| 209 | elif caller == "plot": |
| 210 | check_start = "" |
| 211 | check_end = "" |
| 212 | else: |
| 213 | raise ValueError("caller should only be one of `iplot` or `plot`") |
| 214 | |
| 215 | return ( |
| 216 | "function downloadimage(format, height, width," |
| 217 | " filename) {{" |
| 218 | "var p = document.getElementById('{{plot_id}}');" |
| 219 | "Plotly.downloadImage(p, {{format: format, height: height, " |
| 220 | "width: width, filename: filename}});}};" |
| 221 | + check_start |
| 222 | + "downloadimage('{format}', {height}, {width}, " |
| 223 | "'{filename}');" + check_end |
| 224 | ) |
| 225 | |
| 226 | |
| 227 | def build_save_image_post_script( |
no outgoing calls
no test coverage detected