Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New code: strip the charts down to the basics.

  • Loading branch information...
commit 4f516ffc32212a8fd7756d6944d3f495a41ee4c7 1 parent b5ee7eb
@davidw authored
View
166 flotr-lib/build.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Flotr" default="build.release">
+
+ <property name="framework" value="prototype"/>
+ <property name="version" value="0.2.0-test"/>
+ <property name="date" value="Jan 12, 2009"/>
+ <property name="example_dir" value="examples/${framework}"/>
+ <property name="release_dir" value="release"/>
+ <property name="flotr_dir" value="flotr/${framework}"/>
+ <property name="build_dir" value="${release_dir}/${framework}/flotr-${version}"/>
+ <property name="jar_dir" location="${basedir}" />
+ <property name="header" value="Flotr ${version} Copyright (c) 2009 Bas Wenneker, &lt;http://solutoire.com&gt;, MIT License." />
+ <property name="replace_dir" value="../../flotr/${framework}/"/>
+ <property name="online_dir" value="${release_dir}/${framework}/online-${version}"/>
+
+ <property name="firefox_exe"
+ value="C:\Program Files\Mozilla Firefox\firefox.exe"
+ description="Location of firefox.exe, used for testing"/>
+
+ <property name="ie7_exe"
+ value="C:\Program Files\Internet Explorer\iexplore.exe"
+ description="Location of iexplore.exe, used for testing"/>
+
+ <property name="opera_exe"
+ value="C:\Program Files\Opera\opera.exe"
+ description="Location of opera.exe, used for testing"/>
+
+ <property name="safari_exe"
+ value="C:\Program Files\Safari\Safari.exe"
+ description="Location of Safari.exe, used for testing"/>
+
+ <property name="prototype_testsuite"
+ value="http://127.0.0.1/Flotr/tests/testRunner.html?testpage=127.0.0.1/Flotr/tests/prototype/prototypeTestSuite.html&amp;autorun=true"
+ description="URL of the prototype test suite"/>
+
+ <target name="build.clean" description="Deletes release and online directories.">
+ <delete dir="${build_dir}"/>
+ <delete dir="${online_dir}"/>
+ </target>
+
+ <target name="build.preprocess" depends="build.clean" description="Places all files in the right directories. Also adds version numbering to files and folders.">
+ <mkdir dir="${build_dir}"/>
+ <copy todir="${build_dir}/examples">
+ <fileset dir="${example_dir}"/>
+ </copy>
+ <copy todir="${build_dir}/flotr">
+ <fileset dir="${flotr_dir}"/>
+ </copy>
+ <copy todir="${build_dir}">
+ <fileset dir="${basedir}" includes="license.txt, readme.txt"/>
+ </copy>
+ <copy file="${build_dir}/flotr/flotr.js" tofile="${build_dir}/flotr/flotr-tmp.js"/>
+ <concat destfile="${build_dir}/flotr/flotr.debug-${version}.js">
+ <header filtering="no" trimleading="yes">//${header}
+ </header>
+ <fileset file="${build_dir}/flotr/flotr.js"/>
+ </concat>
+ <replace dir="${build_dir}" token="%version%" value="${version}">
+ <include name="*.*"/>
+ <include name="flotr/*.*"/>
+ </replace>
+ <replace dir="${build_dir}" token="%date%" value="${date}">
+ <include name="*.*"/>
+ </replace>
+ <replace dir="${build_dir}/examples" token="${replace_dir}" value="../flotr/">
+ <include name="*.html"/>
+ </replace>
+ <replace dir="${build_dir}/examples" token="../flotr/flotr.js" value="../flotr/flotr-${version}.js">
+ <include name="*.html"/>
+ </replace>
+ </target>
+
+ <target name="build.compress" depends="build.preprocess" description="Minifies the js to test the minified version of Flotr.">
+ <apply executable="java" parallel="false">
+ <fileset file="${build_dir}/flotr/flotr.js"/>
+ <arg line="-jar"/>
+ <arg path="${jar_dir}/yuicompressor-2.4.2.jar"/>
+ <srcfile/>
+ <arg line="-o"/>
+ <mapper type="glob" from="*.js" to="${build_dir}/flotr/*-min.js"/>
+ <targetfile/>
+ </apply>
+ </target>
+
+ <target name="build.release" depends="build.compress" description="Builds a release folder, this includes a zip package of the folder.">
+ <echo>
+ IMPORTANT: REMOVE THE PRIVATES, CHECK BUILD NUMBER
+ </echo>
+ <concat destfile="${build_dir}/flotr/flotr-${version}.js">
+ <header filtering="no" trimleading="yes">//${header}
+ </header>
+ <fileset file="${build_dir}/flotr/flotr-min.js"/>
+ </concat>
+ <delete>
+ <fileset dir="${build_dir}/flotr/" includes="flotr.js, *-min.js, *-tmp.js"/>
+ </delete>
+ <zip destfile="${build_dir}/${framework}.flotr-${version}.zip" comment="${header}">
+ <zipfileset dir="${build_dir}" prefix="flotr-${version}"/>
+ </zip>
+ </target>
+
+ <target name="build.online" depends="build.compress" description="Builds special version for online usage. This target includes Adsense ads in the examples.">
+ <echo>
+ IMPORTANT: REMOVE THE PRIVATES, CHECK BUILD NUMBER
+ </echo>
+ <copy todir="${online_dir}/examples">
+ <fileset dir="${build_dir}/examples"/>
+ </copy>
+ <copy todir="${online_dir}/flotr">
+ <fileset dir="${build_dir}/flotr"/>
+ </copy>
+ <concat destfile="${online_dir}/flotr/flotr-${version}.js">
+ <header filtering="no" trimleading="yes">//${header}
+ </header>
+ <fileset file="${online_dir}/flotr/flotr-min.js"/>
+ </concat>
+ <delete>
+ <fileset dir="${online_dir}/flotr/" includes="flotr.js, *-min.js, *-tmp.js"/>
+ </delete>
+ <replace dir="${online_dir}/examples" token="&lt;!-- ad --&gt;">
+ <include name="*.html"/>
+ <replacevalue>&lt;div class=&quot;ad&quot;&gt;
+&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
+google_ad_client = &quot;pub-5018807259634553&quot;;
+/* 728x90, created 2/27/08, flotr example pages */
+google_ad_slot = &quot;1173802751&quot;;
+google_ad_width = 728;
+google_ad_height = 90;
+//--&gt;
+&lt;/script&gt;
+&lt;script type=&quot;text/javascript&quot;
+src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
+&lt;/script&gt;
+&lt;/div&gt;</replacevalue>
+ </replace>
+
+ <replace dir="${online_dir}/examples" token="&lt;!-- analytics --&gt;">
+ <include name="*.html"/>
+ <replacevalue>&lt;script src=&quot;http://www.google-analytics.com/urchin.js&quot; type=&quot;text/javascript&quot;&gt;
+ &lt;/script&gt;
+ &lt;script type=&quot;text/javascript&quot;&gt;
+ _uacct = &quot;UA-658367-1&quot;;
+ urchinTracker();
+ &lt;/script&gt;</replacevalue>
+ </replace>
+ </target>
+
+ <target name="test.prototype"
+ description="Opens multiple browsers and starts unit testing.">
+
+ <exec executable="${safari_exe}" spawn="true">
+ <arg value="-url"/>
+ <arg value="${prototype_testsuite}"/>
+ </exec>
+ <exec executable="${firefox_exe}" spawn="true">
+ <arg value="-new-tab"/>
+ <arg value="${prototype_testsuite}" />
+ </exec>
+ <exec executable="${ie7_exe}" spawn="true">
+ <arg value="${prototype_testsuite}" />
+ </exec>
+ <exec executable="${opera_exe}" spawn="true">
+ <arg value="${prototype_testsuite}"/>
+ </exec>
+ </target>
+</project>
View
2  init.rb
@@ -6,4 +6,4 @@
##
## Run the install script, too, just to make sure
##
-require File.dirname(__FILE__) + '/install'
+require File.dirname(__FILE__) + '/install'
View
22 install.rb
@@ -1,23 +1,27 @@
# 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/
+ ## Copy over asset files (javascript/css/images) from the plugin
+ ## directory to public/
##
-
- plotr = "plotr-#{PLOTR_VERSION}"
+
chartr_path = RAILS_ROOT + "/vendor/plugins/chartr"
destination = RAILS_ROOT + "/public/javascripts/chartr"
-
+
+ flotr = "flotr-lib/release/prototype/flotr-0.2.0-test/flotr"
+
# Files to be copied
- files = ["#{chartr_path}/#{plotr}/plotr-proto16/plotr.js", "#{chartr_path}/#{plotr}/lib/excanvas/excanvas.js"]
-
+ files = ["#{chartr_path}/#{flotr}/flotr-min.js",
+ "#{chartr_path}/#{flotr}/lib/canvastext.js",
+ "#{chartr_path}/#{flotr}/lib/canvas2image.js"]
+
# Create destination directory (RAILS_ROOT/public/javascripts/chartr)
FileUtils.mkdir_p(destination)
-
+
# Copy each file to the destination directory
files.each do |f|
FileUtils.cp_r(f, destination)
end
-end
+end
View
137 lib/chart.rb
@@ -1,108 +1,37 @@
-class Chartr::Chart
- attr_accessor :options, :dataset
- def initialize(params = {})
- # params = params.reverse_merge!({ :colorScheme => "blue",
- # :backgroundColor => "#f2f2f2",
- # :barOrientation => "vertical"})
- # @options = {
- # :axis => {
- # :lineWidth => 1.0,
- # :lineColor => '#000000',
- # :tickSize => 3.0,
- # :labelColor => '#666666',
- # :labelFont => 'Tahoma',
- # :labelFontSize => 9,
- # :labelWidth => 50.0,
- # :x => {
- # :hide => false,
- # :ticks => nil,
- # :tickCount => 10,
- # :tickPrecision => 1,
- # :values => nil
- # },
- # :y => {
- # :hide => false,
- # :ticks => nil,
- # :tickCount => 10,
- # :tickPrecision => 1,
- # :values => nil
- # }
- # },
- # :background => {
- # :color => params[:backgroundColor],
- # :hide => false,
- # :lineColor => '#ffffff',
- # :lineWidth => 1.5
- # },
- # :legend => {
- # :opacity => 0.8,
- # :borderColor => '#000000',
- # :style => {},
- # :hide => false,
- # :position => {:top => '20px', :left => '40px'}
- # },
- # :padding => {
- # :left => 30,
- # :right => 30,
- # :top => 5,
- # :bottom => 10
- # },
- # :stroke => {
- # :color => '#ffffff',
- # :hide => false,
- # :shadow => true,
- # :width => 2
- # },
- # :fillOpacity => 1.0,
- # :shouldFill => true,
- # :barWidthFillFraction => 0.75,
- # :barOrientation => params[:barOrientation],
- # :xOriginIsZero => true,
- # :yOriginIsZero => true,
- # :pieRadius => 0.4,
- # :colorScheme => params[:colorScheme]
- # }
-
- @axis = "x"
- @labels = []
- @xLabels = []
- @dataset = {}
- @xticks = []
- @title = nil
- end
-
- def add_data(chartdata)
- if @xLabels.any?
- title = @xLabels[@dataset.size]
- end
- @dataset[(chartdata.title || title || "Data #{(@dataset.size+1).to_s}")] = chartdata.data
- end
-
- def add_xtick(label)
- @xticks.push({:v => @xticks.size, :label => label})
- end
-
- def xLabels=(labels)
- @xLabels = labels
- end
-
- def set_xticks
- @xLabels.each do |label|
- self.add_xtick(label)
- end
-
- # Default to the dataset titles if no labels
- # have been explicitly given.
- if @xticks.empty?
- @dataset.each do |data|
- self.add_xtick(data.first)
+class Hash
+
+ # Merges self with another hash, recursively.
+ #
+ # This code was lovingly stolen from some random gem:
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
+ #
+ # Thanks to whoever made it.
+
+ def deep_merge(hash)
+ target = dup
+
+ hash.keys.each do |key|
+ if hash[key].is_a? Hash and self[key].is_a? Hash
+ target[key] = target[key].deep_merge(hash[key])
+ next
end
+
+ target[key] = hash[key]
end
+ target
+ end
+end
+
+class Chartr::Chart
+ attr_accessor :data
+
+ def initialize(params = {})
+ @options ||= {}
+ @options = @options.deep_merge(params)
+ @data = []
end
-
- def options
- self.set_xticks
- @options[:axis][@axis.to_sym][:ticks] = @xticks
- @options
+
+ def output(canvasname)
+ return "Flotr.draw($('#{canvasname}'), #{@data.to_json}, #{@options.to_json});"
end
-end
+end
View
77 lib/charts/bar_chart.rb
@@ -1,76 +1,9 @@
class Chartr::BarChart < Chartr::Chart
+ attr_accessor :data
+
def initialize(params = {})
+ @options = { :bars => { :show => true } }
super
- params = params.reverse_merge!({ :axisLabelColor => "#000000",
- :axisLabelFont => "Tahoma",
- :axisLabelFontSize => 9,
- :axisLabelWidth => 50.0,
- :axisLineWidth => 1.0,
- :axisLineColor => "#000000",
- :axisTickSize => 3.0,
- :axisXHide => false,
- :backgroundColor => "#f2f2f2",
- :barOrientation => "vertical",
- :barWidthFillFraction => 0.75,
- :colorScheme => "blue",
- :legendPositionTop => "20px",
- :legendPositionLeft => "40px",
- :legendHide => false,
- :paddingLeft => 30,
- :paddingRight => 0,
- :paddingTop => 10,
- :paddingBottom => 30 })
- @options = {
- :barOrientation => params[:barOrientation],
-
- # Define a padding for the canvas node
- :padding => {
- :left => params[:paddingLeft],
- :right => params[:paddingRight],
- :top => params[:paddingTop],
- :bottom => params[:paddingBottom]
- },
-
- # Legend positioning.
- :legend => {
- :hide => params[:legendHide],
- :position => {
- :top => params[:legendPositionTop],
- :left => params[:legendPositionLeft]
- }
- },
-
- # Background color to render.
- :background => { :color => params[:backgroundColor] },
-
- # Use the predefined blue colorscheme.
- :colorScheme => params[:colorScheme],
-
- :axis => {
- :lineWidth => params[:axisLineWidth],
- :lineColor => params[:axisLineColor],
- :tickSize => params[:axisTickSize],
- :labelColor => params[:axisLabelColor],
- :labelFont => params[:axisLabelFont],
- :labelFontSize => params[:axisLabelFontSize],
- :labelWidth => params[:axisLabelWidth],
- :x => {
- :hide => params[:axisXHide],
- :ticks => nil,
- #:values => nil
- },
- :y => {
- :tickPrecision => 0
- }
- },
-
- :barWidthFillFraction => params[:barWidthFillFraction]
- }
end
-
- def output(canvasname = (@title || "chart"))
- o = "var chart = new Plotr.BarChart(#{canvasname.to_json}, #{self.options.to_json});
- chart.addDataset(#{@dataset.to_json});
- chart.render();"
- end
-end
+
+end
View
85 lib/charts/line_chart.rb
@@ -1,87 +1,6 @@
class Chartr::LineChart < Chartr::Chart
def initialize(params = {})
super
- params = params.reverse_merge!({ :axisLabelColor => "#000000",
- :axisLabelFont => "Tahoma",
- :axisLabelFontSize => 9,
- :axisLabelWidth => 50.0,
- :axisLineWidth => 1.0,
- :axisLineColor => "#000000",
- :axisTickSize => 3.0,
- :backgroundColor => "#f2f2f2",
- :barOrientation => "vertical",
- :colorScheme => "blue",
- :fillOpacity => 1.0,
- :legendPositionTop => "20px",
- :legendPositionLeft => "40px",
- :legendHide => false,
- :paddingLeft => 30,
- :paddingRight => 0,
- :paddingTop => 10,
- :paddingBottom => 30,
- :shouldFill => true,
- :strokeColor => "#ffffff",
- :strokeHide => false,
- :strokeShadow => true,
- :strokeWidth => 2,
- :xOriginIsZero => true,
- :yOriginIsZero => true })
- @options = {
- :barOrientation => params[:barOrientation],
-
- # Define a padding for the canvas node
- :padding => {
- :left => params[:paddingLeft],
- :right => params[:paddingRight],
- :top => params[:paddingTop],
- :bottom => params[:paddingBottom]
- },
-
- # Legend positioning.
- :legend => {
- :hide => params[:legendHide],
- :position => {
- :top => params[:legendPositionTop],
- :left => params[:legendPositionLeft]
- }
- },
-
- :stroke => {
- :color => params[:strokeColor],
- :hide => params[:strokeHide],
- :shadow => params[:strokeShadow],
- :width => params[:strokeWidth]
- },
-
- # Background color to render.
- :background => { :color => params[:backgroundColor] },
-
- # Use the predefined blue colorscheme.
- :colorScheme => params[:colorScheme],
-
- :axis => {
- :lineWidth => params[:axisLineWidth],
- :lineColor => params[:axisLineColor],
- :tickSize => params[:axisTickSize],
- :labelColor => params[:axisLabelColor],
- :labelFont => params[:axisLabelFont],
- :labelFontSize => params[:axisLabelFontSize],
- :labelWidth => params[:axisLabelWidth],
- :x => {
- :ticks => nil
- }
- },
-
- :fillOpacity => params[:fillOpacity],
- :shouldFill => params[:shouldFill],
- :xOriginIsZero => params[:xOriginIsZero],
- :yOriginIsZero => params[:yOriginIsZero]
- }
end
-
- def output(canvasname = (@title || "chart"))
- o = "var chart = new Plotr.LineChart(#{canvasname.to_json}, #{self.options.to_json});
- chart.addDataset(#{@dataset.to_json});
- chart.render();"
- end
-end
+
+end
View
85 lib/charts/pie_chart.rb
@@ -1,81 +1,16 @@
class Chartr::PieChart < Chartr::Chart
def initialize(params = {})
+ @options = { :pie => { :show => true } }
+
super
- params = params.reverse_merge!({ :axisLabelColor => "#000000",
- :axisLabelFont => "Tahoma",
- :axisLabelFontSize => 9,
- :axisLabelWidth => 50.0,
- :axisLineWidth => 1.0,
- :axisLineColor => "#000000",
- :axisTickSize => 3.0,
- :backgroundColor => "#f2f2f2",
- :colorScheme => "blue",
- :legendPositionTop => "20px",
- :legendPositionLeft => "40px",
- :legendHide => false,
- :paddingLeft => 30,
- :paddingRight => 0,
- :paddingTop => 10,
- :paddingBottom => 30,
- :pieRadius => "0.4" })
- @options = {
- # Define a padding for the canvas node
- :padding => {
- :left => params[:paddingLeft],
- :right => params[:paddingRight],
- :top => params[:paddingTop],
- :bottom => params[:paddingBottom]
- },
-
- # Legend positioning.
- :legend => {
- :hide => params[:legendHide],
- :position => {
- :top => params[:legendPositionTop],
- :left => params[:legendPositionLeft]
- }
- },
-
- # Background color to render.
- :background => { :color => params[:backgroundColor] },
-
- # Use the predefined blue colorscheme.
- :colorScheme => params[:colorScheme],
-
- :axis => {
- :lineWidth => params[:axisLineWidth],
- :lineColor => params[:axisLineColor],
- :tickSize => params[:axisTickSize],
- :labelColor => params[:axisLabelColor],
- :labelFont => params[:axisLabelFont],
- :labelFontSize => params[:axisLabelFontSize],
- :labelWidth => params[:axisLabelWidth],
- :x => {
- :ticks => nil
- }
- },
-
- :pieRadius => params[:pieRadius]
- }
end
-
- def set_xticks
- @dataset.each do |data|
- @xLabels.each do |label|
- if data.first == label
- self.add_xtick(label)
- end
- end
+
+ # Piechart data is a bit different. We can't really have different
+ # series, so we just take the data as a simply array.
+ def data=(series)
+ @data = []
+ series.each do |d|
+ @data << [[0,d]]
end
-
- if @xticks.empty?
- super
- end
- end
-
- def output(canvasname = (@title || "chart"))
- o = "var chart = new Plotr.PieChart(#{canvasname.to_json}, #{self.options.to_json});
- chart.addDataset(#{@dataset.to_json});
- chart.render();"
end
-end
+end
View
4 lib/helpers/chartr_helpers.rb
@@ -2,7 +2,7 @@ module ActionView::Helpers
module ChartrHelpers
# easy way to include Chartr assets
def chartr_includes
- javascript_include_tag "chartr/excanvas", "chartr/plotr"
+ javascript_include_tag "chartr/canvas2image.js", "chartr/canvastext.js", "chartr/flotr-min"
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.