lib/gruff/base.rb
# Return a formatted string representing a number value that should be
# printed as a label.
Return a formatted string representing a number value that should be
printed as a label.
Return a formatted string representing a number value that should be printed as a label .
def label(value, increment)
      label = begin
        if increment
          if increment >= 10 || (increment * 1) == (increment * 1).to_i.to_f
            sprintf('%0i', value)
          elsif increment >= 1.0 || (increment * 10) == (increment * 10).to_i.to_f
            sprintf('%0.1f', value)
          elsif increment >= 0.1 || (increment * 100) == (increment * 100).to_i.to_f
            sprintf('%0.2f', value)
          elsif increment >= 0.01 || (increment * 1000) == (increment * 1000).to_i.to_f
            sprintf('%0.3f', value)
          elsif increment >= 0.001 || (increment * 10000) == (increment * 10000).to_i.to_f
            sprintf('%0.4f', value)
          else
            value.to_s
          end
        elsif (@spread.to_f % (marker_count.to_f == 0 ? 1 : marker_count.to_f) == 0) || !@y_axis_increment.nil?
          value.to_i.to_s
        elsif @spread > 10.0
          sprintf('%0i', value)
        elsif @spread >= 3.0
          sprintf('%0.2f', value)
        else
          value.to_s
        end
      end
      parts = label.split('.')
      parts[0] = parts[0].commify
      parts.join('.')
    end
def label ( value , increment ) label = begin if increment if increment >= 10 || ( increment * 1 ) == ( increment * 1 ) . to_i . to_f sprintf ( '%0i' , value ) elsif increment >= 1.0 || ( increment * 10 ) == ( increment * 10 ) . to_i . to_f sprintf ( '%0.1f' , value ) elsif increment >= 0.1 || ( increment * 100 ) == ( increment * 100 ) . to_i . to_f sprintf ( '%0.2f' , value ) elsif increment >= 0.01 || ( increment * 1000 ) == ( increment * 1000 ) . to_i . to_f sprintf ( '%0.3f' , value ) elsif increment >= 0.001 || ( increment * 10000 ) == ( increment * 10000 ) . to_i . to_f sprintf ( '%0.4f' , value ) else value . to_s end elsif ( @spread . to_f % ( marker_count . to_f == 0 ? 1 : marker_count . to_f ) == 0 ) || ! @y_axis_increment . nil? value . to_i . to_s elsif @spread > 10.0 sprintf ( '%0i' , value ) elsif @spread >= 3.0 sprintf ( '%0.2f' , value ) else value . to_s end end parts = label . split ( '.' ) parts [ 0 ] = parts [ 0 ] . commify parts . join ( '.' ) end
Return a formatted string representing a number value that should be
printed as a label.
Return a formatted string representing a number value that should be printed as a label .
value
<not_specific>
increment
<not_specific>