| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | // this will store the images for each chart rendered. |
| 6 | 6 | var __visualizer_chart_images = []; |
| 7 | 7 | var chartWrapperError = []; |
| 8 | -var isResizeRequest = false; | |
| 9 | 8 | |
| 10 | 9 | (function($) { |
| 11 | 10 | var gv; |
| 12 | 11 | var all_charts, objects; |
| @@ -13,40 +12,22 @@ | ||
| 13 | 12 | // so that we know which charts belong to our library. |
| 14 | 13 | var rendered_charts = []; |
| 15 | 14 | |
| 16 | 15 | function renderChart(id) { |
| 17 | - | |
| 18 | - if ( ! all_charts || 0 === Object.keys( all_charts ).length ) { | |
| 19 | - return; | |
| 20 | - } | |
| 21 | - | |
| 22 | 16 | var chart = all_charts[id]; |
| 23 | 17 | var hasAnnotation = false; |
| 24 | 18 | |
| 25 | - if ( ! chart ) { | |
| 26 | - return; | |
| 27 | - } | |
| 28 | - | |
| 29 | - if ( chart.library && chart.library !== 'google' && chart.library !== 'GoogleCharts' ) { | |
| 30 | - return; | |
| 31 | - } | |
| 32 | - | |
| 33 | 19 | // re-render the chart only if it doesn't have annotations and it is on the front-end |
| 34 | 20 | // this is to prevent the chart from showing "All series on a given axis must be of the same data type" during resize. |
| 35 | 21 | // remember, some charts do not support annotations so they should not be included in this. |
| 36 | 22 | var no_annotation_charts = ['tabular', 'timeline', 'gauge', 'geo', 'bubble', 'candlestick']; |
| 37 | 23 | if ( undefined !== chart.settings && undefined !== chart.settings.series && undefined === chart.settings.series.length ) { |
| 38 | - var seriesKeys = Object.keys( chart.settings.series ); | |
| 39 | - // Only convert when keys are numeric indices (PHP JSON-encoded array). | |
| 40 | - // String keys (e.g. named series from manual config) must be left as-is. | |
| 41 | - if ( seriesKeys.every( function( k ) { return ! isNaN( k ); } ) ) { | |
| 42 | - var chartSeries = []; | |
| 43 | - var chartSeriesValue = Object.values( chart.settings.series ); | |
| 44 | - $.each( seriesKeys, function( index, element ) { | |
| 45 | - chartSeries[ element ] = chartSeriesValue[ index ]; | |
| 46 | - } ); | |
| 47 | - chart.settings.series = chartSeries; | |
| 48 | - } | |
| 24 | + var chartSeries = []; | |
| 25 | + var chartSeriesValue = Object.values( chart.settings.series ); | |
| 26 | + $.each( Object.keys( chart.settings.series ), function( index, element ) { | |
| 27 | + chartSeries[element] = chartSeriesValue[index]; | |
| 28 | + } ); | |
| 29 | + chart.settings.series = chartSeries; | |
| 49 | 30 | } |
| 50 | 31 | if(id !== 'canvas' && typeof chart.series !== 'undefined' && typeof chart.settings.series !== 'undefined' && ! no_annotation_charts.includes(chart.type) ) { |
| 51 | 32 | hasAnnotation = chart.series.length - chart.settings.series.length > 1; |
| 52 | 33 | } |
| @@ -58,14 +39,13 @@ | ||
| 58 | 39 | |
| 59 | 40 | function renderSpecificChart(id, chart) { |
| 60 | 41 | var render, container, series, data, table, settings, i, j, row, date, axis, property, format, formatter; |
| 61 | 42 | |
| 62 | - if( chart.library !== 'google' ) { | |
| 43 | + if ( $('#' + id).hasClass('visualizer-chart-loaded') || $('#' + id).children( ':not(.loader)' ).length > 0 ) { | |
| 63 | 44 | return; |
| 64 | 45 | } |
| 65 | - | |
| 66 | - // Bail if the chart is already rendered or is being rendered. | |
| 67 | - if ( ! window.isResizeRequest && ( $('#' + id).hasClass('visualizer-chart-loaded') || ( 'canvas' !== id && $('#' + id).children( ':not(.loader, style)' ).length > 0 ) ) ) { | |
| 46 | + | |
| 47 | + if(chart.library !== 'google'){ | |
| 68 | 48 | return; |
| 69 | 49 | } |
| 70 | 50 | rendered_charts[id] = 'yes'; |
| 71 | 51 | |
| @@ -136,13 +116,8 @@ | ||
| 136 | 116 | { |
| 137 | 117 | settings['animation']['startup'] = true; |
| 138 | 118 | settings['animation']['duration'] = parseInt(settings['animation']['duration']); |
| 139 | 119 | } |
| 140 | - if ( settings['controls'] ) { | |
| 141 | - settings['controls']['ui']['allowMultiple'] = 'true' === settings['controls']['allowMultiple'] ? true : false; | |
| 142 | - settings['controls']['ui']['allowTyping'] = 'true' === settings['controls']['allowTyping'] ? true : false; | |
| 143 | - settings['controls']['ui']['showRangeValues'] = 'true' === settings['controls']['showRangeValues'] ? true : false; | |
| 144 | - } | |
| 145 | 120 | |
| 146 | 121 | // mark roles for series that have specified a role |
| 147 | 122 | // and then remove them from future processing |
| 148 | 123 | // and also adjust the indices of the series array so that |
| @@ -360,16 +335,21 @@ | ||
| 360 | 335 | format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1); |
| 361 | 336 | } |
| 362 | 337 | break; |
| 363 | 338 | default: |
| 364 | - // Single-pass: walk columns, skip annotation/helper roles, apply formats in order. | |
| 365 | - var k = 0; // index into settings.series (visible series) | |
| 366 | - for (var c = 1; c < series.length && k < settings.series.length; c++) { // skip label at 0 | |
| 367 | - if (table.getColumnProperty(c, 'role')) continue; // helper/annotation column | |
| 368 | - var s = settings.series[k++]; | |
| 369 | - if (!s || !s.format) continue; | |
| 370 | - if (!series[c]) continue; | |
| 371 | - format_data(id, table, series[c].type, s.format, c); | |
| 339 | + for (i = 0; i < settings.series.length; i++) { | |
| 340 | + if (!series[i + 1] || typeof settings.series[i] === 'undefined') { | |
| 341 | + continue; | |
| 342 | + } | |
| 343 | + var seriesIndexToUse = i + 1; | |
| 344 | + | |
| 345 | + // if an annotation "swallowed" a series, use the following one. | |
| 346 | + if(series_annotations.includes(i)){ | |
| 347 | + seriesIndexToUse++; | |
| 348 | + } | |
| 349 | + if ( series[seriesIndexToUse] ) { | |
| 350 | + format_data(id, table, series[seriesIndexToUse].type, settings.series[i].format, seriesIndexToUse); | |
| 351 | + } | |
| 372 | 352 | } |
| 373 | 353 | break; |
| 374 | 354 | } |
| 375 | 355 | } else if (chart.type === 'pie' && settings.format && settings.format !== '') { |
| @@ -452,32 +432,21 @@ | ||
| 452 | 432 | return; |
| 453 | 433 | } |
| 454 | 434 | |
| 455 | 435 | var formatter = null; |
| 456 | - var $formatInput = $('input.control-text[name*="[format]"]').filter(function() { | |
| 457 | - return $(this).val() === format; | |
| 458 | - }); | |
| 459 | - try { | |
| 460 | - switch (type) { | |
| 461 | - case 'number': | |
| 462 | - formatter = new gv.NumberFormat({pattern: format}); | |
| 463 | - break; | |
| 464 | - case 'date': | |
| 465 | - case 'datetime': | |
| 466 | - case 'timeofday': | |
| 467 | - formatter = new gv.DateFormat({pattern: format}); | |
| 468 | - break; | |
| 469 | - } | |
| 436 | + switch (type) { | |
| 437 | + case 'number': | |
| 438 | + formatter = new gv.NumberFormat({pattern: format}); | |
| 439 | + break; | |
| 440 | + case 'date': | |
| 441 | + case 'datetime': | |
| 442 | + case 'timeofday': | |
| 443 | + formatter = new gv.DateFormat({pattern: format}); | |
| 444 | + break; | |
| 445 | + } | |
| 470 | 446 | |
| 471 | - if (formatter) { | |
| 472 | - formatter.format(table, index); | |
| 473 | - $formatInput.nextAll('.visualizer-format-error').remove(); | |
| 474 | - } | |
| 475 | - } catch (e) { | |
| 476 | - if ($formatInput.length) { | |
| 477 | - $formatInput.nextAll('.visualizer-format-error').remove(); | |
| 478 | - $('<p class="visualizer-format-error" style="color:#cc0000;margin:4px 0 0"></p>').text(visualizer.l10n.invalid_format).insertAfter($formatInput); | |
| 479 | - } | |
| 447 | + if (formatter) { | |
| 448 | + formatter.format(table, index); | |
| 480 | 449 | } |
| 481 | 450 | |
| 482 | 451 | var arr = id.split('-'); |
| 483 | 452 | $('body').trigger('visualizer:format:chart', {id: parseInt(arr[1]), data: table, column: index}); |
| @@ -507,11 +476,10 @@ | ||
| 507 | 476 | |
| 508 | 477 | var resizeTimeout; |
| 509 | 478 | |
| 510 | 479 | $(document).ready(function() { |
| 511 | - $(window).resize(function(e) { | |
| 480 | + $(window).resize(function() { | |
| 512 | 481 | clearTimeout(resizeTimeout); |
| 513 | - window.isResizeRequest = 'undefined' !== typeof e.originalEvent ? true : false; | |
| 514 | 482 | resizeTimeout = setTimeout(render, 100); |
| 515 | 483 | }); |
| 516 | 484 | |
| 517 | 485 | resizeHiddenContainers(true); |
| @@ -563,12 +531,8 @@ | ||
| 563 | 531 | if(v.is_front == true){ // jshint ignore:line |
| 564 | 532 | // check what all chart types to load. |
| 565 | 533 | $chart_types = []; |
| 566 | 534 | $.each(v.charts, function(i, c){ |
| 567 | - // Only consider charts rendered by Google Charts. | |
| 568 | - if ( c.library && c.library !== 'google' && c.library !== 'GoogleCharts' ) { | |
| 569 | - return; | |
| 570 | - } | |
| 571 | 535 | var $type = c.type; |
| 572 | 536 | switch($type){ |
| 573 | 537 | case 'bar': |
| 574 | 538 | case 'column': |
| @@ -597,9 +561,9 @@ | ||
| 597 | 561 | case 'radar': |
| 598 | 562 | $type = null; |
| 599 | 563 | break; |
| 600 | 564 | } |
| 601 | - if($type != null && $type !== ''){ | |
| 565 | + if($type != null){ | |
| 602 | 566 | $chart_types.push($type); |
| 603 | 567 | } |
| 604 | 568 | }); |
| 605 | 569 | } |
| @@ -606,9 +570,9 @@ | ||
| 606 | 570 | |
| 607 | 571 | objects = {}; |
| 608 | 572 | if ( 'object' === typeof google ) { |
| 609 | 573 | $chart_types.push( 'controls' ); |
| 610 | - google.load( 'visualization', '51', {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language, | |
| 574 | + google.load( 'visualization', 'current', {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language, | |
| 611 | 575 | callback: function () { |
| 612 | 576 | gv = google.visualization; |
| 613 | 577 | all_charts = v.charts; |
| 614 | 578 | if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line |