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

Always

Just for now

Added PlotList examples

  • Loading branch information...
Prakriti-nith committed Jul 28, 2018
commit ea1e25ffcfe146806e5acaa6514071bba49bb007
Copy path View file
@@ -26,6 +26,11 @@
erb :datatables, :layout => :datatables_layout
end

get '/multiplecharts' do
multiple_charts
erb :multiple_charts, :layout => :multiple_charts_layout
end

get '/highchartstockmap' do
highchart_stock_map
erb :highchart_stock_map, :layout => :highcharts_layout
@@ -731,3 +736,128 @@ def handling_events_googlecharts
}
@column_chart = Daru::View::Plot.new(@table.table, { type: :column, width: 800 }, user_options_chart)
end

def multiple_charts
idx_sarah = Daru::Index.new ['Topping', 'Slices']
data_rows_sarah = [
['Mushrooms', 1],
['Onions', 1],
['Olives', 2],
['Zucchini', 2],
['Pepperoni', 1]
]
df_sarah = Daru::DataFrame.rows(data_rows_sarah)
df_sarah.vectors = idx_sarah

idx_anthony = Daru::Index.new ['Topping', 'Slices']
data_rows_anthony = [
['Mushrooms', 2],
['Onions', 2],
['Olives', 2],
['Zucchini', 0],
['Pepperoni', 3]
]
df_anthony = Daru::DataFrame.rows(data_rows_anthony)
df_anthony.vectors = idx_anthony

options_sarah = {
type: :pie,
title:'How Much Pizza Sarah Ate Last Night',
width:400,
height:300,
adapter: :googlecharts
}
options_anthony = {
type: :pie,
title:'How Much Pizza Anthony Ate Last Night',
width:400,
height:300,
adapter: :googlecharts
}

@pizza_sarah = Daru::View::Plot.new(df_sarah, options_sarah)
@pizza_anthony = Daru::View::Plot.new(df_anthony, options_anthony)
@combined_pizza = Daru::View::PlotList.new([@pizza_sarah, @pizza_anthony])


df = Daru::DataFrame.new(
{
data1: ['Website visits', 'Downloads', 'Requested price list', 'Invoice sent', 'Finalized'],
data2: [15654, 4064, 1987, 976, 846]
}
)
opts_funnel = {
chart: {
type: 'funnel'
},
modules: ['modules/funnel'],
title: {
text: 'Sales funnel'
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
format: '<b>{point.name}</b> ({point.y:,.0f})',
softConnector: true
},
center: ['40%', '50%'],
neckWidth: '30%',
neckHeight: '25%',
width: '80%'
}
},
legend: {
enabled: false
},
adapter: 'highcharts'
}
opts_pyramid = {
chart: {
type: 'pyramid'
},
title: {
text: 'Sales pyramid',
x: -50
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
format: '<b>{point.name}</b> ({point.y:,.0f})',
softConnector: true
},
center: ['40%', '50%'],
width: '80%'
}
},
legend: {
enabled: false
},
adapter: 'highcharts'
}
@funnel_hc = Daru::View::Plot.new(df, opts_funnel)
@pyramid_hc = Daru::View::Plot.new(df, opts_pyramid)
@combined_sales = Daru::View::PlotList.new([@funnel_hc, @pyramid_hc])


dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category
dv = Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5, type: :category, categories: ['I', 'II', 'III']
@bar_graph1 = Daru::View::Plot.new(dv, type: :bar, adapter: :nyaplot)
@bar_graph2 = Daru::View::Plot.new(dv, type: :bar, adapter: :nyaplot)
@bar_combined = Daru::View::PlotList.new([@bar_graph1, @bar_graph2])


options_hc = {
chart: {
type: 'pie'
},
title: {
text: 'How Much Pizza Sarah Ate Last Night'
},
adapter: 'highcharts'
}
@pizza_sarah_hc = Daru::View::Plot.new(df_sarah, options_hc)
@pizza_sarah_table = Daru::View::Table.new(df_sarah, adapter: :googlecharts)
@combined_adapters = Daru::View::PlotList.new([@pizza_sarah_table, @pizza_sarah, @pizza_sarah_hc])
end
@@ -0,0 +1,96 @@
<h3> Google Charts - Comparision</h3>
<table>
<tr>
<th></th>
<th>&emsp;&ensp;Data</th>
<th>Options</th>
</tr>
<tr>
<td>Sarah</td>
<td>&emsp;&emsp;<%= @pizza_sarah.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @pizza_sarah.options %></td>
</tr>
<tr>
<td>Anthony</td>
<td>&emsp;&emsp;<%= @pizza_anthony.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @pizza_anthony.options %></td>
</tr>
</table>
<br>
<b>Combined Chart : </b>
<br>
<%= @combined_pizza.div %>

<h3> HighCharts - Comparision</h3>
<table style="width:100%">
<tr>
<th></th>
<th>&emsp;&ensp;Data</th>
<th>Options</th>
</tr>
<tr>
<td>Funnel Chart</td>
<td>&emsp;&emsp;<%= @funnel_hc.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @funnel_hc.options %></td>
</tr>
<tr>
<td>Pyramid Chart</td>
<td>&emsp;&emsp;<%= @pyramid_hc.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @pyramid_hc.options %></td>
</tr>
</table>
<br>
<b>Combined Chart : </b>
<br>
<%= @combined_sales.div %>

<h3> Nyaplot - Comparision</h3>
<table>
<tr>
<th></th>
<th>&emsp;&ensp;Data</th>
<th>Options</th>
</tr>
<tr>
<td>Bar Graph 1</td>
<td>&emsp;&emsp;<%= @bar_graph1.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @bar_graph1.options %></td>
</tr>
<tr>
<td>Bar Graph 2</td>
<td>&emsp;&emsp;<%= @bar_graph2.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @bar_graph2.options %></td>
</tr>
</table>
<br>
<b>Combined Chart : </b>
<br>
<%= @bar_combined.div %>

<h3> Multiple Adapters - Comparision</h3>
<table>
<tr>
<th></th>
<th>&emsp;&ensp;Data</th>
<th>Options</th>
</tr>
<tr>
<td>Google DataTable</td>
<td>&emsp;&emsp;<%= @pizza_sarah_table.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @pizza_sarah_table.options %></td>
</tr>
<tr>
<td>GoogleChart</td>
<td>&emsp;&emsp;<%= @pizza_sarah.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @pizza_sarah.options %></td>
</tr>
<tr>
<td>HighChart</td>
<td>&emsp;&emsp;<%= @pizza_sarah_hc.data %></td>
<td>&emsp;&emsp;&emsp;&emsp;<%= @pizza_sarah_hc.options %></td>
</tr>
</table>
<br>
<b>Combined Chart : </b>
<br>
<%= @combined_adapters.div %>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Multiple Charts</title>

<!-- dependent script -->
<%= Daru::View.dependent_script(:googlecharts) %>
<%= Daru::View.dependent_script(:highcharts) %>
<%= Daru::View.dependent_script(:nyaplot) %>
</head>

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