class Spyro::ActionViewExtension::CollectionForHelper::Output::BarGraphTable

Public Class Methods

new(unicollection, helper, parser_class) click to toggle source
# File lib/spyro/collections/outputs/bar_graph_table.rb, line 10
def initialize unicollection, helper, parser_class
  super unicollection, helper, parser_class
end

Public Instance Methods

build_popover(title, popovers) click to toggle source
# File lib/spyro/collections/outputs/bar_graph_table.rb, line 21
def build_popover title, popovers
  "class='has-popover' data-title='#{title}' data-html='true' data-content='#{popovers.map {|elem| elem.join(': ')}.join('<br/>')}'"
end
format_prct(value) click to toggle source
# File lib/spyro/collections/outputs/bar_graph_table.rb, line 14
def format_prct value
  @min ||=  @unicollection.meta[:min] || 0
  @max ||= @unicollection.meta[:max] || 100

  [[(value - @min) * 100 / (@max - @min), 0].max, 100].min
end
render() click to toggle source
# File lib/spyro/collections/outputs/bar_graph_table.rb, line 25
def render
  html = @unicollection.rows.map do |row|
    html_row = row[:'data'].map do |elem|
      @unicollection.meta[:'data-primary'].include?(elem.name.to_sym) ? elem.value : nil
    end.compact

    popovers = row[:'data'].map do |elem|
      @unicollection.meta[:'data-secondary'].include?(elem.name.to_sym) ? elem.value : nil
    end.compact

    title = html_row.first
    value = html_row.last
    span = "<span style='position: absolute; left: 10px; color: black'>#{html_row[0..-2].join ' - '}</span><span style='position: absolute; right: 10px; color: black'>#{value}</span>"
    "<li #{build_popover(title, @unicollection.meta[:'data-secondary'].zip(popovers))}><div class='progress progress-info' style='position: relative'><div class='progress-bar' style='width: #{self.format_prct(value)}%'>#{span}</div></div></li>".html_safe
  end.join('')
  "<ul class='list-unstyled'>#{html}</ul>".html_safe
end