Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hide_labels attribute in Gruff::Dot #623

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/gruff/dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# g.write('dot.png')
#
class Gruff::Dot < Gruff::Base
# Prevent drawing of column labels below a stacked bar graph. Default is +false+.
attr_writer :hide_labels

def initialize(*)
super
@has_left_labels = true
Expand All @@ -22,6 +25,23 @@ def initialize(*)

private

def initialize_attributes
super
@hide_labels = false
end

def hide_labels?
@hide_labels
end

def hide_left_label_area?
hide_labels? && @y_axis_label.nil?
end

def hide_bottom_label_area?
@hide_line_markers && @x_axis_label.nil? && @legend_at_bottom == false
end

def draw_graph
# Setup spacing.
#
Expand Down
Binary file added test/expected/dot_no_labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/expected/dot_no_line_markers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/test_dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def test_dot_graph_small
assert_same_image('test/expected/dot_small.png', 'test/output/dot_small.png')
end

def test_no_labels
g = setup_basic_graph(400)
g.title = 'No Labels'
g.hide_labels = true
g.write('test/output/dot_no_labels.png')

assert_same_image('test/expected/dot_no_labels.png', 'test/output/dot_no_labels.png')
end

def test_no_line_markers
g = setup_basic_graph(400)
g.title = 'No Line Markers'
Expand Down