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

Sinatra examples #15

Merged
merged 5 commits into from Jul 28, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+64 −0
Diff settings

Always

Just for now

Sinatra handling events examples

  • Loading branch information...
Prakriti-nith committed Jul 28, 2018
commit 687404cdc90cbf1091514e65512c87cdde976cbf
Copy path View file
@@ -36,6 +36,11 @@
erb :highcharts_css, :layout => :highcharts_layout
end

get '/handlingevents' do
handling_events_googlecharts
erb :handling_events, :layout => :googlecharts_layout
end

def highchart_example
# bar chart
opts = {
@@ -694,3 +699,35 @@ def highcharts_css
# initialize
@column_graph = Daru::View::Plot.new(series_dt2, opts2)
end

def handling_events_googlecharts
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)
end
@@ -0,0 +1,27 @@
<h3> Handling Events in Google Table</h3>
<p>
<b>Data : </b>
<%= @table.data %>
<br>
<b>Options</b>
<%= @table.options %>
<br>
<b>Table : </b>
<br>
<%= @table.div %>
</p>
<br>

<h3> Handling events in Google charts</h3>
<p>
<b>Data : </b>
<%= @column_chart.data %>
<br>
<b>Options</b>
<%= @column_chart.options %>
<br>
<b>Chart : </b>
<br>
<%= @column_chart.div %>
</p>
<br>
ProTip! Use n and p to navigate between commits in a pull request.