Skip to content

Added Event Handling examples #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo_rails/app/assets/javascripts/handling_events.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions demo_rails/app/assets/stylesheets/handling_events.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the HandlingEvents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
35 changes: 35 additions & 0 deletions demo_rails/app/controllers/handling_events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class HandlingEventsController < ApplicationController
def handling_events
Daru::View.plotting_library = :googlecharts

data = [
['Year', 'Sales', 'Expenses'],
['2013', 1000, 400],
['2014', 1170, 460],
['2015', 660, 1120],
['2016', 1030, 540]
]
user_options = {
listeners: {
page: "alert('The user is navigating to page ' + (e['page'] + 1));",
select: "alert('A table row was selected');"
}
}
@table = Daru::View::Table.new(data, {page: 'enable', pageSize: 2}, user_options)

user_options_chart = {
listeners: {
select: " var selection = chart.getSelection();
var selectedValue = data_table.getFormattedValue(selection[0].row, 0);
alert('You selected ' + selectedValue + ' year');",
# exports the chart to PDF format
ready: "var doc = new jsPDF();
doc.addImage(chart.getImageURI(), 0, 0);
doc.save('chart.pdf');"
}
}
@column_chart = Daru::View::Plot.new(@table.table, { type: :column, width: 800 }, user_options_chart)

render "handling_events" , layout: "googlecharts_layout"
end
end
2 changes: 2 additions & 0 deletions demo_rails/app/helpers/handling_events_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HandlingEventsHelper
end
27 changes: 27 additions & 0 deletions demo_rails/app/views/handling_events/handling_events.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h3> Handling Events in Google Table</h3>
<p>
<b>Data : </b>
<%=raw @table.data %>
<br>
<b>Options</b>
<%=raw @table.options %>
<br>
<b>Table : </b>
<br>
<%=raw @table.div %>
</p>
<br>

<h3> Handling events in Google charts</h3>
<p>
<b>Data : </b>
<%=raw @column_chart.data %>
<br>
<b>Options</b>
<%=raw @column_chart.options %>
<br>
<b>Chart : </b>
<br>
<%=raw @column_chart.div %>
</p>
<br>
1 change: 1 addition & 0 deletions demo_rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
get '/highchartscss', to: 'highcharts_css#highcharts_css'
get '/highchartstockmap', to: 'highchart_stock_map#highchart_stock_map'
get '/multiplecharts', to: 'multiple_charts#multiple_charts'
get '/handlingevents', to: 'handling_events#handling_events'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class HandlingEventsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end