-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for various countries data
- Loading branch information
1 parent
78af296
commit 39db236
Showing
12 changed files
with
220 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CountriesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<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(%{ | ||
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_chart( | ||
@countries_df.row[0..50][:Country, :NumericCode], | ||
adapter: :highcharts, | ||
chart: { type: 'column' }, | ||
css: ['.highcharts-xaxis-grid .highcharts-grid-line {stroke-width: 2px;stroke: #d8d8d8;}', | ||
'.highcharts-xaxis .highcharts-tick {stroke-width: 2px;stroke: #d8d8d8;}'], | ||
xAxis: { categories: @countries_df.row[0..50][:Country].to_a }, | ||
title: { text: 'NumericCode of countries'} | ||
) | ||
%> | ||
</div> | ||
<div role="tabpanel" class="tab-pane" id="code-3"> | ||
<%= rouge(%{ | ||
daru_chart( | ||
@countries_df.row[0..50][:Country, :NumericCode], | ||
adapter: :highcharts, | ||
chart: { type: 'column' }, | ||
css: ['.highcharts-xaxis-grid .highcharts-grid-line {stroke-width: 2px;stroke: #d8d8d8;}', | ||
'.highcharts-xaxis .highcharts-tick {stroke-width: 2px;stroke: #d8d8d8;}'], | ||
xAxis: { categories: @countries_df.row[0..50][:Country].to_a }, | ||
title: { text: 'NumericCode of countries'} | ||
) | ||
}) %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |