Skip to content

Commit

Permalink
view multiple data sets in the same graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wiggins committed Nov 2, 2008
1 parent f46cad4 commit edd2b7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
10 changes: 7 additions & 3 deletions main.rb
Expand Up @@ -30,12 +30,16 @@ def self.make_table(db)
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 = [ params[:id] ] + (params[:and] || '').split(',')
graphs.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] }
end

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

get '/graphs/:id/data.csv' do
Expand Down
42 changes: 24 additions & 18 deletions views/amstock_settings.erb
Expand Up @@ -10,23 +10,27 @@
</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>
<compare_list_box selected="true">true</compare_list_box>

<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>
Expand All @@ -53,6 +57,8 @@
<close>close</close>
</data_sources>

<compare_source>close</compare_source>

<bullet>round_outline</bullet>

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

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

<period_selector>
Expand Down
2 changes: 1 addition & 1 deletion views/graph.erb
Expand Up @@ -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");
// ]]>
Expand Down

0 comments on commit edd2b7b

Please sign in to comment.