Sha256: 56f419ff81e04b5d877f31bbd22f8bac7b9114674f7316defc50fbf826462890

Contents?: true

Size: 984 Bytes

Versions: 6

Compression:

Stored size: 984 Bytes

Contents

# frozen_string_literal: true

module Gruff
  class Renderer::Dot
    def initialize(style, config)
      @style = style
      @color = config[:color]
      @width = config[:width] || 1.0
    end

    def render(new_x, new_y, circle_radius)
      draw = Renderer.instance.draw

      # draw.push # TODO
      draw.stroke_width(@width)
      draw.stroke(@color)
      draw.fill(@color)
      if @style.to_s == 'square'
        square(draw, new_x, new_y, circle_radius)
      else
        circle(draw, new_x, new_y, circle_radius)
      end
      # draw.pop # TODO
    end

    def circle(draw, new_x, new_y, circle_radius)
      draw.circle(new_x, new_y, new_x - circle_radius, new_y)
    end

    def square(draw, new_x, new_y, circle_radius)
      offset = (circle_radius * 0.8).to_i
      corner1 = new_x - offset
      corner2 = new_y - offset
      corner3 = new_x + offset
      corner4 = new_y + offset
      draw.rectangle(corner1, corner2, corner3, corner4)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gruff-0.11.0 lib/gruff/renderer/dot.rb
gruff-0.11.0-java lib/gruff/renderer/dot.rb
gruff-0.10.0 lib/gruff/renderer/dot.rb
gruff-0.10.0-java lib/gruff/renderer/dot.rb
gruff-0.9.0 lib/gruff/renderer/dot.rb
gruff-0.9.0-java lib/gruff/renderer/dot.rb