| @@ -1,11 +1,6 @@ | ||
| 1 | 1 | /* global google */ |
| 2 | 2 | /* global visualizer */ |
| 3 | -/* global console */ | |
| 4 | - | |
| 5 | -// this will store the images for each chart rendered. | |
| 6 | -var __visualizer_chart_images = []; | |
| 7 | - | |
| 8 | 3 | (function(v, g) { |
| 9 | 4 | var gv; |
| 10 | 5 | |
| 11 | 6 | v.objects = {}; |
| @@ -18,11 +13,8 @@ | ||
| 18 | 13 | data = chart.data; |
| 19 | 14 | settings = chart.settings; |
| 20 | 15 | |
| 21 | 16 | container = document.getElementById(id); |
| 22 | - if (container == null) { | |
| 23 | - return; | |
| 24 | - } | |
| 25 | 17 | table = new gv.DataTable({cols: series}); |
| 26 | 18 | |
| 27 | 19 | render = v.objects[id] || null; |
| 28 | 20 | if (!render) { |
| @@ -39,15 +31,9 @@ | ||
| 39 | 31 | |
| 40 | 32 | render = new gv[render](container); |
| 41 | 33 | } |
| 42 | 34 | |
| 43 | - if (settings['animation'] && parseInt(settings['animation']['startup']) === 1) | |
| 44 | - { | |
| 45 | - settings['animation']['startup'] = true; | |
| 46 | - settings['animation']['duration'] = parseInt(settings['animation']['duration']); | |
| 47 | - } | |
| 48 | - | |
| 49 | - switch (chart.type) { | |
| 35 | + switch (v.charts[id].type) { | |
| 50 | 36 | case 'pie': |
| 51 | 37 | if (settings.slices) { |
| 52 | 38 | for (i in settings.slices) { |
| 53 | 39 | if (settings.slices[i]['color'] === '') { |
| @@ -119,9 +105,9 @@ | ||
| 119 | 105 | } |
| 120 | 106 | |
| 121 | 107 | if (series[0] && (series[0].type === 'date' || series[0].type === 'datetime')) { |
| 122 | 108 | axis = false; |
| 123 | - switch (chart.type) { | |
| 109 | + switch (v.charts[id].type) { | |
| 124 | 110 | case 'line': |
| 125 | 111 | case 'area': |
| 126 | 112 | case 'scatter': |
| 127 | 113 | case 'candlestick': |
| @@ -149,19 +135,15 @@ | ||
| 149 | 135 | } |
| 150 | 136 | |
| 151 | 137 | if(settings.hAxis){ |
| 152 | 138 | if(settings.hAxis.textStyle && settings.hAxis.textStyle !== ''){ |
| 153 | - if(typeof(settings.hAxis.textStyle) === "string") { | |
| 154 | - settings.hAxis.textStyle = {color: settings.hAxis.textStyle}; | |
| 155 | - } | |
| 139 | + settings.hAxis.textStyle = {color: settings.hAxis.textStyle}; | |
| 156 | 140 | } |
| 157 | 141 | } |
| 158 | 142 | |
| 159 | 143 | if(settings.vAxis){ |
| 160 | 144 | if(settings.vAxis.textStyle && settings.vAxis.textStyle !== ''){ |
| 161 | - if(typeof(settings.vAxis.textStyle) === "string") { | |
| 162 | - settings.vAxis.textStyle = {color: settings.vAxis.textStyle}; | |
| 163 | - } | |
| 145 | + settings.vAxis.textStyle = {color: settings.vAxis.textStyle}; | |
| 164 | 146 | } |
| 165 | 147 | } |
| 166 | 148 | |
| 167 | 149 | for (i = 0; i < data.length; i++) { |
| @@ -183,9 +165,9 @@ | ||
| 183 | 165 | |
| 184 | 166 | if (settings.series) { |
| 185 | 167 | for (i = 0; i < settings.series.length; i++) { |
| 186 | 168 | format = settings.series[i].format; |
| 187 | - if (!format || format === '' || !series[i + 1]) { | |
| 169 | + if (!format || format === '') { | |
| 188 | 170 | continue; |
| 189 | 171 | } |
| 190 | 172 | |
| 191 | 173 | formatter = null; |
| @@ -203,41 +185,13 @@ | ||
| 203 | 185 | if (formatter) { |
| 204 | 186 | formatter.format(table, i + 1); |
| 205 | 187 | } |
| 206 | 188 | } |
| 207 | - } else if (chart.type === 'pie' && settings.format && settings.format !== '') { | |
| 208 | - formatter = new g.visualization.NumberFormat({pattern: settings.format}); | |
| 209 | - formatter.format(table, 1); | |
| 210 | - } | |
| 189 | + } | |
| 211 | 190 | |
| 212 | - v.override(settings); | |
| 213 | - | |
| 214 | - g.visualization.events.addListener(render, 'ready', function () { | |
| 215 | - var arr = id.split('-'); | |
| 216 | - try{ | |
| 217 | - var img = render.getImageURI(); | |
| 218 | - __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = img; | |
| 219 | - jQuery('body').trigger('visualizer:render:chart', {id: arr[1], image: img}); | |
| 220 | - }catch(error){ | |
| 221 | - console.warn('render.getImageURI not defined for ' + arr[0] + '-' + arr[1]); | |
| 222 | - } | |
| 223 | - }); | |
| 224 | - | |
| 225 | 191 | render.draw(table, settings); |
| 226 | 192 | }; |
| 227 | 193 | |
| 228 | - v.override = function(settings) { | |
| 229 | - if (settings.manual) { | |
| 230 | - try{ | |
| 231 | - var options = JSON.parse(settings.manual); | |
| 232 | - jQuery.extend(settings, options); | |
| 233 | - delete settings.manual; | |
| 234 | - }catch(error){ | |
| 235 | - console.error("Error while adding manual configuration override " + settings.manual); | |
| 236 | - } | |
| 237 | - } | |
| 238 | - }; | |
| 239 | - | |
| 240 | 194 | v.render = function() { |
| 241 | 195 | for (var id in (v.charts || {})) { |
| 242 | 196 | v.renderChart(id); |
| 243 | 197 | } |
| @@ -242,9 +196,9 @@ | ||
| 242 | 196 | v.renderChart(id); |
| 243 | 197 | } |
| 244 | 198 | }; |
| 245 | 199 | |
| 246 | - g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language}); | |
| 200 | + g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"]}); | |
| 247 | 201 | g.charts.setOnLoadCallback(function() { |
| 248 | 202 | gv = g.visualization; |
| 249 | 203 | v.render(); |
| 250 | 204 | }); |
| @@ -259,9 +213,8 @@ | ||
| 259 | 213 | resizeTimeout = setTimeout(v.render, 100); |
| 260 | 214 | }); |
| 261 | 215 | |
| 262 | 216 | resizeHiddenContainers(true); |
| 263 | - initActionsButtons(); | |
| 264 | 217 | }); |
| 265 | 218 | |
| 266 | 219 | $(window).load(function(){ |
| 267 | 220 | resizeHiddenContainers(true); |
| @@ -266,73 +219,8 @@ | ||
| 266 | 219 | $(window).load(function(){ |
| 267 | 220 | resizeHiddenContainers(true); |
| 268 | 221 | }); |
| 269 | 222 | |
| 270 | - function initActionsButtons() { | |
| 271 | - if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) { | |
| 272 | - var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line | |
| 273 | - clipboard.on('success', function(e) { | |
| 274 | - window.alert(v.i10n['copied']); | |
| 275 | - }); | |
| 276 | - } | |
| 277 | - $('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) { | |
| 278 | - var type = $(this).attr( 'data-visualizer-type' ); | |
| 279 | - var chart = $(this).attr( 'data-visualizer-chart-id' ); | |
| 280 | - var lock = $('.visualizer-front.visualizer-front-' + chart); | |
| 281 | - lock.lock(); | |
| 282 | - e.preventDefault(); | |
| 283 | - $.ajax({ | |
| 284 | - url : v.rest_url.replace('#id#', chart).replace('#type#', type), | |
| 285 | - success: function(data) { | |
| 286 | - if (data && data.data) { | |
| 287 | - switch(type){ | |
| 288 | - case 'csv': | |
| 289 | - var a = document.createElement("a"); | |
| 290 | - document.body.appendChild(a); | |
| 291 | - a.style = "display: none"; | |
| 292 | - var blob = new Blob([data.data.csv], {type: $(this).attr( 'data-visualizer-mime' ) }), | |
| 293 | - url = window.URL.createObjectURL(blob); | |
| 294 | - a.href = url; | |
| 295 | - a.download = data.data.name; | |
| 296 | - a.click(); | |
| 297 | - setTimeout(function () { | |
| 298 | - window.URL.revokeObjectURL(url); | |
| 299 | - }, 100); | |
| 300 | - break; | |
| 301 | - case 'xls': | |
| 302 | - var $a = $("<a>"); | |
| 303 | - $a.attr("href",data.data.csv); | |
| 304 | - $("body").append($a); | |
| 305 | - $a.attr("download",data.data.name); | |
| 306 | - $a[0].click(); | |
| 307 | - $a.remove(); | |
| 308 | - break; | |
| 309 | - case 'print': | |
| 310 | - var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute"); | |
| 311 | - iframe.appendTo($('body')); | |
| 312 | - var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument; | |
| 313 | - iframe_doc.document.open(); | |
| 314 | - iframe_doc.document.write(data.data.csv); | |
| 315 | - iframe_doc.document.close(); | |
| 316 | - setTimeout(function(){ | |
| 317 | - window.frames['print-visualization'].focus(); | |
| 318 | - window.frames['print-visualization'].print(); | |
| 319 | - iframe.remove(); | |
| 320 | - }, 500); | |
| 321 | - break; | |
| 322 | - default: | |
| 323 | - if(window.visualizer_perform_action) { | |
| 324 | - window.visualizer_perform_action(type, chart, data.data); | |
| 325 | - } | |
| 326 | - break; | |
| 327 | - } | |
| 328 | - } | |
| 329 | - lock.unlock(); | |
| 330 | - } | |
| 331 | - }); | |
| 332 | - }); | |
| 333 | - } | |
| 334 | - | |
| 335 | 223 | function resizeHiddenContainers(everytime){ |
| 336 | 224 | $(".visualizer-front").parents().each(function(){ |
| 337 | 225 | if(!$(this).is(":visible") && !$(this).hasClass("visualizer-hidden-container")){ |
| 338 | 226 | $(this).addClass("visualizer-hidden-container"); |
| @@ -357,54 +245,5 @@ | ||
| 357 | 245 | mutateObserver.observe($(this)[0], {attributes: true}); |
| 358 | 246 | }); |
| 359 | 247 | } |
| 360 | 248 | |
| 361 | -})(jQuery, visualizer); | |
| 362 | - | |
| 363 | -(function ($) { | |
| 364 | - $.fn.lock = function () { | |
| 365 | - $(this).each(function () { | |
| 366 | - var $this = $(this); | |
| 367 | - var position = $this.css('position'); | |
| 368 | - | |
| 369 | - if (!position) { | |
| 370 | - position = 'static'; | |
| 371 | - } | |
| 372 | - | |
| 373 | - switch (position) { | |
| 374 | - case 'absolute': | |
| 375 | - case 'relative': | |
| 376 | - break; | |
| 377 | - default: | |
| 378 | - $this.css('position', 'relative'); | |
| 379 | - break; | |
| 380 | - } | |
| 381 | - $this.data('position', position); | |
| 382 | - | |
| 383 | - var width = $this.width(), | |
| 384 | - height = $this.height(); | |
| 385 | - | |
| 386 | - var locker = $('<div class="locker"></div>'); | |
| 387 | - locker.width(width).height(height); | |
| 388 | - | |
| 389 | - var loader = $('<div class="locker-loader"></div>'); | |
| 390 | - loader.width(width).height(height); | |
| 391 | - | |
| 392 | - locker.append(loader); | |
| 393 | - $this.append(locker); | |
| 394 | - $(window).resize(function () { | |
| 395 | - $this.find('.locker,.locker-loader').width($this.width()).height($this.height()); | |
| 396 | - }); | |
| 397 | - }); | |
| 398 | - | |
| 399 | - return $(this); | |
| 400 | - }; | |
| 401 | - | |
| 402 | - $.fn.unlock = function () { | |
| 403 | - $(this).each(function () { | |
| 404 | - $(this).find('.locker').remove(); | |
| 405 | - $(this).css('position', $(this).data('position')); | |
| 406 | - }); | |
| 407 | - | |
| 408 | - return $(this); | |
| 409 | - }; | |
| 410 | -})(jQuery); | |
| 249 | +})(jQuery, visualizer); | |