1
2 from GChartWrapper import *
3 from GChartWrapper.constants import PY_VER,_print
4 import unittest
5
7 """
8 Extensive unit tests, more are welcome
9
10 All methods should be commented and must return a GChart instance as the last line.
11 """
12
13 all = {
14 'currency_bar':'8ec06bda7223eb500e7f0357efd6e717543d9abb',
15 'financial':'0c3dee619eb6c43d8b5405f537438467a7d736e5',
16 'text_pin':'42558403a2a9d66e9b54deea094114029c86d529',
17 'simple':'1fb72aac2758d164bca43a40472ae185091291b1',
18 'text':'4e1f2755c9f6160d959ed91829543e0687b55a0e',
19 'guide_granularity_20':'1dfcb2ba4444e3c09be3b55221cc04e5a5c0bf32',
20 'pie':'3fe7636938cda678be044848799a2c87ecad6099',
21 'small_bubble_icon':'65d1df5f7bda98cfaea2a96dfe8dcca1058c444c',
22 'guide_granularity_40':'dc7d8714f28d7a59d2b768ecba7f685814a73bd4',
23 'guide_radar':'9703b8ca52e8c38c37353c6935d5053f8120c37a',
24 'icon_pin':'01110b589dbe1ed9aed7a3eb057bd9020b6d21a2',
25 'guide_sparkline':'767bab6609f60b6c7185b0ed0a1434ad9d73f4c7',
26 'guide_bhg':'b051f7ab51afd534f89095fab7db3c161fcb3bc3',
27 'margins':'4f995e40b16a49d0c407c0bf1b536f7642f6253d',
28 'venn':'cf327d123a3a2fdf04620a966903fc20f096f82c',
29 'fill':'1766f4b8b774d41985a4a3b2ab3f9791dedab2a3',
30 'guide_line_lc':'11ec3b84d8de22e8bf6a32cbca3b62374aa68a46',
31 'large_bubble_icon_texts':'20c705a0e3038594749b8b9cdf8f09e470e76b17',
32 'large_bubble_texts':'ff1474c87defa687727a4ee42dca9c641a46668c',
33 'guide_granularity_300':'0d5a40563ad832312bd357564a9da9787e38d6ef',
34 'large_bubble_icon':'f09ebedf3cc5c461604539afdcff9dac09817d71',
35 'adv_icon_pin':'b8a2ec08aeb3fb0a839598a82dfba02c7cdc8638',
36 'axes':'6040f894d8e71160b9e87541f7ef9db224efae9c',
37 'qr_code':'bdcea2f3b1dbb331de2ed8a730736c99f2d81c90',
38 'markers':'fc7ab02d17a07a611a02b0a4dda7763c4bfec712',
39 'guide_granularity_80':'014f1a251dab5fa14fdadf7868b64a210bb1cf5e',
40 'axes_position':'7d6d5d0fa5565ef3e1069ba91db472484a339696',
41 'jacobian':'6d0d251ac640c0d5185124cb5ea9ccc636268f14',
42 'multiline':'5f27957e39363ca470c0e97d1fcffdc19fa00afb',
43 'numpy':'9b0fb89df43d69b64755153b919e598180fc1a9d',
44 'guide_meter':'cdad708a80c49b705212d098bf83f9ccb30610aa',
45 'letter_pin':'430c921aa8d73e80feae07b2ba04909c6a6b1ab3',
46 'guide_granularity_150':'35281ef165d532021290c003e2068527d40003b0',
47 'guide_intro':'0b3b189c0675fd51bda46714706e3f7dfb4164dc',
48 'thought_note':'9375cabf12b442764db34862c68ae74f85c42ca9',
49 'czech_and_unicode':'ead386ad75dabb21e13fd4b3a357d6025bdd4506',
50 'guide_bvg':'36ce2efaf74fad1912b8351147b821d0253f9c56',
51 'min_max':'5aae24644331ca33c0cb83dc01a34d389edd6adf',
52 'guide_bhs':'a1d1801762105d58f67c544be36e2af7bf69a2a8',
53 'guide_map':'2391235ee09f58cc194eaf16b3c87f839613ebc5',
54 'guide_bvs':'e65f1bea45ae7197943366d8de1268aad6e5b66d',
55 'grid':'90953636424f46e568bf8a316efbba4df0461eef',
56 'legend2':'acc8c1a1199e2363fee076486365b6f8a29e72a0',
57 'line':'9b6f9a566b49fa23c91a6f992e4a4737caac4ae5',
58 'guide_chbh_size':'a6b043ed705fe90afef78c393403fc813ca7aa1e',
59 'legend':'33cd2c7acdc4aa9745ed95a0aa1ff641525adf5c',
60 'adv_letter_pin':'97cd7dac85adad57e2cf8209d0795a4f5216cb6a',
61 'sticky_note':'a3a55893fc130abd814c80c9841e3547e2c2877a',
62 'bar':'d3251fb77a28a5918955020c745fa435b0f4a314',
63 'bar_text':'c01b4efa34a4850f6888ebcde3d9ee28ba621f85',
64 'title':'40d64c1c3aeb9c3836e501033c4bf65da2ff2f83',
65 'tick_marks':'9cab6532523a353cd87d3edec45d9222de9dde5d',
66 'concentric_pie':'cb6325bb97779fabdc77c8ab76e6bf4ed1d5447b',
67 'hvz':'7a890b9c2c6016faff3cb6789d9732a5caf8fa9d',
68 'guide_chbh_clipped':'83ff879fc173bbcf80350d62d7d880b619424d10',
69 'guide_bvs_scale':'a327b4be8fa55deccba5b4baab7680c75f621064',
70 'weather_note':'9a7988231bc235bda5ab21e19288fba5b554adf7',
71 'markerfill':'95664c2d4aeae5bcb94b1b003b361e2035d44e64',
72 'packman':'2cd25d4a258abb9d62d144668e3cb54f71b01af1',
73 'interval':'5e60f45fb27f32aefe048d9eb22f17a7d117c162',
74 'bar_zero':'94219f27b54883078db0ef744292a40e46de2da7',
75 'omitted_colors':'bc72f51d748767fc1692b6a227d5184415e9e2f5',
76 'scatter':'36f99c6a7e93af8d164af220ae626c10002f808e',
77 'fancy_radar':'049d0fe4a213204e8e31f07658c7a665ea866698',
78 'legend_position':'5f2d550e98ae1a85312b4d7e33761d30ca89acfd'
79 }
80
83
85 chart_name = rep.split('test_')[1][:-1]
86 self.assertEqual(self.all[chart_name], test, '%s: %s != %s'%(chart_name,self.all[chart_name],test))
87
89 G = Scatter([[12,87,75,41,23,96,68,71,34,9],[98,60,27,34,56,79,58,74,18,76],[84,23,69,81,47,94,60,93,64,54]])
90 G.axes('xy')
91 G.axes.label(0, 0,20,30,40,50,60,70,80,90,10)
92 G.axes.label(1, 0,25,50,75,100)
93 G.size(300,200)
94 self._test_a_chart(repr(self), G.checksum())
95 return G
96
98 G = RadarSpline(['voJATd9v','MW9BA9'],encoding='simple')
99 G.color('red','orange')
100 G.size(400,400)
101 G.line(2,4,0)
102 G.line(2,4,0)
103 G.axes('x')
104 G.axes.label(0, 0,45,90,135,180,225,270,315)
105 G.axes.range(0, 0.0,360.0)
106 G.grid(25.0,25.0,4.0,4.0)
107 G.marker('B','FF000080',0,1.0,5.0)
108 G.marker('B','FF990080',1,1.0,5.0)
109 G.marker('h','blue',0,1.0,4.0)
110 G.marker('h','3366CC80',0,0.5,5.0)
111 G.marker('V','00FF0080',0,1.0,5.0)
112 G.marker('V','008000',0,5.5,5.0)
113 G.marker('v','00A000',0,6.5,4)
114 self._test_a_chart(repr(self), G.checksum())
115 return G
116
118 G = Line([[20,10,15,25,17,30],[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',series=1)
119 G.scale(0,100,-50,100)
120 G.marker('F','',1,'1:4',20)
121 self._test_a_chart(repr(self), G.checksum())
122 return G
123
130
139
146
159
161
162 G = VerticalBarGroup( [[31],[59],[4]], encoding='text' )
163 G.scale(0,59)
164 G.color('lime','red','blue')
165 G.legend('Goucher(31)','Truman(59)','Kansas(4)')
166 G.fill('c','lg',45,'cccccc',0,'black',1)
167 G.fill('bg','s','cccccc')
168 G.size(200,100)
169 self._test_a_chart(repr(self), G.checksum())
170 return G
171
173
174
175 G = QRCode('''To the human eye QR Codes look like hieroglyphics,
176 but they can be read by any device that has
177 the appropriate software installed.''')
178
179 G.output_encoding('UTF-8')
180
181 G.level_data('M',0)
182 self._test_a_chart(repr(self), G.checksum())
183 return G
184
186
187 G = Line( ['GurMrabsClgubaolGvzCrgrefOrnhgvshyvforggregunahtyl'] )
188 G.title('The Zen of Python','00cc00',36)
189 G.color('00cc00')
190 self._test_a_chart(repr(self), G.checksum())
191 return G
192
194
195
196 G = Line( ['hX1xPj'] )
197 G.axes('xy')
198 G.axes.label(0, 'Mar', 'Apr', 'May', 'June', 'July')
199 G.axes.label(1, None, '50+Kb')
200 G.color('red')
201 G.line(6,5,2)
202 self._test_a_chart(repr(self), G.checksum())
203 return G
204
213
221
228
230
231
232
233 G = Line( ['foobarbaz'] )
234 G.color('76A4FB')
235 G.axes('xyrx')
236 G.axes.label(0,'Foo', 'Bar', 'Baz')
237 G.axes.style(0, '0000dd', 14)
238 G.axes.label(1, None, '20K', '60K', '100K')
239 G.axes.label(2, 'A', 'B', 'C')
240 G.axes.label(3, None,'20','40','60','80')
241 self._test_a_chart(repr(self), G.checksum())
242 return G
243
253
255
256 G = Line( ['helloWorldZZZZ098236561'] )
257 G.marker('c','red',0,1,20)
258 G.marker('d','80C65A',0,6,15)
259 G.marker('o','FF9900',0,4.0,20.0)
260 G.marker('s','3399CC',0,5.0,10.0)
261 G.marker('v','BBCCED',0,6.0,1.0)
262 G.marker('V','3399CC',0,7.0,1.0)
263 G.marker('x','FFCC33',0,8.0,20.0)
264 G.marker('h','black',0,0.30,0.5 )
265 G.marker('a','000099',0,4,10)
266 G.marker('R','A0BAE9',0,8,0.6)
267 G.marker('r','E5ECF9',0,1,0.25)
268 self._test_a_chart(repr(self), G.checksum())
269 return G
270
272
273 G = Line(['ALAtBmC1EcGYIsLWOXRuVdZhd9ivn4tYzO5b..'],encoding='extended')
274 G.size(300,200)
275 G.color('cc0000')
276 G.fill('c','s','eeeeee')
277 G.legend('Sweet')
278 self._test_a_chart(repr(self), G.checksum())
279 return G
280
282
283 G = Line( ['99','cefhjkqwrlgYcfgc',
284 'QSSVXXdkfZUMRTUQ','HJJMOOUbVPKDHKLH','AA'] )
285 G.marker('b','76A4FB',0,1,0)
286 G.marker('b','224499',1,2,0)
287 G.marker('b','red',2,3,0)
288 G.marker('B','80C65A',3,4,0)
289 self._test_a_chart(repr(self), G.checksum())
290 return G
291
293
294 G = Line( ['pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp'] )
295 G.color('red')
296 G.line(4,3,0)
297 G.axes('xy')
298 G.axes.label(0, 1,2,3,4,5)
299 G.axes.label(1, None,50,100)
300 G.fill('c','lg',45,'white',0,'76A4FB',0.75)
301 G.fill('bg','s','EFEFEF')
302 self._test_a_chart(repr(self), G.checksum())
303 return G
304
305
307
308 G = Line( ['FOETHECat','leafgreen','IRON4YOUs'] )
309 G.color('red','lime','blue')
310 G.legend('Animals','Vegetables','Minerals')
311 G.axes('y')
312 self._test_a_chart(repr(self), G.checksum())
313 return G
314
324
326
327 G = Venn([100,20,20,20,20,0,0])
328 G.legend('First','Second','Third')
329 G.legend_pos('t')
330 G.color('red','lime','blue')
331 self._test_a_chart(repr(self), G.checksum())
332 return G
333
335
336 G = LineXY( [
337 [0,30,60,70,90,95,100],
338 [20,30,40,50,60,70,80],
339 [10,30,40,45,52],
340 [100,90,40,20,10],
341 ['-1'],
342 [5,33,50,55,7],
343 ])
344 G.scale(0,100)
345 G.color('3072F3','red','00aaaa')
346 G.marker('s','red',0,-1,5)
347 G.marker('s','blue',1,-1,5)
348 G.marker('s','00aa00',2,-1,5)
349 G.line(2,4,1)
350 self._test_a_chart(repr(self), G.checksum())
351 return G
352
354
355
356 data = [[4.6, 6.0, 7.4, 11.6, 12.0, 14.8, 18.1, 25.1,
357 27.9, 28.3, 30.6, 34.4, 43.7, 48.3, 57.6, 64.6,
358 72.5, 74.4, 76.2, 77.2, 86.0, 86.9, 93.9, 96.7, 99.0],
359 [80.5, 100.0, 95.4, 93.7, 96.3, 91.7, 71.5, 63.0,
360 65.2, 65.5, 66.0, 75.9, 65.8, 64.4, 64.2, 62.5, 37.2,
361 35.3, 32.4, 35.2, 38.4, 37.9, 69.8, 38.0, 64.5]]
362
363
364 axis = [ [0, 13, 28, 42, 56, 71, 84, 100],
365 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] ]
366
367
368 min_value = float(min(data[1]))
369 max_value = float(max(data[1]))
370 last_value = float(data[1][-1])
371
372 G = LineXY(data, encoding='text')
373 G.color('76A4FB')
374 G.marker('o', '0077CC',0,-1,5)
375 G.marker('r', 'E6F2FA',0,(min_value/max_value),1.0)
376 G.axes("xyr")
377 G.axes.label(0, *axis[1])
378 G.axes.position(0, *axis[0])
379 G.axes.label(1, '%d'%min_value, '%d'%max_value)
380 G.axes.position(1, int(100*min_value/max_value),100)
381 G.axes.label(2, '%d'%last_value)
382 G.axes.position(2, int(100*last_value/max_value))
383 self._test_a_chart(repr(self), G.checksum())
384 return G
385
386
387
388
395
404
413
415 G = Line('formostthisamazingdayfortheleapinggreenlformostthisamazingdayfortheleapinggreenl',
416 encoding='simple')
417 G.size(200,100)
418 G.axes('xy')
419 G.axes.label(0, 'April','May','June')
420 G.axes.label(1, None, '50+Kb')
421 self._test_a_chart(repr(self), G.checksum())
422 return G
423
425 G = Line('ithankYouGodformostthisamazingdayfortheleapinggreenlyspiritsoftreesandabluetruedreamofskyandforeverythingwhichisnaturalwhichisinfinitewhichisyeseecumm',
426 encoding='simple')
427 G.size(200,100)
428 G.axes('xy')
429 G.axes.label(0, 'April','May','June')
430 G.axes.label(1, None, '50+Kb')
431 self._test_a_chart(repr(self), G.checksum())
432 return G
433
435 G = Line('ithankYouGodformostthisamazingdayfortheleapinggreenlyspiritsoftreesandabluetruedreamofskyandforeverythingwhichisnaturalwhichisinfinitewhichisyesithankYouGodformostthisamazingdayfortheleapinggreenlyspiritsoftreesandabluetruedreamofskyandforeverythingwhichisnaturalwhichisinfinitewhichisyeseecummings',
436 encoding='simple')
437 G.size(200,100)
438 G.axes('xy')
439 G.axes.label(0, 'April','May','June')
440 G.axes.label(1, None, '50+Kb')
441 self._test_a_chart(repr(self), G.checksum())
442 return G
443
450
451
452
454
455 G = Sparkline([27,25,25,25,25,27,100,31,25,36,25,25,39,
456 25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,
457 27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,
458 26,37,33,33,37,37,39,25,25,25,25], encoding='text')
459 G.color('0077CC')
460 G.size(200,40)
461 G.marker('B', 'E6F2FA',0,0,0)
462 G.line(1,0,0)
463 self._test_a_chart(repr(self), G.checksum())
464 return G
465
466
474
476 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text')
477 G.color('4d89f9', 'c6d9fd')
478 G.size(200,125)
479 self._test_a_chart(repr(self), G.checksum())
480 return G
481
483 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text')
484 G.color('4d89f9', 'c6d9fd')
485 G.size(200,125)
486 G.scale(0,160)
487 self._test_a_chart(repr(self), G.checksum())
488 return G
489
496
503
510
518
520
521 G = Radar([ [77,66,15,0,31,48,100,77],[20,36,100,2,0,100] ], encoding='text')
522 G.size(200,200)
523 G.color('red','FF9900')
524 G.line(2,4,0)
525 G.line(2,4,0)
526 G.axes('x')
527 G.axes.label(0, 0,45,90,135,180,225,270,315)
528 G.axes.range(0, 0,360)
529 self._test_a_chart(repr(self), G.checksum())
530 return G
531
533
534 G = Map('fSGBDQBQBBAGABCBDAKLCDGFCLBBEBBEPASDKJBDD9BHHEAACAC', encoding='simple')
535 G.color('f5f5f5','edf0d4','6c9642','365e24','13390a')
536 G.fill('bg','s','eaf7fe')
537 G.size(440,220)
538 G.map('usa', 'NYPATNWVNVNJNHVAHIVTNMNCNDNELASDDCDEFLWAKSWIORKYMEOHIAIDCTWYUTINILAKTXCOMDMAALMOMNCAOKMIGAAZMTMSSCRIAR')
539 self._test_a_chart(repr(self), G.checksum())
540 return G
541
549
551
552
553 data = [10,20,30,40,50,60,70,80,90]
554 try:
555 from numpy import array
556 data = array(data)
557 except ImportError:
558 _print('Warning: numpy must be installed to do this test correctly')
559 G = Radar(data, encoding='text')
560 G.size(200,200)
561 self._test_a_chart(repr(self), G.checksum())
562 return G
563
570
572
573 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')
574 G.marker('F','blue',0,'1:4',20)
575 G.size(200,125)
576 self._test_a_chart(repr(self), G.checksum())
577 return G
578
579 - def test_bar_text(self):
580
581 G = HorizontalBarGroup([[40,60],[50,30]], encoding='text')
582 G.size(200,125)
583 G.marker('tApril mobile hits','black',0,0,13)
584 G.marker('tMay mobile hits','black',0,1,13,-1)
585 G.marker('tApril desktop hits','black',1,0,13)
586 G.marker('tMay desktop hits', 'black',1,1,13)
587 G.color('FF9900','FFCC33')
588 self._test_a_chart(repr(self), G.checksum())
589 return G
590
592 G = Line(['Uf9a','a3fG'], encoding='simple')
593 G.size(250,100)
594 G.label(1,2,3,4)
595 G.fill('bg','s','e0e0e0')
596 G.color('black','blue')
597 G.margin(20,20,20,30,80,20)
598 G.legend('Temp','Sales')
599 self._test_a_chart(repr(self), G.checksum())
600 return G
601
603 G = Line('mHMza', encoding='simple')
604 G.color('008000')
605 G.line(2.0,4.0,1.0)
606 G.size(200,140)
607 G.axes('x')
608 G.axes.label(0, None,'t',None,'F',None)
609 G.marker('tMin','blue',0,1,10)
610 G.marker('fMax','red',0,3,15)
611 G.margin(0,0,30,0)
612 self._test_a_chart(repr(self), G.checksum())
613 return G
614
615 - def test_text(self):
616
617
618 text = '''
619 1600 Ampitheatre Parkway
620 Mountain View, CA
621 (650)+253-0000
622 '''
623 G = Text('darkred',16,'h','red','b',text)
624 self._test_a_chart(repr(self), G.checksum())
625 return G
626
632
638
640 G = Pin('xpin_letter','star','A','aqua','black','red')
641 self._test_a_chart(repr(self), G.checksum())
642 return G
643
649
650 - def test_text_pin(self):
651
652 G = Pin('spin',1.2,30,'FFFF88',10,'_','Foo\nBar')
653 self._test_a_chart(repr(self), G.checksum())
654 return G
655
657
658 G = Note('note_title','pinned_c',1,'darkgreen','l',"Joe's\nToday 2-for-1 !\n555-1234")
659 self._test_a_chart(repr(self), G.checksum())
660 return G
661
663
664 G = Note('note','thought',1,'navy','h',"wouldn't it be\ngreat to eat\nat Joe's?")
665 self._test_a_chart(repr(self), G.checksum())
666 return G
667
669
670 G = Note('weather','taped_y','sunny','Barcelona','max 25°','min 15°')
671 self._test_a_chart(repr(self), G.checksum())
672 return G
673
675
676 G = Bubble('icon_text_small','petrol','bb','$3/gal','khaki','black')
677 self._test_a_chart(repr(self), G.checksum())
678 return G
679
681
682 G = Bubble('icon_text_big','snack','bb','$2.99','ffbb00','black')
683 self._test_a_chart(repr(self), G.checksum())
684 return G
685
687
688 G = Bubble('icon_texts_big','petrol','bb','khaki','black','LoCost Fuel\n$3.05/gal unleaded\n$2.10/gal diesel')
689 self._test_a_chart(repr(self), G.checksum())
690 return G
691
693
694 G = Bubble('texts_big','bb','teal','khaki',"Joe\'s Restaurant\n123 Long St\n92745 Mountain View")
695 self._test_a_chart(repr(self), G.checksum())
696 return G
697
706
708 G = Line('cEAELFJHHHKUju9uuXUc', encoding="simple")
709 G.color('76A4FB')
710 G.size(220, 125)
711 G.line(2)
712 G.axes('xyrx')
713 G.axes.range(1, 0,4)
714 G.axes.label(2, 'min','avg','max')
715 G.axes.label(3, 'Jan','Feb','Mar')
716 G.axes.style(2, '0000DD',13,-1,'t','FF0000')
717 G.axes.position(2, 10,35,95)
718 G.axes.tick(1,10)
719 G.axes.tick(2,-180)
720 self._test_a_chart(repr(self), G.checksum())
721 return G
722
724 G = VerticalBarStack([43.56,35.62,48.34,57.50,67.30,60.91])
725 G.color('blue')
726 G.bar(17,15)
727 G.marker('N*cEUR1*','black',0,-1,11)
728 self._test_a_chart(repr(self), G.checksum())
729 return G
730
732 url='http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World'
733 self.assertEqual(GChart.fromurl(url).checksum(),'4e53c7add42ce61a933ce106a9854222c54c9147')
734
735
738
743
744
745
746
747
748 head = """
749 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
750 <html xmlns="http://www.w3.org/1999/xhtml">
751 <head>
752 <title>
753 Welcome - Chartography.net
754 </title>
755 <link rel="stylesheet" type="text/css" href="http://chartography.net/media/css/style.css" /> <link rel="shortcut icon" href="http://chartography.net/media/favicon.ico" type="image/x-icon" />
756 <meta name="keywords" content="chartography, open source, chart, pastebin, blog, weather" />
757 <meta name="description" content="Chartography.net: It's a blog! It's a pastebin! It's a chart editor?" />
758 <script type="text/javascript" src="http://chartography.net/media/jquery-1.2.1.js"></script>
759 </head>
760 <body >
761 <div style="position: absolute; float:left; width: 14%;" align="right">
762 <br>
763 <br>
764 <br>
765 <script type="text/javascript"><!--
766 google_ad_client = "pub-6864487851298261";
767 /* ChartographySkyscraper */
768 google_ad_slot = "7196398796";
769 google_ad_width = 120;
770 google_ad_height = 600;
771 //-->
772 </script>
773 <script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
774 </div>
775 <div class="container">
776 <div class="titleblock" style="background-image:url(http://chartography.net/media/globe1.png);">
777 <h1>
778 Chartography.net
779 </h1>
780 </div>
781 <div>
782 <ul class="navbar">
783 <li><a href="http://chartography.net/" class="nav">Home</a></li>
784 <li><a href="http://chartography.net/charts/" class="nav">Sandbox</a></li>
785 <li><a href="http://chartography.net/charts/all/" class="nav">Charts</a></li>
786 <li><a href="http://chartography.net/pastebin/" class="nav">Paste Bin</a></li>
787 <li><a href="http://chartography.net/weather/" class="nav">Weather</a></li>
788 </ul>
789 </div>
790 <div>
791 <div style="position; absolute; float: left;" align="left">
792
793 </div>
794 <div style="position; absolute; float: right;" align="right">
795 <script type="text/javascript">var addthis_pub = "justquick";</script>
796 <a href="http://www.addthis.com/bookmark.php" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" border="0" alt="" /></a>
797 <script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
798 </div>
799 </div>
800 <div class="content">"""
801
802 foot = """
803 </div>
804 </div>
805 <script type="text/javascript">
806 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
807 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
808 </script>
809 <script type="text/javascript">
810 try {
811 var pageTracker = _gat._getTracker("UA-2806385-6");
812 pageTracker._trackPageview();
813 } catch(err) {}</script>
814 </body>
815 </html>"""
816
817
819 from inspect import getsource
820
821 html = """
822 <style>
823 %(css)s
824 </style>
825 %(img)s
826 <pre>%(code)s</pre>"""
827 lnks = []
828 from pygments import highlight
829 from pygments.lexers import PythonLexer
830 from pygments.formatters import HtmlFormatter
831
832 for chart in TestChartTypes.all:
833 obj = getattr(TestChartTypes('test_%s'%chart),'test_%s'%chart)
834 lines = getsource(obj).splitlines()
835 lines[0] = lines[0].replace('(self)','()').replace('def test_','def ')
836 del lines[-2]
837 lines = ['from GChartWrapper import *'] + [x[8:] for x in lines[1:-1]]
838 w = 225
839 if chart.find('pin')>-1: w = 50
840 o = obj()
841 lnks.append('<a href="%s" class="thickbox">%s</a>' %
842 ('%s.html'%chart,o.img(border=0,width=w)) )
843 fo=open('demo/%s.html'%chart,'w')
844 fo.write(head)
845 fo.write(html % {
846 'css': HtmlFormatter(encoding='utf-8').get_style_defs('.highlight'),
847 'code':highlight('\n'.join(lines), PythonLexer(encoding='chardet'),
848 HtmlFormatter(encoding='utf-8')),
849 'img':o.img(),
850 'name':chart
851 })
852 fo.write(foot)
853 fo.close()
854 fo = open('demo/index.html','w')
855 fo.write(head+'<table>')
856 for i,x in enumerate(lnks):
857 if i == 0:
858 fo.write('<tr>')
859 if i % 3 == 0:
860 fo.write('</tr><tr>')
861 fo.write('<td width="25%%">%s</td>'%x)
862 fo.write(foot)
863 fo.close()
864
865 if __name__ == '__main__':
866 import sys
867 calls = {
868 'unit': lambda: unittest.main(),
869 'save': lambda: saveall(),
870 'demo': demo,
871 }
872 arg = sys.argv[-1]
873 sys.argv = sys.argv[:-1]
874 if arg in calls:
875 calls[arg]()
876 else:
877 for chart in TestChartTypes.all:
878 _print( chart,'\t',get_chart(chart))
879