plugins/resource_management/app/helpers/resource_management/resource_bar_helper.rb
# This prepares a list of all the progress bars that we're placing in the
# resource bar (i.e. all the <div class="progress-bar">).
This prepares a list of all the progress bars that we're placing in the
resource bar .
This prepares a list of all the progress bars that we ' re placing in the resource bar .
def resbar_compile_bars(fill, maximum, threshold, warning_level, danger_level, marker)
      bars = []
      if fill[:value] > 0
        fill_level = fill[:value].to_f / [ threshold[:value], maximum[:value] ].select { |x| x > 0 }.min.to_f
        bar_type   = fill_level >= danger_level  ? 'danger'
                   : fill_level >= warning_level ? 'warning' : 'default'
        if threshold[:value] >= 0
          percent = [ fill[:percent], threshold[:percent] ].min
        else
          percent = fill[:percent]
        end
        bars << { type: bar_type, percent: percent } 
        if fill[:value] > threshold[:value]
          bars << { type: 'danger-overcommit', percent: fill[:percent] - threshold[:percent] }
        end
      end
      if maximum[:value] > 0
        if threshold[:value] < maximum[:value]
          if fill[:value] >= threshold[:value]
            bars << { type: 'empty-overcommit', percent:                 100 - fill[:percent] }
          else
            bars << { type: 'empty',            percent: threshold[:percent] - fill[:percent] }
            bars << { type: 'empty-overcommit', percent: 100 - threshold[:percent] }
          end
        else
          bars << { type: 'empty', percent: 100 - fill[:percent] }
        end
      else
        bars << { type: 'empty-overcommit', percent: 100 - fill[:percent] }
      end
      bars = bars.reject { |bar| bar[:percent] <= 0 }
      required_size_for_label = 1.5 * fill[:label].size
      bar_for_label = bars.find { |bar| bar[:percent] > required_size_for_label }
      bar_for_label[:label] = fill[:label]
      bars.pop if bars.last[:type] == 'empty' and not bars.last.has_key?(:label)
      bars.last[:percent] -= 0.1 if bars.map { |bar| bar[:percent] }.sum > 99.99
      return bars
    end
def resbar_compile_bars ( fill , maximum , threshold , warning_level , danger_level , marker ) bars = [ ] if fill [ :value ] > 0 fill_level = fill [ :value ] . to_f / [ threshold [ :value ] , maximum [ :value ] ] . select { | x | x > 0 } . min . to_f bar_type = fill_level >= danger_level ? 'danger' : fill_level >= warning_level ? 'warning' : 'default' if threshold [ :value ] >= 0 percent = [ fill [ :percent ] , threshold [ :percent ] ] . min else percent = fill [ :percent ] end bars << { type : bar_type , percent : percent } if fill [ :value ] > threshold [ :value ] bars << { type : 'danger-overcommit' , percent : fill [ :percent ] - threshold [ :percent ] } end end if maximum [ :value ] > 0 if threshold [ :value ] < maximum [ :value ] if fill [ :value ] >= threshold [ :value ] bars << { type : 'empty-overcommit' , percent : 100 - fill [ :percent ] } else bars << { type : 'empty' , percent : threshold [ :percent ] - fill [ :percent ] } bars << { type : 'empty-overcommit' , percent : 100 - threshold [ :percent ] } end else bars << { type : 'empty' , percent : 100 - fill [ :percent ] } end else bars << { type : 'empty-overcommit' , percent : 100 - fill [ :percent ] } end bars = bars . reject { | bar | bar [ :percent ] <= 0 } required_size_for_label = 1.5 * fill [ :label ] . size bar_for_label = bars . find { | bar | bar [ :percent ] > required_size_for_label } bar_for_label [ :label ] = fill [ :label ] bars . pop if bars . last [ :type ] == 'empty' and not bars . last . has_key? ( :label ) bars . last [ :percent ] -= 0.1 if bars . map { | bar | bar [ :percent ] } . sum > 99.99 return bars end
This prepares a list of all the progress bars that we're placing in the
resource bar (i.e.
This prepares a list of all the progress bars that we ' re placing in the resource bar ( i . e .
# render normal bar # the normal bar may not exceed the threshold mark # label will be added at the end # mark the filled part beyond the threshold as "overcommit" # for finite maximum, mark empty area beyond the threshold as "overcommit" # for infinite maximum, mark all empty area as "overcommit" # remove all bars with fixed width that was calculated to be non-positive # place the fill label on the first bar that is not small # remove unused trailing spacer # if all the bars add up to 100%, make the last one ever so slightly # slimmer to avoid a line break (which might occur if there are rounding # errors in the browser's rendering engine)
fill
<not_specific>
maximum
<not_specific>
threshold
<not_specific>
warning_level
<not_specific>
danger_level
<not_specific>
marker
<not_specific>