| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | |
| 8 | 8 | (function($) { |
| 9 | 9 | var gv; |
| 10 | 10 | var all_charts, objects; |
| 11 | + // so that we know which charts belong to our library. | |
| 12 | + var rendered_charts = []; | |
| 11 | 13 | |
| 12 | 14 | function renderChart(id) { |
| 13 | 15 | renderSpecificChart(id, all_charts[id]); |
| 14 | 16 | } |
| @@ -18,8 +20,9 @@ | ||
| 18 | 20 | |
| 19 | 21 | if(chart.library !== 'google'){ |
| 20 | 22 | return; |
| 21 | 23 | } |
| 24 | + rendered_charts[id] = 'yes'; | |
| 22 | 25 | |
| 23 | 26 | series = chart.series; |
| 24 | 27 | data = chart.data; |
| 25 | 28 | settings = chart.settings; |
| @@ -131,8 +134,9 @@ | ||
| 131 | 134 | case 'area': |
| 132 | 135 | case 'scatter': |
| 133 | 136 | case 'candlestick': |
| 134 | 137 | case 'column': |
| 138 | + case 'combo': | |
| 135 | 139 | axis = settings.hAxis; |
| 136 | 140 | break; |
| 137 | 141 | case 'bar': |
| 138 | 142 | axis = settings.vAxis; |
| @@ -213,8 +217,9 @@ | ||
| 213 | 217 | override(settings); |
| 214 | 218 | |
| 215 | 219 | gv.events.addListener(render, 'ready', function () { |
| 216 | 220 | var arr = id.split('-'); |
| 221 | + __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = ''; | |
| 217 | 222 | try{ |
| 218 | 223 | var img = render.getImageURI(); |
| 219 | 224 | __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = img; |
| 220 | 225 | $('body').trigger('visualizer:render:chart', {id: arr[1], image: img}); |
| @@ -288,9 +293,9 @@ | ||
| 288 | 293 | |
| 289 | 294 | resizeHiddenContainers(true); |
| 290 | 295 | }); |
| 291 | 296 | |
| 292 | - $(window).load(function(){ | |
| 297 | + $(window).on('load', function(){ | |
| 293 | 298 | resizeHiddenContainers(true); |
| 294 | 299 | }); |
| 295 | 300 | |
| 296 | 301 | function resizeHiddenContainers(everytime){ |
| @@ -319,10 +324,44 @@ | ||
| 319 | 324 | }); |
| 320 | 325 | } |
| 321 | 326 | |
| 322 | 327 | $('body').on('visualizer:render:chart:start', function(event, v){ |
| 328 | + var $chart_types = ['corechart', 'geochart', 'gauge', 'table', 'timeline']; | |
| 329 | + if(v.is_front == true){ // jshint ignore:line | |
| 330 | + // check what all chart types to load. | |
| 331 | + $chart_types = []; | |
| 332 | + $.each(v.charts, function(i, c){ | |
| 333 | + var $type = c.type; | |
| 334 | + switch($type){ | |
| 335 | + case 'bar': | |
| 336 | + case 'column': | |
| 337 | + case 'line': | |
| 338 | + case 'area': | |
| 339 | + case 'stepped area': | |
| 340 | + case 'bubble': | |
| 341 | + case 'pie': | |
| 342 | + case 'donut': | |
| 343 | + case 'combo': | |
| 344 | + case 'candlestick': | |
| 345 | + case 'histogram': | |
| 346 | + case 'scatter': | |
| 347 | + $type = 'corechart'; | |
| 348 | + break; | |
| 349 | + case 'geo': | |
| 350 | + $type = 'geochart'; | |
| 351 | + break; | |
| 352 | + case 'dataTable': | |
| 353 | + $type = null; | |
| 354 | + break; | |
| 355 | + } | |
| 356 | + if($type != null){ | |
| 357 | + $chart_types.push($type); | |
| 358 | + } | |
| 359 | + }); | |
| 360 | + } | |
| 361 | + | |
| 323 | 362 | objects = {}; |
| 324 | - google.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language}); | |
| 363 | + google.charts.load("current", {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language}); | |
| 325 | 364 | google.charts.setOnLoadCallback(function() { |
| 326 | 365 | gv = google.visualization; |
| 327 | 366 | all_charts = v.charts; |
| 328 | 367 | render(); |
| @@ -332,7 +371,27 @@ | ||
| 332 | 371 | $('body').on('visualizer:render:specificchart:start', function(event, v){ |
| 333 | 372 | objects = {}; |
| 334 | 373 | gv = google.visualization; |
| 335 | 374 | renderSpecificChart(v.id, v.chart); |
| 375 | + }); | |
| 376 | + | |
| 377 | + // front end actions | |
| 378 | + $('body').on('visualizer:action:specificchart', function(event, v){ | |
| 379 | + switch(v.action){ | |
| 380 | + case 'print': | |
| 381 | + var id = v.id; | |
| 382 | + if(typeof rendered_charts[id] === 'undefined'){ | |
| 383 | + return; | |
| 384 | + } | |
| 385 | + var arr = id.split('-'); | |
| 386 | + var img = __visualizer_chart_images[ arr[0] + '-' + arr[1] ]; | |
| 387 | + // for charts that have no rendered image defined, we print the data instead. | |
| 388 | + var html = v.data; | |
| 389 | + if(img !== ''){ | |
| 390 | + html = "<html><body><img src='" + img + "' /></body></html>"; | |
| 391 | + } | |
| 392 | + $('body').trigger('visualizer:action:specificchart:defaultprint', {data: html}); | |
| 393 | + break; | |
| 394 | + } | |
| 336 | 395 | }); |
| 337 | 396 | |
| 338 | 397 | })(jQuery); |