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.
+179 −0
Diff settings

Always

Just for now

Next

Sinatra datatables examples

  • Loading branch information...
Prakriti-nith committed Jul 28, 2018
commit cfb50da810294e29cf66c8e3a7b4c0e40493d9ec
Copy path View file
@@ -21,6 +21,11 @@
erb :googlecharts, :layout => :googlecharts_layout
end

get '/datatables' do
datatables_examples
erb :datatables, :layout => :datatables_layout
end

get '/highchartstockmap' do
highchart_stock_map
erb :highchart_stock_map, :layout => :highcharts_layout
@@ -144,6 +149,78 @@ def googlecharts_example
@table.table, type: :geo, adapter: :googlecharts, height: 500, width: 800)
end

def datatables_examples
# need to give name, otherwise generated thead html code will not work.
# Because no name means no thead in vector.
dv = Daru::Vector.new [1, 2, 3, 4, 5, 6], name: 'series1'
options = {
adapter: :datatables,
html_options: {
table_options: {
table_thead: "<thead>
<tr>
<th></th>
<th>Demo Column Name</th>
</tr>
</thead>",
width: '90%'
}
}
}
# default adapter is nyaplot only
@dt_dv = Daru::View::Table.new(dv, options)

df1 = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
c: [11,22,33,44,55]},
order: [:a, :b, :c],
index: [:one, :two, :three, :four, :five])
options2 = {
adapter: :datatables,
html_options: {
table_options: {
cellspacing: '0',
width: "100%"
}
}
}
@dt_df1 = Daru::View::Table.new(df1, options2)

df2 = Daru::DataFrame.new({
a: [1, 3, 5, 7, 5, 0],
b: [1, 5, 2, 5, 1, 0],
c: [1, 6, 7, 2, 6, 0]
}, index: 'a'..'f')
@dt_df2 = Daru::View::Table.new(df2, pageLength: 3, adapter: :datatables)

dv_arr = [1, 2, 3, 4, 5, 6]
@dt_dv_arr = Daru::View::Table.new(dv_arr, pageLength: 3, adapter: :datatables)

df1_arr = [
[11,12,13,14,15],
[1,2,3,4,5],
[11,22,33,44,55]
]
@dt_df1_arr = Daru::View::Table.new(df1_arr, pageLength: 3, adapter: :datatables)

df2_arr = [
[1, 3, 5, 7, 5, 0],
[1, 5, 2, 5, 1, 0],
[1, 6, 7, 2, 6, 0]
]
@dt_df2_arr = Daru::View::Table.new(df2_arr, pageLength: 3, adapter: :datatables)

data = []
for i in 0..100000
data << i
end
options = {
searching: false,
pageLength: 7,
adapter: :datatables
}
@table_array_large = Daru::View::Table.new(data, options)
end

def make_random_series(step)
data = []
for i in 0..10
@@ -0,0 +1,90 @@
<h3> Large set of data: </h3>
<p>
<b>Data : </b>
A large set of data
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @table_array_large.div %></div>
</p>

<br>

<h3> Daru DataFrame: </h3>
<p style="color:blue;width: 100px;">
<b>Data : </b>
<%= @dt_df2.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @dt_df2.div %></div>

</p>


<br>


<h3> Daru DataFrame: </h3>
<p>
<b>Data : </b>
<%= @dt_df1.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @dt_df1.div %></div>
</p>

<br>

<h3> Daru Vector: </h3>
<p>
<b>Data : </b>
<%= @dt_dv.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @dt_dv.div %></div>
</p>
<br>


<h1> Using array : </h1>
<br>
<h3> 2D array: </h3>
<p style='width: 50px'>
<b>Data : </b>
<%= @dt_df2_arr.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @dt_df2_arr.div %></div>
</p>


<br>


<h3> 2D array : </h3>
<p>
<b>Data : </b>
<%= @dt_df1_arr.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @dt_df1_arr.div %></div>
</p>

<br>

<h3> 1D array: </h3>
<p>
<b>Data : </b>
<%= @dt_dv_arr.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%= @dt_dv_arr.div %></div>
</p>

<br>
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>DataTables</title>
<!-- dependent script -->
<%= Daru::View.dependent_script(:datatables) %>
</head>

<body>
<%= yield %>
</body>
</html>
ProTip! Use n and p to navigate between commits in a pull request.