-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add example for various countries data #18
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Countries controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CountriesController < ApplicationController | ||
def data_countries | ||
# getting data from url : http://countryapi.gear.host/v1/Country/getCountries | ||
url = 'http://countryapi.gear.host/v1/Country/getCountries' | ||
complex_read_instance = Daru::IO::Importers::JSON.read(url) | ||
@countries_df = complex_read_instance.call( | ||
Country: "$..Response..Name", | ||
NumericCode: "$..Response..NumericCode", | ||
Area: "$..Response..Area" | ||
) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,20 @@ def home | |
Routes: [ | ||
'SciRuby repos', | ||
'SciRuby repo watchers', | ||
'Indian election data' | ||
'Indian election data', | ||
'Countries data' | ||
], | ||
Desc: [ | ||
'Shows import from JSON API, charts, tables, and export', | ||
'Shows import from JSON API, charts, tables, and export', | ||
'Shows import from HTML pages, charts and tables' | ||
'Shows import from HTML pages, charts and tables', | ||
'Shows import from JSON API, multiple charts using PlotList, tables with formatters and CSS styling in HighCharts' | ||
], | ||
Link: [ | ||
view_context.link_to('sciruby/repos', {action: 'repos', controller: 'sciruby_github'}, target: '_blank'), | ||
view_context.link_to('sciruby/watchers', {action: 'watchers', controller: 'sciruby_github'}, target: '_blank'), | ||
view_context.link_to('election/data', {action: 'data', controller: 'election'}, target: '_blank'), | ||
view_context.link_to('countries', {action: 'data_countries', controller: 'countries'}, target: '_blank'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line length < 79 |
||
] | ||
}, order: %i[Routes Desc Link]) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CountriesHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<h1>Countries Data</h1> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading">Code to import data from API into <code>Daru::DataFrame</code> (yes, that's all!):</div> | ||
<div class="panel-body"> | ||
<%= | ||
rouge(%{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better if we put these lines of code (in string) and use it in view (in all the places), isn't it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any update on this ? |
||
url = 'http://countryapi.gear.host/v1/Country/getCountries' | ||
complex_read_instance = Daru::IO::Importers::JSON.read(url) | ||
@countries_df = complex_read_instance.call( | ||
Country: "$..Response..Name", | ||
NumericCode: "$..Response..NumericCode", | ||
Area: "$..Response..Area" | ||
) | ||
}) | ||
%> | ||
</div> | ||
</div> | ||
|
||
<h2>Data table - 250 rows</h2> | ||
|
||
<div class="view-and-code"> | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<li role="presentation" class="active"><a href="#view-1" aria-controls="view" role="tab" data-toggle="view-1">View</a></li> | ||
<li role="presentation"><a href="#code-1" aria-controls="code" role="tab" data-toggle="code-1">Code</a></li> | ||
</ul> | ||
<div class="tab-content"> | ||
<div role="tabpanel" class="tab-pane active" id="view-1"> | ||
<%= | ||
Daru::View::Table.new( | ||
@countries_df, | ||
{ adapter: :googlecharts, pageSize: 25, | ||
height: 300, allowHtml: true }, | ||
{ formatters: { | ||
f1: { | ||
type: 'Color', | ||
range: [[0, 30000, 'white', 'red'], | ||
[30001, 100000, 'white', 'yellow'], | ||
[100001, nil, 'white', 'green']], | ||
columns: 2 | ||
}, | ||
f2: { | ||
type: 'Bar', | ||
options: { | ||
base: 500 | ||
}, | ||
columns: 1 | ||
} | ||
} | ||
} | ||
).div.html_safe | ||
%> | ||
</div> | ||
<div role="tabpanel" class="tab-pane" id="code-1"> | ||
<%= rouge(%{ | ||
Daru::View::Table.new( | ||
@countries_df, | ||
{ adapter: :googlecharts, pageSize: 25, | ||
height: 300, allowHtml: true }, | ||
{ formatters: { | ||
f1: { | ||
type: 'Color', | ||
range: [[0, 30000, 'white', 'red'], | ||
[30001, 100000, 'white', 'yellow'], | ||
[100001, nil, 'white', 'green']], | ||
columns: 2 | ||
}, | ||
f2: { | ||
type: 'Bar', | ||
options: { | ||
base: 500 | ||
}, | ||
columns: 1 | ||
} | ||
} | ||
} | ||
).div.html_safe | ||
}) %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h2>Multiple Charts using PlotList</h2> | ||
|
||
<div class="view-and-code"> | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<li role="presentation" class="active"><a href="#view-2" aria-controls="view" role="tab" data-toggle="view-2">View</a></li> | ||
<li role="presentation"><a href="#code-2" aria-controls="code" role="tab" data-toggle="code-2">Code</a></li> | ||
</ul> | ||
<div class="tab-content"> | ||
<div role="tabpanel" class="tab-pane active" id="view-2"> | ||
<%= | ||
Daru::View::PlotList.new( | ||
[ Daru::View::Plot.new( | ||
@countries_df.row[0..7][:Country, :Area], | ||
adapter: :googlecharts, type: :pie, title: "Relative Area distribution for 8 countries - GoogleChart" | ||
), | ||
Daru::View::Plot.new( | ||
@countries_df.row[0..7][:Country, :Area], | ||
adapter: :highcharts, chart: { type: 'pie' }, title: { text: 'Relative Area distribution for 8 countries - HighChart'} | ||
) | ||
] | ||
).div.html_safe | ||
%> | ||
</div> | ||
<div role="tabpanel" class="tab-pane" id="code-2"> | ||
<%= rouge(%{ | ||
Daru::View::PlotList.new( | ||
[ Daru::View::Plot.new( | ||
@countries_df.row[0..7][:Country, :Area], | ||
adapter: :googlecharts, type: :pie, title: "Relative Area distribution for 8 countries - GoogleChart" | ||
), | ||
Daru::View::Plot.new( | ||
@countries_df.row[0..7][:Country, :Area], | ||
adapter: :highcharts, chart: { type: 'pie' }, title: { text: 'Relative Area distribution for 8 countries - HighChart'} | ||
) | ||
] | ||
).div.html_safe | ||
}) %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h2>Scatter chart with styling grid and ticks</h2> | ||
|
||
<div class="view-and-code"> | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<li role="presentation" class="active"><a href="#view-3" aria-controls="view-3" role="tab" data-toggle="view-3">View</a></li> | ||
<li role="presentation"><a href="#code-3" aria-controls="code-3" role="tab" data-toggle="code-3">Code</a></li> | ||
</ul> | ||
<div class="tab-content"> | ||
<div role="tabpanel" class="tab-pane active" id="view-3"> | ||
<%= | ||
Daru::View::Plot.new( | ||
@countries_df.row[0..50][:Country, :NumericCode], | ||
{ adapter: :highcharts, | ||
chart: { type: 'column' }, | ||
xAxis: { categories: @countries_df.row[0..50][:Country].to_a }, | ||
title: { text: 'NumericCode of countries'} | ||
}, | ||
{ css: ['.highcharts-xaxis-grid .highcharts-grid-line {stroke-width: 2px;stroke: #d8d8d8;}', | ||
'.highcharts-xaxis .highcharts-tick {stroke-width: 2px;stroke: #d8d8d8;}'] | ||
} | ||
).div.html_safe | ||
%> | ||
</div> | ||
<div role="tabpanel" class="tab-pane" id="code-3"> | ||
<%= rouge(%{ | ||
Daru::View::Plot.new( | ||
@countries_df.row[0..50][:Country, :NumericCode], | ||
{ adapter: :highcharts, | ||
chart: { type: 'column' }, | ||
xAxis: { categories: @countries_df.row[0..50][:Country].to_a }, | ||
title: { text: 'NumericCode of countries'} | ||
}, | ||
{ css: ['.highcharts-xaxis-grid .highcharts-grid-line {stroke-width: 2px;stroke: #d8d8d8;}', | ||
'.highcharts-xaxis .highcharts-tick {stroke-width: 2px;stroke: #d8d8d8;}'] | ||
} | ||
).div.html_safe | ||
}) %> | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class CountriesControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length < 79