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 chart editor examples #9

Merged
merged 1 commit into from Aug 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo_rails/app/assets/javascripts/chart_editor.coffee
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,2 @@
module ChartEditorHelper
end
55 changes: 55 additions & 0 deletions demo_rails/app/views/chart_editor/chart_editor.erb
@@ -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
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'
end
7 changes: 7 additions & 0 deletions demo_rails/test/controllers/chart_editor_controller_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

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