Total Complexity | 8 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 94.44% |
Changes | 0 |
1 | """utils.export |
||
2 | --- |
||
3 | |||
4 | Exports the plots as interactive html |
||
5 | """ |
||
6 | 1 | import logging |
|
7 | 1 | import os |
|
8 | |||
9 | 1 | log = logging.getLogger("MetaStalk") |
|
10 | |||
11 | |||
12 | 1 | def export(choice: str, output_dir: str, plots: dict): |
|
13 | """export |
||
14 | |||
15 | Exports the plots to the chosen format |
||
16 | |||
17 | Arguments: |
||
18 | choice {str}: -- The type of export. {html, pdf, svg, png} |
||
19 | output_dir {str} -- Name of the directory to output charts to. |
||
20 | plots {dict} -- The plots to export. |
||
21 | """ |
||
22 | 1 | if not os.path.isdir(output_dir): |
|
23 | 1 | os.makedirs(output_dir) |
|
24 | else: |
||
25 | 1 | if len(os.listdir(output_dir)) != 0: |
|
26 | log.warning("The chosen output directory contain files.") |
||
27 | |||
28 | 1 | if choice == "html": |
|
29 | 1 | for name, chart in plots.items(): |
|
30 | 1 | chart.write_html(f"{output_dir}/{name}.html") |
|
31 | 1 | elif choice in ["pdf", "svg", "png"]: |
|
32 | 1 | try: |
|
33 | 1 | for name, chart in plots.items(): |
|
34 | 1 | chart.write_image(f"{output_dir}/{name}.{choice}") |
|
35 | 1 | except ValueError: |
|
36 | 1 | log.error("Dash requires orca to be install to export images.") |
|
37 | raise EnvironmentError("Dash requires orca to be install to export images.") |
||
38 |