Skip to content

Commit

Permalink
Merge pull request #9 from Prakriti-nith/charteditor
Browse files Browse the repository at this point in the history
Added chart editor examples
  • Loading branch information
Prakriti-nith authored Aug 2, 2018
2 parents e3f0185 + c9c19d1 commit 77b8485
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions demo_rails/app/assets/javascripts/chart_editor.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_editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the ChartEditor controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
26 changes: 26 additions & 0 deletions demo_rails/app/controllers/chart_editor_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class ChartEditorController < ApplicationController
def chart_editor
# 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]
]
data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='
area_chart_options = {
type: :area
}

@area_table = Daru::View::Table.new(data, {}, chart_class: 'Charteditor')
@area_chart = Daru::View::Plot.new(@area_table.table, area_chart_options, chart_class: 'Charteditor')

@table = Daru::View::Table.new(data_str, {width: 500}, chart_class: 'Charteditor')
@plot = Daru::View::Plot.new(data, {width: 500}, chart_class: 'Charteditor')

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

<h3> Area Chart</h3>
<p>
<b>Data : </b>
<%=raw @area_chart.data %>
<br>
<b>Options</b>
<%=raw @area_chart.options %>
<br>
<b>Chart : </b>
<br>
<%=raw @area_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>
1 change: 1 addition & 0 deletions demo_rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
get '/googlecharts', to: 'application#googlecharts'
get '/datatables', to: 'application#datatables'
get '/chartwrapper', to: 'chart_wrapper#chart_wrapper'
get '/charteditor', to: 'chart_editor#chart_editor'
get '/highchartscss', to: 'highcharts_css#highcharts_css'
get '/highchartstockmap', to: 'highchart_stock_map#highchart_stock_map'
get '/multiplecharts', to: 'multiple_charts#multiple_charts'
Expand Down
7 changes: 7 additions & 0 deletions demo_rails/test/controllers/chart_editor_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

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

0 comments on commit 77b8485

Please sign in to comment.