Skip to content

Commit b68e5f2

Browse files
authored
Merge pull request #401 from palewire/map-tests
Add map tests and introduce an `add_json` method for uploading markers, areas and lines to locator maps
2 parents 43ab29b + e17c5c6 commit b68e5f2

File tree

3 files changed

+1799
-0
lines changed

3 files changed

+1799
-0
lines changed

datawrapper/__main__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,37 @@ def add_data(self, chart_id: str, data: pd.DataFrame | str) -> bool:
11801180
dump_data=False,
11811181
)
11821182

1183+
def add_json(self, chart_id: str, data: Any) -> bool:
1184+
"""Add JSON data to a specified chart.
1185+
1186+
Can be used to add point, area and line markers to a locator map or other chart.
1187+
1188+
Parameters
1189+
----------
1190+
chart_id : str
1191+
ID of chart, table or map to add data to.
1192+
data : Any
1193+
JSON data to add to the chart.
1194+
1195+
Returns
1196+
-------
1197+
bool
1198+
True if the data was added successfully.
1199+
"""
1200+
# Set the chart metadata to accept JSON data
1201+
self.update_chart(
1202+
chart_id=chart_id,
1203+
metadata={
1204+
"data": {"json": True},
1205+
},
1206+
)
1207+
1208+
# Dump the provided data as a JSON string
1209+
json_data = json.dumps(data)
1210+
1211+
# Post it to the chart via the add_data method
1212+
return self.add_data(chart_id, json_data)
1213+
11831214
def refresh_data(self, chart_id: str) -> dict:
11841215
"""Fetch configured external data and add it to the chart.
11851216

0 commit comments

Comments
 (0)