app/assets/javascripts/effective_datatables/charts.js.coffee in effective_datatables-2.12.0 vs app/assets/javascripts/effective_datatables/charts.js.coffee in effective_datatables-2.12.1
- old
+ new
@@ -1,15 +1,26 @@
initializeCharts = ->
+ $charts = $('.effective-datatables-chart:not(.initialized)')
+ return unless $charts.length > 0
+
+ if typeof(google) != 'undefined' && typeof(google.charts) != 'undefined'
+ google.charts.load('current', { packages: ['corechart'] })
+ google.charts.setOnLoadCallback(renderCharts)
+
+ $charts.addClass('initialized')
+
+renderCharts = ->
+ return if (typeof(google) == 'undefined' || typeof(google.visualization) == 'undefined')
+
$('.effective-datatables-chart').each ->
$chart = $(this)
data = $chart.data('data') || []
type = $chart.data('type') || 'BarChart'
options = $chart.data('options') || {}
- if google
- chart = new google.visualization[type](document.getElementById($chart.attr('id')))
- chart.draw(google.visualization.arrayToDataTable(data), options)
+ chart = new google.visualization[type](document.getElementById($chart.attr('id')))
+ chart.draw(google.visualization.arrayToDataTable(data), options)
$ -> initializeCharts()
$(document).on 'page:change', -> initializeCharts()
$(document).on 'turbolinks:load', -> initializeCharts()