Skip to content

Commit

Permalink
Merge pull request #401 from palewire/map-tests
Browse files Browse the repository at this point in the history
Add map tests and introduce an `add_json` method for uploading markers, areas and lines to locator maps
  • Loading branch information
chekos authored Nov 10, 2023
2 parents 43ab29b + e17c5c6 commit b68e5f2
Show file tree
Hide file tree
Showing 3 changed files with 1,799 additions and 0 deletions.
31 changes: 31 additions & 0 deletions datawrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,37 @@ def add_data(self, chart_id: str, data: pd.DataFrame | str) -> bool:
dump_data=False,
)

def add_json(self, chart_id: str, data: Any) -> bool:
"""Add JSON data to a specified chart.
Can be used to add point, area and line markers to a locator map or other chart.
Parameters
----------
chart_id : str
ID of chart, table or map to add data to.
data : Any
JSON data to add to the chart.
Returns
-------
bool
True if the data was added successfully.
"""
# Set the chart metadata to accept JSON data
self.update_chart(
chart_id=chart_id,
metadata={
"data": {"json": True},
},
)

# Dump the provided data as a JSON string
json_data = json.dumps(data)

# Post it to the chart via the add_data method
return self.add_data(chart_id, json_data)

def refresh_data(self, chart_id: str) -> dict:
"""Fetch configured external data and add it to the chart.
Expand Down
Loading

0 comments on commit b68e5f2

Please sign in to comment.