Skip to content

Add support for version param #7

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

Merged
merged 1 commit into from
Aug 18, 2021
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions quickchart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down