| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | /* global google */ |
| 2 | 2 | /* global visualizer */ |
| 3 | -/* global console */ | |
| 4 | 3 | (function(v, g) { |
| 5 | 4 | var gv; |
| 6 | 5 | |
| 7 | 6 | v.objects = {}; |
| @@ -14,11 +13,8 @@ | ||
| 14 | 13 | data = chart.data; |
| 15 | 14 | settings = chart.settings; |
| 16 | 15 | |
| 17 | 16 | container = document.getElementById(id); |
| 18 | - if (container == null) { | |
| 19 | - return; | |
| 20 | - } | |
| 21 | 17 | table = new gv.DataTable({cols: series}); |
| 22 | 18 | |
| 23 | 19 | render = v.objects[id] || null; |
| 24 | 20 | if (!render) { |
| @@ -35,9 +31,9 @@ | ||
| 35 | 31 | |
| 36 | 32 | render = new gv[render](container); |
| 37 | 33 | } |
| 38 | 34 | |
| 39 | - switch (chart.type) { | |
| 35 | + switch (v.charts[id].type) { | |
| 40 | 36 | case 'pie': |
| 41 | 37 | if (settings.slices) { |
| 42 | 38 | for (i in settings.slices) { |
| 43 | 39 | if (settings.slices[i]['color'] === '') { |
| @@ -109,9 +105,9 @@ | ||
| 109 | 105 | } |
| 110 | 106 | |
| 111 | 107 | if (series[0] && (series[0].type === 'date' || series[0].type === 'datetime')) { |
| 112 | 108 | axis = false; |
| 113 | - switch (chart.type) { | |
| 109 | + switch (v.charts[id].type) { | |
| 114 | 110 | case 'line': |
| 115 | 111 | case 'area': |
| 116 | 112 | case 'scatter': |
| 117 | 113 | case 'candlestick': |
| @@ -139,19 +135,15 @@ | ||
| 139 | 135 | } |
| 140 | 136 | |
| 141 | 137 | if(settings.hAxis){ |
| 142 | 138 | if(settings.hAxis.textStyle && settings.hAxis.textStyle !== ''){ |
| 143 | - if(typeof(settings.hAxis.textStyle) === "string") { | |
| 144 | - settings.hAxis.textStyle = {color: settings.hAxis.textStyle}; | |
| 145 | - } | |
| 139 | + settings.hAxis.textStyle = {color: settings.hAxis.textStyle}; | |
| 146 | 140 | } |
| 147 | 141 | } |
| 148 | 142 | |
| 149 | 143 | if(settings.vAxis){ |
| 150 | 144 | if(settings.vAxis.textStyle && settings.vAxis.textStyle !== ''){ |
| 151 | - if(typeof(settings.vAxis.textStyle) === "string") { | |
| 152 | - settings.vAxis.textStyle = {color: settings.vAxis.textStyle}; | |
| 153 | - } | |
| 145 | + settings.vAxis.textStyle = {color: settings.vAxis.textStyle}; | |
| 154 | 146 | } |
| 155 | 147 | } |
| 156 | 148 | |
| 157 | 149 | for (i = 0; i < data.length; i++) { |
| @@ -193,30 +185,13 @@ | ||
| 193 | 185 | if (formatter) { |
| 194 | 186 | formatter.format(table, i + 1); |
| 195 | 187 | } |
| 196 | 188 | } |
| 197 | - } else if (chart.type === 'pie' && settings.format && settings.format !== '') { | |
| 198 | - formatter = new g.visualization.NumberFormat({pattern: settings.format}); | |
| 199 | - formatter.format(table, 1); | |
| 200 | - } | |
| 189 | + } | |
| 201 | 190 | |
| 202 | - v.override(settings); | |
| 203 | - | |
| 204 | 191 | render.draw(table, settings); |
| 205 | 192 | }; |
| 206 | 193 | |
| 207 | - v.override = function(settings) { | |
| 208 | - if (settings.manual) { | |
| 209 | - try{ | |
| 210 | - var options = JSON.parse(settings.manual); | |
| 211 | - jQuery.extend(settings, options); | |
| 212 | - delete settings.manual; | |
| 213 | - }catch(error){ | |
| 214 | - console.error("Error while adding manual configuration override " + settings.manual); | |
| 215 | - } | |
| 216 | - } | |
| 217 | - }; | |
| 218 | - | |
| 219 | 194 | v.render = function() { |
| 220 | 195 | for (var id in (v.charts || {})) { |
| 221 | 196 | v.renderChart(id); |
| 222 | 197 | } |
| @@ -221,9 +196,9 @@ | ||
| 221 | 196 | v.renderChart(id); |
| 222 | 197 | } |
| 223 | 198 | }; |
| 224 | 199 | |
| 225 | - g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key}); | |
| 200 | + g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"]}); | |
| 226 | 201 | g.charts.setOnLoadCallback(function() { |
| 227 | 202 | gv = g.visualization; |
| 228 | 203 | v.render(); |
| 229 | 204 | }); |
| @@ -238,9 +213,8 @@ | ||
| 238 | 213 | resizeTimeout = setTimeout(v.render, 100); |
| 239 | 214 | }); |
| 240 | 215 | |
| 241 | 216 | resizeHiddenContainers(true); |
| 242 | - initActionsButtons(); | |
| 243 | 217 | }); |
| 244 | 218 | |
| 245 | 219 | $(window).load(function(){ |
| 246 | 220 | resizeHiddenContainers(true); |
| @@ -245,73 +219,8 @@ | ||
| 245 | 219 | $(window).load(function(){ |
| 246 | 220 | resizeHiddenContainers(true); |
| 247 | 221 | }); |
| 248 | 222 | |
| 249 | - function initActionsButtons() { | |
| 250 | - if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) { | |
| 251 | - var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line | |
| 252 | - clipboard.on('success', function(e) { | |
| 253 | - window.alert(v.i10n['copied']); | |
| 254 | - }); | |
| 255 | - } | |
| 256 | - $('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) { | |
| 257 | - var type = $(this).attr( 'data-visualizer-type' ); | |
| 258 | - var chart = $(this).attr( 'data-visualizer-chart-id' ); | |
| 259 | - var lock = $('.visualizer-front.visualizer-front-' + chart); | |
| 260 | - lock.lock(); | |
| 261 | - e.preventDefault(); | |
| 262 | - $.ajax({ | |
| 263 | - url : v.rest_url.replace('#id#', chart).replace('#type#', type), | |
| 264 | - success: function(data) { | |
| 265 | - if (data && data.data) { | |
| 266 | - switch(type){ | |
| 267 | - case 'csv': | |
| 268 | - var a = document.createElement("a"); | |
| 269 | - document.body.appendChild(a); | |
| 270 | - a.style = "display: none"; | |
| 271 | - var blob = new Blob([data.data.csv], {type: $(this).attr( 'data-visualizer-mime' ) }), | |
| 272 | - url = window.URL.createObjectURL(blob); | |
| 273 | - a.href = url; | |
| 274 | - a.download = data.data.name; | |
| 275 | - a.click(); | |
| 276 | - setTimeout(function () { | |
| 277 | - window.URL.revokeObjectURL(url); | |
| 278 | - }, 100); | |
| 279 | - break; | |
| 280 | - case 'xls': | |
| 281 | - var $a = $("<a>"); | |
| 282 | - $a.attr("href",data.data.csv); | |
| 283 | - $("body").append($a); | |
| 284 | - $a.attr("download",data.data.name); | |
| 285 | - $a[0].click(); | |
| 286 | - $a.remove(); | |
| 287 | - break; | |
| 288 | - case 'print': | |
| 289 | - var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute"); | |
| 290 | - iframe.appendTo($('body')); | |
| 291 | - var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument; | |
| 292 | - iframe_doc.document.open(); | |
| 293 | - iframe_doc.document.write(data.data.csv); | |
| 294 | - iframe_doc.document.close(); | |
| 295 | - setTimeout(function(){ | |
| 296 | - window.frames['print-visualization'].focus(); | |
| 297 | - window.frames['print-visualization'].print(); | |
| 298 | - iframe.remove(); | |
| 299 | - }, 500); | |
| 300 | - break; | |
| 301 | - default: | |
| 302 | - if(window.visualizer_perform_action) { | |
| 303 | - window.visualizer_perform_action(type, chart, data.data); | |
| 304 | - } | |
| 305 | - break; | |
| 306 | - } | |
| 307 | - } | |
| 308 | - lock.unlock(); | |
| 309 | - } | |
| 310 | - }); | |
| 311 | - }); | |
| 312 | - } | |
| 313 | - | |
| 314 | 223 | function resizeHiddenContainers(everytime){ |
| 315 | 224 | $(".visualizer-front").parents().each(function(){ |
| 316 | 225 | if(!$(this).is(":visible") && !$(this).hasClass("visualizer-hidden-container")){ |
| 317 | 226 | $(this).addClass("visualizer-hidden-container"); |
| @@ -336,54 +245,5 @@ | ||
| 336 | 245 | mutateObserver.observe($(this)[0], {attributes: true}); |
| 337 | 246 | }); |
| 338 | 247 | } |
| 339 | 248 | |
| 340 | -})(jQuery, visualizer); | |
| 341 | - | |
| 342 | -(function ($) { | |
| 343 | - $.fn.lock = function () { | |
| 344 | - $(this).each(function () { | |
| 345 | - var $this = $(this); | |
| 346 | - var position = $this.css('position'); | |
| 347 | - | |
| 348 | - if (!position) { | |
| 349 | - position = 'static'; | |
| 350 | - } | |
| 351 | - | |
| 352 | - switch (position) { | |
| 353 | - case 'absolute': | |
| 354 | - case 'relative': | |
| 355 | - break; | |
| 356 | - default: | |
| 357 | - $this.css('position', 'relative'); | |
| 358 | - break; | |
| 359 | - } | |
| 360 | - $this.data('position', position); | |
| 361 | - | |
| 362 | - var width = $this.width(), | |
| 363 | - height = $this.height(); | |
| 364 | - | |
| 365 | - var locker = $('<div class="locker"></div>'); | |
| 366 | - locker.width(width).height(height); | |
| 367 | - | |
| 368 | - var loader = $('<div class="locker-loader"></div>'); | |
| 369 | - loader.width(width).height(height); | |
| 370 | - | |
| 371 | - locker.append(loader); | |
| 372 | - $this.append(locker); | |
| 373 | - $(window).resize(function () { | |
| 374 | - $this.find('.locker,.locker-loader').width($this.width()).height($this.height()); | |
| 375 | - }); | |
| 376 | - }); | |
| 377 | - | |
| 378 | - return $(this); | |
| 379 | - }; | |
| 380 | - | |
| 381 | - $.fn.unlock = function () { | |
| 382 | - $(this).each(function () { | |
| 383 | - $(this).find('.locker').remove(); | |
| 384 | - $(this).css('position', $(this).data('position')); | |
| 385 | - }); | |
| 386 | - | |
| 387 | - return $(this); | |
| 388 | - }; | |
| 389 | -})(jQuery); | |
| 249 | +})(jQuery, visualizer); | |