module UnicodePlot::Utils
Constants
- INT64_MAX
- INT64_MIN
Public Instance Methods
ceil_neg_log10(x)
click to toggle source
# File lib/unicode_plot/utils.rb, line 59 def ceil_neg_log10(x) if roundable?(-Math.log10(x)) (-Math.log10(x)).ceil else (-Math.log10(x)).floor end end
extend_limits(values, limits)
click to toggle source
# File lib/unicode_plot/utils.rb, line 5 def extend_limits(values, limits) mi, ma = limits.minmax.map(&:to_f) if mi == 0 && ma == 0 mi, ma = values.minmax.map(&:to_f) end diff = ma - mi if diff == 0 ma = mi + 1 mi = mi - 1 end if limits == [0, 0] plotting_range_narrow(mi, ma) else [mi, ma] end end
float_round_log10(x, m)
click to toggle source
# File lib/unicode_plot/utils.rb, line 29 def float_round_log10(x, m) if x == 0 0.0 elsif x > 0 x.round(ceil_neg_log10(m) + 1).to_f else -(-x).round(ceil_neg_log10(m) + 1).to_f end end
plotting_range_narrow(xmin, xmax)
click to toggle source
# File lib/unicode_plot/utils.rb, line 22 def plotting_range_narrow(xmin, xmax) diff = xmax - xmin xmax = round_up_subtick(xmax, diff) xmin = round_down_subtick(xmin, diff) [xmin.to_f, xmax.to_f] end
round_down_subtick(x, m)
click to toggle source
# File lib/unicode_plot/utils.rb, line 49 def round_down_subtick(x, m) if x == 0 0.0 elsif x > 0 x.floor(ceil_neg_log10(m) + 1) else -(-x).ceil(ceil_neg_log10(m) + 1) end end
round_up_subtick(x, m)
click to toggle source
# File lib/unicode_plot/utils.rb, line 39 def round_up_subtick(x, m) if x == 0 0.0 elsif x > 0 x.ceil(ceil_neg_log10(m) + 1) else -(-x).floor(ceil_neg_log10(m) + 1) end end
roundable?(x)
click to toggle source
# File lib/unicode_plot/utils.rb, line 70 def roundable?(x) x.to_i == x && INT64_MIN <= x && x < INT64_MAX end