Skip to content

Commit f994e2d

Browse files
authored
Add support for version param (#7)
1 parent bb3a7ee commit f994e2d

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ The background color of the chart. Any valid HTML color works. Defaults to #ffff
116116
### device_pixel_ratio: float
117117
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.
118118

119+
### version: str
120+
The version of Chart.js to use. Acceptable values are documented [here](https://quickchart.io/documentation/#parameters). Usually used to select Chart.js 3+.
121+
119122
### host
120123
Override the host of the chart render server. Defaults to quickchart.io.
121124

quickchart/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(self):
4444
self.background_color = '#ffffff'
4545
self.device_pixel_ratio = 1.0
4646
self.format = 'png'
47+
self.version = '2.9.4'
4748
self.key = None
4849
self.scheme = 'https'
4950
self.host = 'quickchart.io'
@@ -65,6 +66,7 @@ def get_url(self):
6566
'bkg': self.background_color,
6667
'devicePixelRatio': self.device_pixel_ratio,
6768
'f': self.format,
69+
'v': self.version,
6870
}
6971
if self.key:
7072
params['key'] = self.key
@@ -83,6 +85,7 @@ def _post(self, url):
8385
'backgroundColor': self.background_color,
8486
'devicePixelRatio': self.device_pixel_ratio,
8587
'format': self.format,
88+
'version': self.version,
8689
}
8790
if self.key:
8891
postdata['key'] = self.key

tests.py

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ def test_simple(self):
2626
self.assertIn('devicePixelRatio=2', url)
2727
self.assertIn('Hello+world', url)
2828

29+
def test_version(self):
30+
qc = QuickChart()
31+
qc.version = '3.4.0'
32+
qc.config = {
33+
"type": "bar",
34+
"data": {
35+
"labels": ["Hello world", "Test"],
36+
"datasets": [{
37+
"label": "Foo",
38+
"data": [1, 2]
39+
}]
40+
}
41+
}
42+
43+
url = qc.get_url()
44+
self.assertIn('v=3.4.0', url)
45+
2946
def test_no_chart(self):
3047
qc = QuickChart()
3148
qc.width = 600

0 commit comments

Comments
 (0)