| @@ -25,28 +25,19 @@ | ||
| 25 | 25 | if ( ! chart ) { |
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ( chart.library && chart.library !== 'google' && chart.library !== 'GoogleCharts' ) { | |
| 30 | - return; | |
| 31 | - } | |
| 32 | - | |
| 33 | 29 | // re-render the chart only if it doesn't have annotations and it is on the front-end |
| 34 | 30 | // this is to prevent the chart from showing "All series on a given axis must be of the same data type" during resize. |
| 35 | 31 | // remember, some charts do not support annotations so they should not be included in this. |
| 36 | 32 | var no_annotation_charts = ['tabular', 'timeline', 'gauge', 'geo', 'bubble', 'candlestick']; |
| 37 | 33 | 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 | - } | |
| 34 | + var chartSeries = []; | |
| 35 | + var chartSeriesValue = Object.values( chart.settings.series ); | |
| 36 | + $.each( Object.keys( chart.settings.series ), function( index, element ) { | |
| 37 | + chartSeries[element] = chartSeriesValue[index]; | |
| 38 | + } ); | |
| 39 | + chart.settings.series = chartSeries; | |
| 49 | 40 | } |
| 50 | 41 | if(id !== 'canvas' && typeof chart.series !== 'undefined' && typeof chart.settings.series !== 'undefined' && ! no_annotation_charts.includes(chart.type) ) { |
| 51 | 42 | hasAnnotation = chart.series.length - chart.settings.series.length > 1; |
| 52 | 43 | } |
| @@ -360,16 +351,21 @@ | ||
| 360 | 351 | format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1); |
| 361 | 352 | } |
| 362 | 353 | break; |
| 363 | 354 | 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); | |
| 355 | + for (i = 0; i < settings.series.length; i++) { | |
| 356 | + if (!series[i + 1] || typeof settings.series[i] === 'undefined') { | |
| 357 | + continue; | |
| 358 | + } | |
| 359 | + var seriesIndexToUse = i + 1; | |
| 360 | + | |
| 361 | + // if an annotation "swallowed" a series, use the following one. | |
| 362 | + if(series_annotations.includes(i)){ | |
| 363 | + seriesIndexToUse++; | |
| 364 | + } | |
| 365 | + if ( series[seriesIndexToUse] ) { | |
| 366 | + format_data(id, table, series[seriesIndexToUse].type, settings.series[i].format, seriesIndexToUse); | |
| 367 | + } | |
| 372 | 368 | } |
| 373 | 369 | break; |
| 374 | 370 | } |
| 375 | 371 | } else if (chart.type === 'pie' && settings.format && settings.format !== '') { |
| @@ -452,32 +448,21 @@ | ||
| 452 | 448 | return; |
| 453 | 449 | } |
| 454 | 450 | |
| 455 | 451 | 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 | - } | |
| 452 | + switch (type) { | |
| 453 | + case 'number': | |
| 454 | + formatter = new gv.NumberFormat({pattern: format}); | |
| 455 | + break; | |
| 456 | + case 'date': | |
| 457 | + case 'datetime': | |
| 458 | + case 'timeofday': | |
| 459 | + formatter = new gv.DateFormat({pattern: format}); | |
| 460 | + break; | |
| 461 | + } | |
| 470 | 462 | |
| 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 | - } | |
| 463 | + if (formatter) { | |
| 464 | + formatter.format(table, index); | |
| 480 | 465 | } |
| 481 | 466 | |
| 482 | 467 | var arr = id.split('-'); |
| 483 | 468 | $('body').trigger('visualizer:format:chart', {id: parseInt(arr[1]), data: table, column: index}); |
| @@ -563,12 +548,8 @@ | ||
| 563 | 548 | if(v.is_front == true){ // jshint ignore:line |
| 564 | 549 | // check what all chart types to load. |
| 565 | 550 | $chart_types = []; |
| 566 | 551 | $.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 | 552 | var $type = c.type; |
| 572 | 553 | switch($type){ |
| 573 | 554 | case 'bar': |
| 574 | 555 | case 'column': |
| @@ -597,9 +578,9 @@ | ||
| 597 | 578 | case 'radar': |
| 598 | 579 | $type = null; |
| 599 | 580 | break; |
| 600 | 581 | } |
| 601 | - if($type != null && $type !== ''){ | |
| 582 | + if($type != null){ | |
| 602 | 583 | $chart_types.push($type); |
| 603 | 584 | } |
| 604 | 585 | }); |
| 605 | 586 | } |