-
Notifications
You must be signed in to change notification settings - Fork 239
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 to stacked side bar graphs #452
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,6 +504,14 @@ def hide_labels? | |
@hide_line_markers | ||
end | ||
|
||
def hide_left_label_area? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes in base.rb are the same ones made in PR #450, which should make the PRs compatible for merging. |
||
@hide_line_markers | ||
end | ||
|
||
def hide_bottom_label_area? | ||
@hide_line_markers | ||
end | ||
|
||
## | ||
# Calculates size of drawable area, general font dimensions, etc. | ||
|
||
|
@@ -750,7 +758,7 @@ def sort_norm_data | |
private | ||
|
||
def setup_marker_caps_height | ||
hide_labels? ? 0 : calculate_caps_height(@marker_font_size) | ||
hide_bottom_label_area? ? 0 : calculate_caps_height(@marker_font_size) | ||
end | ||
|
||
def setup_title_caps_height | ||
|
@@ -773,7 +781,7 @@ def extra_room_for_long_label | |
end | ||
|
||
def setup_left_margin | ||
return @left_margin if @hide_line_markers | ||
return @left_margin if hide_left_label_area? | ||
|
||
if @has_left_labels | ||
longest_left_label_width = calculate_width(@marker_font_size, | ||
|
@@ -799,7 +807,7 @@ def setup_top_margin | |
end | ||
|
||
def setup_bottom_margin | ||
graph_bottom_margin = hide_labels? ? @bottom_margin : @bottom_margin + @marker_caps_height + LABEL_MARGIN | ||
graph_bottom_margin = hide_bottom_label_area? ? @bottom_margin : @bottom_margin + @marker_caps_height + LABEL_MARGIN | ||
|
||
x_axis_label_height = @x_axis_label.nil? ? 0.0 : @marker_caps_height + LABEL_MARGIN | ||
# FIXME: Consider chart types other than bar | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,85 +12,91 @@ def setup | |
#[:Philip, [90, 34, 23, 12, 78, 89, 98, 88]], | ||
#["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]], | ||
] | ||
@sample_labels = { | ||
@labels = { | ||
0 => '5/6', | ||
1 => '5/15', | ||
2 => '5/24' | ||
2 => '5/24', | ||
3 => '5/30' | ||
} | ||
@long_labels = { | ||
0 => 'September', | ||
1 => 'Oct', | ||
2 => 'Nov', | ||
3 => 'Dec' | ||
} | ||
end | ||
|
||
def test_bar_graph | ||
g = Gruff::SideStackedBar.new | ||
g = setup_basic_graph | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored tests to use the setup_basic_graph pattern. |
||
g.title = 'Visual Stacked Bar Graph Test' | ||
g.labels = { | ||
0 => '5/6', | ||
1 => '5/15', | ||
2 => '5/24', | ||
3 => '5/30' | ||
} | ||
@datasets.each do |data| | ||
g.data(data[0], data[1]) | ||
end | ||
g.write('test/output/side_stacked_bar_keynote.png') | ||
assert_same_image('test/expected/side_stacked_bar_keynote.png', 'test/output/side_stacked_bar_keynote.png') | ||
end | ||
|
||
def test_bar_graph_small | ||
g = Gruff::SideStackedBar.new(400) | ||
g = setup_basic_graph(400) | ||
g.title = 'Visual Stacked Bar Graph Test' | ||
g.labels = { | ||
0 => '5/6', | ||
1 => '5/15', | ||
2 => '5/24', | ||
3 => '5/30' | ||
} | ||
@datasets.each do |data| | ||
g.data(data[0], data[1]) | ||
end | ||
g.write('test/output/side_stacked_bar_keynote_small.png') | ||
assert_same_image('test/expected/side_stacked_bar_keynote_small.png', 'test/output/side_stacked_bar_keynote_small.png') | ||
end | ||
|
||
def test_wide | ||
@labels = { | ||
0 => '5/6', | ||
1 => '5/15', | ||
2 => '5/24' | ||
} | ||
g = setup_basic_graph('800x400') | ||
g.title = 'Wide SSBar' | ||
g.write('test/output/side_stacked_bar_wide.png') | ||
assert_same_image('test/expected/side_stacked_bar_wide.png', 'test/output/side_stacked_bar_wide.png') | ||
end | ||
|
||
def test_should_space_long_left_labels_appropriately | ||
g = Gruff::SideStackedBar.new | ||
@labels = @long_labels | ||
g = setup_basic_graph | ||
g.title = 'Stacked Bar Long Label' | ||
g.labels = { | ||
0 => 'September', | ||
1 => 'Oct', | ||
2 => 'Nov', | ||
3 => 'Dec' | ||
} | ||
@datasets.each do |data| | ||
g.data(data[0], data[1]) | ||
end | ||
g.write('test/output/side_stacked_bar_long_label.png') | ||
assert_same_image('test/expected/side_stacked_bar_long_label.png', 'test/output/side_stacked_bar_long_label.png') | ||
end | ||
|
||
def test_bar_labels | ||
g = Gruff::SideStackedBar.new | ||
@labels = @long_labels | ||
g = setup_basic_graph | ||
g.title = 'Stacked Bar Long Label' | ||
g.labels = { | ||
0 => 'September', | ||
1 => 'Oct', | ||
2 => 'Nov', | ||
3 => 'Dec' | ||
} | ||
@datasets.each do |data| | ||
g.data(data[0], data[1]) | ||
end | ||
g.show_labels_for_bar_values = true | ||
g.write('test/output/side_stacked_bar_labels.png') | ||
assert_same_image('test/expected/side_stacked_bar_labels.png', 'test/output/side_stacked_bar_labels.png') | ||
end | ||
|
||
def test_no_labels | ||
@labels = @long_labels | ||
g = setup_basic_graph(400) | ||
g.title = 'No Labels' | ||
g.hide_labels = true | ||
g.write('test/output/side_stacked_bar_no_labels.png') | ||
assert_same_image('test/expected/side_stacked_bar_no_labels.png', 'test/output/side_stacked_bar_no_labels.png') | ||
end | ||
|
||
def test_no_line_markers_or_labels | ||
@labels = @long_labels | ||
g = setup_basic_graph(400) | ||
g.title = 'No Line Markers or Labels' | ||
g.hide_labels = true | ||
g.hide_line_markers = true | ||
g.write('test/output/side_stacked_bar_no_line_markers_or_labels.png') | ||
assert_same_image('test/expected/side_stacked_bar_no_line_markers_or_labels.png', 'test/output/side_stacked_bar_no_line_markers_or_labels.png') | ||
end | ||
|
||
def test_no_line_markers | ||
@labels = @long_labels | ||
g = setup_basic_graph(400) | ||
g.title = 'No Line Markers' | ||
g.hide_line_markers = true | ||
g.write('test/output/side_stacked_bar_no_line_markers.png') | ||
assert_same_image('test/expected/side_stacked_bar_no_line_markers.png', 'test/output/side_stacked_bar_no_line_markers.png') | ||
end | ||
|
||
def test_draw_twice | ||
g = setup_basic_graph | ||
g.show_labels_for_bar_values = true | ||
|
@@ -105,7 +111,7 @@ def test_draw_twice | |
def setup_basic_graph(size = 800) | ||
g = Gruff::SideStackedBar.new(size) | ||
g.title = 'My Graph Title' | ||
g.labels = @sample_labels | ||
g.labels = @labels | ||
@datasets.each do |data| | ||
g.data(data[0], data[1]) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in bar.rb are the same ones made in PR #450, which should make the PRs compatible for merging.