Sha256: 6fc245ee42c7e6e4887b9abf8808b5394b00b3721cf924e614ff109167c76351

Contents?: true

Size: 917 Bytes

Versions: 6

Compression:

Stored size: 917 Bytes

Contents

# frozen_string_literal: true

# @private
module Gruff::Base::BarValueLabelMixin
  using String::GruffCommify

  # @private
  class BarValueLabel
    attr_accessor :coordinates, :values

    def initialize(size, bar_width)
      @coordinates = Array.new(size)
      @values = Hash.new(0)
      @bar_width = bar_width
    end

    def prepare_rendering(format)
      @coordinates.each_with_index do |(left_x, left_y, right_x, _right_y), index|
        value = @values[index]
        val = (format || '%.2f') % value
        y = value >= 0 ? left_y - 30 : left_y + 12
        yield left_x + (right_x - left_x) / 2, y, val.commify
      end
    end

    def prepare_sidebar_rendering(format)
      @coordinates.each_with_index do |(_left_x, _left_y, right_x, right_y), index|
        val = (format || '%.2f') % @values[index]
        yield right_x + 40, right_y - @bar_width / 2, val.commify
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gruff-0.12.2 lib/gruff/helper/bar_value_label_mixin.rb
gruff-0.12.2-java lib/gruff/helper/bar_value_label_mixin.rb
gruff-0.12.1 lib/gruff/helper/bar_value_label_mixin.rb
gruff-0.12.1-java lib/gruff/helper/bar_value_label_mixin.rb
gruff-0.12.0 lib/gruff/helper/bar_value_label_mixin.rb
gruff-0.12.0-java lib/gruff/helper/bar_value_label_mixin.rb