GoogleCharts.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. smalltalk.addPackage('GoogleCharts', {});
  2. smalltalk.addClass('ChartApp', smalltalk.Object, [], 'GoogleCharts');
  3. smalltalk.ChartApp.comment="A chart app is an example App which loads the google JSAPI and visualization API."
  4. smalltalk.addMethod(
  5. "_begin",
  6. smalltalk.method({
  7. selector: "begin",
  8. category: 'not yet classified',
  9. fn: function (){
  10. var self=this;
  11. return self;
  12. },
  13. args: [],
  14. source: "begin\x0a\x09\x22Start the executiong of the ChartApp\x22\x0a\x09^self",
  15. messageSends: [],
  16. referencedClasses: []
  17. }),
  18. smalltalk.ChartApp);
  19. smalltalk.addMethod(
  20. "_initialize",
  21. smalltalk.method({
  22. selector: "initialize",
  23. category: 'not yet classified',
  24. fn: function (){
  25. var self=this;
  26. smalltalk.send(smalltalk.send(self,"_class",[]),"_loadGoogleLoader_",[(function(){
  27. return smalltalk.send(smalltalk.send(self,"_class",[]),"_loadVisualization_",[(function(){
  28. return smalltalk.send(self,"_begin",[]);
  29. })]);
  30. })]);
  31. return self},
  32. args: [],
  33. source: "initialize\x0a\x09\x22Load my external JS\x22\x0a self class loadGoogleLoader:[self class loadVisualization:[self begin]]\x0a ",
  34. messageSends: ["loadGoogleLoader:", "loadVisualization:", "begin", "class"],
  35. referencedClasses: []
  36. }),
  37. smalltalk.ChartApp);
  38. smalltalk.addMethod(
  39. "_loadGoogleLoader_",
  40. smalltalk.method({
  41. selector: "loadGoogleLoader:",
  42. category: 'not yet classified',
  43. fn: function (callback){
  44. var self=this;
  45. $.ajax({url:"https://www.google.com/jsapi",dataType:"script",success:callback});;
  46. ;
  47. return self},
  48. args: ["callback"],
  49. source: "loadGoogleLoader: callback\x0a\x09\x22Load the Google JSAPI - Use JQuery.ajax() since that is available\x22\x0a\x09<$.ajax({url:\x22https://www.google.com/jsapi\x22,dataType:\x22script\x22,success:callback});>",
  50. messageSends: [],
  51. referencedClasses: []
  52. }),
  53. smalltalk.ChartApp.klass);
  54. smalltalk.addMethod(
  55. "_loadVisualization_",
  56. smalltalk.method({
  57. selector: "loadVisualization:",
  58. category: 'not yet classified',
  59. fn: function (callback){
  60. var self=this;
  61. var packages;
  62. packages=smalltalk.send(self,"_neededVisualizationPackages",[]);
  63. google.load("visualization","1",{"callback" : callback , "packages":packages});;
  64. ;
  65. return self},
  66. args: ["callback"],
  67. source: "loadVisualization: callback\x0a\x09\x22Use google.load() to load visualization and load the needed packages\x22\x0a |packages|\x0a packages := self neededVisualizationPackages.\x0a <google.load(\x22visualization\x22,\x221\x22,{\x22callback\x22 : callback , \x22packages\x22:packages});>",
  68. messageSends: ["neededVisualizationPackages"],
  69. referencedClasses: []
  70. }),
  71. smalltalk.ChartApp.klass);
  72. smalltalk.addMethod(
  73. "_neededVisualizationPackages",
  74. smalltalk.method({
  75. selector: "neededVisualizationPackages",
  76. category: 'not yet classified',
  77. fn: function (){
  78. var self=this;
  79. var $1;
  80. $1=[];
  81. return $1;
  82. },
  83. args: [],
  84. source: "neededVisualizationPackages\x0a\x22This is a hook for subclasses to define which visualization packages to load.\x22\x0a\x09^{}",
  85. messageSends: [],
  86. referencedClasses: []
  87. }),
  88. smalltalk.ChartApp.klass);
  89. smalltalk.addClass('ChartButton', smalltalk.Object, ['element', 'clickBlock'], 'GoogleCharts');
  90. smalltalk.addMethod(
  91. "_activate",
  92. smalltalk.method({
  93. selector: "activate",
  94. category: 'not yet classified',
  95. fn: function (){
  96. var self=this;
  97. var button;
  98. button=smalltalk.send(smalltalk.send(self,"_element",[]),"_asJQuery",[]);
  99. smalltalk.send(button,"_click_",[(function(){
  100. return smalltalk.send(smalltalk.send(self,"_clickBlock",[]),"_value",[]);
  101. })]);
  102. return self},
  103. args: [],
  104. source: "activate\x0a\x09|button|\x0a\x09button := self element asJQuery.\x0a button click:[self clickBlock value]",
  105. messageSends: ["asJQuery", "element", "click:", "value", "clickBlock"],
  106. referencedClasses: []
  107. }),
  108. smalltalk.ChartButton);
  109. smalltalk.addMethod(
  110. "_clickBlock",
  111. smalltalk.method({
  112. selector: "clickBlock",
  113. category: 'not yet classified',
  114. fn: function (){
  115. var self=this;
  116. return self["@clickBlock"];
  117. },
  118. args: [],
  119. source: "clickBlock\x0a\x09^clickBlock",
  120. messageSends: [],
  121. referencedClasses: []
  122. }),
  123. smalltalk.ChartButton);
  124. smalltalk.addMethod(
  125. "_clickBlock_",
  126. smalltalk.method({
  127. selector: "clickBlock:",
  128. category: 'not yet classified',
  129. fn: function (aBlock){
  130. var self=this;
  131. self["@clickBlock"]=aBlock;
  132. return self},
  133. args: ["aBlock"],
  134. source: "clickBlock: aBlock\x0a\x09clickBlock := aBlock",
  135. messageSends: [],
  136. referencedClasses: []
  137. }),
  138. smalltalk.ChartButton);
  139. smalltalk.addMethod(
  140. "_element",
  141. smalltalk.method({
  142. selector: "element",
  143. category: 'not yet classified',
  144. fn: function (){
  145. var self=this;
  146. return self["@element"];
  147. },
  148. args: [],
  149. source: "element\x0a\x09^element",
  150. messageSends: [],
  151. referencedClasses: []
  152. }),
  153. smalltalk.ChartButton);
  154. smalltalk.addMethod(
  155. "_element_",
  156. smalltalk.method({
  157. selector: "element:",
  158. category: 'not yet classified',
  159. fn: function (aSymbol){
  160. var self=this;
  161. self["@element"]=aSymbol;
  162. return self},
  163. args: ["aSymbol"],
  164. source: "element: aSymbol\x0a\x09element := aSymbol",
  165. messageSends: [],
  166. referencedClasses: []
  167. }),
  168. smalltalk.ChartButton);
  169. smalltalk.addMethod(
  170. "_element_clickBlock_",
  171. smalltalk.method({
  172. selector: "element:clickBlock:",
  173. category: 'not yet classified',
  174. fn: function (elementSymbol,clickBlock){
  175. var self=this;
  176. var $2,$3,$1;
  177. $2=smalltalk.send(self,"_new",[]);
  178. smalltalk.send($2,"_element_",[elementSymbol]);
  179. smalltalk.send($2,"_clickBlock_",[clickBlock]);
  180. smalltalk.send($2,"_activate",[]);
  181. $3=smalltalk.send($2,"_yourself",[]);
  182. $1=$3;
  183. return $1;
  184. },
  185. args: ["elementSymbol", "clickBlock"],
  186. source: "element: elementSymbol clickBlock: clickBlock\x0a\x09^self new element: elementSymbol; clickBlock: clickBlock; activate;yourself",
  187. messageSends: ["element:", "new", "clickBlock:", "activate", "yourself"],
  188. referencedClasses: []
  189. }),
  190. smalltalk.ChartButton.klass);
  191. smalltalk.addMethod(
  192. "_popUpChart_atDom_",
  193. smalltalk.method({
  194. selector: "popUpChart:atDom:",
  195. category: 'not yet classified',
  196. fn: function (chart,element){
  197. var self=this;
  198. var $1;
  199. $1=smalltalk.send(self,"_element_clickBlock_",[element,(function(){
  200. return smalltalk.send(chart,"_drawChart",[]);
  201. })]);
  202. return $1;
  203. },
  204. args: ["chart", "element"],
  205. source: "popUpChart: chart atDom: element\x0a\x09\x22Make the chart popup on click of an element\x22\x0a ^self element: element clickBlock:[chart drawChart]\x0a\x09",
  206. messageSends: ["element:clickBlock:", "drawChart"],
  207. referencedClasses: []
  208. }),
  209. smalltalk.ChartButton.klass);
  210. smalltalk.addClass('GoogleChart', smalltalk.Object, ['chartId', 'chartType'], 'GoogleCharts');
  211. smalltalk.addMethod(
  212. "_arrayToDataTable_",
  213. smalltalk.method({
  214. selector: "arrayToDataTable:",
  215. category: 'data table',
  216. fn: function (array){
  217. var self=this;
  218. var $1;
  219. $1=google.visualization.arrayToDataTable(array);
  220. ;
  221. return $1;
  222. },
  223. args: ["array"],
  224. source: "arrayToDataTable: array\x0a\x0a\x09^ <google.visualization.arrayToDataTable(array)>",
  225. messageSends: [],
  226. referencedClasses: []
  227. }),
  228. smalltalk.GoogleChart);
  229. smalltalk.addMethod(
  230. "_chartId",
  231. smalltalk.method({
  232. selector: "chartId",
  233. category: 'accessor',
  234. fn: function (){
  235. var self=this;
  236. return self["@chartId"];
  237. },
  238. args: [],
  239. source: "chartId\x0a\x09^chartId",
  240. messageSends: [],
  241. referencedClasses: []
  242. }),
  243. smalltalk.GoogleChart);
  244. smalltalk.addMethod(
  245. "_chartId_",
  246. smalltalk.method({
  247. selector: "chartId:",
  248. category: 'accessor',
  249. fn: function (aString){
  250. var self=this;
  251. self["@chartId"]=aString;
  252. return self},
  253. args: ["aString"],
  254. source: "chartId: aString\x0a\x09chartId := aString",
  255. messageSends: [],
  256. referencedClasses: []
  257. }),
  258. smalltalk.GoogleChart);
  259. smalltalk.addMethod(
  260. "_chartType",
  261. smalltalk.method({
  262. selector: "chartType",
  263. category: 'accessor',
  264. fn: function (){
  265. var self=this;
  266. return self["@chartType"];
  267. },
  268. args: [],
  269. source: "chartType\x0a\x09^ chartType",
  270. messageSends: [],
  271. referencedClasses: []
  272. }),
  273. smalltalk.GoogleChart);
  274. smalltalk.addMethod(
  275. "_chartType_",
  276. smalltalk.method({
  277. selector: "chartType:",
  278. category: 'accessor',
  279. fn: function (aString){
  280. var self=this;
  281. self["@chartType"]=aString;
  282. return self},
  283. args: ["aString"],
  284. source: "chartType: aString\x0a\x09chartType := aString",
  285. messageSends: [],
  286. referencedClasses: []
  287. }),
  288. smalltalk.GoogleChart);
  289. smalltalk.addMethod(
  290. "_drawChart",
  291. smalltalk.method({
  292. selector: "drawChart",
  293. category: 'chart',
  294. fn: function (){
  295. var self=this;
  296. var chart;
  297. var data;
  298. var options;
  299. data=smalltalk.send(self,"_makeData",[]);
  300. chart=smalltalk.send(self,"_makeChart_",[smalltalk.send(self,"_chartId",[])]);
  301. options=smalltalk.send(self,"_makeOptions",[]);
  302. chart.draw(data,options);
  303. ;
  304. return self},
  305. args: [],
  306. source: "drawChart\x0a | chart data options|\x0a data := self makeData.\x0a chart :=self makeChart:self chartId.\x0a options :=self makeOptions.\x0a <chart.draw(data,options)>\x0a",
  307. messageSends: ["makeData", "makeChart:", "chartId", "makeOptions"],
  308. referencedClasses: []
  309. }),
  310. smalltalk.GoogleChart);
  311. smalltalk.addMethod(
  312. "_getElementById_",
  313. smalltalk.method({
  314. selector: "getElementById:",
  315. category: 'DOM',
  316. fn: function (id){
  317. var self=this;
  318. var $1;
  319. $1=document.getElementById(id);
  320. ;
  321. return $1;
  322. },
  323. args: ["id"],
  324. source: "getElementById: id\x0a\x09\x22Find element by the id in the DOM\x22\x0a\x09^ <document.getElementById(id)>",
  325. messageSends: [],
  326. referencedClasses: []
  327. }),
  328. smalltalk.GoogleChart);
  329. smalltalk.addMethod(
  330. "_initialize",
  331. smalltalk.method({
  332. selector: "initialize",
  333. category: 'init',
  334. fn: function (){
  335. var self=this;
  336. return self;
  337. },
  338. args: [],
  339. source: "initialize\x0a\x09^self",
  340. messageSends: [],
  341. referencedClasses: []
  342. }),
  343. smalltalk.GoogleChart);
  344. smalltalk.addMethod(
  345. "_makeChart_",
  346. smalltalk.method({
  347. selector: "makeChart:",
  348. category: 'chart',
  349. fn: function (id){
  350. var self=this;
  351. var $1;
  352. var e;
  353. var t;
  354. e=smalltalk.send(self,"_getElementById_",[id]);
  355. t=smalltalk.send(self,"_chartType",[]);
  356. $1=new google.visualization[t](e);
  357. ;
  358. return $1;
  359. },
  360. args: ["id"],
  361. source: "makeChart: id\x0a\x22build a chart at specific element id in the DOM and return\x22\x0a\x09|e t|\x0a e := self getElementById:id.\x0a t := self chartType.\x0a ^ <new google.visualization[t](e)>",
  362. messageSends: ["getElementById:", "chartType"],
  363. referencedClasses: []
  364. }),
  365. smalltalk.GoogleChart);
  366. smalltalk.addMethod(
  367. "_makeData",
  368. smalltalk.method({
  369. selector: "makeData",
  370. category: 'abstraction',
  371. fn: function (){
  372. var self=this;
  373. var $1;
  374. $1=smalltalk.send(self,"_subclassresponsibility",[]);
  375. return $1;
  376. },
  377. args: [],
  378. source: "makeData\x0a\x09\x22abstraction - return the data for a google chart\x22\x0a \x09 ^self subclassresponsibility",
  379. messageSends: ["subclassresponsibility"],
  380. referencedClasses: []
  381. }),
  382. smalltalk.GoogleChart);
  383. smalltalk.addMethod(
  384. "_makeOptions",
  385. smalltalk.method({
  386. selector: "makeOptions",
  387. category: 'abstraction',
  388. fn: function (){
  389. var self=this;
  390. var $1;
  391. $1=smalltalk.send(self,"_subclassresponsibility",[]);
  392. return $1;
  393. },
  394. args: [],
  395. source: "makeOptions\x0a\x09\x22Abstract method - return options for a Google Chart\x22\x0a ^\x09 self subclassresponsibility",
  396. messageSends: ["subclassresponsibility"],
  397. referencedClasses: []
  398. }),
  399. smalltalk.GoogleChart);
  400. smalltalk.addMethod(
  401. "_chartId_",
  402. smalltalk.method({
  403. selector: "chartId:",
  404. category: 'not yet classified',
  405. fn: function (aString){
  406. var self=this;
  407. var $2,$3,$1;
  408. $2=smalltalk.send(self,"_new",[]);
  409. smalltalk.send($2,"_chartId_",[aString]);
  410. $3=smalltalk.send($2,"_yourself",[]);
  411. $1=$3;
  412. return $1;
  413. },
  414. args: ["aString"],
  415. source: "chartId: aString\x0a\x09^self new chartId:aString;yourself",
  416. messageSends: ["chartId:", "new", "yourself"],
  417. referencedClasses: []
  418. }),
  419. smalltalk.GoogleChart.klass);
  420. smalltalk.addClass('GaugeChart', smalltalk.GoogleChart, [], 'GoogleCharts');
  421. smalltalk.addMethod(
  422. "_initialize",
  423. smalltalk.method({
  424. selector: "initialize",
  425. category: 'not yet classified',
  426. fn: function (){
  427. var self=this;
  428. smalltalk.send(self,"_initialize",[],smalltalk.GoogleChart);
  429. smalltalk.send(self,"_chartType_",["Gauge"]);
  430. return self;
  431. },
  432. args: [],
  433. source: "initialize\x0a\x09\x22 Create a Guage with the chartId that identifies the chart graphic placement and the chartType to be created at that id.\x22\x0a super initialize.\x0a self chartType:'Gauge'.\x0a\x09^self",
  434. messageSends: ["initialize", "chartType:"],
  435. referencedClasses: []
  436. }),
  437. smalltalk.GaugeChart);
  438. smalltalk.addClass('GeoChart', smalltalk.GoogleChart, [], 'GoogleCharts');
  439. smalltalk.addMethod(
  440. "_initialize",
  441. smalltalk.method({
  442. selector: "initialize",
  443. category: 'not yet classified',
  444. fn: function (){
  445. var self=this;
  446. smalltalk.send(self,"_initialize",[],smalltalk.GoogleChart);
  447. smalltalk.send(self,"_chartType_",["GeoChart"]);
  448. return self;
  449. },
  450. args: [],
  451. source: "initialize\x0a\x09\x22 Create a Geo Chart\x22\x0a super initialize.\x0a self chartType:'GeoChart'.\x0a\x09^self",
  452. messageSends: ["initialize", "chartType:"],
  453. referencedClasses: []
  454. }),
  455. smalltalk.GeoChart);
  456. smalltalk.addClass('PieChart', smalltalk.GoogleChart, [], 'GoogleCharts');
  457. smalltalk.addMethod(
  458. "_initialize",
  459. smalltalk.method({
  460. selector: "initialize",
  461. category: 'not yet classified',
  462. fn: function (){
  463. var self=this;
  464. smalltalk.send(self,"_initialize",[],smalltalk.GoogleChart);
  465. smalltalk.send(self,"_chartType_",["PieChart"]);
  466. return self;
  467. },
  468. args: [],
  469. source: "initialize\x0a\x09super initialize.\x0a self chartType:'PieChart'.\x0a\x09^self",
  470. messageSends: ["initialize", "chartType:"],
  471. referencedClasses: []
  472. }),
  473. smalltalk.PieChart);
  474. smalltalk.addClass('ScatterChart', smalltalk.GoogleChart, [], 'GoogleCharts');
  475. smalltalk.addMethod(
  476. "_initialize",
  477. smalltalk.method({
  478. selector: "initialize",
  479. category: 'not yet classified',
  480. fn: function (){
  481. var self=this;
  482. smalltalk.send(self,"_initialize",[],smalltalk.GoogleChart);
  483. smalltalk.send(self,"_chartType_",["ScatterChart"]);
  484. return self;
  485. },
  486. args: [],
  487. source: "initialize\x0a\x09super initialize.\x0a self chartType:'ScatterChart'.\x0a\x09^self",
  488. messageSends: ["initialize", "chartType:"],
  489. referencedClasses: []
  490. }),
  491. smalltalk.ScatterChart);