=begin
= Gfdnavi においてどうやって可視化機能を増やすか
#
# 履歴情報 (新しい更新履歴を上に追記していくこと)
#
# * 2006/12/05 (堀之内) 編集
# * 2006/11/11 (西澤) 編集
# * 2006/11/07 (堀之内) 作成
== 例1:コンター/トーンの最大値、最小値を指定できるようにする
2006/10/30 に西澤氏がコミットした変更より。
=== 変更したファイル
app/controllers/analysis_controller.rb: revision 1.50 -> 1.51
app/views/analysis/_draw_tone_settings.rhtml: revision 1.1 -> 1.2
app/models/analysis.rb: revision 1.14 -> 1.15
ただし、analysis_controller.rb の変更にはバグフィックスを含む。
=== 概要
作業の流れは次のようになる。
* app/views/analysis/_draw_tone_settings.rhtml に入力窓を追加。
文字で入力する場合、text_field メソッドを使う。
入力は内部変数 @analysis (Analysisクラス) のメソッドコールを通じて伝える。
そのためには、text_field の第一引数を 'analysis' にし、
第二引数をそのメソッド名にする。
* app/models/analysis.rb で定義される Analysis クラスに、対応するメソッド
を追加して、入力窓より伝えられた情報を保存・取出しできるようにする。
* app/controllers/analysis_controller.rb の draw メソッドが、
上記の Analysis オブジェクトから情報を読み出して、今追加した設定を
可視化に反映するようにする。
* 最大、最小指定は GGraph の tone / contour メソッドのオプション
になっている。このため、可視化エンジン VizShot オブジェクトの plot
メソッドに与えるオプションにそのまま追加すれば、GGraph::tone
等に渡される。
=== 各ファイルについての補足
==== app/views/analysis/_draw_tone_settings.rhtml
ユーザーは、tone/contourに関する指定は analysis の左下の
Draw メニュー内の Specific Settings サブメニューで行う。
本ファイルはその rhtml ソースである(このファイルは
Draw で Tone and Contour を指定した場合専用)。
==== app/models/analysis.rb
Analysis クラスを定義。このクラスは、解析・可視化に関する設定をため込
んで、 AnalysisController#draw に伝えるのが役目。models に入っているが、
対応するデータベーステーブルは存在しない。
==== app/controllers/analysis_controller.rb
analysis/ のコントローラー。可視化等の設定受付は index で、
可視化アクションは draw で行われる。
=== 変更内容の実際
==== app/controllers/analysis_controller.rb
次のうち :transpose --> "transpose" の変更はバグフィックス。
それ以外の部分が、最大値、最小値指定を追加するための変更。
(∴一部掲載を省略)
diff -u -r1.50 -r1.51
--- app/controllers/analysis_controller.rb 26 Oct 2006 12:14:34 -0000 1.50
+++ app/controllers/analysis_controller.rb 30 Oct 2006 15:16:43 -0000 1.51
@@ -333,10 +333,12 @@
else
options[:method] = :tone_cont
if analysis.x_axis > analysis.y_axis
- options[:transpose] = true
+ options["transpose"] = true
end
options[:tone] = analysis.draw_tone
options[:contour] = analysis.draw_contour
+ options["min"] = analysis.tone_min
+ options["max"] = analysis.tone_max
end
when "vector"
if vars.length != 2
ここでは、options[:method] = :tone_cont となってるところの下に追加する
ことで、tone and contour のオプション設定となる。
VizShot 固有のオプションはシンボルで、そうでなく GGraph
の可視化メソッドに引き継いでほしいオプションは文字列で指定する。
上では文字列で指定した "min", "max" が GGraph::tone,
GGraph::contour に渡される。
==== app/views/analysis/_draw_tone_settings.rhtml
diff -u -r1.1 -r1.2
--- app/views/analysis/_draw_tone_settings.rhtml 30 Sep 2006 05:59:21 -0000 1.1
+++ app/views/analysis/_draw_tone_settings.rhtml 30 Oct 2006 15:16:44 -0000 1.2
@@ -3,4 +3,10 @@
<%= check_box("analysis", "draw_contour") %>
+
+
+ <%= text_field("analysis", "tone_min", :size => 4) %>
+
+
+ <%= text_field("analysis", "tone_max", :size => 4) %>
==== app/models/analysis.rb
diff -u -r1.14 -r1.15
--- app/models/analysis.rb 8 Oct 2006 06:29:11 -0000 1.14
+++ app/models/analysis.rb 30 Oct 2006 15:16:44 -0000 1.15
@@ -42,6 +42,7 @@
attr_reader :draw_projection
attr_reader :draw_keep, :draw_size
attr_reader :draw_tone, :draw_contour
+ attr_reader :tone_min, :tone_max
attr_reader :function
@@ -81,6 +82,10 @@
self.draw_tone = v
when "draw_contour"
self.draw_contour = v
+ when "tone_min"
+ self.tone_min = v
+ when "tone_max"
+ self.tone_max = v
when "function"
self.function = v
end
@@ -237,6 +242,22 @@
end
end
+ def tone_min=(val)
+ if val==""
+ @tone_min = nil
+ else
+ @tone_min = val.to_f
+ end
+ end
+
+ def tone_max=(val)
+ if val==""
+ @tone_max = nil
+ else
+ @tone_max = val.to_f
+ end
+ end
+
def index
@index = Array.new
dims = @region
追記(2006/11/11):
* case文の削除により、attr_reader, when tone_* の部分は @@attrsの設定部を書き換えるようになった
* url_paramsメソッドの編集も必要
追記(2006/12/05):
図を再現するリンクをサポートするため、analysis_controller.rb の draw
メソッドに次の追加が必要になった。
@@ -305,6 +305,8 @@
if DRAW_TYPE[@draw_type] == "tone"
params.push "analysis[draw_tone]=#{@draw_tone ? 1 : 0}"
params.push "analysis[draw_contour]=#{@draw_contour ? 1 : 0}"
+ params.push "analysis[tone_min]=#{@tone_min}"
+ params.push "analysis[tone_max]=#{@tone_max}"
elsif DRAW_TYPE[@draw_type] == "vector"
@vector_variables_order.each{|k,v|
v.length.times{|i|
=end