dvandersluis / amcharts.rb

Ruby/Rails wrapper for Amcharts
MIT License
12 stars 9 forks source link

AmCharts with Turbolinks #2

Open allenwyma opened 10 years ago

allenwyma commented 10 years ago

AmCharts.ready works fine if you don't use Turbolinks, but we need to have a way to trigger what's inside of AmCharts.ready. What about creating something inside of the AmCharts.helper that gets triggered using document ready and the page load events from turbolinks?

dvandersluis commented 10 years ago

I don't actually use Turbolinks at all. If you want to contribute a PR, I'll certainly take a look at it.

A starting point might be calling validateNow() on a previously created chart on the page load event? The chart can be accessed through the AmCharts.charts array or by name via AmCharts.RB.Charts.name.

allenwyma commented 10 years ago

Problem lies within the AmCharts.ready method that you use. It is triggered even after the document's ready event, which i think is a bit odd, but alright. I'm in talks with how to fix this issue with turbolinks, so far was not able to figure it out.

dvandersluis commented 10 years ago

AmCharts.ready is a function provided by the core of AmCharts, not something added by amcharts.rb, and is the recommended way of creating/setting up a chart. As far as I can tell, it's pretty much just a wrapper around a window.load event listener (it pushes the function passed in to AmCharts.onReadyArray, which is then iterated over in AmCharts.handleLoad).

Again, I'm not really familiar with turbolinks, but would it maybe be possible add an event listener for the turbolinks event that calls AmCharts.handleLoad.

kmallory commented 9 years ago

anyone ever figure this out?