OSDN Git Service

refs #1577 集計機能: 期間別集計でグラフが表示されない不具合を修正
authorYOSHIDA Hiroki <hyoshida@appirits.com>
Mon, 20 May 2013 02:58:46 +0000 (11:58 +0900)
committerYOSHIDA Hiroki <hyoshida@appirits.com>
Mon, 20 May 2013 03:00:49 +0000 (12:00 +0900)
config/initializers/gruff_ruby1.9_patch.rb [new file with mode: 0644]

diff --git a/config/initializers/gruff_ruby1.9_patch.rb b/config/initializers/gruff_ruby1.9_patch.rb
new file mode 100644 (file)
index 0000000..c557af2
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Ruby 1.9 + gruff-0.3.6 環境での『ZeroDivisionError: divided by 0』エラー対策
+
+require 'gruff'
+
+module Gruff
+  class Base
+    alias :label_org :label
+
+    # HACK: もとメソッドの下記コードにおいて @marker_count が nil or 0 のとき例外が発生するので、
+    #       この条件が揃わないように小細工
+    #   label = if (@spread.to_f % @marker_count.to_f == 0) || !@y_axis_increment.nil?
+    def label(value)
+      marker_count_org = @marker_count
+      # 左辺+1を右辺にすることで必ず 0 以外が返る
+      @marker_count = @spread.to_f + 1 if @marker_count.to_f.zero?
+      result = label_org(value)
+      @marker_count = marker_count_org
+      result
+    end
+  end
+end