Skip to content

Commit

Permalink
Better code: Improve Squid::Graph#draw
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiob committed Aug 6, 2015
1 parent 63fe209 commit 1dee4dc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/squid/graph/grid.rb
Expand Up @@ -4,16 +4,22 @@ module Squid
# Adds all the gridlines and axis values to the graph.
class Grid < Base
def draw
y = bounds.top
data.each.with_index do |labels, index|
draw_gridline y unless index == data.size - 1
each_line do |y, labels, is_baseline|
draw_gridline y unless is_baseline
labels.each{|position, label| draw_label label, y, position}
y -= bounds.height / (data.size - 1)
end
end

private

def each_line
y = bounds.top
data.each.with_index do |labels, index|
yield y, labels, (index == data.size - 1)
y -= bounds.height / (data.size - 1)
end
end

def draw_gridline(y)
transparent(0.25) do
with(line_width: 0.5) do
Expand Down

0 comments on commit 1dee4dc

Please sign in to comment.