Skip to content

Commit

Permalink
Add support for version param (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
typpo authored Aug 18, 2021
1 parent bb3a7ee commit f994e2d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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

0 comments on commit f994e2d

Please sign in to comment.