1
2 """
3 GChartWrapper - Google Chart API Wrapper
4
5 Unit tests, see tests.py for actually running these
6 """
7 from GChartWrapper import *
8 from GChartWrapper.constants import *
9
11 """
12 Extensive unit tests, more are welcome
13
14 All methods must be commented and return a GChart instance as the last line.
15 """
16
17 all = {
18 'simple':'a6de27c4891b513efe669892f7d5304edd276427',
19 'financial':'72c6cfb524af4ad7c8286e796c4501ab40910f7a',
20 'bar_text':'e9028a1ff3a1d42bc1a3dcf51780b0321d5d2c96',
21 'concentric_pie':'d47836a02b6fcc6c5b78b568302c5fa1f9cb3777',
22 'margins':'5c10e93e398edb49d9d675b7ec764352d537f806',
23 'min_max':'422b3dc4174d048d7105383d06cb7acd815d2d3e',
24 'text':'7f10b9de58840d2161aa5f32d4a12d86f772fe92',
25 'letter_pin':'196a01c0923628290c867a77438b22be4e811d41',
26 'icon_pin':'8ac735930b99165d343385fc41958d925a9db931',
27 'adv_icon_pin':'f400bd7857e77cd1ec52f82564db301a18902174',
28 'adv_letter_pin':'64cd43483e19828a63987cb2e6cffcf6eeeac5a5',
29 'text_pin':'2b77242c21c673a4ddce1219ebe4befe9f0c5d03',
30 'sticky_note':'90fe055d338ddfa38b17d6ad94efcfec475ed265',
31 'thought_note':'2720d0512907598f6ed13320d431935dbcb26acd',
32 'small_bubble_icon':'22fcf71930a0dc574cfb305bbec38278dc06cbae',
33 'large_bubble_icon':'f456afa8c7098c57c38fb584c01ebf234b6f5e7c',
34 'large_bubble_icon_texts':'92e5b034421b097d87cc990179f16e65538c2d8a',
35 'large_bubble_texts':'a6687d18fc3264f5938b5c203a968e32e9f954ca',
36 'qr_code':'330016ec1f94d2ba2baf1914df427ad86db7dd0f',
37 'legend':'f181827b3618dac12f564e2be63b4274990c5258',
38 'bar':'09ff756b63075bb40e9c97a6fdb5f63f2bbfebf4',
39 'pie':'cc4eae489458948e81474533b422e007a08d92ef',
40 'guide_granularity_20':'d330e4275208e2c5f8affed3e391909f73415907',
41 'guide_granularity_40':'6b9142f87a777ae69484008a57737bbc53096a9d',
42 'guide_granularity_80':'6950bb2691e45ca2698e65c2f1e867c77e8bed37',
43 'guide_radar':'44225362446694d17cb2950b65bf7fcc5aa6cfce',
44 'hvz':'0df9d1d9c97d380e3daf1e81037ec25576f5edd8',
45 'guide_sparkline':'e61609da9d1b38b8401249b434bc5150dab9bc77',
46 'venn':'63bd278cc8b8abbb2cae317747a6ea79c5a1b708',
47 'fill':'938182d2a9c9c218de0259c88d583c4f2c2d70c9',
48 'guide_line_lc':'b0a0446b4fba55b6b48c23cd1487817d17a7ac3d',
49 'title':'385fcf0b6eeba2aba55302a0f71ed420a2908446',
50 'axes':'e892afdd2cad44f50c9ca3213a2b3b43da9bf34c',
51 'markers':'0bffa272991d6193e74b8844e44ebb5e07986ced',
52 'line':'d0346bb5e3d7e3cc8851ff0c1b2ad2d18aff8f72',
53 'multiline':'f087681acf24c9257c8985bb013b98ddd01975de',
54 'axes_position':'3845671d4f57f7232d3837df6f1c73a7f8137059',
55 'jacobian':'4056ac217c6cda014a9dff55011a9a3a702caaf1',
56 'numpy':'066457dee12063d00ee66aaf505140cfa6b37116',
57 'guide_meter':'12657d113593b4a3465ab6d79286b0d849601204',
58 'guide_intro':'bde2d538696e0d598c5359de40e7c92d8efecd16',
59 'guide_map':'5a9068f2689e783749e90b683df1142c89057f03',
60 'grid':'645388ffdbd2bd4f117daa265adfc90baa572f74',
61 'legend2':'28af098f2faef3f7072b07833e85a8c9c75684e9',
62 'guide_bhs':'1591e5ea4e8f8886613e73941a10a2c547750e0e',
63 'guide_bvs':'cb2f5344e816f1b1ae2214131f11547ec3f9549a',
64 'guide_bvs_scale':'0f47d77a1aa449b27c90e4b01e8c84a3b3d161d9',
65 'guide_bvg':'35d7126f7ccbf56c30254a1403b15affcb49db4f',
66 'guide_bhg':'ef88b9e73a7a08d16d39d0dd14de9486a8d52a1a',
67 'guide_chbh_clipped':'fe87216a7ce5cc496420de787b52b9eac1c056f9',
68 'guide_chbh_size':'03e1fd7393c87c5c65d88469f557f60e5ca0378b',
69 }
70 if PY_VER.startswith('3'):
71 all['weather_note'] = 'a6e78f827cccdcc15979cd9787deb198e4dc33a6'
72 else:
73 all['weather_note'] = '7e7e87b94bdd3b8cb1fd208b2d565b58a1bc595e'
74
76
77
78 G = GChart()
79
80 G.type('pie')
81
82 G.dataset( 'helloworld' )
83
84 G.size(250,100)
85 return G
86
88
89 G = VerticalBarGroup( [[31],[59],[4]], encoding='text' )
90 G.scale(0,59)
91 G.color('00ff00','ff0000','0000ff')
92 G.legend('Goucher(31)','Truman(59)','Kansas(4)')
93 G.fill('c','lg',45,'cccccc',0,'000000',1)
94 G.fill('bg','s','cccccc')
95 G.size(200,100)
96 return G
97
99
100
101 G = QRCode('''To the human eye QR Codes look like hieroglyphics,
102 but they can be read by any device that has
103 the appropriate software installed.''')
104
105 G.output_encoding('UTF-8')
106
107 G.level_data('M',0)
108 return G
109
111
112 G = Line( ['GurMrabsClgubaolGvzCrgrefOrnhgvshyvforggregunahtyl'] )
113 G.title('The Zen of Python','00cc00',36)
114 G.color('00cc00')
115 return G
116
118
119
120 G = Line( ['hX1xPj'] )
121 G.axes.type('xy')
122 G.axes.label('Mar', 'Apr', 'May', 'June', 'July')
123 G.axes.label(None, '50+Kb')
124 G.color('ff0000')
125 G.line(6,5,2)
126 return G
127
128
136
138
139 G = Pie3D( [1,2,3,4] )
140 G.label('A','B','C','D')
141 G.color('00dd00')
142 return G
143
145
146 G = Venn( [100,80,60,30,30,30,10], encoding='text')
147 G.scale(0,100)
148 return G
149
151
152
153
154 G = Line( ['foobarbaz'] )
155 G.color('76A4FB')
156 G.axes.type('xyrx')
157 G.axes.label('Foo', 'Bar', 'Baz')
158 G.axes.label(None, '20K', '60K', '100K')
159 G.axes.label('A', 'B', 'C')
160 G.axes.label(None,'20','40','60','80')
161 G.axes.style('0000dd', 14)
162 return G
163
165
166
167 G = Line( ['foobarbaz'] )
168 G.color('76A4FB')
169 G.line(3,6,3)
170 G.grid(20.0,25.0,1,0)
171 return G
172
174
175 G = Line( ['helloWorldZZZZ098236561'] )
176 G.marker('c','ff0000',0,1,20)
177 G.marker('d','80C65A',0,6,15)
178 G.marker('o','FF9900',0,4.0,20.0)
179 G.marker('s','3399CC',0,5.0,10.0)
180 G.marker('v','BBCCED',0,6.0,1.0)
181 G.marker('V','3399CC',0,7.0,1.0)
182 G.marker('x','FFCC33',0,8.0,20.0)
183 G.marker('h','000000',0,0.30,0.5 )
184 G.marker('a','000099',0,4,10)
185 G.marker('R','A0BAE9',0,8,0.6)
186 G.marker('r','E5ECF9',0,1,0.25)
187 return G
188
190
191 G = Line(['ALAtBmC1EcGYIsLWOXRuVdZhd9ivn4tYzO5b..'],encoding='extended')
192 G.size(300,200)
193 G.color('cc0000')
194 G.fill('c','s','eeeeee')
195 G.legend('Sweet')
196 return G
197
199
200 G = Line( ['99','cefhjkqwrlgYcfgc',
201 'QSSVXXdkfZUMRTUQ','HJJMOOUbVPKDHKLH','AA'] )
202 G.marker('b','76A4FB',0,1,0)
203 G.marker('b','224499',1,2,0)
204 G.marker('b','FF0000',2,3,0)
205 G.marker('B','80C65A',3,4,0)
206 return G
207
209
210 G = Line( ['pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp'] )
211 G.color('ff0000')
212 G.line(4,3,0)
213 G.axes.type('xy')
214 G.axes.label(1,2,3,4,5)
215 G.axes.label(None,50,100)
216 G.fill('c','lg',45,'ffffff',0,'76A4FB',0.75)
217 G.fill('bg','s','EFEFEF')
218 return G
219
220
222
223 G = Line( ['FOETHECat','leafgreen','IRON4YOUs'] )
224 G.color('ff0000','00ff00','0000ff')
225 G.legend('Animals','Vegetables','Minerals')
226 G.axes.type('y')
227 return G
228
230
231 G = Line( ['abcde','FGHIJ','09876'] )
232 G.color('ff0000','00ff00','0000ff')
233 G.legend('Animals','Vegetables','Minerals')
234 G.legend_pos('l')
235 G.axes.type('y')
236 return G
237
239
240 G = LineXY( [
241 [0,30,60,70,90,95,100],
242 [20,30,40,50,60,70,80],
243 [10,30,40,45,52],
244 [100,90,40,20,10],
245 ['-1'],
246 [5,33,50,55,7],
247 ])
248 G.scale(0,100)
249 G.color('3072F3','ff0000','00aaaa')
250 G.marker('s','FF0000',0,-1,5)
251 G.marker('s','0000ff',1,-1,5)
252 G.marker('s','00aa00',2,-1,5)
253 G.line(2,4,1)
254 return G
255
256
258
259
260 data = [[4.6, 6.0, 7.4, 11.6, 12.0, 14.8, 18.1, 25.1,
261 27.9, 28.3, 30.6, 34.4, 43.7, 48.3, 57.6, 64.6,
262 72.5, 74.4, 76.2, 77.2, 86.0, 86.9, 93.9, 96.7, 99.0],
263 [80.5, 100.0, 95.4, 93.7, 96.3, 91.7, 71.5, 63.0,
264 65.2, 65.5, 66.0, 75.9, 65.8, 64.4, 64.2, 62.5, 37.2,
265 35.3, 32.4, 35.2, 38.4, 37.9, 69.8, 38.0, 64.5]]
266
267
268 axis = [ [0, 13, 28, 42, 56, 71, 84, 100],
269 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] ]
270
271
272 min_value = float(min(data[1]))
273 max_value = float(max(data[1]))
274 last_value = float(data[1][-1])
275
276 G = LineXY(data, encoding='text')
277 G.color('76A4FB')
278 G.marker('o', '0077CC',0,-1,5)
279 G.marker('r', 'E6F2FA',0,(min_value/max_value),1.0)
280 G.axes.type("xyr")
281 G.axes.label(*axis[1])
282 G.axes.position(*axis[0])
283 G.axes.label('%d'%min_value, '%d'%max_value)
284 G.axes.position(int(100*min_value/max_value),100)
285 G.axes.label('%d'%last_value)
286 G.axes.position(int(100*last_value/max_value))
287 return G
288
289
290
291
297
305
313
315 G = Line('formostthisamazingdayfortheleapinggreenlformostthisamazingdayfortheleapinggreenl',
316 encoding='simple')
317 G.size(200,100)
318 G.axes.type('xy')
319 G.axes.label('April','May','June')
320 G.axes.label(None, '50+Kb')
321 return G
322
323
325
326 G = Line('fooZaroo', encoding='simple')
327 G.size(200,100)
328 return G
329
330
331
333
334 G = Sparkline([27,25,25,25,25,27,100,31,25,36,25,25,39,
335 25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,
336 27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,
337 26,37,33,33,37,37,39,25,25,25,25], encoding='text')
338 G.color('0077CC')
339 G.size(200,40)
340 G.marker('B', 'E6F2FA',0,0,0)
341 G.line(1,0,0)
342 return G
343
344
351
353 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text')
354 G.color('4d89f9', 'c6d9fd')
355 G.size(200,125)
356 return G
357
359 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text')
360 G.color('4d89f9', 'c6d9fd')
361 G.size(200,125)
362 G.scale(0,160)
363 return G
364
370
376
382
389
390
392
393 G = Radar([ [77,66,15,0,31,48,100,77],[20,36,100,2,0,100] ], encoding='text')
394 G.size(200,200)
395 G.color('FF0000','FF9900')
396 G.line(2,4,0)
397 G.line(2,4,0)
398 G.axes.type('x')
399 G.axes.label(0,45,90,135,180,225,270,315)
400 G.axes.range(0,360)
401 return G
402
404
405 G = Map('fSGBDQBQBBAGABCBDAKLCDGFCLBBEBBEPASDKJBDD9BHHEAACAC', encoding='simple')
406 G.color('f5f5f5','edf0d4','6c9642','365e24','13390a')
407 G.fill('bg','s','eaf7fe')
408 G.size(440,220)
409 G.map('usa', 'NYPATNWVNVNJNHVAHIVTNMNCNDNELASDDCDEFLWAKSWIORKYMEOHIAIDCTWYUTINILAKTXCOMDMAALMOMNCAOKMIGAAZMTMSSCRIAR')
410 return G
411
413
414 G = Meter(70)
415 G.label('Hello')
416 G.size(225,125)
417 return G
418
420
421
422 data = [10,20,30,40,50,60,70,80,90]
423 try:
424 from numpy import array
425 data = array(data)
426 except ImportError:
427 print('Warning: numpy must be installed to do this test correctly')
428 G = Radar(data, encoding='text')
429 G.size(200,200)
430 return G
431
433
434 G = PieC(['Helo','Wrld'], encoding='simple')
435 G.size(200,100)
436 return G
437
439
440 G = Line([[0,5,10,7,12,6],[35,25,45,47,24,46],[15,40,30,27,39,54],[70,55,63,59,80,60]], encoding='text')
441 G.marker('F','0000FF',0,'1:4',20)
442 G.size(200,125)
443 return G
444
445 - def bar_text(self):
446
447 G = HorizontalBarGroup([[40,60],[50,30]], encoding='text')
448 G.size(200,125)
449 G.marker('tApril mobile hits','000000',0,0,13)
450 G.marker('tMay mobile hits','000000',0,1,13,-1)
451 G.marker('tApril desktop hits','000000',1,0,13)
452 G.marker('tMay desktop hits', '000000',1,1,13)
453 G.color('FF9900','FFCC33')
454 return G
455
457 G = Line(['Uf9a','a3fG'], encoding='simple')
458 G.size(250,100)
459 G.label(1,2,3,4)
460 G.fill('bg','s','e0e0e0')
461 G.color('000000','0000FF')
462 G.margin(20,20,20,30,80,20)
463 G.legend('Temp','Sales')
464 return G
465
467 G = Line('mHMza', encoding='simple')
468 G.color('008000')
469 G.line(2.0,4.0,1.0)
470 G.size(200,140)
471 G.axes.type('x')
472 G.axes.label(None,'t',None,'F',None)
473 G.marker('tMin','0000FF',0,1,10)
474 G.marker('fMax','FF0000',0,3,15)
475 G.margin(0,0,30,0)
476 return G
477
479 text = '''
480 1600 Ampitheatre Parkway
481 Mountain View, CA
482 (650)+253-0000
483 '''
484 G = Text('darkred',16,'h','red','b',text)
485 return G
486
488 G = Pin('pin_letter','A','red','black')
489 return G
490
492 G = Pin('pin_icon','home','yellow')
493 return G
494
496 G = Pin('xpin_letter','star','A','aqua','black','red')
497 return G
498
500 G = Pin('xpin_icon','star','home','aqua','red')
501 return G
502
503 - def text_pin(self):
504 G = Pin('spin',1.2,30,'FFFF88',10,'_','Foo\nBar')
505 return G
506
508 G = Note('note_title','pinned_c',1,'darkgreen','l',"Joe's\nToday 2-for-1 !\n555-1234")
509 return G
510
512 G = Note('note','thought',1,'navy','h',"wouldn't it be\ngreat to eat\nat Joe's?")
513 return G
514
516 G = Note('weather','taped_y','sunny','Barcelona','max 25°','min 15°')
517 return G
518
520 G = Bubble('icon_text_small','petrol','bb','$3/gal','khaki','black')
521 return G
522
524 G = Bubble('icon_text_big','snack','bb','$2.99','ffbb00','black')
525 return G
526
528 G = Bubble('icon_texts_big','petrol','bb','khaki','black','LoCost Fuel\n$3.05/gal unleaded\n$2.10/gal diesel')
529 return G
530
532 G = Bubble('texts_big','bb','teal','khaki',"Joe\'s Restaurant\n123 Long St\n92745 Mountain View")
533 return G
534