module TbdHelper

  def percentage_jauge(percent, ratio = 1.0, good=100.0, success="success",primary="primary" )
    raw('<br>
  <div class="left-percentage">
    '+number_to_percentage(percent, :precision => (percent < 10.0 ? 1 : 0))+'
  </div>
  <div class="inline-block">
    <div class="progress" style="width:100px;">
      <div aria-valuemax="50" aria-valuemin="0" aria-valuenow="'+percent.to_s+'" class="progress-bar bg-'+(percent > good ? "#{success}" : "#{primary}")+'-dark" role="progressbar" style="width: '+(percent*ratio).round(2).to_s+'%;"></div>
    </div>
  </div>
  <div class="clear"></div>

')
  end
  
  
  def color_scale(value, ref, ecart, minus= "red", max="#28a745")
    if value.to_f >= (ref.to_f + ecart.to_f)
      raw("<span style='font-weight:bold;color:#{max};'>#{value}</span>")
    elsif value.to_f <= (ref.to_f - ecart.to_f)
      raw("<span style='font-weight:bold;color:#{minus};'>#{value}</span>")
    else
      value.to_s
    end
  end

end
