From 2d1581eb4275aad0f1d4ec7969b9bad8998a0640 Mon Sep 17 00:00:00 2001 From: Ben Welsh Date: Sun, 28 Jan 2024 11:25:46 -0500 Subject: [PATCH 1/3] Switch from iPython HTML to IFrame --- datawrapper/__main__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index c6818ae..db7f41d 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -10,7 +10,7 @@ import pandas as pd import requests as r -from IPython.display import HTML, Image +from IPython.display import IFrame, Image from .exceptions import FailedRequest, InvalidRequest @@ -922,7 +922,7 @@ def delete_chart(self, chart_id: str) -> bool: """ return self.delete(f"{self._CHARTS_URL}/{chart_id}") - def display_chart(self, chart_id: str) -> HTML: + def display_chart(self, chart_id: str) -> IFrame: """Displays a datawrapper chart. Parameters @@ -932,12 +932,12 @@ def display_chart(self, chart_id: str) -> HTML: Returns ------- - IPython.display.HTML - HTML displaying the chart. + IPython.display.IFrame + IFrame displaying the chart. """ obj = self.get_chart(chart_id) iframe = obj["metadata"]["publish"]["embed-codes"]["embed-method-iframe"] - return HTML(iframe) + return IFrame(iframe) def copy_chart(self, chart_id: str) -> dict: """Copy one of your charts, tables, or maps and create a new editable copy. @@ -988,7 +988,7 @@ def move_chart(self, chart_id: int, folder_id: int) -> dict: data={"folderId": folder_id}, ) - def publish_chart(self, chart_id: str, display: bool = False) -> dict | HTML: + def publish_chart(self, chart_id: str, display: bool = False) -> dict | IFrame: """Publishes a chart, table or map. Parameters @@ -1000,8 +1000,8 @@ def publish_chart(self, chart_id: str, display: bool = False) -> dict | HTML: Returns ------- - dict | HTML - Either a dictionary containing the published chart's information or an HTML + dict | IFrame + Either a dictionary containing the published chart's information or an IFrame object displaying the chart. """ obj = self.post(f"{self._CHARTS_URL}/{chart_id}/publish") @@ -1010,7 +1010,7 @@ def publish_chart(self, chart_id: str, display: bool = False) -> dict | HTML: iframe = obj["data"]["metadata"]["publish"]["embed-codes"][ "embed-method-iframe" ] - return HTML(iframe) + return IFrame(iframe) else: return obj From 1f45622a540a75d0824ef35c43dcac88358dcd06 Mon Sep 17 00:00:00 2001 From: Ben Welsh Date: Sun, 28 Jan 2024 11:44:33 -0500 Subject: [PATCH 2/3] Add width and height --- datawrapper/__main__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index db7f41d..a009495 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -937,7 +937,9 @@ def display_chart(self, chart_id: str) -> IFrame: """ obj = self.get_chart(chart_id) iframe = obj["metadata"]["publish"]["embed-codes"]["embed-method-iframe"] - return IFrame(iframe) + width = obj["metadata"]["publish"]['embed-width'] + height = obj["metadata"]["publish"]['embed-height'] + return IFrame(iframe, width=width, height=height) def copy_chart(self, chart_id: str) -> dict: """Copy one of your charts, tables, or maps and create a new editable copy. @@ -1010,7 +1012,9 @@ def publish_chart(self, chart_id: str, display: bool = False) -> dict | IFrame: iframe = obj["data"]["metadata"]["publish"]["embed-codes"][ "embed-method-iframe" ] - return IFrame(iframe) + width = obj["data"]["metadata"]["publish"]['embed-width'] + height = obj["data"]["metadata"]["publish"]['embed-height'] + return IFrame(iframe, width=width, height=height) else: return obj From 13c782943df2aa7e7cf33943adafdb4a698c8919 Mon Sep 17 00:00:00 2001 From: palewire Date: Sun, 28 Jan 2024 12:34:25 -0500 Subject: [PATCH 3/3] Fix IFrame --- datawrapper/__main__.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index a009495..86868b7 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -936,10 +936,10 @@ def display_chart(self, chart_id: str) -> IFrame: IFrame displaying the chart. """ obj = self.get_chart(chart_id) - iframe = obj["metadata"]["publish"]["embed-codes"]["embed-method-iframe"] - width = obj["metadata"]["publish"]['embed-width'] - height = obj["metadata"]["publish"]['embed-height'] - return IFrame(iframe, width=width, height=height) + src = obj["publicUrl"] + width = obj["metadata"]["publish"]["embed-width"] + height = obj["metadata"]["publish"]["embed-height"] + return IFrame(src, width=width, height=height) def copy_chart(self, chart_id: str) -> dict: """Copy one of your charts, tables, or maps and create a new editable copy. @@ -1009,12 +1009,10 @@ def publish_chart(self, chart_id: str, display: bool = False) -> dict | IFrame: obj = self.post(f"{self._CHARTS_URL}/{chart_id}/publish") assert isinstance(obj, dict) if display: - iframe = obj["data"]["metadata"]["publish"]["embed-codes"][ - "embed-method-iframe" - ] - width = obj["data"]["metadata"]["publish"]['embed-width'] - height = obj["data"]["metadata"]["publish"]['embed-height'] - return IFrame(iframe, width=width, height=height) + src = obj["data"]["publicUrl"] + width = obj["data"]["metadata"]["publish"]["embed-width"] + height = obj["data"]["metadata"]["publish"]["embed-height"] + return IFrame(src, width=width, height=height) else: return obj