From f994e2d815247a406f8d05da6cf0404a969fcd7e Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Tue, 17 Aug 2021 17:02:47 -0700 Subject: [PATCH] Add support for version param (#7) --- README.md | 3 +++ quickchart/__init__.py | 3 +++ tests.py | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 54c10a7..dbbdd49 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,9 @@ The background color of the chart. Any valid HTML color works. Defaults to #ffff ### device_pixel_ratio: float The device pixel ratio of the chart. This will multiply the number of pixels by the value. This is usually used for retina displays. Defaults to 1.0. +### version: str +The version of Chart.js to use. Acceptable values are documented [here](https://quickchart.io/documentation/#parameters). Usually used to select Chart.js 3+. + ### host Override the host of the chart render server. Defaults to quickchart.io. diff --git a/quickchart/__init__.py b/quickchart/__init__.py index 80a8cef..ae57207 100644 --- a/quickchart/__init__.py +++ b/quickchart/__init__.py @@ -44,6 +44,7 @@ def __init__(self): self.background_color = '#ffffff' self.device_pixel_ratio = 1.0 self.format = 'png' + self.version = '2.9.4' self.key = None self.scheme = 'https' self.host = 'quickchart.io' @@ -65,6 +66,7 @@ def get_url(self): 'bkg': self.background_color, 'devicePixelRatio': self.device_pixel_ratio, 'f': self.format, + 'v': self.version, } if self.key: params['key'] = self.key @@ -83,6 +85,7 @@ def _post(self, url): 'backgroundColor': self.background_color, 'devicePixelRatio': self.device_pixel_ratio, 'format': self.format, + 'version': self.version, } if self.key: postdata['key'] = self.key diff --git a/tests.py b/tests.py index a3d29cf..31b6a3f 100644 --- a/tests.py +++ b/tests.py @@ -26,6 +26,23 @@ def test_simple(self): self.assertIn('devicePixelRatio=2', url) self.assertIn('Hello+world', url) + def test_version(self): + qc = QuickChart() + qc.version = '3.4.0' + qc.config = { + "type": "bar", + "data": { + "labels": ["Hello world", "Test"], + "datasets": [{ + "label": "Foo", + "data": [1, 2] + }] + } + } + + url = qc.get_url() + self.assertIn('v=3.4.0', url) + def test_no_chart(self): qc = QuickChart() qc.width = 600