Sha256: b3fa92b39de8c171e3b65da04c082bd1f078ba8faac27cda9e9963eeef4b6b7c
Contents?: true
Size: 882 Bytes
Versions: 3
Compression:
Stored size: 882 Bytes
Contents
require "subtle/dominikh/graph" module Dominikh class Bar < Graph attr_reader :value def initialize(width, height, orientation = :vertical) super(width, height) @orientation = orientation @value = 0 end # @return The value def value=(val) val = 100 if val > 100 @value = val render @value end # @return [void] def render super if @orientation == :vertical top = ((height / 100.0) * value).round 0.upto(width) do |x| height.downto(height - top) do |y| draw(x, y) end end elsif @orientation == :horizontal right = ((width / 100.0) * value).round 0.upto(height) do |y| 0.upto(right) do |x| draw(x, y) end end else # TODO raise end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
subtle-graph-0.0.3 | lib/subtle/dominikh/graph/bar.rb |
subtle-graph-0.0.2 | lib/subtle/dominikh/graph/bar.rb |
subtle-graph-0.0.1 | lib/subtle/dominikh/graph/bar.rb |