Skip to content
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

Added ChartWrapper exmples #6

Merged
merged 3 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo_rails/app/assets/javascripts/chart_wrapper.coffee
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/
3 changes: 3 additions & 0 deletions demo_rails/app/assets/stylesheets/chart_wrapper.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the ChartWrapper controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
47 changes: 47 additions & 0 deletions demo_rails/app/controllers/chart_wrapper_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class ChartWrapperController < ApplicationController
def chart_wrapper
# set the library, to plot charts
Daru::View.plotting_library = :googlecharts

data = [
['Year', 'Sales', 'Expenses'],
['2013', 1000, 400],
['2014', 1170, 460],
['2015', 660, 1120],
['2016', 1030, 540]
]
@area_chart_table = Daru::View::Table.new(data, {}, chart_class: 'Chartwrapper')

area_chart_options = {
type: :area,
view: {columns: [0, 1]}
}
@area_chart_chart = Daru::View::Plot.new(@area_chart_table.table, area_chart_options, chart_class: 'Chartwrapper')

data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='
@table = Daru::View::Table.new(data_str, {width: 500}, chart_class: 'Chartwrapper')
@plot = Daru::View::Plot.new(data, {width: 500, view: {columns: [0, 1]}}, chart_class: 'Chartwrapper')

idx = Daru::Index.new ['City', '2010 Population',]
data_rows = [
['New York City, NY', 8175000],
['Los Angeles, CA', 3792000],
['Chicago, IL', 2695000],
['Houston, TX', 2099000],
['Philadelphia, PA', 1526000]
]
df_city_pop = Daru::DataFrame.rows(data_rows)
df_city_pop.vectors = idx
@bar_basic_table = Daru::View::Table.new(df_city_pop, {}, chart_class: 'Chartwrapper')

@bar_custom_table = Daru::View::Table.new(df_city_pop, {view: {columns: [0]}}, chart_class: 'Chartwrapper')

bar_basic_options = {
title: 'Population of Largest U.S. Cities',
type: :bar
}
@bar_basic_chart = Daru::View::Plot.new(@bar_basic_table.table, bar_basic_options, chart_class: 'Chartwrapper')

render "chart_wrapper" , layout: "googlecharts_layout"
end
end
2 changes: 2 additions & 0 deletions demo_rails/app/helpers/chart_wrapper_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ChartWrapperHelper
end
97 changes: 97 additions & 0 deletions demo_rails/app/views/chart_wrapper/chart_wrapper.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<h3> Area Chart Table</h3>
<p>
<b>Data : </b>
<%=raw @area_chart_table.data %>
<br>
<b>Options</b>
<%=raw @area_chart_table.options %>
<br>
<b>Table : </b>
<br>
<%=raw @area_chart_table.div %>
</p>
<br>

<h3> Area Chart</h3>
<p>
<b>Data : </b>
<%=raw @area_chart_chart.data %>
<br>
<b>Options</b>
<%=raw @area_chart_chart.options %>
<br>
<b>Chart : </b>
<br>
<%=raw @area_chart_chart.div %>
</p>
<br>

<h3> Table using data as google spreadsheet URL</h3>
<p>
<b>Data : </b>
<%=raw @table.data %>
<br>
<b>Options</b>
<%=raw @table.options %>
<br>
<b>Table : </b>
<br>
<%=raw @table.div %>
</p>
<br>

<h3> Chart using data as google spreadsheet URL</h3>
<p>
<b>Data : </b>
<%=raw @plot.data %>
<br>
<b>Options</b>
<%=raw @plot.options %>
<br>
<b>Chart : </b>
<br>
<%=raw @plot.div %>
</p>
<br>

<h3> Bar Basic Table</h3>
<p>
<b>Data : </b>
<%=raw @bar_basic_table.data %>
<br>
<b>Options</b>
<%=raw @bar_basic_table.options %>
<br>
<b>Table : </b>
<br>
<%=raw @bar_basic_table.div %>
</p>
<br>

<h3> Bar Custom Table</h3>
<p>
<b>Data : </b>
<%=raw @bar_custom_table.data %>
<br>
<b>Options</b>
<%=raw @bar_custom_table.options %>
<br>
<b>Table : </b>
<br>
<%=raw @bar_custom_table.div %>
</p>
<br>

<h3> Bar Basic Chart</h3>
<p>
<b>Data : </b>
<%=raw @bar_basic_chart.data %>
<br>
<b>Options</b>
<%=raw @bar_basic_chart.options %>
<br>
<b>Chart : </b>
<br>
<%=raw @bar_basic_chart.div %>
</p>
<br>
1 change: 1 addition & 0 deletions demo_rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
get '/highcharts', to: 'application#highcharts'
get '/googlecharts', to: 'application#googlecharts'
get '/datatables', to: 'application#datatables'
get '/chartwrapper', to: 'chart_wrapper#chart_wrapper'
get '/highchartscss', to: 'highcharts_css#highcharts_css'
get '/highchartstockmap', to: 'highchart_stock_map#highchart_stock_map'
end
7 changes: 7 additions & 0 deletions demo_rails/test/controllers/chart_wrapper_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ChartWrapperControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end