Skip to content

Commit

Permalink
Upgraded open_flash_chart
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Oct 21, 2010
1 parent 367f2da commit b89a845
Show file tree
Hide file tree
Showing 65 changed files with 1,348 additions and 1,138 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Expand Up @@ -34,6 +34,10 @@ The current version of OpenMind is 3.0. 3.0 adds many improvements, including:
* Added a compatibility matrix of product release versions
* Re-implemented the searching using Thinking Sphinx for improved search capability and reliability

Contributors
============
Bob Sturim
Rich Sturim

License
=======
Expand Down
39 changes: 20 additions & 19 deletions app/controllers/polls_controller.rb
Expand Up @@ -19,36 +19,37 @@ def index

def show
session[:polls_show_toggle_detail] ||= "HIDE"
@poll = Poll.find(params[:id])
# @chart_data = []
# for option in @poll.poll_options
# data_point = [ option.description, option.user_responses.size]
# @chart_data << data_point unless option.user_responses.size == 0
# end

@graph = open_flash_chart_object(450,450, pie_polls_path(:id => @poll.id), true, '/')
@poll = Poll.find(params[:id])
puts "============ #{pie_poll_url(@poll)}"
@graph = open_flash_chart_object(450,450, pie_poll_url(@poll))
end

def pie
poll = Poll.find(params[:id])
data = []
labels = []
g = Graph.new

# total_responses = poll.poll_options.collect(&:user_responses).size
pie_values = []
for option in poll.poll_options
if option.user_responses.size > 0
data << option.user_responses.size
labels << "#{StringUtils.truncate option.description, 16}"
pie_values << PieValue.new(option.user_responses.size, "#{StringUtils.truncate option.description, 16}")
end
end

g.pie(70, '#505050', '{background-color:#FFFFFF; font-size: 12px; color: #404040;}')
g.pie_values(data, labels)
g.set_bg_color('#FFFFFF')
g.pie_slice_colors(%w(#CF2626 #5767AF #D01FC3 #356AA0 #CF5ACD #CF750C #FF7200 #8F1A1A #ADD700 #57AF9D #C3CF5A #456F4F #C79810))
# g.set_tool_tip("#val#")
# g.title("Pie Chart", '{font-size:18px; color: #d01f3c}' )
render :text => g.render
pie_chart = Pie.new
pie_chart.start_angle = 35
pie_chart.animate = true
pie_chart.tooltip = '#val# of #total#<br>#percent#'
pie_chart.values = pie_values
pie_chart.colours = %w(#CF2626 #5767AF #D01FC3 #356AA0 #CF5ACD #CF750C #FF7200 #8F1A1A #ADD700 #57AF9D #C3CF5A #456F4F #C79810)

chart = OpenFlashChart.new

chart.bg_colour = '#ffffcc'
chart.title = Title.new("Survey Responses")
chart.add_element(pie_chart)
chart.x_axis = nil
render :text => chart.to_s
end


Expand Down
3 changes: 1 addition & 2 deletions app/views/polls/show.rhtml
@@ -1,5 +1,4 @@
<%content_for :head do -%>
<%= javascript_include_tag "swfobject" %>
<%end%>
<%= javascript_include_tag "wz_tooltip.js", :cache => "cache/tooltip" %>
Expand Down Expand Up @@ -124,7 +123,7 @@
</div>

<% if @poll.total_responses > 0 %>
<div id="pollChart">
<div id="pollChart" style="background-color:#ffffcc;">
<%= @graph %>
</div>
<% end %>
4 changes: 2 additions & 2 deletions config/routes.rb
Expand Up @@ -28,9 +28,9 @@
map.resources :lookup_codes
map.resources :merge_ideas
map.resources :periodic_jobs, :member => { :rerun => :post }
map.resources :polls, :member => { :publish => :post, :unpublish => :post,
map.resources :polls, :member => { :publish => :post, :unpublish => :post, :pie => :get,
:present_survey => :get, :take_survey => :post},
:collection => {:toggle_details => :get, :pie => :get, :display_comments => :get }
:collection => {:toggle_details => :get, :display_comments => :get }
map.resources :portal, :only => :index,
:collection => {:auto_complete_for_user_email => :get }
map.resources :products
Expand Down
238 changes: 5 additions & 233 deletions public/javascripts/swfobject.js

Large diffs are not rendered by default.

Binary file added public/open-flash-chart-bar-clicking.swf
Binary file not shown.
Binary file modified public/open-flash-chart.swf
Binary file not shown.
2 changes: 1 addition & 1 deletion vendor/plugins/open_flash_chart/MIT-LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2007 Skizmo, Inc. and PullMonkey.com
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
80 changes: 54 additions & 26 deletions vendor/plugins/open_flash_chart/README
@@ -1,26 +1,54 @@
= open_flash_chart

This library was ported from the open flash chart project's php code to be used with Ruby on Rails.
Vish the open flash chart project here - http://teethgrinder.co.uk/open-flash-chart/

== Resources

Install

* script/plugin install http://svn.pullmonkey.com/plugins/trunk/open_flash_chart/
* move the open_flash_chart.swf file to your public directory
* move the swfobject.js file to your public/javascripts directory
* visit http://pullmonkey.com/projects/open_flash_chart for examples
* visit http://teethgrinder.co.uk/open-flash-chart/ for even more examples

Rubyforge project

*

RDocs

*

Subversion

* http://svn.pullmonkey.com/plugins/trunk/open_flash_chart
OpenFlashChart Version 2.0.0 11/14/2008
==============

1) rails ofc2_test_app
2) cd ofc2_test_app
3) script/plugin install git://github.com/pullmonkey/open_flash_chart.git
3.1) If the install didn't copy the contents of the assets directory to your RAILS_ROOT/public directory, make sure to do so.
4) script/generate controller test_it

5) Add the following to the test_it_controller.rb in RAILS_ROOT/app/controllers:
class TestItController < ApplicationController

def index
respond_to do |wants|
wants.html {
@graph = open_flash_chart_object( 600, 300, url_for( :action => 'index', :format => :json ) )
}
wants.json {
chart = OpenFlashChart.new( "MY TITLE" ) do |c|
c << BarGlass.new( :values => (1..10).sort_by{rand} )
end
render :text => chart, :layout => false
}
end
end

end

6) Add the following to index.html.erb in RAILS_ROOT/app/views/test_it/:
<html>
<head>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
</head>
<body>
<%= @graph %>
</body>
</html>

7) script/server
8) Let me know how it goes, thanks.


Example
=======

Example above and more to follow here - http://www.pullmonkey.com/projects/open_flash_chart

Notes
======
The plugin breaks if the json gem is included, because of the way that the gem generates json vs the rails native json generator.

Not tested, but klochner claims to have implemented a fix for it here - http://github.com/klochner/open_flash_chart/commit/00cf531387880af8c49ed5118737f0492b437f75

Copyright (c) 2008 PullMonkey, released under the MIT license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion vendor/plugins/open_flash_chart/init.rb
@@ -1,3 +1,9 @@
# Include hook code here
require 'open_flash_chart'

ActionView::Base.send :include, OpenFlashChart::View
OpenFlashChart::Base.send :include, OpenFlashChart::View
ActionController::Base.send :include, OpenFlashChart::Controller
ActionController::Base.send :include, OpenFlashChart
ActiveRecord::Base.send :include, OpenFlashChart::View
ActiveRecord::Base.send :include, OpenFlashChart::Controller
ActiveRecord::Base.send :include, OpenFlashChart
18 changes: 17 additions & 1 deletion vendor/plugins/open_flash_chart/install.rb
@@ -1 +1,17 @@
# Install hook code here
# Workaround a problem with script/plugin and http-based repos.
# See http://dev.rubyonrails.org/ticket/8189
Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do

##
## Copy over asset files (javascript/css/images) from the plugin directory to public/
##

def copy_files(source_path, destination_path, directory)
source, destination = File.join(directory, source_path), File.join(RAILS_ROOT, destination_path)
# FileUtils.mkdir(destination) unless File.exist?(destination)
FileUtils.cp_r(Dir.glob(source+'/*.*'), destination)
end

directory = File.dirname(__FILE__)
copy_files("/assets", "/public", directory)
end

0 comments on commit b89a845

Please sign in to comment.