Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wiggins committed Apr 29, 2009
2 parents ed96bab + 9e03214 commit 80f8c23
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
14 changes: 11 additions & 3 deletions main.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,17 +23,25 @@ def self.make_table(db)
end end
end end


helpers do
def graphs_from_params(seperator)
[ params[:id] ] + (params[:and] || '').split(seperator)
end
end

get '/' do get '/' do
erb :about erb :about
end end


get '/graphs/:id' do get '/graphs/:id' do
throw :halt, [ 404, "No such graph" ] unless Points.data.filter(:graph => params[:id]).count > 0 graphs_from_params(',').each do |graph|
erb :graph, :locals => { :id => params[:id] } 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 end


get '/graphs/:id/amstock_settings.xml' do get '/graphs/:id/amstock_settings.xml' do
erb :amstock_settings, :locals => { :id => params[:id] } erb :amstock_settings, :locals => { :graphs => graphs_from_params(' ') }
end end


get '/graphs/:id/data.csv' do get '/graphs/:id/data.csv' do
Expand Down
2 changes: 2 additions & 0 deletions views/about.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
RestClient.delete 'http://rifgraf.heroku.com/graphs/sample' RestClient.delete 'http://rifgraf.heroku.com/graphs/sample'
</code> </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> <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/> <hr/>
Expand Down
48 changes: 30 additions & 18 deletions views/amstock_settings.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@
</letters> </letters>
</number_format> </number_format>
<data_sets> <data_sets>
<data_set> <% graphs.each do |id| %>
<title><%= id %></title> <data_set>
<short><%= id %></short> <% if graphs.size > 1 %>
<color>004090</color> <compare_list_box selected="true">true</compare_list_box>
<file_name>/graphs/<%= id %>/data.csv</file_name> <% end %>
<csv>
<reverse>true</reverse> <title><%= id %></title>
<separator>,</separator> <short><%= id %></short>
<date_format>YYYY-MM-DD hh:mm:ss</date_format> <color><%= sprintf("%02x02x02x", rand(200), rand(200), rand(200)) %></color>
<decimal_separator>.</decimal_separator> <file_name>/graphs/<%= id %>/data.csv</file_name>
<columns> <csv>
<column>date</column> <reverse>true</reverse>
<column>volume</column> <separator>,</separator>
<column>close</column> <date_format>YYYY-MM-DD hh:mm:ss</date_format>
</columns> <decimal_separator>.</decimal_separator>
</csv> <columns>
</data_set> <column>date</column>
<column>volume</column>
<column>close</column>
</columns>
</csv>
</data_set>
<% end %>
</data_sets> </data_sets>


<charts> <charts>
Expand All @@ -47,12 +53,18 @@


<column_width>100</column_width> <column_width>100</column_width>


<comparing>
<recalculate>false</recalculate>
</comparing>

<graphs> <graphs>
<graph> <graph>
<data_sources> <data_sources>
<close>close</close> <close>close</close>
</data_sources> </data_sources>


<compare_source>close</compare_source>

<bullet>round_outline</bullet> <bullet>round_outline</bullet>


<legend> <legend>
Expand All @@ -66,7 +78,7 @@
</charts> </charts>


<data_set_selector> <data_set_selector>
<enabled>false</enabled> <enabled><%= graphs.size > 1 ? 'true' : 'false' %></enabled>
</data_set_selector> </data_set_selector>


<period_selector> <period_selector>
Expand Down
2 changes: 1 addition & 1 deletion views/graph.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script type="text/javascript"> <script type="text/javascript">
// <![CDATA[ // <![CDATA[
var so = new SWFObject("/amstock.swf", "amline", "100%", "100%", "8", "#FFFFFF"); 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.addVariable("preloader_color", "#999999");
so.write("flashcontent"); so.write("flashcontent");
// ]]> // ]]>
Expand Down

0 comments on commit 80f8c23

Please sign in to comment.