| @@ -54,8 +54,42 @@ | ||
| 54 | 54 | settings['animation']['startup'] = true; |
| 55 | 55 | settings['animation']['duration'] = parseInt(settings['animation']['duration']); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + // mark roles for series that have specified a role | |
| 59 | + // and then remove them from future processing | |
| 60 | + // and also adjust the indices of the series array so that | |
| 61 | + // the ones with a role are ignored | |
| 62 | + // e.g. if there are 6 columns (0-5) out of which 1, 3 and 5 are annotations | |
| 63 | + // the final series will only include 0, 2, 4 (reindexed as 0, 1, 2) | |
| 64 | + if (settings.series) { | |
| 65 | + var adjusted_series = []; | |
| 66 | + for (i = 0; i < settings.series.length; i++) { | |
| 67 | + if (!series[i + 1] || typeof settings.series[i] === 'undefined') { | |
| 68 | + continue; | |
| 69 | + } | |
| 70 | + if(typeof settings.series[i].role !== 'undefined'){ | |
| 71 | + table.setColumnProperty(i + 1, 'role', settings.series[i].role); | |
| 72 | + if(settings.series[i].role === '') { | |
| 73 | + adjusted_series.push(settings.series[i]); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + } | |
| 77 | + if(adjusted_series.length > 0){ | |
| 78 | + settings.series = adjusted_series; | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + if ( settings['explorer_enabled'] && settings['explorer_enabled'] == 'true' ) { // jshint ignore:line | |
| 83 | + var $explorer = {}; | |
| 84 | + $explorer['keepInBounds'] = true; | |
| 85 | + | |
| 86 | + if ( settings['explorer_actions'] ) { | |
| 87 | + $explorer['actions'] = settings['explorer_actions']; | |
| 88 | + } | |
| 89 | + settings['explorer'] = $explorer; | |
| 90 | + } | |
| 91 | + | |
| 58 | 92 | switch (chart.type) { |
| 59 | 93 | case 'pie': |
| 60 | 94 | if (settings.slices) { |
| 61 | 95 | for (i in settings.slices) { |
| @@ -96,8 +130,11 @@ | ||
| 96 | 130 | } |
| 97 | 131 | break; |
| 98 | 132 | case 'gauge': |
| 99 | 133 | break; |
| 134 | + case 'bubble': | |
| 135 | + settings.sortBubblesBySize = settings.sortBubblesBySize ? settings.sortBubblesBySize == 1 : false; // jshint ignore:line | |
| 136 | + break; | |
| 100 | 137 | case 'timeline': |
| 101 | 138 | settings['timeline'] = []; |
| 102 | 139 | settings['timeline']['groupByRowLabel'] = settings['groupByRowLabel'] ? true : false; |
| 103 | 140 | settings['timeline']['colorByRowLabel'] = settings['colorByRowLabel'] ? true : false; |
| @@ -176,16 +213,30 @@ | ||
| 176 | 213 | |
| 177 | 214 | for (i = 0; i < data.length; i++) { |
| 178 | 215 | row = []; |
| 179 | 216 | for (j = 0; j < series.length; j++) { |
| 180 | - if (series[j].type === 'date' || series[j].type === 'datetime') { | |
| 181 | - date = new Date(data[i][j]); | |
| 182 | - data[i][j] = null; | |
| 183 | - if (Object.prototype.toString.call(date) === "[object Date]") { | |
| 184 | - if (!isNaN(date.getTime())) { | |
| 185 | - data[i][j] = date; | |
| 186 | - } | |
| 187 | - } | |
| 217 | + switch(series[j].type) { | |
| 218 | + case 'string': | |
| 219 | + if(data[i][j] === ''){ | |
| 220 | + data[i][j] = null; | |
| 221 | + } | |
| 222 | + break; | |
| 223 | + case 'boolean': | |
| 224 | + if (typeof data[i][j] === 'string'){ | |
| 225 | + data[i][j] = data[i][j] === 'true'; | |
| 226 | + } | |
| 227 | + break; | |
| 228 | + case 'date': | |
| 229 | + // fall-through. | |
| 230 | + case 'datetime': | |
| 231 | + date = new Date(data[i][j]); | |
| 232 | + data[i][j] = null; | |
| 233 | + if (Object.prototype.toString.call(date) === "[object Date]") { | |
| 234 | + if (!isNaN(date.getTime())) { | |
| 235 | + data[i][j] = date; | |
| 236 | + } | |
| 237 | + } | |
| 238 | + break; | |
| 188 | 239 | } |
| 189 | 240 | row.push(data[i][j]); |
| 190 | 241 | } |
| 191 | 242 | table.addRow(row); |
| @@ -203,9 +254,9 @@ | ||
| 203 | 254 | } |
| 204 | 255 | break; |
| 205 | 256 | default: |
| 206 | 257 | for (i = 0; i < settings.series.length; i++) { |
| 207 | - if (!series[i + 1]) { | |
| 258 | + if (!series[i + 1] || typeof settings.series[i] === 'undefined') { | |
| 208 | 259 | continue; |
| 209 | 260 | } |
| 210 | 261 | format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1); |
| 211 | 262 | } |
| @@ -213,8 +264,13 @@ | ||
| 213 | 264 | } |
| 214 | 265 | } else if (chart.type === 'pie' && settings.format && settings.format !== '') { |
| 215 | 266 | format_data(id, table, 'number', settings.format, 1); |
| 216 | 267 | } |
| 268 | + | |
| 269 | + if(settings.hAxis && series[0]) { | |
| 270 | + format_data(id, table, series[0].type, settings.hAxis.format, 0); | |
| 271 | + } | |
| 272 | + | |
| 217 | 273 | override(settings); |
| 218 | 274 | |
| 219 | 275 | gv.events.addListener(render, 'ready', function () { |
| 220 | 276 | var arr = id.split('-'); |
| @@ -227,8 +283,10 @@ | ||
| 227 | 283 | console.warn('render.getImageURI not defined for ' + arr[0] + '-' + arr[1]); |
| 228 | 284 | } |
| 229 | 285 | }); |
| 230 | 286 | |
| 287 | + $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings, data: table}); | |
| 288 | + | |
| 231 | 289 | render.draw(table, settings); |
| 232 | 290 | } |
| 233 | 291 | |
| 234 | 292 | function format_data(id, table, type, format, index) { |
| @@ -274,16 +332,8 @@ | ||
| 274 | 332 | renderChart(id); |
| 275 | 333 | } |
| 276 | 334 | } |
| 277 | 335 | |
| 278 | - if(typeof visualizer !== 'undefined'){ | |
| 279 | - // called while updating the chart. | |
| 280 | - visualizer.update = function(){ | |
| 281 | - renderChart('canvas'); | |
| 282 | - }; | |
| 283 | - } | |
| 284 | - | |
| 285 | - | |
| 286 | 336 | var resizeTimeout; |
| 287 | 337 | |
| 288 | 338 | $(document).ready(function() { |
| 289 | 339 | $(window).resize(function() { |
| @@ -324,10 +374,47 @@ | ||
| 324 | 374 | }); |
| 325 | 375 | } |
| 326 | 376 | |
| 327 | 377 | $('body').on('visualizer:render:chart:start', function(event, v){ |
| 378 | + var $chart_types = ['corechart', 'geochart', 'gauge', 'table', 'timeline']; | |
| 379 | + if(v.is_front == true){ // jshint ignore:line | |
| 380 | + // check what all chart types to load. | |
| 381 | + $chart_types = []; | |
| 382 | + $.each(v.charts, function(i, c){ | |
| 383 | + var $type = c.type; | |
| 384 | + switch($type){ | |
| 385 | + case 'bar': | |
| 386 | + case 'column': | |
| 387 | + case 'line': | |
| 388 | + case 'area': | |
| 389 | + case 'stepped area': | |
| 390 | + case 'bubble': | |
| 391 | + case 'pie': | |
| 392 | + case 'donut': | |
| 393 | + case 'combo': | |
| 394 | + case 'candlestick': | |
| 395 | + case 'histogram': | |
| 396 | + case 'scatter': | |
| 397 | + case 'bubble': | |
| 398 | + $type = 'corechart'; | |
| 399 | + break; | |
| 400 | + case 'geo': | |
| 401 | + $type = 'geochart'; | |
| 402 | + break; | |
| 403 | + case 'dataTable': | |
| 404 | + case 'polarArea': | |
| 405 | + case 'radar': | |
| 406 | + $type = null; | |
| 407 | + break; | |
| 408 | + } | |
| 409 | + if($type != null){ | |
| 410 | + $chart_types.push($type); | |
| 411 | + } | |
| 412 | + }); | |
| 413 | + } | |
| 414 | + | |
| 328 | 415 | objects = {}; |
| 329 | - google.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language}); | |
| 416 | + google.charts.load("current", {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language}); | |
| 330 | 417 | google.charts.setOnLoadCallback(function() { |
| 331 | 418 | gv = google.visualization; |
| 332 | 419 | all_charts = v.charts; |
| 333 | 420 | render(); |
| @@ -337,8 +424,12 @@ | ||
| 337 | 424 | $('body').on('visualizer:render:specificchart:start', function(event, v){ |
| 338 | 425 | objects = {}; |
| 339 | 426 | gv = google.visualization; |
| 340 | 427 | renderSpecificChart(v.id, v.chart); |
| 428 | + }); | |
| 429 | + | |
| 430 | + $('body').on('visualizer:render:currentchart:update', function(event, v){ | |
| 431 | + renderChart('canvas'); | |
| 341 | 432 | }); |
| 342 | 433 | |
| 343 | 434 | // front end actions |
| 344 | 435 | $('body').on('visualizer:action:specificchart', function(event, v){ |