Permalink
Browse files

merge

  • Loading branch information...
2 parents ed96bab + 9e03214 commit 80f8c237afbe9456f55aeef7995faf8145263f95 @adamwiggins committed Apr 29, 2009
Showing with 44 additions and 22 deletions.
  1. +11 −3 main.rb
  2. +2 −0 views/about.erb
  3. +30 −18 views/amstock_settings.erb
  4. +1 −1 views/graph.erb
View
14 main.rb
@@ -23,17 +23,25 @@ def self.make_table(db)
end
end
+helpers do
+ def graphs_from_params(seperator)
+ [ params[:id] ] + (params[:and] || '').split(seperator)
+ end
+end
+
get '/' do
erb :about
end
get '/graphs/:id' do
- throw :halt, [ 404, "No such graph" ] unless Points.data.filter(:graph => params[:id]).count > 0
- erb :graph, :locals => { :id => params[:id] }
+ graphs_from_params(',').each do |graph|
+ throw :halt, [ 404, "No such graph \"#{graph}\"" ] unless Points.data.filter(:graph => graph).count > 0
+ end
+ erb :graph, :locals => { :id => params[:id], :others => (params[:and] || '').gsub(/,/, '+') }
end
get '/graphs/:id/amstock_settings.xml' do
- erb :amstock_settings, :locals => { :id => params[:id] }
+ erb :amstock_settings, :locals => { :graphs => graphs_from_params(' ') }
end
get '/graphs/:id/data.csv' do
View
@@ -62,6 +62,8 @@
RestClient.delete 'http://rifgraf.heroku.com/graphs/sample'
</code>
+ <p>Compare multiple graphs on the same chart with the "and" parameter: <a href="/graphs/pirates?and=ninjas,robots">http://rifgraf.heroku.com/graphs/pirates?and=ninjas,robots</a></p>
+
<p>Use rifgraf as a service by posting to rifgraf.heroku.com, or <a href="http://github.com/adamwiggins/rifgraf">grab the source</a> and host your own.</p>
<hr/>
View
@@ -10,23 +10,29 @@
</letters>
</number_format>
<data_sets>
- <data_set>
- <title><%= id %></title>
- <short><%= id %></short>
- <color>004090</color>
- <file_name>/graphs/<%= id %>/data.csv</file_name>
- <csv>
- <reverse>true</reverse>
- <separator>,</separator>
- <date_format>YYYY-MM-DD hh:mm:ss</date_format>
- <decimal_separator>.</decimal_separator>
- <columns>
- <column>date</column>
- <column>volume</column>
- <column>close</column>
- </columns>
- </csv>
- </data_set>
+ <% graphs.each do |id| %>
+ <data_set>
+ <% if graphs.size > 1 %>
+ <compare_list_box selected="true">true</compare_list_box>
+ <% end %>
+
+ <title><%= id %></title>
+ <short><%= id %></short>
+ <color><%= sprintf("%02x02x02x", rand(200), rand(200), rand(200)) %></color>
+ <file_name>/graphs/<%= id %>/data.csv</file_name>
+ <csv>
+ <reverse>true</reverse>
+ <separator>,</separator>
+ <date_format>YYYY-MM-DD hh:mm:ss</date_format>
+ <decimal_separator>.</decimal_separator>
+ <columns>
+ <column>date</column>
+ <column>volume</column>
+ <column>close</column>
+ </columns>
+ </csv>
+ </data_set>
+ <% end %>
</data_sets>
<charts>
@@ -47,12 +53,18 @@
<column_width>100</column_width>
+ <comparing>
+ <recalculate>false</recalculate>
+ </comparing>
+
<graphs>
<graph>
<data_sources>
<close>close</close>
</data_sources>
+ <compare_source>close</compare_source>
+
<bullet>round_outline</bullet>
<legend>
@@ -66,7 +78,7 @@
</charts>
<data_set_selector>
- <enabled>false</enabled>
+ <enabled><%= graphs.size > 1 ? 'true' : 'false' %></enabled>
</data_set_selector>
<period_selector>
View
@@ -12,7 +12,7 @@
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("/amstock.swf", "amline", "100%", "100%", "8", "#FFFFFF");
- so.addVariable("settings_file", escape("/graphs/<%= id %>/amstock_settings.xml"));
+ so.addVariable("settings_file", escape("/graphs/<%= id %>/amstock_settings.xml?and=<%= others %>"));
so.addVariable("preloader_color", "#999999");
so.write("flashcontent");
// ]]>

0 comments on commit 80f8c23

Please sign in to comment.