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':'ea187e300c593867b2f9c17824da34c5bd9a1bef',
20 'bar_text':'e9028a1ff3a1d42bc1a3dcf51780b0321d5d2c96',
21 'concentric_pie':'d47836a02b6fcc6c5b78b568302c5fa1f9cb3777',
22 'margins':'cfa4d80ae660fa4200d5f70c21ba9bff9d2e240b',
23 'min_max':'62d19b35934e091f6d616d9515f8566e44eef474',
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':'f0f6cea482cc874beb06b9ca2a689d08bda2285b',
37 'legend':'ffd2fd1e34749569c39d22024ea97bd677e2ca13',
38 'bar':'09ff756b63075bb40e9c97a6fdb5f63f2bbfebf4',
39 'pie':'cc4eae489458948e81474533b422e007a08d92ef',
40 'guide_granularity_20':'d330e4275208e2c5f8affed3e391909f73415907',
41 'guide_granularity_40':'6b9142f87a777ae69484008a57737bbc53096a9d',
42 'guide_granularity_80':'6950bb2691e45ca2698e65c2f1e867c77e8bed37',
43 'guide_radar':'13a21487482f1b341a36bb2d735f97d309b2a47f',
44 'hvz':'5ae5be08294efdb63fa39b5b6c33a8d6423196d6',
45 'guide_sparkline':'e61609da9d1b38b8401249b434bc5150dab9bc77',
46 'venn':'63bd278cc8b8abbb2cae317747a6ea79c5a1b708',
47 'fill':'70add0b67f4f86c2c508a28c3bf5c6aab5775ee9',
48 'guide_line_lc':'b0a0446b4fba55b6b48c23cd1487817d17a7ac3d',
49 'title':'385fcf0b6eeba2aba55302a0f71ed420a2908446',
50 'axes':'e892afdd2cad44f50c9ca3213a2b3b43da9bf34c',
51 'markers':'966a8dbe40048a36b647d344c9a7f379ea136c80',
52 'line':'4e2b17fd477830ae144d50e557c873a76f46deb1',
53 'multiline':'e4281cbc408cf31d551fd3776a890d5b33c7b74d',
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':'e785ef2737453840a0756798fb16160fdf3d28f5',
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 'currency_bar':'ab7245c0c005ee99ee198fd6baab45e68fd6e188',
70 'czech_and_unicode':'3bb3ae7cd462a8fc2724ee52b6ca5bc5f39e908d',
71 'tick_marks':'d33a9c7555d75dfadc6446bf5686bf988ccc592b',
72 }
73 if PY_VER.startswith('3'):
74
75 all['weather_note'] = 'a6e78f827cccdcc15979cd9787deb198e4dc33a6'
76 else:
77 all['weather_note'] = '7e7e87b94bdd3b8cb1fd208b2d565b58a1bc595e'
78
80
81
82 G = GChart()
83
84 G.type('pie')
85
86 G.dataset( 'helloworld' )
87
88 G.size(250,100)
89 return G
90
92
93 G = VerticalBarGroup( [[31],[59],[4]], encoding='text' )
94 G.scale(0,59)
95 G.color('lime','red','blue')
96 G.legend('Goucher(31)','Truman(59)','Kansas(4)')
97 G.fill('c','lg',45,'cccccc',0,'black',1)
98 G.fill('bg','s','cccccc')
99 G.size(200,100)
100 return G
101
103
104
105 G = QRCode('''To the human eye QR Codes look like hieroglyphics,
106 but they can be read by any device that has
107 the appropriate software installed.''')
108
109 G.output_encoding('UTF-8')
110
111 G.level_data('M',0)
112 return G
113
115
116 G = Line( ['GurMrabsClgubaolGvzCrgrefOrnhgvshyvforggregunahtyl'] )
117 G.title('The Zen of Python','00cc00',36)
118 G.color('00cc00')
119 return G
120
122
123
124 G = Line( ['hX1xPj'] )
125 G.axes.type('xy')
126 G.axes.label(0, 'Mar', 'Apr', 'May', 'June', 'July')
127 G.axes.label(1, None, '50+Kb')
128 G.color('red')
129 G.line(6,5,2)
130 return G
131
132
140
142
143 G = Pie3D( [1,2,3,4] )
144 G.label('A','B','C','D')
145 G.color('00dd00')
146 return G
147
149
150 G = Venn( [100,80,60,30,30,30,10], encoding='text')
151 G.scale(0,100)
152 return G
153
155
156
157
158 G = Line( ['foobarbaz'] )
159 G.color('76A4FB')
160 G.axes.type('xyrx')
161 G.axes.label(0,'Foo', 'Bar', 'Baz')
162 G.axes.style(0, '0000dd', 14)
163 G.axes.label(1, None, '20K', '60K', '100K')
164 G.axes.label(2, 'A', 'B', 'C')
165 G.axes.label(3, None,'20','40','60','80')
166 return G
167
169
170
171 G = Line( ['foobarbaz'] )
172 G.color('76A4FB')
173 G.line(3,6,3)
174 G.grid(20.0,25.0,1,0)
175 return G
176
178
179 G = Line( ['helloWorldZZZZ098236561'] )
180 G.marker('c','red',0,1,20)
181 G.marker('d','80C65A',0,6,15)
182 G.marker('o','FF9900',0,4.0,20.0)
183 G.marker('s','3399CC',0,5.0,10.0)
184 G.marker('v','BBCCED',0,6.0,1.0)
185 G.marker('V','3399CC',0,7.0,1.0)
186 G.marker('x','FFCC33',0,8.0,20.0)
187 G.marker('h','black',0,0.30,0.5 )
188 G.marker('a','000099',0,4,10)
189 G.marker('R','A0BAE9',0,8,0.6)
190 G.marker('r','E5ECF9',0,1,0.25)
191 return G
192
194
195 G = Line(['ALAtBmC1EcGYIsLWOXRuVdZhd9ivn4tYzO5b..'],encoding='extended')
196 G.size(300,200)
197 G.color('cc0000')
198 G.fill('c','s','eeeeee')
199 G.legend('Sweet')
200 return G
201
203
204 G = Line( ['99','cefhjkqwrlgYcfgc',
205 'QSSVXXdkfZUMRTUQ','HJJMOOUbVPKDHKLH','AA'] )
206 G.marker('b','76A4FB',0,1,0)
207 G.marker('b','224499',1,2,0)
208 G.marker('b','red',2,3,0)
209 G.marker('B','80C65A',3,4,0)
210 return G
211
213
214 G = Line( ['pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp'] )
215 G.color('red')
216 G.line(4,3,0)
217 G.axes.type('xy')
218 G.axes.label(0, 1,2,3,4,5)
219 G.axes.label(1, None,50,100)
220 G.fill('c','lg',45,'white',0,'76A4FB',0.75)
221 G.fill('bg','s','EFEFEF')
222 return G
223
224
226
227 G = Line( ['FOETHECat','leafgreen','IRON4YOUs'] )
228 G.color('red','lime','blue')
229 G.legend('Animals','Vegetables','Minerals')
230 G.axes.type('y')
231 return G
232
234
235 G = Line( ['abcde','FGHIJ','09876'] )
236 G.color('red','lime','blue')
237 G.legend('Animals','Vegetables','Minerals')
238 G.legend_pos('l')
239 G.axes.type('y')
240 return G
241
243
244 G = LineXY( [
245 [0,30,60,70,90,95,100],
246 [20,30,40,50,60,70,80],
247 [10,30,40,45,52],
248 [100,90,40,20,10],
249 ['-1'],
250 [5,33,50,55,7],
251 ])
252 G.scale(0,100)
253 G.color('3072F3','red','00aaaa')
254 G.marker('s','red',0,-1,5)
255 G.marker('s','blue',1,-1,5)
256 G.marker('s','00aa00',2,-1,5)
257 G.line(2,4,1)
258 return G
259
260
262
263
264 data = [[4.6, 6.0, 7.4, 11.6, 12.0, 14.8, 18.1, 25.1,
265 27.9, 28.3, 30.6, 34.4, 43.7, 48.3, 57.6, 64.6,
266 72.5, 74.4, 76.2, 77.2, 86.0, 86.9, 93.9, 96.7, 99.0],
267 [80.5, 100.0, 95.4, 93.7, 96.3, 91.7, 71.5, 63.0,
268 65.2, 65.5, 66.0, 75.9, 65.8, 64.4, 64.2, 62.5, 37.2,
269 35.3, 32.4, 35.2, 38.4, 37.9, 69.8, 38.0, 64.5]]
270
271
272 axis = [ [0, 13, 28, 42, 56, 71, 84, 100],
273 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] ]
274
275
276 min_value = float(min(data[1]))
277 max_value = float(max(data[1]))
278 last_value = float(data[1][-1])
279
280 G = LineXY(data, encoding='text')
281 G.color('76A4FB')
282 G.marker('o', '0077CC',0,-1,5)
283 G.marker('r', 'E6F2FA',0,(min_value/max_value),1.0)
284 G.axes.type("xyr")
285 G.axes.label(0, *axis[1])
286 G.axes.position(0, *axis[0])
287 G.axes.label(1, '%d'%min_value, '%d'%max_value)
288 G.axes.position(1, int(100*min_value/max_value),100)
289 G.axes.label(2, '%d'%last_value)
290 G.axes.position(2, int(100*last_value/max_value))
291 return G
292
293
294
295
301
309
317
319 G = Line('formostthisamazingdayfortheleapinggreenlformostthisamazingdayfortheleapinggreenl',
320 encoding='simple')
321 G.size(200,100)
322 G.axes.type('xy')
323 G.axes.label(0, 'April','May','June')
324 G.axes.label(1, None, '50+Kb')
325 return G
326
327
329
330 G = Line('fooZaroo', encoding='simple')
331 G.size(200,100)
332 return G
333
334
335
337
338 G = Sparkline([27,25,25,25,25,27,100,31,25,36,25,25,39,
339 25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,
340 27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,
341 26,37,33,33,37,37,39,25,25,25,25], encoding='text')
342 G.color('0077CC')
343 G.size(200,40)
344 G.marker('B', 'E6F2FA',0,0,0)
345 G.line(1,0,0)
346 return G
347
348
355
357 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text')
358 G.color('4d89f9', 'c6d9fd')
359 G.size(200,125)
360 return G
361
363 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text')
364 G.color('4d89f9', 'c6d9fd')
365 G.size(200,125)
366 G.scale(0,160)
367 return G
368
374
380
386
393
394
396
397 G = Radar([ [77,66,15,0,31,48,100,77],[20,36,100,2,0,100] ], encoding='text')
398 G.size(200,200)
399 G.color('red','FF9900')
400 G.line(2,4,0)
401 G.line(2,4,0)
402 G.axes.type('x')
403 G.axes.label(0, 0,45,90,135,180,225,270,315)
404 G.axes.range(0, 0,360)
405 return G
406
408
409 G = Map('fSGBDQBQBBAGABCBDAKLCDGFCLBBEBBEPASDKJBDD9BHHEAACAC', encoding='simple')
410 G.color('f5f5f5','edf0d4','6c9642','365e24','13390a')
411 G.fill('bg','s','eaf7fe')
412 G.size(440,220)
413 G.map('usa', 'NYPATNWVNVNJNHVAHIVTNMNCNDNELASDDCDEFLWAKSWIORKYMEOHIAIDCTWYUTINILAKTXCOMDMAALMOMNCAOKMIGAAZMTMSSCRIAR')
414 return G
415
417
418 G = Meter(70)
419 G.label('Hello')
420 G.size(225,125)
421 return G
422
424
425
426 data = [10,20,30,40,50,60,70,80,90]
427 try:
428 from numpy import array
429 data = array(data)
430 except ImportError:
431 print('Warning: numpy must be installed to do this test correctly')
432 G = Radar(data, encoding='text')
433 G.size(200,200)
434 return G
435
437
438 G = PieC(['Helo','Wrld'], encoding='simple')
439 G.size(200,100)
440 return G
441
443
444 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')
445 G.marker('F','blue',0,'1:4',20)
446 G.size(200,125)
447 return G
448
449 - def bar_text(self):
450
451 G = HorizontalBarGroup([[40,60],[50,30]], encoding='text')
452 G.size(200,125)
453 G.marker('tApril mobile hits','black',0,0,13)
454 G.marker('tMay mobile hits','black',0,1,13,-1)
455 G.marker('tApril desktop hits','black',1,0,13)
456 G.marker('tMay desktop hits', 'black',1,1,13)
457 G.color('FF9900','FFCC33')
458 return G
459
461 G = Line(['Uf9a','a3fG'], encoding='simple')
462 G.size(250,100)
463 G.label(1,2,3,4)
464 G.fill('bg','s','e0e0e0')
465 G.color('black','blue')
466 G.margin(20,20,20,30,80,20)
467 G.legend('Temp','Sales')
468 return G
469
471 G = Line('mHMza', encoding='simple')
472 G.color('008000')
473 G.line(2.0,4.0,1.0)
474 G.size(200,140)
475 G.axes.type('x')
476 G.axes.label(0, None,'t',None,'F',None)
477 G.marker('tMin','blue',0,1,10)
478 G.marker('fMax','red',0,3,15)
479 G.margin(0,0,30,0)
480 return G
481
483
484
485 text = '''
486 1600 Ampitheatre Parkway
487 Mountain View, CA
488 (650)+253-0000
489 '''
490 G = Text('darkred',16,'h','red','b',text)
491 return G
492
494
495 G = Pin('pin_letter','A','red','black')
496 return G
497
499
500 G = Pin('pin_icon','home','yellow')
501 return G
502
504 G = Pin('xpin_letter','star','A','aqua','black','red')
505 return G
506
508
509 G = Pin('xpin_icon','star','home','aqua','red')
510 return G
511
512 - def text_pin(self):
513
514 G = Pin('spin',1.2,30,'FFFF88',10,'_','Foo\nBar')
515 return G
516
518
519 G = Note('note_title','pinned_c',1,'darkgreen','l',"Joe's\nToday 2-for-1 !\n555-1234")
520 return G
521
523
524 G = Note('note','thought',1,'navy','h',"wouldn't it be\ngreat to eat\nat Joe's?")
525 return G
526
528
529 G = Note('weather','taped_y','sunny','Barcelona','max 25°','min 15°')
530 return G
531
533
534 G = Bubble('icon_text_small','petrol','bb','$3/gal','khaki','black')
535 return G
536
538
539 G = Bubble('icon_text_big','snack','bb','$2.99','ffbb00','black')
540 return G
541
543
544 G = Bubble('icon_texts_big','petrol','bb','khaki','black','LoCost Fuel\n$3.05/gal unleaded\n$2.10/gal diesel')
545 return G
546
548
549 G = Bubble('texts_big','bb','teal','khaki',"Joe\'s Restaurant\n123 Long St\n92745 Mountain View")
550 return G
551
559
570
572 G = VerticalBarStack([43.56,35.62,48.34,57.50,67.30,60.91])
573 G.color('blue')
574 G.bar(17,15)
575 G.marker('N*cEUR1*','black',0,-1,11)
576 return G
577