Skip to content

Commit dcd1332

Browse files
authored
Merge pull request #429 from palewire/export
Add more methods to the export_chart function
2 parents b3dc5c7 + 8a9047d commit dcd1332

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

datawrapper/__main__.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,11 +1043,19 @@ def export_chart(
10431043
unit: str = "px",
10441044
mode: str = "rgb",
10451045
width: int = 400,
1046+
height: int | str | None = None,
10461047
plain: bool = False,
10471048
zoom: int = 2,
10481049
scale: int = 1,
10491050
border_width: int = 20,
1051+
border_color: str | None = None,
10501052
transparent: bool = False,
1053+
download: bool = False,
1054+
full_vector: bool = False,
1055+
ligatures: bool = True,
1056+
logo: str = "auto",
1057+
logo_id: str | None = None,
1058+
dark: bool = False,
10511059
output: str = "png",
10521060
filepath: str = "./image.png",
10531061
display: bool = False,
@@ -1066,7 +1074,9 @@ def export_chart(
10661074
by default "rgb"
10671075
width : int, optional
10681076
Width of visualization. If not specified, it takes the chart width,
1069-
by default None
1077+
by default 400
1078+
height : int | str, optional
1079+
Height of visualization. Can be a number or "auto", by default None
10701080
plain : bool, optional
10711081
Defines if only the visualization should be exported (True), or if it should
10721082
include header and footer as well (False), by default False
@@ -1075,9 +1085,24 @@ def export_chart(
10751085
scale : int, optional
10761086
Defines the multiplier for the pdf size, by default 1
10771087
border_width : int, optional
1078-
Margin arouund the visualization, by default 20
1088+
Margin around the visualization, by default 20
1089+
border_color : str, optional
1090+
Color of the border around the visualization, by default None
10791091
transparent : bool, optional
1080-
Set to `True` to export your visualization with a transparent background.
1092+
Set to `True` to export your visualization with a transparent background,
1093+
by default False
1094+
download : bool, optional
1095+
Whether to trigger a download, by default False
1096+
full_vector : bool, optional
1097+
Export as full vector graphic (for supported formats), by default False
1098+
ligatures : bool, optional
1099+
Enable typographic ligatures, by default True
1100+
logo : str, optional
1101+
Logo display setting. One of "auto", "on", or "off", by default "auto"
1102+
logo_id : str, optional
1103+
Custom logo ID to use, by default None
1104+
dark : bool, optional
1105+
Export in dark mode, by default False
10811106
output : str, optional
10821107
One of png, pdf, or svg, by default "png"
10831108
filepath : str, optional
@@ -1099,9 +1124,22 @@ def export_chart(
10991124
"zoom": zoom,
11001125
"scale": scale,
11011126
"borderWidth": border_width,
1102-
"transparent": transparent,
1127+
"transparent": json.dumps(transparent),
1128+
"download": json.dumps(download),
1129+
"fullVector": json.dumps(full_vector),
1130+
"ligatures": json.dumps(ligatures),
1131+
"logo": logo,
1132+
"dark": json.dumps(dark),
11031133
}
11041134

1135+
# Add optional parameters only if provided
1136+
if height is not None:
1137+
_query["height"] = height
1138+
if border_color is not None:
1139+
_query["borderColor"] = border_color
1140+
if logo_id is not None:
1141+
_query["logoId"] = logo_id
1142+
11051143
content = self.get(
11061144
f"{self._CHARTS_URL}/{chart_id}/export/{output}", params=_query
11071145
)

0 commit comments

Comments
 (0)