Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 61554857b662285da0dae0f4658140244c5509e8 Charles J. Snider committed Jul 24, 2008
@@ -0,0 +1,20 @@
+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
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47 README
@@ -0,0 +1,47 @@
+OpenFlashChart
+==============
+
+1) rails testing_ofc_2
+2) cd testing_ofc_2
+3) script/plugin install git://github.com/pullmonkey/open-flash-chart-plugin-for-rails.git
+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
+ @graph = @graph = open_flash_chart_object(600,300,"/test_it/graph_code")
+ end
+
+ def graph_code
+ max = 20
+ tmp = []
+ 10.times do |x|
+ tmp << rand(max)
+ end
+
+ title = Title.new("MY TITLE")
+ bar = BarGlass.new
+ bar.set_values([1,2,3,4,5,6,7,8,9])
+ chart = OpenFlashChart.new
+ chart.set_title(title)
+ chart.add_element(bar)
+ render :text => chart.to_s
+ end
+end
+
+6) Add the following to index.html.erb in RAILS_ROOT/app/views/test_it/:
+<script type="text/javascript" src="/javascripts/swfobject.js"></script>
+<%= @graph %>
+
+7) Copy swfobject.js from the plugin's assets/ directory (will make this happen at install time later) to your RAILS_ROOT/public/javascripts directory
+8) Copy open-flash-chart.swf from the plugin's assets/ director to your RAILS_ROOT/public/ directory
+9) script/server
+10) Let me know how it goes, thanks.
+
+
+Example
+=======
+
+Example above and more to follow here - http://www.pullmonkey.com/projects/open_flash_chart
+
+
+Copyright (c) 2008 PullMonkey, released under the MIT license
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the open_flash_chart plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the open_flash_chart plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'OpenFlashChart'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
Binary file not shown.
Oops, something went wrong.
25 init.rb
@@ -0,0 +1,25 @@
+# Include hook code here
+require 'open_flash_chart_object'
+require 'open_flash_chart'
+require 'bar_base'
+require 'bar'
+require 'bar_3d'
+require 'bar_glass'
+require 'bar_sketch'
+require 'bar_stack'
+require 'h_bar'
+require 'line_base'
+require 'line'
+require 'line_dot'
+require 'line_hollow'
+require 'pie'
+require 'scatter'
+require 'title'
+require 'x_axis_label'
+require 'x_axis_labels'
+require 'x_axis'
+require 'x_legend'
+require 'y_axis_base'
+require 'y_axis'
+require 'y_axis_right'
+require 'y_legend'
@@ -0,0 +1 @@
+# Install hook code here
@@ -0,0 +1,7 @@
+class AreaHollow < OpenFlashChart
+ def initialize
+ @type = "area_hollow"
+ @fill_area = 0.35
+ @values = []
+ end
+end
@@ -0,0 +1,9 @@
+require 'bar_base'
+require 'bar_3d'
+require 'bar_glass'
+class Bar < BarBase
+ def initialize
+ @type = "bar"
+ super
+ end
+end
@@ -0,0 +1,6 @@
+class Bar3d < BarBase
+ def initialize
+ @type = "bar_3d"
+ super
+ end
+end
@@ -0,0 +1,2 @@
+class BarBase < OpenFlashChart
+end
@@ -0,0 +1,8 @@
+require 'bar_base'
+
+class BarGlass < BarBase
+ def initialize
+ @type = "bar_glass"
+ super
+ end
+end
@@ -0,0 +1,11 @@
+require 'bar_base'
+class BarSketch < BarBase
+ def initialize(colour, outline_color, fun_factor)
+ @type = "bar_sketch"
+ super
+
+ @colour = colour
+ @outline_colour = outline_colour
+ @offset = fun_factor
+ end
+end
@@ -0,0 +1,9 @@
+require 'bar_base'
+class BarStack < BarBase
+ def initialize
+ @type = "bar_stack"
+ super
+ end
+
+ alias_method :append_stack, :append_value
+end
@@ -0,0 +1,9 @@
+class HBar < OpenFlashChart
+ def initialize(left,right)
+ @type = "hbar"
+ @colour = "#9933CC"
+ @text = "Page Views"
+ @font_size = 10
+ @values = []
+ end
+end
@@ -0,0 +1,6 @@
+require 'line_base'
+class Line < LineBase
+ def initialize
+ @type = "line"
+ end
+end
@@ -0,0 +1,8 @@
+class LineBase < OpenFlashChart
+ def initialize
+ @type = "line_dot"
+ @text = "Page Views"
+ @font_size = 10
+ @values = [9,6,7,9,5,7,6,9,7]
+ end
+end
@@ -0,0 +1,6 @@
+require 'line_base'
+class LineDot < LineBase
+ def initialize
+ @type = "line_dot"
+ end
+end
@@ -0,0 +1,6 @@
+require 'line_base'
+class LineHollow < LineBase
+ def initialize
+ @type = "line_hollow"
+ end
+end
@@ -0,0 +1,71 @@
+# OpenFlashChart
+class OpenFlashChart
+
+ def initialize(args={})
+ # set all the instance variables we want
+ # assuming something like this OpenFlashChart.new(:x_axis => 5, :y_axis => 10, :elements => ["one", "two"], ...)
+ args.each do |k,v|
+ self.instance_variable_set("@#{k}", v)
+ end
+ end
+
+ def to_s
+ # need to return the following like this
+ # 1) font_size as font-size
+ # 2) dot_size as dot-size
+ # 3) outline_colour as outline-colour
+ # 4) halo_size as halo-size
+ # 5) start_angle as start-angle
+ # 6) tick_height as tick-height
+ # 7) grid_colour as grid-colour
+ # 8) threed as 3d
+ # 9) tick_length as tick-length
+ self.to_json
+ end
+ alias_method :render, :to_s
+
+ def add_element(element)
+ @elements ||= []
+ @elements << element
+ end
+
+ def set_key(text, size)
+ @text = text
+ @font_size = size
+ end
+
+ def append_value(v)
+ @values ||= []
+ @values << v
+ end
+
+ def set_range(min,max,steps=1)
+ @min = min
+ @max = max
+ @steps = steps
+ end
+
+ def set_offset(v)
+ @offset = v ? true : false
+ end
+
+ def set_colours(colour, grid_colour)
+ @colour = colour
+ @grid_colour = grid_colour
+ end
+
+ def method_missing(method_name, *args)
+ method_name = method_name.to_s
+ if method_name =~ /.*=/ # i.e., if it is something x_legend=
+ # if the user wants to set an instance variable then let them
+ # the other args (args[0]) are ignored since it is a set method
+ return self.instance_variable_set("@#{method_name}", args[0])
+ elsif method_name =~/^set_(.*)/
+ # backwards compatible ... the user can still use the same set_y_legend methods if they want
+ return self.instance_variable_set("@#{$1}", args[0])
+ else
+ # if the method/attribute is missing and it is not a set method then hmmmm better let the user know
+ super
+ end
+ end
+end
@@ -0,0 +1,26 @@
+def open_flash_chart_object(width, height, url, use_swfobject=true, base="/")
+ url = CGI::escape(url)
+ obj_id = "chart_#{Time.now.to_f}" # some sequencing without all the work of tracking it
+ div_name = "flash_content_#{Time.now.to_f}"
+ protocol = "http" # !request.nil? ? request.env["HTTPS"] || "http" : "http"
+
+ # NOTE: users should put this in the <head> section themselves:
+ ## <script type="text/javascript" src="#{base}/javascripts/swfobject.js"></script>
+
+ return %[
+ <div id="#{div_name}"></div>
+ <script type="text/javascript">
+ swfobject.embedSWF("#{base}open-flash-chart.swf", "#{div_name}", "#{width}", "#{height}", "9.0.0", "expressInstall.swf",{"data-file":"#{url}"});
+ </script>
+ <noscript>
+ <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="#{protocol}://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="#{width}" height="#{height}" id="#{obj_id}" align="middle">
+ <param name="allowScriptAccess" value="sameDomain" />
+ <param name="movie" value="#{base}open-flash-chart.swf?data=#{url}" />
+ <param name="quality" value="high" />
+ <param name="bgcolor" value="#FFFFFF" />
+ <embed src="#{base}open-flash-chart.swf?data=#{url}" quality="high" bgcolor="#FFFFFF" width="#{width}" height="#{height}" name="#{obj_id}" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="#{protocol}://www.macromedia.com/go/getflashplayer" id="#{obj_id}" />
+ </object>
+ </noscript>
+ ]
+end
+
@@ -0,0 +1,16 @@
+class PieValue < OpenFlashChart
+ def initialize(value, text)
+ @value = value
+ @text = text
+ end
+end
+
+class Pie < OpenFlashChart
+ def initialize
+ @type = "pie"
+ @colors = ["#d01f3c","#356aa0","#C79810"]
+ @alpha = 0.6
+ @border = 2
+ @values = [2,3,PieValue(6.5,"hello (6.5)")]
+ end
+end
@@ -0,0 +1,7 @@
+class Scatter < OpenFlashChart
+ def initialize(colour, dot_size)
+ @type = "scatter"
+ @colour = colour
+ @dot_size = dot_size
+ end
+end
@@ -0,0 +1,5 @@
+class Title < OpenFlashChart
+ def initialize(text='')
+ @text = text
+ end
+end
@@ -0,0 +1,5 @@
+class XAxis < OpenFlashChart
+ def set_3d(v)
+ @threed = v
+ end
+end
@@ -0,0 +1,16 @@
+class XAxisLabel < OpenFlashChart
+ def initialize(text, colour, size, rotate)
+ @text = text
+ @colour = color
+ @size = size
+ @rotate = rotate
+ end
+
+ def set_vertical
+ @rotate = "vertical"
+ end
+
+ def set_visible
+ @visible = true
+ end
+end
@@ -0,0 +1,5 @@
+class XAxisLabels < OpenFlashChart
+ def set_vertical
+ @rotate = "vertical"
+ end
+end
@@ -0,0 +1,5 @@
+class XLegend < OpenFlashChart
+ def initialize(text)
+ @text = text
+ end
+end
@@ -0,0 +1,3 @@
+require 'y_axis_base'
+class YAxis < YAxisBase
+end
@@ -0,0 +1,2 @@
+class YAxisBase < OpenFlashChart
+end
Oops, something went wrong.

0 comments on commit 6155485

Please sign in to comment.