Saves a SeleniumBase-generated chart to a file for later use. @Params chart_name - If creating multiple charts at the same time, use this to select the one you wish to use. filename - The name of the HTML file that you wish to save the
(self, chart_name=None, filename=None, folder=None)
| 13245 | self._chart_label[chart_name].append(label) |
| 13246 | |
| 13247 | def save_chart(self, chart_name=None, filename=None, folder=None): |
| 13248 | """Saves a SeleniumBase-generated chart to a file for later use. |
| 13249 | @Params |
| 13250 | chart_name - If creating multiple charts at the same time, |
| 13251 | use this to select the one you wish to use. |
| 13252 | filename - The name of the HTML file that you wish to |
| 13253 | save the chart to. (filename must end in ".html") |
| 13254 | folder - The name of the folder where you wish to |
| 13255 | save the HTML file. (Default: "./saved_charts/")""" |
| 13256 | if not chart_name: |
| 13257 | chart_name = "default" |
| 13258 | if not filename: |
| 13259 | filename = "my_chart.html" |
| 13260 | if chart_name not in self._chart_data: |
| 13261 | raise Exception("Chart {%s} does not exist!" % chart_name) |
| 13262 | if not filename.endswith(".html"): |
| 13263 | raise Exception('Chart file must end in ".html"!') |
| 13264 | the_html = '<meta charset="utf-8">\n' |
| 13265 | the_html += '<meta http-equiv="Content-Type" content="text/html">\n' |
| 13266 | the_html += '<meta name="viewport" content="shrink-to-fit=no">\n' |
| 13267 | for chart_data_point in self._chart_data[chart_name]: |
| 13268 | the_html += chart_data_point |
| 13269 | the_html += """ |
| 13270 | ] |
| 13271 | }] |
| 13272 | }); |
| 13273 | </script> |
| 13274 | """ |
| 13275 | axis = "xAxis: {\n" |
| 13276 | axis += " labels: {\n" |
| 13277 | axis += " useHTML: true,\n" |
| 13278 | axis += " style: {\n" |
| 13279 | axis += " fontSize: '14px',\n" |
| 13280 | axis += " },\n" |
| 13281 | axis += " },\n" |
| 13282 | axis += "categories: [" |
| 13283 | for label in self._chart_label[chart_name]: |
| 13284 | axis += "'%s'," % label |
| 13285 | axis += "], crosshair: false}," |
| 13286 | the_html = the_html.replace("xAxis: { },", axis) |
| 13287 | if not folder: |
| 13288 | saved_charts_folder = constants.Charts.SAVED_FOLDER |
| 13289 | else: |
| 13290 | saved_charts_folder = folder |
| 13291 | if saved_charts_folder.endswith("/"): |
| 13292 | saved_charts_folder = saved_charts_folder[:-1] |
| 13293 | if not os.path.exists(saved_charts_folder): |
| 13294 | with suppress(Exception): |
| 13295 | os.makedirs(saved_charts_folder) |
| 13296 | file_path = os.path.join(saved_charts_folder, filename) |
| 13297 | out_file = open(file_path, mode="w+", encoding="utf-8") |
| 13298 | out_file.writelines(the_html) |
| 13299 | out_file.close() |
| 13300 | if self._output_file_saves: |
| 13301 | print("\n>>> [%s] was saved!" % file_path) |
| 13302 | return file_path |
| 13303 | |
| 13304 | def display_chart(self, chart_name=None, filename=None, interval=0): |