| @@ -1,7 +1,4 @@ | ||
| 1 | -/* global google */ | |
| 2 | -/* global visualizer */ | |
| 3 | -/* global console */ | |
| 4 | 1 | (function(v, g) { |
| 5 | 2 | var gv; |
| 6 | 3 | |
| 7 | 4 | v.objects = {}; |
| @@ -14,11 +11,8 @@ | ||
| 14 | 11 | data = chart.data; |
| 15 | 12 | settings = chart.settings; |
| 16 | 13 | |
| 17 | 14 | container = document.getElementById(id); |
| 18 | - if (container == null) { | |
| 19 | - return; | |
| 20 | - } | |
| 21 | 15 | table = new gv.DataTable({cols: series}); |
| 22 | 16 | |
| 23 | 17 | render = v.objects[id] || null; |
| 24 | 18 | if (!render) { |
| @@ -35,13 +29,13 @@ | ||
| 35 | 29 | |
| 36 | 30 | render = new gv[render](container); |
| 37 | 31 | } |
| 38 | 32 | |
| 39 | - switch (chart.type) { | |
| 33 | + switch (v.charts[id].type) { | |
| 40 | 34 | case 'pie': |
| 41 | 35 | if (settings.slices) { |
| 42 | 36 | for (i in settings.slices) { |
| 43 | - if (settings.slices[i]['color'] === '') { | |
| 37 | + if (settings.slices[i]['color'] == '') { | |
| 44 | 38 | delete settings.slices[i]['color']; |
| 45 | 39 | } |
| 46 | 40 | } |
| 47 | 41 | } |
| @@ -53,26 +47,26 @@ | ||
| 53 | 47 | case 'scatter': |
| 54 | 48 | case 'candlestick': |
| 55 | 49 | if (settings.series) { |
| 56 | 50 | for (i in settings.series) { |
| 57 | - if (settings.series[i]['color'] === '') { | |
| 51 | + if (settings.series[i]['color'] == '') { | |
| 58 | 52 | delete settings.series[i]['color']; |
| 59 | 53 | } |
| 60 | 54 | } |
| 61 | 55 | } |
| 62 | 56 | |
| 63 | - if (settings.series && settings.legend && settings.legend.position === "left") | |
| 57 | + if (settings.series && settings.legend && settings.legend.position == "left") | |
| 64 | 58 | { |
| 65 | 59 | settings.targetAxisIndex = 1; |
| 66 | 60 | } |
| 67 | 61 | break; |
| 68 | 62 | case 'geo': |
| 69 | - if (settings.region !== undefined && settings.region.replace(/^\s+|\s+$/g, '') === '') { | |
| 63 | + if (settings.region != undefined && settings.region.replace(/^\s+|\s+$/g, '') == '') { | |
| 70 | 64 | settings['region'] = 'world'; |
| 71 | 65 | } |
| 72 | 66 | break; |
| 73 | 67 | case 'table': |
| 74 | - if (parseInt(settings['pagination']) !== 1) | |
| 68 | + if (parseInt(settings['pagination']) != 1) | |
| 75 | 69 | { |
| 76 | 70 | delete settings['pageSize']; |
| 77 | 71 | } |
| 78 | 72 | break; |
| @@ -82,9 +76,9 @@ | ||
| 82 | 76 | settings['timeline'] = []; |
| 83 | 77 | settings['timeline']['groupByRowLabel'] = settings['groupByRowLabel'] ? true : false; |
| 84 | 78 | settings['timeline']['colorByRowLabel'] = settings['colorByRowLabel'] ? true : false; |
| 85 | 79 | settings['timeline']['showRowLabels'] = settings['showRowLabels'] ? true : false; |
| 86 | - if(settings['singleColor'] !== '') { | |
| 80 | + if(settings['singleColor'] != '') { | |
| 87 | 81 | settings['timeline']['singleColor'] = settings['singleColor']; |
| 88 | 82 | } |
| 89 | 83 | break; |
| 90 | 84 | case 'combo': |
| @@ -89,18 +83,18 @@ | ||
| 89 | 83 | break; |
| 90 | 84 | case 'combo': |
| 91 | 85 | if (settings.series) { |
| 92 | 86 | for (i in settings.series) { |
| 93 | - if (settings.series[i]['type'] === '') { | |
| 87 | + if (settings.series[i]['type'] == '') { | |
| 94 | 88 | delete settings.series[i]['type']; |
| 95 | 89 | } |
| 96 | - if (settings.series[i]['color'] === '') { | |
| 90 | + if (settings.series[i]['color'] == '') { | |
| 97 | 91 | delete settings.series[i]['color']; |
| 98 | 92 | } |
| 99 | 93 | } |
| 100 | 94 | } |
| 101 | 95 | |
| 102 | - if (settings.series && settings.legend && settings.legend.position === "left") | |
| 96 | + if (settings.series && settings.legend && settings.legend.position == "left") | |
| 103 | 97 | { |
| 104 | 98 | settings.targetAxisIndex = 1; |
| 105 | 99 | } |
| 106 | 100 | break; |
| @@ -107,11 +101,11 @@ | ||
| 107 | 101 | default: |
| 108 | 102 | return; |
| 109 | 103 | } |
| 110 | 104 | |
| 111 | - if (series[0] && (series[0].type === 'date' || series[0].type === 'datetime')) { | |
| 105 | + if (series[0] && (series[0].type == 'date' || series[0].type == 'datetime')) { | |
| 112 | 106 | axis = false; |
| 113 | - switch (chart.type) { | |
| 107 | + switch (v.charts[id].type) { | |
| 114 | 108 | case 'line': |
| 115 | 109 | case 'area': |
| 116 | 110 | case 'scatter': |
| 117 | 111 | case 'candlestick': |
| @@ -138,20 +132,16 @@ | ||
| 138 | 132 | } |
| 139 | 133 | } |
| 140 | 134 | |
| 141 | 135 | if(settings.hAxis){ |
| 142 | - if(settings.hAxis.textStyle && settings.hAxis.textStyle !== ''){ | |
| 143 | - if(typeof(settings.hAxis.textStyle) === "string") { | |
| 144 | - settings.hAxis.textStyle = {color: settings.hAxis.textStyle}; | |
| 145 | - } | |
| 136 | + if(settings.hAxis.textStyle && settings.hAxis.textStyle != ''){ | |
| 137 | + settings.hAxis.textStyle = {color: settings.hAxis.textStyle}; | |
| 146 | 138 | } |
| 147 | 139 | } |
| 148 | 140 | |
| 149 | 141 | if(settings.vAxis){ |
| 150 | - if(settings.vAxis.textStyle && settings.vAxis.textStyle !== ''){ | |
| 151 | - if(typeof(settings.vAxis.textStyle) === "string") { | |
| 152 | - settings.vAxis.textStyle = {color: settings.vAxis.textStyle}; | |
| 153 | - } | |
| 142 | + if(settings.vAxis.textStyle && settings.vAxis.textStyle != ''){ | |
| 143 | + settings.vAxis.textStyle = {color: settings.vAxis.textStyle}; | |
| 154 | 144 | } |
| 155 | 145 | } |
| 156 | 146 | |
| 157 | 147 | for (i = 0; i < data.length; i++) { |
| @@ -156,9 +146,9 @@ | ||
| 156 | 146 | |
| 157 | 147 | for (i = 0; i < data.length; i++) { |
| 158 | 148 | row = []; |
| 159 | 149 | for (j = 0; j < series.length; j++) { |
| 160 | - if (series[j].type === 'date' || series[j].type === 'datetime') { | |
| 150 | + if (series[j].type == 'date' || series[j].type == 'datetime') { | |
| 161 | 151 | date = new Date(data[i][j]); |
| 162 | 152 | data[i][j] = null; |
| 163 | 153 | if (Object.prototype.toString.call(date) === "[object Date]") { |
| 164 | 154 | if (!isNaN(date.getTime())) { |
| @@ -173,9 +163,9 @@ | ||
| 173 | 163 | |
| 174 | 164 | if (settings.series) { |
| 175 | 165 | for (i = 0; i < settings.series.length; i++) { |
| 176 | 166 | format = settings.series[i].format; |
| 177 | - if (!format || format === '' || !series[i + 1]) { | |
| 167 | + if (!format || format == '') { | |
| 178 | 168 | continue; |
| 179 | 169 | } |
| 180 | 170 | |
| 181 | 171 | formatter = null; |
| @@ -193,30 +183,13 @@ | ||
| 193 | 183 | if (formatter) { |
| 194 | 184 | formatter.format(table, i + 1); |
| 195 | 185 | } |
| 196 | 186 | } |
| 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 | - } | |
| 187 | + } | |
| 201 | 188 | |
| 202 | - v.override(settings); | |
| 203 | - | |
| 204 | 189 | render.draw(table, settings); |
| 205 | 190 | }; |
| 206 | 191 | |
| 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 | 192 | v.render = function() { |
| 220 | 193 | for (var id in (v.charts || {})) { |
| 221 | 194 | v.renderChart(id); |
| 222 | 195 | } |
| @@ -221,9 +194,9 @@ | ||
| 221 | 194 | v.renderChart(id); |
| 222 | 195 | } |
| 223 | 196 | }; |
| 224 | 197 | |
| 225 | - g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language}); | |
| 198 | + g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"]}); | |
| 226 | 199 | g.charts.setOnLoadCallback(function() { |
| 227 | 200 | gv = g.visualization; |
| 228 | 201 | v.render(); |
| 229 | 202 | }); |
| @@ -237,84 +210,14 @@ | ||
| 237 | 210 | clearTimeout(resizeTimeout); |
| 238 | 211 | resizeTimeout = setTimeout(v.render, 100); |
| 239 | 212 | }); |
| 240 | 213 | |
| 241 | - resizeHiddenContainers(true); | |
| 242 | - initActionsButtons(); | |
| 214 | + resizeHiddenContainers(); | |
| 243 | 215 | }); |
| 244 | 216 | |
| 245 | - $(window).load(function(){ | |
| 246 | - resizeHiddenContainers(true); | |
| 247 | - }); | |
| 248 | - | |
| 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 | - function resizeHiddenContainers(everytime){ | |
| 217 | + function resizeHiddenContainers(){ | |
| 315 | 218 | $(".visualizer-front").parents().each(function(){ |
| 316 | - if(!$(this).is(":visible") && !$(this).hasClass("visualizer-hidden-container")){ | |
| 219 | + if(!$(this).is(":visible")){ | |
| 317 | 220 | $(this).addClass("visualizer-hidden-container"); |
| 318 | 221 | } |
| 319 | 222 | }); |
| 320 | 223 | |
| @@ -319,16 +222,13 @@ | ||
| 319 | 222 | }); |
| 320 | 223 | |
| 321 | 224 | var mutateObserver = new MutationObserver(function(records) { |
| 322 | 225 | records.forEach(function(record) { |
| 323 | - if(record.attributeName === "style" || record.attributeName === "class"){ | |
| 226 | + if(record.attributeName == "style" || record.attributeName == "class"){ | |
| 324 | 227 | var element = $(record.target); |
| 325 | 228 | var displayStyle = window.getComputedStyle(element[0]).getPropertyValue("display"); |
| 326 | - if(element.hasClass("visualizer-hidden-container-resized") || displayStyle === "none") { return ; } | |
| 327 | - element.find(".visualizer-front").resize(); | |
| 328 | - if(!everytime) { | |
| 329 | - element.addClass("visualizer-hidden-container-resized"); | |
| 330 | - } | |
| 229 | + if(element.hasClass("visualizer-hidden-container-resized") || displayStyle == "none") return; | |
| 230 | + element.addClass("visualizer-hidden-container-resized").find(".visualizer-front").resize(); | |
| 331 | 231 | } |
| 332 | 232 | }); |
| 333 | 233 | }); |
| 334 | 234 | |
| @@ -336,54 +236,5 @@ | ||
| 336 | 236 | mutateObserver.observe($(this)[0], {attributes: true}); |
| 337 | 237 | }); |
| 338 | 238 | } |
| 339 | 239 | |
| 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); | |
| 240 | +})(jQuery, visualizer); | |