Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map tests and introduce an add_json method for uploading markers, areas and lines to locator maps #401

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions datawrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,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
Loading